Procházet zdrojové kódy

wxGUI: clean up vdigit/nviz error messages
(merge https://trac.osgeo.org/grass/changeset/42878 from devbr6)


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@42880 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa před 14 roky
rodič
revize
7174f85eb1

+ 13 - 7
gui/wxpython/gui_modules/mapdisp.py

@@ -326,15 +326,21 @@ class MapFrame(wx.Frame):
             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.mapdisplay.toolbars['map'].combo.SetValue (_("2D view"))
+                dlg = wx.MessageDialog(parent = self.mapdisplay,
+                                       message = msg,
+                                       caption=_("Vector digitizer failed"),
+                                       style = wx.YES_NO | wx.CENTRE)
+                if dlg.ShowModal() == wx.ID_YES:
+                    self.lmgr.goutput.RunCmd(['v.digit', 'map=%s' % maplayer.GetName()],
+                                             switchPage=False)
+                dlg.Destroy()
                 
                 self.toolbars['map'].combo.SetValue (_("2D view"))
-                wx.MessageBox(parent=self,
-                              message=msg,
-                              caption=_("Error"),
-                              style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
                 return
             
             if self._layerManager:

+ 4 - 7
gui/wxpython/gui_modules/nviz.py

@@ -1,4 +1,4 @@
-"""
+"""!
 @package nviz.py
 
 @brief Nviz (3D view) module
@@ -29,13 +29,10 @@ try:
     import nviz_mapdisp
     import nviz_tools
     haveNviz = True
-except ImportError, e:
+except ImportError, err:
     haveNviz = False
-    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)
+    errorMsg = err
+
 if haveNviz:
     GLWindow = nviz_mapdisp.GLWindow
     NvizToolWindow = nviz_tools.NvizToolWindow

+ 33 - 11
gui/wxpython/gui_modules/toolbars.py

@@ -178,22 +178,43 @@ class MapToolbar(AbstractToolbar):
         self.InitToolbar(self.ToolbarData())
         
         # optional tools
-        choices = [_('2D view')]
-        lmgr = self.parent.GetLayerManager()
+        choices = [ _('2D view'), ]
+        self.toolId = { '2d' : 0 }
+        log = self.parent.GetLayerManager().GetLogWindow()
         if haveNviz:
             choices.append(_('3D view'))
+            self.toolId['3d'] = 1
         else:
-            from nviz import errorMsg
-            lmgr.goutput.WriteWarning(errorMsg)
+            from nviz import errorMsg as errorMsg1
+            from wxnviz import errorMsg as errorMsg2
+            if errorMsg2:
+                errorMsg = str(errorMsg1) + ' (' + str(errorMsg2) + ')'
+            log.WriteCmdLog(_('3D view mode not available'))
+            log.WriteWarning(_('Reason: %s') % errorMsg)
+            log.WriteLog(_('Note that the 3D view mode is currently not working under MS Windows '
+                           '(hopefully this will be fixed soon). '
+                           'Please keep an eye out for updated versions of GRASS.'), wrap = 60)
+            
+            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
-            lmgr.goutput.WriteWarning(errorMsg)
+            log.WriteCmdLog(_('Vector digitizer not available'))
+            log.WriteWarning(_('Reason: %s') % errorMsg)
+            log.WriteLog(_('Note that the vector digitizer is currently not working under MS Windows '
+                           '(hopefully this will be fixed soon). '
+                           'Please keep an eye out for updated versions of GRASS.'), wrap = 60)
+            
+            self.toolId['vdigit'] = -1
         
         self.combo = wx.ComboBox(parent = self, id = wx.ID_ANY,
                                  choices = choices,
-                                 style=wx.CB_READONLY, size=(90, -1))
+                                 style = wx.CB_READONLY, size = (90, -1))
         self.combo.SetSelection(0)
         
         self.comboid = self.AddControl(self.combo)
@@ -289,20 +310,21 @@ class MapToolbar(AbstractToolbar):
             )
     
     def OnSelectTool(self, event):
-        """!
-        Select / enable tool available in tools list
+        """!Select / enable tool available in tools list
         """
         tool =  event.GetSelection()
         
-        if tool == 0:
+        if tool == self.toolId['2d']:
             self.ExitToolbars()
             self.Enable2D(True)
         
-        elif tool == 1 and not self.parent.toolbars['nviz']:
+        elif tool == self.toolId['3d'] and \
+                not self.parent.toolbars['nviz']:
             self.ExitToolbars()
             self.parent.AddToolbar("nviz")
             
-        elif tool == 2 and not self.parent.toolbars['vdigit']:
+        elif tool == self.toolId['vdigit'] and \
+                not self.parent.toolbars['vdigit']:
             self.ExitToolbars()
             self.parent.AddToolbar("vdigit")
             self.parent.MapWindow.SetFocus()

+ 1 - 5
gui/wxpython/gui_modules/vdigit.py

@@ -54,11 +54,7 @@ except ImportError, err:
     haveVDigit = False
     GV_LINES = None
     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)
+    errorMsg = err
     
 class AbstractDigit:
     """!Abstract digitization class

+ 3 - 3
gui/wxpython/gui_modules/wxnviz.py

@@ -26,9 +26,9 @@ try:
     from grass.lib.grass import *
     from grass.lib.ogsf  import *
     from grass.lib.nviz  import *
-except ImportError, e:
-    print >> sys.stderr, "\nWARNING: Nviz extension (3D view mode) disabled. Reason: %s" % e
-    sys.stderr.flush()
+    errorMsg = ''
+except ImportError, err:
+    errorMsg = err
 
 from debug import Debug