Przeglądaj źródła

wxGUI/dbm: avoid crashing on invalid data input (NULL in key column) [sync'ed with devbr6, r31408]

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@31409 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 17 lat temu
rodzic
commit
d9134660c7
2 zmienionych plików z 25 dodań i 4 usunięć
  1. 18 4
      gui/wxpython/gui_modules/dbm.py
  2. 7 0
      gui/wxpython/wxgui.py

+ 18 - 4
gui/wxpython/gui_modules/dbm.py

@@ -223,7 +223,18 @@ class VirtualAttributeList(wx.ListCtrl,
                     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 @@ class VirtualAttributeList(wx.ListCtrl,
     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))

+ 7 - 0
gui/wxpython/wxgui.py

@@ -1159,11 +1159,18 @@ class GMFrame(wx.Frame):
 
         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):