[GRASS-SVN] r33877 - in grass/trunk: display/d.vect
gui/wxpython/gui_modules include lib/gis
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Oct 14 13:35:41 EDT 2008
Author: martinl
Date: 2008-10-14 13:35:41 -0400 (Tue, 14 Oct 2008)
New Revision: 33877
Modified:
grass/trunk/display/d.vect/main.c
grass/trunk/gui/wxpython/gui_modules/gselect.py
grass/trunk/gui/wxpython/gui_modules/menuform.py
grass/trunk/include/gis.h
grass/trunk/lib/gis/parser.c
Log:
wxGUI synchronized with develbranch_6 (dbtable, dbcolumn)
Modified: grass/trunk/display/d.vect/main.c
===================================================================
--- grass/trunk/display/d.vect/main.c 2008-10-14 17:31:00 UTC (rev 33876)
+++ grass/trunk/display/d.vect/main.c 2008-10-14 17:35:41 UTC (rev 33877)
@@ -158,7 +158,7 @@
color_opt->answer = DEFAULT_FG_COLOR;
color_opt->label = _("Line color");
color_opt->guisection = _("Colors");
- color_opt->gisprompt = GISPROMPT_COLOR;
+ color_opt->gisprompt = "old_color,color,color_none";
color_opt->description =
_("Either a standard GRASS color, R:G:B triplet, or \"none\"");
@@ -168,7 +168,7 @@
fcolor_opt->answer = "200:200:200";
fcolor_opt->label = _("Area fill color");
fcolor_opt->guisection = _("Colors");
- fcolor_opt->gisprompt = GISPROMPT_COLOR;
+ fcolor_opt->gisprompt = "old_color,color,color_none";
fcolor_opt->description =
_("Either a standard GRASS color, R:G:B triplet, or \"none\"");
@@ -247,7 +247,7 @@
lcolor_opt->answer = "red";
lcolor_opt->label = _("Label color");
lcolor_opt->guisection = _("Labels");
- lcolor_opt->gisprompt = GISPROMPT_COLOR;
+ lcolor_opt->gisprompt = "old_color,color,color";
lcolor_opt->description = _("Either a standard color name or R:G:B triplet");
bgcolor_opt = G_define_option();
@@ -256,7 +256,7 @@
bgcolor_opt->answer = "none";
bgcolor_opt->guisection = _("Labels");
bgcolor_opt->label = _("Label background color");
- bgcolor_opt->gisprompt = GISPROMPT_COLOR;
+ bgcolor_opt->gisprompt = "old_color,color,color_none";
bgcolor_opt->description =
_("Either a standard GRASS color, R:G:B triplet, or \"none\"");
@@ -266,7 +266,7 @@
bcolor_opt->answer = "none";
bcolor_opt->guisection = _("Labels");
bcolor_opt->label = _("Label border color");
- bcolor_opt->gisprompt = GISPROMPT_COLOR;
+ bcolor_opt->gisprompt = "old_color,color,color_none";
bcolor_opt->description =
_("Either a standard GRASS color, R:G:B triplet, or \"none\"");
Modified: grass/trunk/gui/wxpython/gui_modules/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gselect.py 2008-10-14 17:31:00 UTC (rev 33876)
+++ grass/trunk/gui/wxpython/gui_modules/gselect.py 2008-10-14 17:35:41 UTC (rev 33877)
@@ -41,7 +41,11 @@
"""
wx.combo.ComboCtrl.__init__(self, parent=parent, id=id, size=size)
+ self.GetChildren()[0].SetName("Select")
+ self.GetChildren()[0].type = type
+
self.tcp = TreeCtrlComboPopup()
+
self.SetPopupControl(self.tcp)
self.SetPopupExtents(0,100)
self.tcp.GetElementList(type, mapsets, exceptOf)
@@ -104,6 +108,7 @@
for value in self.value:
str += value + ","
str = str.rstrip(',')
+
return str
def OnPopup(self):
@@ -318,6 +323,9 @@
"-g", "--q",
"map=%s" % self.map],
rerr=None, stderr=None)
+ print ["v.db.connect",
+ "-g", "--q",
+ "map=%s" % self.map]
if layerCommand.returncode != 0:
return False
@@ -417,18 +425,54 @@
super(LayerSelect, self).__init__(parent, id, pos=pos, size=size,
choices=choices)
+ self.SetName("LayerSelect")
- if not vector:
+ if len(choices) > 1:
return
- self.InsertLayers(vector)
+ if vector:
+ self.InsertLayers(vector)
+ else:
+ self.SetItems(['1'])
+ self.SetSelection(0)
def InsertLayers(self, vector):
"""Insert layers for a vector into the layer combobox"""
layerchoices = VectorDBInfo(vector).layers.keys()
+
+ if len(layerchoices) > 1:
+ self.SetItems(map(str, layerchoices))
+ self.SetStringSelection('1')
+ else:
+ self.SetItems(['1'])
+ self.SetSelection(0)
- self.SetItems(map(str, layerchoices))
- self.SetStringSelection('1')
+class TableSelect(wx.ComboBox):
+ """
+ Creates combo box for selecting attribute tables from the database
+ """
+ def __init__(self, parent,
+ id=wx.ID_ANY, value='', pos=wx.DefaultPosition,
+ size=globalvar.DIALOG_COMBOBOX_SIZE,
+ choices=[]):
+
+ super(TableSelect, self).__init__(parent, id, value, pos, size, choices,
+ style=wx.CB_READONLY)
+
+ self.SetName("TableSelect")
+
+ if not choices:
+ self.InsertTables()
+
+ def InsertTables(self):
+ """Insert attribute tables into combobox"""
+ items = []
+ for table in gcmd.Command(['db.tables',
+ '-p']).ReadStdOutput():
+ items.append(table)
+
+ self.SetItems(items)
+ self.SetValue('')
class ColumnSelect(wx.ComboBox):
"""
@@ -437,24 +481,30 @@
"""
def __init__(self, parent,
id=wx.ID_ANY, value='', pos=wx.DefaultPosition,
- size=wx.DefaultSize, vector=None, layer=1, choices=[]):
+ size=globalvar.DIALOG_COMBOBOX_SIZE, vector=None,
+ layer=1, choices=[]):
super(ColumnSelect, self).__init__(parent, id, value, pos, size, choices,
style=wx.CB_READONLY)
- if not vector:
- return
+ self.SetName("ColumnSelect")
- self.InsertColumns(vector, layer)
+ if vector:
+ self.InsertColumns(vector, layer)
def InsertColumns(self, vector, layer):
"""Insert columns for a vector attribute table into the columns combobox"""
dbInfo = VectorDBInfo(vector)
- table = dbInfo.layers[int(layer)]['table']
- columnchoices = dbInfo.tables[table]
- #columnchoices.sort()
+
+ try:
+ table = dbInfo.layers[int(layer)]['table']
+ columnchoices = dbInfo.tables[table]
+ except (KeyError, ValueError):
+ columnchoices = {}
+
self.SetItems(columnchoices.keys())
-
+ self.SetValue('')
+
class DbColumnSelect(wx.ComboBox):
"""
Creates combo box for selecting columns from any table.
Modified: grass/trunk/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/menuform.py 2008-10-14 17:31:00 UTC (rev 33876)
+++ grass/trunk/gui/wxpython/gui_modules/menuform.py 2008-10-14 17:35:41 UTC (rev 33877)
@@ -192,15 +192,14 @@
if grassModule is not None:
xml.sax.parseString( getInterfaceDescription( grassModule ) , processTask( self ) )
- def get_param(self, aParam, raiseError=True):
+ def get_param(self, value, element='name', raiseError=True):
"""Find and return a param by name."""
for p in self.params:
- lparam = len(aParam)
- if p['name'] == aParam or \
- p['name'][:lparam] == aParam:
+ if p[element] == value:
return p
if raiseError:
- raise ValueError, _("Parameter not found: %s") % aParam
+ raise ValueError, _("Parameter not found: %s") % \
+ value
else:
return None
@@ -1123,25 +1122,34 @@
flag=style, border=5)
p['wxId'] = txt3.GetId()
- if p.get('type','string') == 'string' and p.get('gisprompt',False) == True:
+ #
+ # element selection tree combobox (maps, icons, regions, etc.)
+ #
+ if p.get('gisprompt', False) == True:
txt = wx.StaticText(parent=which_panel, label = title + ':')
self.label_id.append(txt.GetId())
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','') not in ('color', 'dbcolumn', 'dbtable') and \
+ # GIS element entry
+ if p.get('prompt','') not in ('color',
+ 'color_none',
+ 'dbcolumn',
+ 'dbtable',
+ 'layer') and \
p.get('element', '') != 'file':
- if p.get('multiple','no') == 'yes':
+ if p.get('multiple', 'no') == 'yes':
multiple = True
else:
multiple = False
- if p.get('age','') == 'new':
+ if p.get('age', '') == 'new':
mapsets = [grassenv.GetGRASSVariable('MAPSET'),]
else:
mapsets = None
-
- selection = gselect.Select(parent=which_panel, id=wx.ID_ANY, size=globalvar.DIALOG_GSELECT_SIZE,
- type=p.get('element',''), multiple=multiple, mapsets=mapsets)
+
+ selection = gselect.Select(parent=which_panel, id=wx.ID_ANY,
+ size=globalvar.DIALOG_GSELECT_SIZE,
+ type=p.get('element', ''),
+ multiple=multiple, mapsets=mapsets)
if p.get('value','') != '':
selection.SetValue(p['value']) # parameter previously set
@@ -1151,37 +1159,41 @@
# we target the textctl here
p['wxId'] = selection.GetChildren()[0].GetId()
selection.Bind(wx.EVT_TEXT, self.OnSetValue)
- # dbcolumn entry
- elif p.get('prompt','') in ('dbcolumn', 'dbtable'):
- if p.get('age', 'old') == 'old' and \
- p.get('multiple', 'no') == 'no':
- style = wx.CB_SIMPLE | wx.CB_READONLY
+ if p.get('prompt', '') == 'vector':
+ selection.Bind(wx.EVT_TEXT, self.OnUpdateSelection)
+
+ # layer, dbcolumn, dbtable entry
+ elif p.get('prompt', '') in ('dbcolumn',
+ 'dbtable',
+ 'layer'):
+ if p.get('prompt', '') == 'layer':
+ win = gselect.LayerSelect(parent=which_panel)
+ p['wxGetValue'] = win.GetStringSelection
+ win.Bind(wx.EVT_CHOICE, self.OnUpdateSelection)
+ win.Bind(wx.EVT_CHOICE, self.OnSetValue)
+ elif p.get('prompt', '') == 'dbtable':
+ win = gselect.TableSelect(parent=which_panel)
+ p['wxGetValue'] = win.GetStringSelection
+ win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
else:
- style = wx.CB_SIMPLE
- columns = wx.ComboBox(parent=which_panel, id=wx.ID_ANY,
- size=globalvar.DIALOG_COMBOBOX_SIZE,
- style=style,
- choices=[])
- p['wxId'] = columns.GetId()
- p['wxGetValue'] = columns.GetStringSelection
- if p.get('prompt', '') == 'dbcolumn':
- columns.Bind(wx.EVT_ENTER_WINDOW, self.OnDbColumn)
- else:
- columns.Bind(wx.EVT_ENTER_WINDOW, self.OnDbTable)
- columns.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
- which_sizer.Add(item=columns, proportion=0,
+ win = gselect.ColumnSelect(parent=which_panel)
+ p['wxGetValue'] = win.GetStringSelection
+ win.Bind(wx.EVT_COMBOBOX, self.OnSetValue)
+
+ p['wxId'] = win.GetId()
+
+ which_sizer.Add(item=win, 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
- handle_transparency = 'none' in p.get('description', '')
+ elif p.get('prompt', '') in ('color',
+ 'color_none'):
default_color = (200,200,200)
label_color = _("Select Color")
if p.get('default','') != '':
default_color, label_color = color_resolve( p['default'] )
if p.get('value','') != '': # parameter previously set
default_color, label_color = color_resolve( p['value'] )
- if handle_transparency:
+ if p.get('prompt', '') == 'color_none':
this_sizer = wx.BoxSizer(orient=wx.HORIZONTAL )
else:
this_sizer = which_sizer
@@ -1194,7 +1206,7 @@
# the selector proper and either a "transparent" button or None
p['wxId'] = [btn_colour.GetId(),]
btn_colour.Bind(csel.EVT_COLOURSELECT, self.OnColorChange )
- if handle_transparency:
+ if p.get('prompt', '') == 'color_none':
none_check = wx.CheckBox(which_panel, wx.ID_ANY, _("Transparent") )
if p.get('value','') != '' and p.get('value',[''])[0] == "none":
none_check.SetValue(True)
@@ -1244,7 +1256,33 @@
if p == first_param:
if type(p['wxId']) == type(1):
self.FindWindowById(p['wxId']).SetFocus()
+
+ #
+ # set widget relations for OnUpdateSelection
+ #
+ pMap = None
+ pLayer = None
+ pColumn = []
+ for p in self.task.params:
+ if p.get('gisprompt', False) == False:
+ continue
+ prompt = p.get('prompt', '')
+
+ if prompt == 'vector':
+ name = p.get('name', '')
+ if name in ('map', 'input'):
+ pMap = p
+ elif prompt == 'layer':
+ pLayer = p
+ elif prompt == 'dbcolumn':
+ pColumn.append(p['wxId'])
+
+ if pMap:
+ pMap['wxId-bind'] = [pLayer['wxId'], ] + pColumn
+ if pLayer:
+ pLayer['wxId-bind'] = pColumn
+
#
# determine panel size
#
@@ -1376,6 +1414,7 @@
"""
myId = event.GetId()
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:
if porf.has_key('wxGetValue') and porf['wxGetValue']:
@@ -1384,83 +1423,54 @@
porf['value'] = me.GetValue()
self.OnUpdateValues()
-
+
event.Skip()
- def OnDbColumn(self, event):
- """Get list of table columns"""
- choices = []
+ def OnUpdateSelection(self, event):
+ """Update list of available layers, tables, columns for
+ vector map layer"""
+ id = event.GetId()
- p = self.task.get_param('table', raiseError=False)
- if p and p.get('prompt', '') == 'dbtable':
- cmd = ['db.columns',
- 'table=%s' % p.get('value')]
- try:
- choices = gcmd.Command(cmd).ReadStdOutput()
- except gcmd.CmdError:
- choices = []
- if not p:
- p = self.task.get_param('map', raiseError=False)
- if not p:
- p = self.task.get_param('input', raiseError=False)
- if p:
- mapName = utils.GetLayerNameFromCmd(self.task.getCmd(ignoreErrors=True))
- if mapName != _('<required>'):
- layer = 1
- p = self.task.get_param('layer')
- if p:
- value = p.get('value', '1')
- if value:
- layer = int(value)
-
- 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:
- choices = []
-
- win = self.FindWindowById(event.GetId())
+ p = self.task.get_param(id, element='wxId', raiseError=False)
+ if not p or \
+ not p.has_key('wxId-bind'):
+ return
+
+ pMap = self.task.get_param('map', raiseError=False)
+ if not pMap:
+ pMap = self.task.get_param('input', raiseError=False)
- win.SetItems(choices)
+ if not pMap or \
+ pMap.get('prompt', '') != 'vector':
+ return
- if len(choices) < 1:
- win.SetValue('')
+ if p == pMap:
+ map = event.GetString()
+ else:
+ map = pMap.get('value', '')
+ if not map:
+ return
+
+ for uid in p['wxId-bind']:
+ win = self.FindWindowById(uid)
+ name = win.GetName()
+ if name == 'LayerSelect':
+ win.InsertLayers(map)
+ elif name == 'ColumnSelect':
+ pLayer = self.task.get_param('layer', element='name', raiseError=False)
+ if pLayer and \
+ pLayer.get('prompt', '') == 'layer':
+ if pLayer.get('value', '') != '':
+ layer = int(pLayer.get('value', 1))
+ else:
+ layer = int(pLayer.get('default', 1))
+ else:
+ layer = 1
+
+ win.InsertColumns(map, layer)
event.Skip()
- def OnDbTable(self, event):
- """Get list of tables"""
- # TODO: add driver/database
- cmd = ['db.tables',
- '-p', '--q']
-
- for p in self.task.params:
- if p.get('name', '') == 'driver' and \
- len(p.get('value', '')) > 0:
- cmd.append('driver=%s' % p.get('value'))
- elif p.get('name', '') == 'database' and \
- len(p.get('value', '')) > 0:
- cmd.append('database=%s' % p.get('value'))
-
- try:
- choices = gcmd.Command(cmd).ReadStdOutput()
- except gcmd.CmdError:
- choices = []
-
- 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.
Modified: grass/trunk/include/gis.h
===================================================================
--- grass/trunk/include/gis.h 2008-10-14 17:31:00 UTC (rev 33876)
+++ grass/trunk/include/gis.h 2008-10-14 17:35:41 UTC (rev 33877)
@@ -103,9 +103,6 @@
#define TYPE_STRING 3
#define YES 1
#define NO 0
-#define GISPROMPT_COLOR "old,color,color"
-#define GISPROMPT_DBCOLUMN "old,dbcolumn,dbcolumn"
-#define GISPROMPT_DBTABLE "old,dbtable,dbtable"
/* File/directory name lengths */
#define GNAME_MAX 256
Modified: grass/trunk/lib/gis/parser.c
===================================================================
--- grass/trunk/lib/gis/parser.c 2008-10-14 17:31:00 UTC (rev 33876)
+++ grass/trunk/lib/gis/parser.c 2008-10-14 17:35:41 UTC (rev 33877)
@@ -364,7 +364,7 @@
Opt->required = NO;
Opt->multiple = NO;
Opt->description = _("Table name");
- Opt->gisprompt = GISPROMPT_DBTABLE;
+ Opt->gisprompt = "old_dbtable,dbtable,dbtable";
break;
case G_OPT_DB_DRIVER:
Opt->key = "driver";
@@ -389,7 +389,7 @@
Opt->required = NO;
Opt->multiple = NO;
Opt->description = _("Name of attribute column");
- Opt->gisprompt = GISPROMPT_DBCOLUMN;
+ Opt->gisprompt = "old_dbcolumn,dbcolumn,dbcolumn";
break;
case G_OPT_DB_COLUMNS:
Opt->key = "columns";
@@ -398,7 +398,7 @@
Opt->required = NO;
Opt->multiple = YES;
Opt->description = _("Name of attribute column(s)");
- Opt->gisprompt = GISPROMPT_DBCOLUMN;
+ Opt->gisprompt = "old_table,table,dbcolumn";
break;
/* imagery group */
@@ -602,6 +602,7 @@
Opt->description =
_("A single vector map can be connected to multiple database "
"tables. This number determines which table to use.");
+ Opt->gisprompt = "old_layer,layer,layer";
break;
case G_OPT_V_CAT:
Opt->key = "cat";
@@ -651,7 +652,7 @@
Opt->key_desc = "name";
Opt->required = NO;
Opt->answer = DEFAULT_FG_COLOR;
- Opt->gisprompt = GISPROMPT_COLOR;
+ Opt->gisprompt = "old_color,color,color";
Opt->label = _("Color");
Opt->description = _("Either a standard color name or R:G:B triplet");
break;
@@ -661,7 +662,7 @@
Opt->key_desc = "name";
Opt->required = NO;
Opt->answer = DEFAULT_BG_COLOR;
- Opt->gisprompt = GISPROMPT_COLOR;
+ Opt->gisprompt = "old_color,color,color_none";
Opt->label = _("Background color");
Opt->description =
_("Either a standard GRASS color, R:G:B triplet, or \"none\"");
More information about the grass-commit
mailing list