瀏覽代碼

gislib: new GISPROMPT_DBCOLUMN, used in wxGUI menuform module
standardize column parameter in d.vect
(merge from devbr6, https://trac.osgeo.org/grass/changeset/32673)


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

Martin Landa 16 年之前
父節點
當前提交
2c3606d1d7
共有 4 個文件被更改,包括 62 次插入11 次删除
  1. 2 6
      display/d.vect/main.c
  2. 56 3
      gui/wxpython/gui_modules/menuform.py
  3. 1 0
      include/gis.h
  4. 3 2
      lib/gis/parser.c

+ 2 - 6
display/d.vect/main.c

@@ -171,14 +171,10 @@ int main(int argc, char **argv)
     fcolor_opt->guisection = _("Colors");
     fcolor_opt->gisprompt = GISPROMPT_COLOR;
 
-    rgbcol_opt = G_define_option();
+    rgbcol_opt = G_define_standard_option(G_OPT_COLUMN);
     rgbcol_opt->key = "rgb_column";
-    rgbcol_opt->type = TYPE_STRING;
-    rgbcol_opt->required = NO;
-    rgbcol_opt->multiple = NO;
     rgbcol_opt->guisection = _("Colors");
-    rgbcol_opt->description =
-	_("Name of color definition column (for use with -a flag)");
+    rgbcol_opt->description = _("Name of color definition column (for use with -a flag)");
     rgbcol_opt->answer = "GRASSRGB";
 
     zcol_opt = G_define_option();

+ 56 - 3
gui/wxpython/gui_modules/menuform.py

@@ -1125,7 +1125,8 @@ class cmdPanel(wx.Panel):
                 which_sizer.Add(item=txt, proportion=0,
                                 flag=wx.ADJUST_MINSIZE | wx.RIGHT | wx.LEFT | wx.TOP, border=5)
                 # element selection tree combobox (maps, icons, regions, etc.)
-                if p.get('prompt','') != 'color' and p.get('element', '') != 'file':
+                if p.get('prompt','') not in ('color', 'dbcolumn') and \
+                       p.get('element', '') != 'file':
                     if p.get('multiple','no') == 'yes':
                         multiple = True
                     else:
@@ -1146,6 +1147,18 @@ class cmdPanel(wx.Panel):
                     # we target the textctl here
                     p['wxId'] = selection.GetChildren()[0].GetId()
                     selection.Bind(wx.EVT_TEXT, self.OnSetValue)
+                # dbcolumn entry
+                elif p.get('prompt','') == 'dbcolumn':
+                    columns = wx.ComboBox(parent=which_panel, id=wx.ID_ANY,
+                                          size=globalvar.DIALOG_COMBOBOX_SIZE,
+                                          style=wx.CB_SIMPLE | wx.CB_READONLY,
+                                          choices=[])
+                    p['wxId'] = columns.GetId()
+                    p['wxGetValue'] = columns.GetStringSelection
+                    columns.Bind(wx.EVT_ENTER_WINDOW, self.OnDbColumn)
+                    columns.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
+                    this_sizer.Add(item=columns, proportion=0,
+                                   flag=wx.ADJUST_MINSIZE | wx.BOTTOM | wx.LEFT, border=5)
                 # color entry
                 elif p.get('prompt','') == 'color':
                     # Heuristic way of finding whether transparent is allowed
@@ -1349,10 +1362,50 @@ class cmdPanel(wx.Panel):
         me = wx.FindWindowById( myId )
         for porf in self.task.params + self.task.flags:
             if 'wxId' in porf and type( porf[ 'wxId' ] ) == type( 1 ) and porf['wxId'] == myId:
-                porf[ 'value' ] = me.GetValue()
-
+                if porf.has_key('wxGetValue') and porf['wxGetValue']:
+                    porf['value'] = porf['wxGetValue']()
+                else:
+                    porf['value'] = me.GetValue()
+        
         self.OnUpdateValues()
 
+        event.Skip()
+        
+    def OnDbColumn(self, event):
+        """Get list of table columns"""
+        choices = []
+        
+        mapName = utils.GetLayerNameFromCmd(self.task.getCmd(ignoreErrors=True))
+        if mapName !=  _('<required>'):
+            layer = 1
+            for p in self.task.params:
+                if p.get('name', '') == 'layer':
+                    value = p.get('value', '1')
+                    if value:
+                        layer = int(value)
+                    break
+                
+            cmd = ['v.info',
+                   'map=%s' % mapName,
+                   'layer=%d' % layer,
+                   '-c', '--q']
+
+            try:
+                for line in gcmd.Command(cmd).ReadStdOutput():
+                    type, name = line.split('|')
+                    choices.append(name.strip())
+            except gcmd.CmdError:
+                pass
+            
+        win = self.FindWindowById(event.GetId())
+
+        win.SetItems(choices)
+
+        if len(choices) < 1:
+            win.SetValue('')
+        
+        event.Skip()
+        
     def createCmd( self, ignoreErrors = False ):
         """
         Produce a command line string (list) or feeding into GRASS.

+ 1 - 0
include/gis.h

@@ -104,6 +104,7 @@ static const char *GRASS_copyright __attribute__ ((unused))
 #define YES           1
 #define NO            0
 #define GISPROMPT_COLOR "color,grass,color"
+#define GISPROMPT_DBCOLUMN "dbcolumn,grass,dbcolumn"
 
 /* File/directory name lengths */
 #define GNAME_MAX 256

+ 3 - 2
lib/gis/parser.c

@@ -321,8 +321,7 @@ struct Option *G_define_standard_option(int opt)
 	Opt->type = TYPE_STRING;
 	Opt->key_desc = "sql_query";
 	Opt->required = NO;
-	Opt->label =
-	    _("WHERE conditions of SQL statement without 'where' keyword");
+	Opt->label = _("WHERE conditions of SQL statement without 'where' keyword");
 	Opt->description = _("Example: income < 1000 and inhab >= 10000");
 	break;
     case G_OPT_TABLE:
@@ -356,6 +355,7 @@ struct Option *G_define_standard_option(int opt)
 	Opt->required = NO;
 	Opt->multiple = NO;
 	Opt->description = _("Name of attribute column");
+	Opt->gisprompt = GISPROMPT_DBCOLUMN;
 	break;
     case G_OPT_COLUMNS:
 	Opt->key = "columns";
@@ -364,6 +364,7 @@ struct Option *G_define_standard_option(int opt)
 	Opt->required = NO;
 	Opt->multiple = YES;
 	Opt->description = _("Name of attribute column(s)");
+	Opt->gisprompt = GISPROMPT_DBCOLUMN;
 	break;
 
 	/* imagery group */