Przeglądaj źródła

avoid crashing wxGUI when vdigit start-up fails
(merge from devbr6 https://trac.osgeo.org/grass/changeset/39408)


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

Martin Landa 15 lat temu
rodzic
commit
2c3342e0f4

+ 16 - 0
gui/wxpython/gui_modules/mapdisp_window.py

@@ -257,6 +257,21 @@ class BufferedWindow(MapWindow, wx.Window):
         # pseudoDC for temporal objects (select box, measurement tool, etc.)
         self.pdcTmp = PseudoDC()
         
+    def CheckPseudoDC(self):
+        """!Try to draw background
+        
+        @return True on success
+        @return False on failure
+        """
+        try:
+            self.pdc.BeginDrawing()
+            self.pdc.SetBackground(wx.Brush(self.GetBackgroundColour()))
+            self.pdc.BeginDrawing()
+        except:
+            return False
+        
+        return True
+    
     def Draw(self, pdc, img=None, drawid=None, pdctype='image', coords=[0, 0, 0, 0]):
         """!
         Draws map and overlay decorations
@@ -281,6 +296,7 @@ class BufferedWindow(MapWindow, wx.Window):
             bg = wx.Brush(self.GetBackgroundColour())
 
         pdc.SetBackground(bg)
+        
         ### pdc.Clear()
 
         Debug.msg (5, "BufferedWindow.Draw(): id=%s, pdctype=%s, coord=%s" % \

+ 6 - 3
gui/wxpython/gui_modules/toolbars.py

@@ -1123,12 +1123,18 @@ class VDigitToolbar(AbstractToolbar):
         # reload vdigit module
         reload(vdigit)
         from vdigit import Digit as Digit
+        # use vdigit's PseudoDC
+        self.parent.MapWindow.DefinePseudoDC(vdigit = True)
         self.parent.digit = Digit(mapwindow=self.parent.MapWindow)
         
         self.mapLayer = mapLayer
         
         # open vector map
         try:
+            if not self.parent.MapWindow.CheckPseudoDC():
+                raise gcmd.DigitError(parent=self.parent,
+                                      message=_("Unable to initialize display driver of vector "
+                                                "digitizer. See 'Command output' for details."))
             self.parent.digit.SetMapName(mapLayer.GetName())
         except gcmd.DigitError, e:
             self.mapLayer = None
@@ -1136,9 +1142,6 @@ class VDigitToolbar(AbstractToolbar):
             print >> sys.stderr, e # wxMessageBox
             return False
 
-        # use vdigit's PseudoDC
-        self.parent.MapWindow.DefinePseudoDC(vdigit = True)
-    
         # update toolbar
         self.combo.SetValue(mapLayer.GetName())
         self.parent.toolbars['map'].combo.SetValue (_('Digitize'))

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

@@ -141,8 +141,9 @@ class AbstractDigit:
                                             'try to run v.build to rebuild '
                                             'the topology (Vector->Develop vector map->'
                                             'Create/rebuild topology).') % map)
-            
-        self.digit.InitCats()
+
+        if self.digit:
+            self.digit.InitCats()
         
     def SelectLinesByQueryThresh(self):
         """!Generic method used for SelectLinesByQuery()
@@ -244,11 +245,11 @@ class VDigit(AbstractDigit):
         try:
             self.digit = wxvdigit.Digit(self.driver.GetDevice(),
                                         mapwindow)
-        except (ImportError, NameError, TypeError):
+        except (ImportError, NameError, TypeError), e:
             # print traceback
             traceback.print_exc(file = self.log)
             self.digit = None
-        
+            
         self.UpdateSettings()
         
     def __del__(self):