[GRASS-SVN] r42874 - grass/branches/releasebranch_6_4/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Jul 21 16:44:51 EDT 2010


Author: martinl
Date: 2010-07-21 20:44:51 +0000 (Wed, 21 Jul 2010)
New Revision: 42874

Modified:
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/mapdisp.py
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/nviz.py
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/toolbars.py
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/vdigit.py
   grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/wxgui_utils.py
Log:
fix #628 (wingrass native: vdigit error on new map)


Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/mapdisp.py	2010-07-21 19:16:16 UTC (rev 42873)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/mapdisp.py	2010-07-21 20:44:51 UTC (rev 42874)
@@ -2766,21 +2766,26 @@
             from vdigit import haveVDigit
             if not haveVDigit:
                 from vdigit import errorMsg
-                msg = _("Unable to start vector digitizer.\nThe VDigit python extension "
-                        "was not found or loaded properly.\n"
-                        "Switching back to 2D display mode.\n\nDetails: %s" % errorMsg)
+                msg = _("Unable to start wxGUI vector digitizer.\nDo you want to start "
+                        "TCL/TK digitizer (v.digit) instead?\n\n"
+                        "Details: %s" % errorMsg)
                 
                 self.toolbars['map'].combo.SetValue (_("2D view"))
-                wx.MessageBox(parent=self,
-                              message=msg,
-                              caption=_("Error"),
-                              style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
+                dlg = wx.MessageDialog(parent = self,
+                                       message = msg,
+                                       caption=_("Vector digitizer failed"),
+                                       style = wx.YES_NO | wx.CENTRE)
+                if dlg.ShowModal() == wx.ID_YES:
+                    mapName = self.tree.GetPyData(self.tree.layer_selected)[0]['maplayer'].name
+                    self.gismanager.goutput.RunCmd(['v.digit', 'map=%s' % mapName],
+                                                   switchPage=False)
+                dlg.Destroy()
                 return
             
             self.toolbars['vdigit'] = toolbars.VDigitToolbar(parent=self, map=self.Map,
                                                              layerTree=self.tree,
                                                              log=self.gismanager.goutput)
-
+            
             for toolRow in range(0, self.toolbars['vdigit'].numOfRows):
                 self._mgr.AddPane(self.toolbars['vdigit'].toolbar[toolRow],
                                   wx.aui.AuiPaneInfo().
@@ -2790,12 +2795,13 @@
                                   BottomDockable(False).TopDockable(True).
                                   CloseButton(False).Layer(2).
                                   BestSize((self.toolbars['vdigit'].GetToolbar().GetSize())))
-	
+            
             # change mouse to draw digitized line
             self.MapWindow.mouse['box'] = "point"
             self.MapWindow.zoomtype = 0
             self.MapWindow.pen     = wx.Pen(colour='red',   width=2, style=wx.SOLID)
             self.MapWindow.polypen = wx.Pen(colour='green', width=2, style=wx.SOLID)
+        
         # georectifier
         elif name == "georect":
             self.toolbars['georect'] = toolbars.GRToolbar(self, self.Map)
@@ -2810,27 +2816,18 @@
         # nviz
         elif name == "nviz":
             import nviz
-
+            
             # check for GLCanvas and OpenGL
-            msg = None
-            if not nviz.haveGLCanvas:
-                msg = _("Unable to switch to 3D display mode.\nThe GLCanvas class has not been "
-                        "included with this build "
-                        "of wxPython!\nSwitching back to "
-                        "2D display mode.\n\nDetails: %s" % nviz.errorMsg)
             if not nviz.haveNviz:
-                msg = _("Unable to switch to 3D display mode.\nThe Nviz python extension "
-                        "was not found or loaded properly.\n"
-                        "Switching back to 2D display mode.\n\nDetails: %s" % nviz.errorMsg)
-
-            if msg:
-                self.toolbars['map'].combo.SetValue (_("2D view"))
                 wx.MessageBox(parent=self,
-                              message=msg,
+                              message = _("Unable to switch to 3D display mode.\nThe Nviz python extension "
+                                          "was not found or loaded properly.\n"
+                                          "Switching back to 2D display mode.\n\nDetails: %s" % nviz.errorMsg),
                               caption=_("Error"),
                               style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
+                self.toolbars['map'].combo.SetValue (_("2D view"))
                 return
-
+            
             #
             # add Nviz toolbar and disable 2D display mode tools
             #

Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/nviz.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/nviz.py	2010-07-21 19:16:16 UTC (rev 42873)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/nviz.py	2010-07-21 20:44:51 UTC (rev 42874)
@@ -23,22 +23,21 @@
 import sys
 
 import wx
-try:
-    from wx import glcanvas
-    haveGLCanvas = True
-except ImportError, e:
-    haveGLCanvas = False
-    errorMsg = e
-
 import globalvar
 try:
+    from wx import glcanvas
     import nviz_mapdisp
     import nviz_tools
+    sys.path.append(os.path.join(globalvar.ETCWXDIR, "nviz"))
+    import grass6_wxnviz as wxnviz
     haveNviz = True
 except ImportError, e:
     haveNviz = False
-    errorMsg = e
-    print >> sys.stderr, "\nWARNING: Nviz extension (3D view) is not available (%s). " % e
+    errorMsg = _("3D view mode is not available.\n"
+                 "Reason: %s\n"
+                 "Note that the 3D view mode is currently not working under\nMS Windows "
+                 "(hopefully this will be fixed soon). "
+                 "Please keep\nan eye out for updated versions of GRASS." % e)
 
 if haveNviz:
     GLWindow = nviz_mapdisp.GLWindow

Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/toolbars.py	2010-07-21 19:16:16 UTC (rev 42873)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/toolbars.py	2010-07-21 20:44:51 UTC (rev 42874)
@@ -30,10 +30,11 @@
 import grassenv
 import gdialogs
 import vdigit
-from vdigit import VDigitSettingsDialog as VDigitSettingsDialog
-from debug import Debug as Debug
-from icon import Icons as Icons
+from vdigit import VDigitSettingsDialog, haveVDigit
+from debug import Debug
+from icon import Icons
 from preferences import globalSettings as UserSettings
+from nviz import haveNviz
 
 gmpath = os.path.join(globalvar.ETCWXDIR, "icons")
 sys.path.append(gmpath)
@@ -159,8 +160,29 @@
         self.InitToolbar(self.mapdisplay, self.toolbar, self.ToolbarData())
         
         # optional tools
+        choices = [ _('2D view'), ]
+        self.toolId = { '2d' : 0 }
+        log = self.parent.gismanager.goutput
+        if haveNviz:
+            choices.append(_('3D view'))
+            self.toolId['3d'] = 1
+        else:
+            from nviz import errorMsg 
+            log.WriteWarning(errorMsg)
+            self.toolId['3d'] = -1
+        if haveVDigit:
+            choices.append(_('Digitize'))
+            if self.toolId['3d'] > -1:
+                self.toolId['vdigit'] = 2
+            else:
+                self.toolId['vdigit'] = 1
+        else:
+            from vdigit import errorMsg 
+            log.WriteWarning(errorMsg)
+            self.toolId['vdigit'] = -1
+        
         self.combo = wx.ComboBox(parent=self.toolbar, id=wx.ID_ANY, value=_('2D view'),
-                                 choices=[_('2D view'), _('3D view'), _('Digitize')],
+                                 choices=choices,
                                  style=wx.CB_READONLY, size=(90, -1))
         
         self.comboid = self.toolbar.AddControl(self.combo)
@@ -257,15 +279,17 @@
         """
         tool =  event.GetSelection()
         
-        if tool == 0:
+        if tool == self.toolId['2d']:
             self.ExitToolbars()
             self.Enable2D(True)
 
-        elif tool == 1 and not self.mapdisplay.toolbars['nviz']:
+        elif tool == self.toolId['3d'] and \
+                not self.mapdisplay.toolbars['nviz']:
             self.ExitToolbars()
             self.mapdisplay.AddToolbar("nviz")
             
-        elif tool == 2 and not self.mapdisplay.toolbars['vdigit']:
+        elif tool == self.toolId['vdigit'] and \
+                not self.mapdisplay.toolbars['vdigit']:
             self.ExitToolbars()
             self.mapdisplay.AddToolbar("vdigit")
 

Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/vdigit.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/vdigit.py	2010-07-21 19:16:16 UTC (rev 42873)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/vdigit.py	2010-07-21 20:44:51 UTC (rev 42874)
@@ -56,14 +56,12 @@
 except ImportError, err:
     haveVDigit = False
     GV_LINES = None
-    PseudoDC = None
-    errorMsg = err
-    # is there a way to have this display on the terminal before the wx gui exits?
-    print >> sys.stderr, "\nWARNING: Vector digitizer is not available (%s).\n\n" \
-        "Note that the vector digitizer is currently not working under MS Windows\n" \
-        "(hopefully this will be fixed soon).\n" \
-        "Please keep an eye out for updated versions of GRASS." % err
-    sys.stderr.flush()
+    PseudoDC = wx.PseudoDC
+    errorMsg = _("Vector digitizer is not available.\n"
+                 "Reason: %s\n"
+                 "Note that the vector digitizer is currently not working under\nMS Windows "
+                 "(hopefully this will be fixed soon). "
+                 "Please keep\nan eye out for updated versions of GRASS." % err)
     
 class AbstractDigit:
     """

Modified: grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/wxgui_utils.py
===================================================================
--- grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/wxgui_utils.py	2010-07-21 19:16:16 UTC (rev 42873)
+++ grass/branches/releasebranch_6_4/gui/wxpython/gui_modules/wxgui_utils.py	2010-07-21 20:44:51 UTC (rev 42874)
@@ -511,33 +511,19 @@
         """
         Start editing vector map layer requested by the user
         """
-        if not haveVDigit:
-            from vdigit import errorMsg
-            msg = _("Unable to start vector digitizer.\nThe VDigit python extension "
-                    "was not found or loaded properly.\n"
-                    "Switching back to 2D display mode.\n\nDetails: %s" % errorMsg)
-            
-            self.mapdisplay.toolbars['map'].combo.SetValue (_("2D view"))
-            wx.MessageBox(parent=self.mapdisplay,
-                          message=msg,
-                          caption=_("Error"),
-                          style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
-            return
-        
         try:
             maplayer = self.GetPyData(self.layer_selected)[0]['maplayer']
         except:
             event.Skip()
             return
-
+        
         if not self.mapdisplay.toolbars['vdigit']: # enable tool
             self.mapdisplay.AddToolbar('vdigit')
-        else: # tool already enabled
-            pass
-
+        
         # mark layer as 'edited'
-        self.mapdisplay.toolbars['vdigit'].StartEditing (maplayer)
-
+        if self.mapdisplay.toolbars['vdigit']:
+            self.mapdisplay.toolbars['vdigit'].StartEditing(maplayer)
+        
     def OnStopEditing(self, event):
         """
         Stop editing the current vector map layer



More information about the grass-commit mailing list