Преглед изворни кода

wxGUI/dbmgr: fix updating existing attributes (encoding and casting issues)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@54841 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa пре 12 година
родитељ
комит
4b62f4ab3e

+ 3 - 7
gui/wxpython/dbmgr/base.py

@@ -45,7 +45,7 @@ from dbmgr.sqlbuilder import SQLBuilderSelect, SQLBuilderUpdate
 from core.gcmd        import RunCommand, GException, GError, GMessage, GWarning
 from core.gcmd        import RunCommand, GException, GError, GMessage, GWarning
 from core.utils       import ListOfCatsToRange
 from core.utils       import ListOfCatsToRange
 from gui_core.dialogs import CreateNewVector
 from gui_core.dialogs import CreateNewVector
-from dbmgr.vinfo      import VectorDBInfo, unicodeValue, createDbInfoDesc
+from dbmgr.vinfo      import VectorDBInfo, GetUnicodeValue, CreateDbInfoDesc
 from core.debug       import Debug
 from core.debug       import Debug
 from dbmgr.dialogs    import ModifyTableRecord, AddColumnDialog
 from dbmgr.dialogs    import ModifyTableRecord, AddColumnDialog
 from core.settings    import UserSettings
 from core.settings    import UserSettings
@@ -289,7 +289,7 @@ class VirtualAttributeList(wx.ListCtrl,
             else:
             else:
                 # encode string values
                 # encode string values
                 try:
                 try:
-                    self.itemDataMap[i].append(unicodeValue(value))
+                    self.itemDataMap[i].append(GetUnicodeValue(value))
                 except UnicodeDecodeError:
                 except UnicodeDecodeError:
                     self.itemDataMap[i].append(_("Unable to decode value. "
                     self.itemDataMap[i].append(_("Unable to decode value. "
                                                  "Set encoding in GUI preferences ('Attributes')."))
                                                  "Set encoding in GUI preferences ('Attributes')."))
@@ -1298,10 +1298,6 @@ class DbMgrBrowsePage(DbMgrNotebookBase):
                                 idx = i
                                 idx = i
                             
                             
                             if column['ctype'] != types.StringType:
                             if column['ctype'] != types.StringType:
-                                if column['ctype'] == types.IntegerType:
-                                    value = float(values[i])
-                                else:
-                                    value = values[i]
                                 tlist.itemDataMap[item][idx] = column['ctype'] (value)
                                 tlist.itemDataMap[item][idx] = column['ctype'] (value)
                             else: # -> string
                             else: # -> string
                                 tlist.itemDataMap[item][idx] = values[i]
                                 tlist.itemDataMap[item][idx] = values[i]
@@ -1949,7 +1945,7 @@ class DbMgrTablesPage(DbMgrNotebookBase):
         dbBox = wx.StaticBox(parent = panel, id = wx.ID_ANY,
         dbBox = wx.StaticBox(parent = panel, id = wx.ID_ANY,
                                       label = " %s " % _("Database connection"))
                                       label = " %s " % _("Database connection"))
         dbSizer = wx.StaticBoxSizer(dbBox, wx.VERTICAL)
         dbSizer = wx.StaticBoxSizer(dbBox, wx.VERTICAL)
-        dbSizer.Add(item = createDbInfoDesc(panel, self.dbMgrData['mapDBInfo'], layer),
+        dbSizer.Add(item = CreateDbInfoDesc(panel, self.dbMgrData['mapDBInfo'], layer),
                     proportion = 1,
                     proportion = 1,
                     flag = wx.EXPAND | wx.ALL,
                     flag = wx.EXPAND | wx.ALL,
                     border = 3)
                     border = 3)

+ 7 - 7
gui/wxpython/dbmgr/dialogs.py

@@ -8,7 +8,7 @@ List of classes:
  - dialogs::ModifyTableRecord
  - dialogs::ModifyTableRecord
  - dialogs::AddColumnDialog
  - dialogs::AddColumnDialog
 
 
-(C) 2007-2012 by the GRASS Development Team
+(C) 2007-2013 by the GRASS Development Team
 
 
 This program is free software under the GNU General Public License
 This program is free software under the GNU General Public License
 (>=v2). Read the file COPYING that comes with GRASS for details.
 (>=v2). Read the file COPYING that comes with GRASS for details.
@@ -27,7 +27,7 @@ import wx.lib.scrolledpanel as scrolled
 from core.gcmd        import RunCommand, GError
 from core.gcmd        import RunCommand, GError
 from core.debug       import Debug
 from core.debug       import Debug
 from core.settings    import UserSettings
 from core.settings    import UserSettings
-from dbmgr.vinfo      import VectorDBInfo
+from dbmgr.vinfo      import VectorDBInfo, GetUnicodeValue
 from gui_core.widgets import IntegerValidator, FloatValidator
 from gui_core.widgets import IntegerValidator, FloatValidator
 
 
 class DisplayAttributesDialog(wx.Dialog):
 class DisplayAttributesDialog(wx.Dialog):
@@ -692,17 +692,17 @@ class ModifyTableRecord(wx.Dialog):
         
         
         If columns is given (list), return only values of given columns.
         If columns is given (list), return only values of given columns.
         """
         """
-        valueList = []
+        valueList = list()
         for labelId, ctypeId, valueId in self.widgets:
         for labelId, ctypeId, valueId in self.widgets:
-            column = self.FindWindowById(labelId).GetLabel().replace(':', '')
+            column = self.FindWindowById(labelId).GetLabel()
             if columns is None or column in columns:
             if columns is None or column in columns:
-                value = str(self.FindWindowById(valueId).GetValue())
+                value = GetUnicodeValue(self.FindWindowById(valueId).GetValue())
                 valueList.append(value)
                 valueList.append(value)
         
         
         # add key value
         # add key value
         if self.usebox:
         if self.usebox:
-            valueList.insert(self.keyId, str(self.cat))
-                             
+            valueList.insert(self.keyId, GetUnicodeValue(str(self.cat)))
+        
         return valueList
         return valueList
 
 
 class AddColumnDialog(wx.Dialog):
 class AddColumnDialog(wx.Dialog):

+ 2 - 2
gui/wxpython/dbmgr/sqlbuilder.py

@@ -33,7 +33,7 @@ from core import globalvar
 import wx
 import wx
 
 
 from core.gcmd   import RunCommand, GError, GMessage
 from core.gcmd   import RunCommand, GError, GMessage
-from dbmgr.vinfo import createDbInfoDesc, VectorDBInfo
+from dbmgr.vinfo import CreateDbInfoDesc, VectorDBInfo
 
 
 import grass.script as grass
 import grass.script as grass
 
 
@@ -81,7 +81,7 @@ class SQLBuilder(wx.Frame):
         databasebox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
         databasebox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
                                    label = " %s " % _("Database connection"))
                                    label = " %s " % _("Database connection"))
         databaseboxsizer = wx.StaticBoxSizer(databasebox, wx.VERTICAL)
         databaseboxsizer = wx.StaticBoxSizer(databasebox, wx.VERTICAL)
-        databaseboxsizer.Add(item=createDbInfoDesc(self.panel, self.dbInfo, layer = self.layer),
+        databaseboxsizer.Add(item = CreateDbInfoDesc(self.panel, self.dbInfo, layer = self.layer),
                              proportion=1,
                              proportion=1,
                              flag=wx.EXPAND | wx.ALL,
                              flag=wx.EXPAND | wx.ALL,
                              border=3)
                              border=3)

+ 11 - 7
gui/wxpython/dbmgr/vinfo.py

@@ -22,11 +22,15 @@ import wx
 from gui_core.gselect import VectorDBInfo as VectorDBInfoBase
 from gui_core.gselect import VectorDBInfo as VectorDBInfoBase
 from core.gcmd        import RunCommand
 from core.gcmd        import RunCommand
 from core.settings    import UserSettings
 from core.settings    import UserSettings
-
 import grass.script as grass
 import grass.script as grass
 
 
-def unicodeValue(value):
-    """!Encode value"""
+def GetUnicodeValue(value):
+    """!Get unicode value
+
+    @param value value to be recoded
+
+    @return unicode value
+    """
     if type(value) == types.UnicodeType:
     if type(value) == types.UnicodeType:
         return value
         return value
     
     
@@ -37,8 +41,8 @@ def unicodeValue(value):
         enc = 'utf-8' # assuming UTF-8
         enc = 'utf-8' # assuming UTF-8
     
     
     return unicode(value, enc, errors = 'replace')
     return unicode(value, enc, errors = 'replace')
-    
-def createDbInfoDesc(panel, mapDBInfo, layer):
+
+def CreateDbInfoDesc(panel, mapDBInfo, layer):
     """!Create database connection information content"""
     """!Create database connection information content"""
     infoFlexSizer = wx.FlexGridSizer (cols = 2, hgap = 1, vgap = 1)
     infoFlexSizer = wx.FlexGridSizer (cols = 2, hgap = 1, vgap = 1)
     infoFlexSizer.AddGrowableCol(1)
     infoFlexSizer.AddGrowableCol(1)
@@ -111,7 +115,7 @@ class VectorDBInfo(VectorDBInfoBase):
                     if self.tables[table][key]['ctype'] != types.StringType:
                     if self.tables[table][key]['ctype'] != types.StringType:
                         value = self.tables[table][key]['ctype'] (value)
                         value = self.tables[table][key]['ctype'] (value)
                     else:
                     else:
-                        value = unicodeValue(value)
+                        value = GetUnicodeValue(value)
                 self.tables[table][key]['values'].append(value)
                 self.tables[table][key]['values'].append(value)
             
             
             for key, value in record.iteritems():
             for key, value in record.iteritems():
@@ -159,7 +163,7 @@ class VectorDBInfo(VectorDBInfoBase):
                     if self.tables[table][name]['ctype'] != type(''):
                     if self.tables[table][name]['ctype'] != type(''):
                         value = self.tables[table][name]['ctype'] (value)
                         value = self.tables[table][name]['ctype'] (value)
                     else:
                     else:
-                        value = unicodeValue(value)
+                        value = GetUnicodeValue(value)
                 else:
                 else:
                     value = None
                     value = None
                 self.tables[table][name]['values'].append(value)
                 self.tables[table][name]['values'].append(value)