Bladeren bron

wxGUI/dbmgr: choose separator for loading table (related ticket https://trac.osgeo.org/grass/ticket/1633)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@52712 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 12 jaren geleden
bovenliggende
commit
522ff4d762
3 gewijzigde bestanden met toevoegingen van 41 en 5 verwijderingen
  1. 3 0
      gui/wxpython/core/settings.py
  2. 17 3
      gui/wxpython/dbmgr/base.py
  3. 21 2
      gui/wxpython/gui_core/preferences.py

+ 3 - 0
gui/wxpython/core/settings.py

@@ -224,6 +224,9 @@ class Settings:
                     },
                     },
                 'encoding' : {
                 'encoding' : {
                     'value' : '',
                     'value' : '',
+                    },
+                'fieldSeparator' : {
+                    'value' : '|',
                     }
                     }
                 },
                 },
             #
             #

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

@@ -163,19 +163,21 @@ class VirtualAttributeList(wx.ListCtrl,
         except:
         except:
             keyId = -1
             keyId = -1
         
         
+        fs = UserSettings.Get(group = 'atm', key = 'fieldSeparator', subkey = 'value')
         # read data
         # read data
         # FIXME: Max. number of rows, while the GUI is still usable
         # FIXME: Max. number of rows, while the GUI is still usable
 
 
         # stdout can be very large, do not use PIPE, redirect to temp file
         # stdout can be very large, do not use PIPE, redirect to temp file
         # TODO: more effective way should be implemented...
         # TODO: more effective way should be implemented...
         outFile = tempfile.NamedTemporaryFile(mode = 'w+b')
         outFile = tempfile.NamedTemporaryFile(mode = 'w+b')
-        
+
         if sql:
         if sql:
             ret = RunCommand('db.select',
             ret = RunCommand('db.select',
                              overwrite = True,
                              overwrite = True,
                              quiet = True,
                              quiet = True,
                              parent = self,
                              parent = self,
                              flags = 'c',
                              flags = 'c',
+                             fs = fs,
                              sql = sql,
                              sql = sql,
                              output = outFile.name)
                              output = outFile.name)
         else:
         else:
@@ -187,6 +189,7 @@ class VirtualAttributeList(wx.ListCtrl,
                                  map = self.mapDBInfo.map,
                                  map = self.mapDBInfo.map,
                                  layer = layer,
                                  layer = layer,
                                  columns = ','.join(columns),
                                  columns = ','.join(columns),
+                                 fs = fs,
                                  where = where,
                                  where = where,
                                  stdout = outFile)
                                  stdout = outFile)
             else:
             else:
@@ -196,6 +199,7 @@ class VirtualAttributeList(wx.ListCtrl,
                                  flags = 'c',
                                  flags = 'c',
                                  map = self.mapDBInfo.map,
                                  map = self.mapDBInfo.map,
                                  layer = layer,
                                  layer = layer,
+                                 fs = fs,
                                  where = where,
                                  where = where,
                                  stdout = outFile) 
                                  stdout = outFile) 
         
         
@@ -233,7 +237,17 @@ class VirtualAttributeList(wx.ListCtrl,
             
             
             if not record:
             if not record:
                 break
                 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)
             self.AddDataRow(i, record, columns, keyId)
 
 
             i += 1
             i += 1
@@ -272,7 +286,7 @@ class VirtualAttributeList(wx.ListCtrl,
             j += 1
             j += 1
             cat = i + 1
             cat = i + 1
         
         
-        for value in record.split('|'):
+        for value in record:
             if self.columns[columns[j]]['ctype'] != types.StringType:
             if self.columns[columns[j]]['ctype'] != types.StringType:
                 try:
                 try:
                     ### casting disabled (2009/03)
                     ### casting disabled (2009/03)

+ 21 - 2
gui/wxpython/gui_core/preferences.py

@@ -46,7 +46,7 @@ from wx.lib.newevent import NewEvent
 from grass.script import core as grass
 from grass.script import core as grass
 
 
 from core          import globalvar
 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.utils    import ListOfMapsets, GetColorTables, ReadEpsgCodes, GetSettingsPath
 from core.settings import UserSettings
 from core.settings import UserSettings
 from gui_core.dialogs import SymbolDialog
 from gui_core.dialogs import SymbolDialog
@@ -216,7 +216,15 @@ class PreferencesBaseDialog(wx.Dialog):
                               caption = _("Error"), style = wx.OK | wx.ICON_ERROR)
                               caption = _("Error"), style = wx.OK | wx.ICON_ERROR)
                 win.SetValue(self.settings.Get(group = 'atm', key = 'keycolumn', subkey = 'value'))
                 win.SetValue(self.settings.Get(group = 'atm', key = 'keycolumn', subkey = 'value'))
                 return False
                 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:
             if subkey1:
                 self.settings.Set(group, value, key, [subkey, subkey1])
                 self.settings.Set(group, value, key, [subkey, subkey1])
             else:
             else:
@@ -1104,6 +1112,17 @@ class PreferencesDialog(PreferencesBaseDialog):
         flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
         flexSizer.Add(label, proportion = 0, flag = wx.ALIGN_CENTER_VERTICAL)
         flexSizer.Add(encoding, proportion = 0, flag = wx.ALIGN_RIGHT | wx.FIXED_MINSIZE)
         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
         # ask on delete record
         askOnDeleteRec = wx.CheckBox(parent = panel, id = wx.ID_ANY,
         askOnDeleteRec = wx.CheckBox(parent = panel, id = wx.ID_ANY,
                                      label = _("Ask when deleting data record(s) from table"),
                                      label = _("Ask when deleting data record(s) from table"),