[GRASS-SVN] r38339 - in grass/trunk: gui/wxpython/gui_modules
include lib/gis vector/v.distance
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Jul 10 04:22:52 EDT 2009
Author: martinl
Date: 2009-07-10 04:22:50 -0400 (Fri, 10 Jul 2009)
New Revision: 38339
Modified:
grass/trunk/gui/wxpython/gui_modules/menuform.py
grass/trunk/include/gis.h
grass/trunk/lib/gis/parser.c
grass/trunk/vector/v.distance/main.c
Log:
attempt to fix trac #671 (wxgui: v.distance to_column option inaccessible)
Modified: grass/trunk/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/menuform.py 2009-07-09 20:23:22 UTC (rev 38338)
+++ grass/trunk/gui/wxpython/gui_modules/menuform.py 2009-07-10 08:22:50 UTC (rev 38339)
@@ -50,6 +50,7 @@
import textwrap
import os
import time
+import types
import copy
import locale
from threading import Thread
@@ -228,7 +229,27 @@
'database' : db }
elif name == 'ColumnSelect':
- pLayer = self.task.get_param('layer', element='element', raiseError=False)
+ if not map:
+ # standard way failed, try to track wxIds manually
+ if p.get('element', '') == 'vector':
+ map = p.get('value', '')
+ # get layer
+ for bid in p['wxId-bind']:
+ p = self.task.get_param(bid, element = 'wxId', raiseError = False)
+ if not p:
+ continue
+ if p.get('element', '') == 'layer':
+ pLayer = p
+ break
+ elif p.get('element', '') == 'layer':
+ pLayer = p
+ # get vector name
+ pMap = self.task.get_param(p['wxId'], element = 'wxId-bind', raiseError = False)
+ if pMap:
+ map = pMap.get('value', '')
+ else:
+ pLayer = self.task.get_param('layer', element='element', raiseError=False)
+
if pLayer:
if pLayer.get('value', '') != '':
layer = int(pLayer.get('value', 1))
@@ -333,12 +354,21 @@
def get_param(self, value, element='name', raiseError=True):
"""!Find and return a param by name."""
- for p in self.params:
- if p[element] == value:
- return p
+ try:
+ for p in self.params:
+ val = p[element]
+ if type(val) in (types.ListType, types.TupleType):
+ if value in val:
+ return p
+ else:
+ if p[element] == value:
+ return p
+ except KeyError:
+ pass
+
if raiseError:
- raise ValueError, _("Parameter not found: %s") % \
- value
+ raise ValueError, _("Parameter element '%s' not found: '%s'") % \
+ (element, value)
else:
return None
@@ -465,22 +495,23 @@
key_desc.append(ki.text)
self.task.params.append( {
- "name" : p.get('name'),
- "type" : p.get('type'),
- "required" : p.get('required'),
- "multiple" : p.get('multiple'),
- "label" : self.__getNodeText(p, 'label'),
- "description" : self.__getNodeText(p, 'description'),
- 'gisprompt' : gisprompt,
- 'age' : age,
- 'element' : element,
- 'prompt' : prompt,
- "guisection" : self.__getNodeText(p, 'guisection'),
- "default" : self.__getNodeText(p, 'default'),
- "values" : values,
- "values_desc" : values_desc,
- "value" : '',
- "key_desc" : key_desc } )
+ "name" : p.get('name'),
+ "type" : p.get('type'),
+ "required" : p.get('required'),
+ "multiple" : p.get('multiple'),
+ "label" : self.__getNodeText(p, 'label'),
+ "description" : self.__getNodeText(p, 'description'),
+ 'gisprompt' : gisprompt,
+ 'age' : age,
+ 'element' : element,
+ 'prompt' : prompt,
+ "guisection" : self.__getNodeText(p, 'guisection'),
+ "guidependency" : self.__getNodeText(p, 'guidependency'),
+ "default" : self.__getNodeText(p, 'default'),
+ "values" : values,
+ "values_desc" : values_desc,
+ "value" : '',
+ "key_desc" : key_desc } )
def __processFlags(self):
"""!Process flags description"""
@@ -1383,8 +1414,18 @@
if p.get('gisprompt', False) == False:
continue
+ guidep = p.get('guidependency', '')
+ if guidep:
+ # fixed options dependency defined
+ options = guidep.split(',')
+ for opt in options:
+ pOpt = self.task.get_param(opt, element = 'name', raiseError = False)
+ if id:
+ if not p.has_key('wxId-bind'):
+ p['wxId-bind'] = list()
+ p['wxId-bind'].append(pOpt['wxId'])
+
prompt = p.get('element', '')
-
if prompt == 'vector':
name = p.get('name', '')
if name in ('map', 'input'):
@@ -1400,6 +1441,7 @@
elif prompt == 'dbtable':
pTable = p
+ # collect ids
pColumnIds = []
for p in pColumn:
pColumnIds.append(p['wxId'])
@@ -1407,13 +1449,15 @@
for p in pLayer:
pLayerIds.append(p['wxId'])
+ # set wxId-bindings
if pMap:
pMap['wxId-bind'] = copy.copy(pColumnIds)
if pLayer:
pMap['wxId-bind'] += pLayerIds
- for p in pLayer:
- p['wxId-bind'] = copy.copy(pColumnIds)
+ if len(pLayer) == 1:
+ # TODO: fix modules with more 'layer' options
+ pLayer[0]['wxId-bind'] = copy.copy(pColumnIds)
if pDriver and pTable:
pDriver['wxId-bind'] = [pTable['wxId'], ]
Modified: grass/trunk/include/gis.h
===================================================================
--- grass/trunk/include/gis.h 2009-07-09 20:23:22 UTC (rev 38338)
+++ grass/trunk/include/gis.h 2009-07-10 08:22:50 UTC (rev 38339)
@@ -319,6 +319,9 @@
struct Option *next_opt; /* Pointer to next option struct */
const char *gisprompt; /* Interactive prompt guidance */
const char *guisection; /* GUI Layout guidance: ';' delimited heirarchical tree position */
+ const char *guidependency; /* GUI dependency, list of options
+ (separated by commas) to be updated
+ if the value is chanched */
int (*checker) (); /* Routine to check answer or NULL */
int count;
};
Modified: grass/trunk/lib/gis/parser.c
===================================================================
--- grass/trunk/lib/gis/parser.c 2009-07-09 20:23:22 UTC (rev 38338)
+++ grass/trunk/lib/gis/parser.c 2009-07-10 08:22:50 UTC (rev 38339)
@@ -233,7 +233,7 @@
* format: <i>key=value</i>. Options identified as REQUIRED must be
* specified by user on command line. The option string can either
* specify a range of values (e.g. "10-100") or a list of acceptable
- * values (e.g. "red,orange,yellow"). Unless the option string is
+ * values (e.g. "red,orange,yellow"). Unless the option string is
* NULL, user provided input will be evaluated agaist this string.
*
* \return pointer to an Option struct
@@ -269,7 +269,8 @@
opt->description = NULL;
opt->descriptions = NULL;
opt->guisection = NULL;
-
+ opt->guidependency = NULL;
+
st->current_option = opt;
st->n_opts++;
@@ -1444,6 +1445,11 @@
print_escaped_for_xml(stdout, opt->guisection);
fprintf(stdout, "\n\t\t</guisection>\n");
}
+ if (opt->guidependency) {
+ fprintf(stdout, "\t\t<guidependency>\n\t\t\t");
+ print_escaped_for_xml(stdout, opt->guidependency);
+ fprintf(stdout, "\n\t\t</guidependency>\n");
+ }
/* TODO:
* - key_desc?
* - there surely are some more. which ones?
Modified: grass/trunk/vector/v.distance/main.c
===================================================================
--- grass/trunk/vector/v.distance/main.c 2009-07-09 20:23:22 UTC (rev 38338)
+++ grass/trunk/vector/v.distance/main.c 2009-07-10 08:22:50 UTC (rev 38339)
@@ -145,12 +145,12 @@
from_field_opt->key = "from_layer";
from_field_opt->label = _("Layer number (from)");
from_field_opt->guisection = _("From");
-
+
to_field_opt = G_define_standard_option(G_OPT_V_FIELD);
to_field_opt->key = "to_layer";
to_field_opt->label = _("Layer number (to)");
to_field_opt->guisection = _("To");
-
+
out_opt = G_define_standard_option(G_OPT_V_OUTPUT);
out_opt->key = "output";
out_opt->required = NO;
@@ -206,7 +206,7 @@
to_column_opt->description =
_("Column name of nearest feature (used with upload=to_attr)");
to_column_opt->guisection = _("To");
-
+
table_opt = G_define_standard_option(G_OPT_DB_TABLE);
table_opt->gisprompt = "new_dbtable,dbtable,dbtable";
table_opt->description =
@@ -225,6 +225,12 @@
_("Calculate distances to all features within the threshold");
all_flag->description = _("The output is written to stdout but may be uploaded " "to a new table created by this module. " "From categories are may be multiple."); /* huh? */
+ /* GUI dependency */
+ from_opt->guidependency = G_store(from_field_opt->key);
+ sprintf(buf1, "%s,%s", to_field_opt->key, to_column_opt->key);
+ to_opt->guidependency = G_store(buf1);
+ to_field_opt->guidependency = G_store(to_column_opt->key);
+
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
More information about the grass-commit
mailing list