[GRASS-SVN] r31408 - in grass/branches/develbranch_6/gui/wxpython: . gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sun May 18 04:51:58 EDT 2008


Author: martinl
Date: 2008-05-18 04:51:58 -0400 (Sun, 18 May 2008)
New Revision: 31408

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/dbm.py
   grass/branches/develbranch_6/gui/wxpython/wxgui.py
Log:
wxGUI/dbm: avoid crashing on invalid data input (NULL in key column)

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/dbm.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/dbm.py	2008-05-18 07:48:49 UTC (rev 31407)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/dbm.py	2008-05-18 08:51:58 UTC (rev 31408)
@@ -223,7 +223,18 @@
                     self.itemDataMap[i].append('')
 
                 if keyId > -1 and keyId == j:
-                    cat = self.columns[columnNames[j]]['ctype'] (value)
+                    try:
+                        cat = self.columns[columnNames[j]]['ctype'] (value)
+                    except ValueError, e:
+                        cat = -1
+                        wx.MessageBox(parent=self,
+                                      message=_("Error loading attribute data. "
+                                                "Record number: %d. Unable to cast value '%s' in "
+                                                "key column (%s) to integer.\n\n"
+                                                "Details: %s") % \
+                                          (i + 1, value, keyColumn, e),
+                                      caption=_("Error"),
+                                      style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
                 j += 1
 
             # insert to table
@@ -336,9 +347,12 @@
     def Sorter(self, key1, key2):
         colName = self.GetColumn(self._col).GetText()
         ascending = self._colSortFlag[self._col]
-        # convert always string
-        item1 = self.columns[colName]["ctype"](self.itemDataMap[key1][self._col])
-        item2 = self.columns[colName]["ctype"](self.itemDataMap[key2][self._col])
+        try:
+            item1 = self.columns[colName]["ctype"](self.itemDataMap[key1][self._col])
+            item2 = self.columns[colName]["ctype"](self.itemDataMap[key2][self._col])
+        except ValueError:
+            item1 = self.itemDataMap[key1][self._col]
+            item2 = self.itemDataMap[key2][self._col]
 
         if type(item1) == type('') or type(item2) == type(''):
             cmpVal = locale.strcoll(str(item1), str(item2))

Modified: grass/branches/develbranch_6/gui/wxpython/wxgui.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/wxgui.py	2008-05-18 07:48:49 UTC (rev 31407)
+++ grass/branches/develbranch_6/gui/wxpython/wxgui.py	2008-05-18 08:51:58 UTC (rev 31408)
@@ -1159,11 +1159,18 @@
 
         pointdata = (icon, size)
 
+        busy = wx.BusyInfo(message=_("Please wait, loading attribute data..."),
+                           parent=self)
+        wx.Yield()
+
         self.dbmanager = dbm.AttributeManager(parent=self, id=wx.ID_ANY,
                                               title="%s - <%s>" % (_("GRASS GIS Attribute Table Manager"),
                                                                    mapname),
                                               size=wx.Size(500,300), vectmap=mapname,
                                               pointdata=pointdata)
+
+        busy.Destroy()
+
         self.dbmanager.Show()
 
     def OnNewDisplay(self, event=None):



More information about the grass-commit mailing list