[GRASS-SVN] r52712 - in grass/trunk/gui/wxpython: core dbmgr gui_core

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Aug 17 07:43:44 PDT 2012


Author: annakrat
Date: 2012-08-17 07:43:43 -0700 (Fri, 17 Aug 2012)
New Revision: 52712

Modified:
   grass/trunk/gui/wxpython/core/settings.py
   grass/trunk/gui/wxpython/dbmgr/base.py
   grass/trunk/gui/wxpython/gui_core/preferences.py
Log:
wxGUI/dbmgr: choose separator for loading table (related ticket #1633)

Modified: grass/trunk/gui/wxpython/core/settings.py
===================================================================
--- grass/trunk/gui/wxpython/core/settings.py	2012-08-17 14:18:13 UTC (rev 52711)
+++ grass/trunk/gui/wxpython/core/settings.py	2012-08-17 14:43:43 UTC (rev 52712)
@@ -224,6 +224,9 @@
                     },
                 'encoding' : {
                     'value' : '',
+                    },
+                'fieldSeparator' : {
+                    'value' : '|',
                     }
                 },
             #

Modified: grass/trunk/gui/wxpython/dbmgr/base.py
===================================================================
--- grass/trunk/gui/wxpython/dbmgr/base.py	2012-08-17 14:18:13 UTC (rev 52711)
+++ grass/trunk/gui/wxpython/dbmgr/base.py	2012-08-17 14:43:43 UTC (rev 52712)
@@ -163,19 +163,21 @@
         except:
             keyId = -1
         
+        fs = UserSettings.Get(group = 'atm', key = 'fieldSeparator', subkey = 'value')
         # read data
         # FIXME: Max. number of rows, while the GUI is still usable
 
         # stdout can be very large, do not use PIPE, redirect to temp file
         # TODO: more effective way should be implemented...
         outFile = tempfile.NamedTemporaryFile(mode = 'w+b')
-        
+
         if sql:
             ret = RunCommand('db.select',
                              overwrite = True,
                              quiet = True,
                              parent = self,
                              flags = 'c',
+                             fs = fs,
                              sql = sql,
                              output = outFile.name)
         else:
@@ -187,6 +189,7 @@
                                  map = self.mapDBInfo.map,
                                  layer = layer,
                                  columns = ','.join(columns),
+                                 fs = fs,
                                  where = where,
                                  stdout = outFile)
             else:
@@ -196,6 +199,7 @@
                                  flags = 'c',
                                  map = self.mapDBInfo.map,
                                  layer = layer,
+                                 fs = fs,
                                  where = where,
                                  stdout = outFile) 
         
@@ -233,7 +237,17 @@
             
             if not record:
                 break
-           
+
+            record = record.split(fs)
+            if len(columns) != len(record):
+                GError(parent = self,
+                       message = _("Inconsistent number of columns "
+                                   "in the table <%(table)s>. "
+                                   "Try to change field separator in GUI Settings, "
+                                   "Attributes tab, Data browser section.") % \
+                               {'table' : tableName })
+                return
+
             self.AddDataRow(i, record, columns, keyId)
 
             i += 1
@@ -272,7 +286,7 @@
             j += 1
             cat = i + 1
         
-        for value in record.split('|'):
+        for value in record:
             if self.columns[columns[j]]['ctype'] != types.StringType:
                 try:
                     ### casting disabled (2009/03)

Modified: grass/trunk/gui/wxpython/gui_core/preferences.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/preferences.py	2012-08-17 14:18:13 UTC (rev 52711)
+++ grass/trunk/gui/wxpython/gui_core/preferences.py	2012-08-17 14:43:43 UTC (rev 52712)
@@ -46,7 +46,7 @@
 from grass.script import core as grass
 
 from core          import globalvar
-from core.gcmd     import RunCommand
+from core.gcmd     import RunCommand, GError
 from core.utils    import ListOfMapsets, GetColorTables, ReadEpsgCodes, GetSettingsPath
 from core.settings import UserSettings
 from gui_core.dialogs import SymbolDialog
@@ -216,7 +216,15 @@
                               caption = _("Error"), style = wx.OK | wx.ICON_ERROR)
                 win.SetValue(self.settings.Get(group = 'atm', key = 'keycolumn', subkey = 'value'))
                 return False
-
+            if key == 'fieldSeparator':
+                try:
+                    value = str(value)
+                except UnicodeEncodeError:
+                    GError(parent = self, message = _("Field separator must be ASCII character "
+                                                      "not <%s> (use e.g. ';', '&', '#')") % value)
+                    return False
+                if value == '':
+                    value = self.settings.Get(group = 'atm', key = 'fieldSeparator', subkey = 'value')
             if subkey1:
                 self.settings.Set(group, value, key, [subkey, subkey1])
             else:
@@ -1104,6 +1112,17 @@
         flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
         flexSizer.Add(encoding, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
 
+        # field separator
+        label = wx.StaticText(parent = panel, id = wx.ID_ANY,
+                              label = _("Field separator:"))
+        separator = wx.TextCtrl(parent = panel, id = wx.ID_ANY,
+                                value = self.settings.Get(group = 'atm', key = 'fieldSeparator', subkey = 'value'),
+                                name = "GetValue", size = (200, -1))
+        self.winId['atm:fieldSeparator:value'] = separator.GetId()
+
+        flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
+        flexSizer.Add(separator, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
+
         # ask on delete record
         askOnDeleteRec = wx.CheckBox(parent = panel, id = wx.ID_ANY,
                                      label = _("Ask when deleting data record(s) from table"),



More information about the grass-commit mailing list