[GRASS-SVN] r39408 - grass/branches/develbranch_6/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Oct 5 05:23:03 EDT 2009


Author: martinl
Date: 2009-10-05 05:23:02 -0400 (Mon, 05 Oct 2009)
New Revision: 39408

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py
Log:
avoid crashing wxGUI when vdigit start-up fails


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py	2009-10-05 08:02:08 UTC (rev 39407)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py	2009-10-05 09:23:02 UTC (rev 39408)
@@ -257,6 +257,21 @@
         # 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 @@
             bg = wx.Brush(self.GetBackgroundColour())
 
         pdc.SetBackground(bg)
+        
         ### pdc.Clear()
 
         Debug.msg (5, "BufferedWindow.Draw(): id=%s, pdctype=%s, coord=%s" % \

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py	2009-10-05 08:02:08 UTC (rev 39407)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py	2009-10-05 09:23:02 UTC (rev 39408)
@@ -1123,12 +1123,18 @@
         # 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 @@
             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'))

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py	2009-10-05 08:02:08 UTC (rev 39407)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/vdigit.py	2009-10-05 09:23:02 UTC (rev 39408)
@@ -141,8 +141,9 @@
                                             '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 @@
         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):



More information about the grass-commit mailing list