浏览代码

wxGUI: dbdriver/dbname widgets implemented
(merge from devbr6, https://trac.osgeo.org/grass/changeset/33895)


git-svn-id: https://svn.osgeo.org/grass/grass/trunk@33897 15284696-431f-4ddb-bdfa-cd5b030d7da7

Martin Landa 16 年之前
父节点
当前提交
e13dcf5521
共有 3 个文件被更改,包括 109 次插入20 次删除
  1. 47 4
      gui/wxpython/gui_modules/gselect.py
  2. 60 16
      gui/wxpython/gui_modules/menuform.py
  3. 2 0
      lib/gis/parser.c

+ 47 - 4
gui/wxpython/gui_modules/gselect.py

@@ -8,6 +8,8 @@ Classes:
  - TreeCrtlComboPopup
  - TreeCrtlComboPopup
  - VectorDBInfo
  - VectorDBInfo
  - LayerSelect
  - LayerSelect
+ - DriverSelect
+ - DatabaseSelect
  - ColumnSelect
  - ColumnSelect
 
 
 (C) 2007-2008 by the GRASS Development Team This program is free
 (C) 2007-2008 by the GRASS Development Team This program is free
@@ -455,6 +457,33 @@ class LayerSelect(wx.Choice):
             self.SetItems(['1'])
             self.SetItems(['1'])
             self.SetStringSelection('1')
             self.SetStringSelection('1')
 
 
+class DriverSelect(wx.ComboBox):
+    """
+    Creates combo box for selecting database driver.
+    """
+    def __init__(self, parent, choices, value,
+                 id=wx.ID_ANY, pos=wx.DefaultPosition,
+                 size=globalvar.DIALOG_LAYER_SIZE, **kargs):
+
+        super(DriverSelect, self).__init__(parent, id, value, pos, size,
+                                           choices, style=wx.CB_READONLY)
+        
+        self.SetName("DriverSelect")
+        
+        self.SetStringSelection(value)
+
+class DatabaseSelect(wx.TextCtrl):
+    """
+    Creates combo box for selecting database driver.
+    """
+    def __init__(self, parent, value='',
+                 id=wx.ID_ANY, pos=wx.DefaultPosition,
+                 size=globalvar.DIALOG_TEXTCTRL_SIZE, **kargs):
+        
+        super(DatabaseSelect, self).__init__(parent, id, value, pos, size)
+                               
+        self.SetName("DatabaseSelect")
+
 class TableSelect(wx.ComboBox):
 class TableSelect(wx.ComboBox):
     """
     """
     Creates combo box for selecting attribute tables from the database
     Creates combo box for selecting attribute tables from the database
@@ -472,12 +501,26 @@ class TableSelect(wx.ComboBox):
         if not choices:
         if not choices:
             self.InsertTables()
             self.InsertTables()
                 
                 
-    def InsertTables(self):
+    def InsertTables(self, driver=None, database=None):
         """Insert attribute tables into combobox"""
         """Insert attribute tables into combobox"""
         items = []
         items = []
-        for table in gcmd.Command(['db.tables',
-                                   '-p']).ReadStdOutput():
-            items.append(table)
+        cmd = ['db.tables',
+               '-p']
+        if driver:
+            cmd.append('driver=%s' % driver)
+        if database:
+            cmd.append('database=%s' % database)
+        
+        try:
+            tableCmd = gcmd.Command(cmd)
+        except gcmd.CmdError:
+            tableCmd = None
+
+        
+        if tableCmd and \
+                tableCmd.returncode == 0:
+            for table in tableCmd.ReadStdOutput():
+                items.append(table)
             
             
         self.SetItems(items)
         self.SetItems(items)
         self.SetValue('')
         self.SetValue('')

+ 60 - 16
gui/wxpython/gui_modules/menuform.py

@@ -1009,6 +1009,7 @@ class cmdPanel(wx.Panel):
                 valuelist=map( str, p.get('values',[]) )
                 valuelist=map( str, p.get('values',[]) )
 
 
                 if p.get('multiple', 'no') == 'yes' and \
                 if p.get('multiple', 'no') == 'yes' and \
+                        p.get('gisprompt',False) == False and \
                         p.get('type', '') == 'string':
                         p.get('type', '') == 'string':
                     txt = wx.StaticBox (parent=which_panel, id=0, label=" " + title + ": ")
                     txt = wx.StaticBox (parent=which_panel, id=0, label=" " + title + ": ")
                     self.label_id.append(txt.GetId())
                     self.label_id.append(txt.GetId())
@@ -1036,7 +1037,7 @@ class cmdPanel(wx.Panel):
                         chkbox.Bind(wx.EVT_CHECKBOX, self.OnCheckBoxMulti)
                         chkbox.Bind(wx.EVT_CHECKBOX, self.OnCheckBoxMulti)
                     which_sizer.Add( item=hSizer, proportion=0,
                     which_sizer.Add( item=hSizer, proportion=0,
                                      flag=wx.EXPAND | wx.TOP | wx.RIGHT | wx.LEFT, border=5 )
                                      flag=wx.EXPAND | wx.TOP | wx.RIGHT | wx.LEFT, border=5 )
-                else:
+                elif p.get('gisprompt',False) == False:
                     if len(valuelist) == 1: # -> textctrl
                     if len(valuelist) == 1: # -> textctrl
                         txt = wx.StaticText(parent=which_panel,
                         txt = wx.StaticText(parent=which_panel,
                                             label = "%s. %s %s" % (title, _('Valid range'),
                                             label = "%s. %s %s" % (title, _('Valid range'),
@@ -1133,8 +1134,10 @@ class cmdPanel(wx.Panel):
                 # GIS element entry
                 # GIS element entry
                 if p.get('prompt','') not in ('color',
                 if p.get('prompt','') not in ('color',
                                               'color_none',
                                               'color_none',
-                                              'dbcolumn',
+                                              'dbdriver',
+                                              'dbname',
                                               'dbtable',
                                               'dbtable',
+                                              'dbcolumn',
                                               'layer',
                                               'layer',
                                               'layer_all') and \
                                               'layer_all') and \
                        p.get('element', '') != 'file':
                        p.get('element', '') != 'file':
@@ -1156,7 +1159,7 @@ class cmdPanel(wx.Panel):
 
 
                     which_sizer.Add(item=selection, proportion=0,
                     which_sizer.Add(item=selection, proportion=0,
                                     flag=wx.ADJUST_MINSIZE| wx.BOTTOM | wx.LEFT | wx.RIGHT, border=5)
                                     flag=wx.ADJUST_MINSIZE| wx.BOTTOM | wx.LEFT | wx.RIGHT, border=5)
-
+                    
                     # A select.Select is a combobox with two children: a textctl and a popupwindow;
                     # A select.Select is a combobox with two children: a textctl and a popupwindow;
                     # we target the textctl here
                     # we target the textctl here
                     p['wxId'] = selection.GetChildren()[0].GetId()
                     p['wxId'] = selection.GetChildren()[0].GetId()
@@ -1164,9 +1167,11 @@ class cmdPanel(wx.Panel):
                     if p.get('prompt', '') == 'vector':
                     if p.get('prompt', '') == 'vector':
                         selection.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
                         selection.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
                     
                     
-                # layer, dbcolumn, dbtable entry
-                elif p.get('prompt', '') in ('dbcolumn',
+                # layer, dbdriver, dbname, dbcolumn, dbtable entry
+                elif p.get('prompt', '') in ('dbdriver',
+                                             'dbname',
                                              'dbtable',
                                              'dbtable',
+                                             'dbcolumn',
                                              'layer',
                                              'layer',
                                              'layer_all'):
                                              'layer_all'):
                     if p.get('prompt', '') in ('layer',
                     if p.get('prompt', '') in ('layer',
@@ -1180,11 +1185,23 @@ class cmdPanel(wx.Panel):
                         p['wxGetValue'] = win.GetStringSelection
                         p['wxGetValue'] = win.GetStringSelection
                         win.Bind(wx.EVT_CHOICE, self.OnUpdateSelection)
                         win.Bind(wx.EVT_CHOICE, self.OnUpdateSelection)
                         win.Bind(wx.EVT_CHOICE, self.OnSetValue)
                         win.Bind(wx.EVT_CHOICE, self.OnSetValue)
+                    elif p.get('prompt', '') == 'dbdriver':
+                        win = gselect.DriverSelect(parent=which_panel,
+                                                   choices=p['values'],
+                                                   value=p['default'])
+                        p['wxGetValue'] = win.GetStringSelection
+                        win.Bind(wx.EVT_COMBOBOX, self.OnUpdateSelection)
+                        win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
+                    elif p.get('prompt', '') == 'dbname':
+                        win = gselect.DatabaseSelect(parent=which_panel,
+                                                     value=p['default'])
+                        win.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
+                        win.Bind(wx.EVT_TEXT, self.OnSetValue)
                     elif p.get('prompt', '') == 'dbtable':
                     elif p.get('prompt', '') == 'dbtable':
                         win = gselect.TableSelect(parent=which_panel)
                         win = gselect.TableSelect(parent=which_panel)
                         p['wxGetValue'] = win.GetStringSelection
                         p['wxGetValue'] = win.GetStringSelection
                         win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
                         win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
-                    else:
+                    elif p.get('prompt', '') == 'dbcolumn':
                         win = gselect.ColumnSelect(parent=which_panel)
                         win = gselect.ColumnSelect(parent=which_panel)
                         p['wxGetValue'] = win.GetStringSelection
                         p['wxGetValue'] = win.GetStringSelection
                         win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
                         win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
@@ -1271,6 +1288,9 @@ class cmdPanel(wx.Panel):
         #
         #
         pMap = None
         pMap = None
         pLayer = None
         pLayer = None
+        pDriver = None
+        pDatabase = None
+        pTable = None
         pColumn = []
         pColumn = []
         for p in self.task.params:
         for p in self.task.params:
             if p.get('gisprompt', False) == False:
             if p.get('gisprompt', False) == False:
@@ -1286,6 +1306,12 @@ class cmdPanel(wx.Panel):
                 pLayer = p
                 pLayer = p
             elif prompt == 'dbcolumn':
             elif prompt == 'dbcolumn':
                 pColumn.append(p['wxId'])
                 pColumn.append(p['wxId'])
+            elif prompt == 'dbdriver':
+                pDriver = p
+            elif prompt == 'dbname':
+                pDatabase = p
+            elif prompt == 'dbtable':
+                pTable = p
         
         
         if pMap:
         if pMap:
             pMap['wxId-bind'] = pColumn
             pMap['wxId-bind'] = pColumn
@@ -1294,6 +1320,15 @@ class cmdPanel(wx.Panel):
         
         
         if pLayer:
         if pLayer:
             pLayer['wxId-bind'] = pColumn
             pLayer['wxId-bind'] = pColumn
+
+        if pDriver and pTable:
+            pDriver['wxId-bind'] = [pTable['wxId'], ]
+
+        if pDatabase and pTable:
+            pDatabase['wxId-bind'] = [pTable['wxId'], ]
+
+        if pTable and pColumn:
+            pTable['wxId-bind'] = pColumn
         
         
 	#
 	#
 	# determine panel size
 	# determine panel size
@@ -1442,34 +1477,43 @@ class cmdPanel(wx.Panel):
         """Update list of available layers, tables, columns for
         """Update list of available layers, tables, columns for
         vector map layer"""
         vector map layer"""
         id = event.GetId()
         id = event.GetId()
-        
+
         p = self.task.get_param(id, element='wxId', raiseError=False)
         p = self.task.get_param(id, element='wxId', raiseError=False)
         if not p or \
         if not p or \
                 not p.has_key('wxId-bind'):
                 not p.has_key('wxId-bind'):
             return
             return
         
         
+        pType = p.get('prompt', '')
+        if not pType:
+            return
+
         pMap = self.task.get_param('map', raiseError=False)
         pMap = self.task.get_param('map', raiseError=False)
         if not pMap:
         if not pMap:
             pMap = self.task.get_param('input', raiseError=False)
             pMap = self.task.get_param('input', raiseError=False)
 
 
-        if not pMap or \
-                pMap.get('prompt', '') != 'vector':
-            return
-
         if p == pMap:
         if p == pMap:
             map = event.GetString()
             map = event.GetString()
-        else:
+        elif pMap:
             map = pMap.get('value', '')
             map = pMap.get('value', '')
-        if not map:
-            return
-
+        
         for uid in p['wxId-bind']:
         for uid in p['wxId-bind']:
             win = self.FindWindowById(uid)
             win = self.FindWindowById(uid)
             name = win.GetName()
             name = win.GetName()
             if name == 'LayerSelect':
             if name == 'LayerSelect':
                 win.InsertLayers(map)
                 win.InsertLayers(map)
+            elif name == 'TableSelect':
+                pDriver = self.task.get_param('dbdriver', element='prompt', raiseError=False)
+                driver = db = None
+                if pDriver:
+                    driver = pDriver['value']
+                pDb = self.task.get_param('dbname', element='prompt', raiseError=False)
+                if pDb:
+                    db = pDb['value']
+                
+                win.InsertTables(driver, db)
+            
             elif name == 'ColumnSelect':
             elif name == 'ColumnSelect':
-                pLayer = self.task.get_param('layer', element='name', raiseError=False)
+                pLayer = self.task.get_param('layer', element='prompt', raiseError=False)
                 if pLayer and \
                 if pLayer and \
                         pLayer.get('prompt', '') == 'layer':
                         pLayer.get('prompt', '') == 'layer':
                     if pLayer.get('value', '') != '':
                     if pLayer.get('value', '') != '':

+ 2 - 0
lib/gis/parser.c

@@ -373,6 +373,7 @@ struct Option *G_define_standard_option(int opt)
 	Opt->required = NO;
 	Opt->required = NO;
 	Opt->multiple = NO;
 	Opt->multiple = NO;
 	Opt->description = _("Driver name");
 	Opt->description = _("Driver name");
+	Opt->gisprompt = "old_dbdriver,dbdriver,dbdriver";
 	break;
 	break;
     case G_OPT_DB_DATABASE:
     case G_OPT_DB_DATABASE:
 	Opt->key = "database";
 	Opt->key = "database";
@@ -381,6 +382,7 @@ struct Option *G_define_standard_option(int opt)
 	Opt->required = NO;
 	Opt->required = NO;
 	Opt->multiple = NO;
 	Opt->multiple = NO;
 	Opt->description = _("Database name");
 	Opt->description = _("Database name");
+	Opt->gisprompt = "old_dbname,dbname,dbname";
 	break;
 	break;
     case G_OPT_DB_COLUMN:
     case G_OPT_DB_COLUMN:
 	Opt->key = "column";
 	Opt->key = "column";