[GRASS-SVN] r62191 - in grass/trunk: general/g.list general/g.remove gui/wxpython/gui_core lib/python/script
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Oct 5 21:16:45 PDT 2014
Author: annakrat
Date: 2014-10-05 21:16:45 -0700 (Sun, 05 Oct 2014)
New Revision: 62191
Modified:
grass/trunk/general/g.list/main.c
grass/trunk/general/g.remove/main.c
grass/trunk/gui/wxpython/gui_core/forms.py
grass/trunk/gui/wxpython/gui_core/gselect.py
grass/trunk/lib/python/script/core.py
Log:
g.list/remove: instead of text field use selection widget with multiple elements
Modified: grass/trunk/general/g.list/main.c
===================================================================
--- grass/trunk/general/g.list/main.c 2014-10-06 03:33:01 UTC (rev 62190)
+++ grass/trunk/general/g.list/main.c 2014-10-06 04:16:45 UTC (rev 62191)
@@ -86,12 +86,14 @@
opt.type->multiple = YES;
opt.type->options = M_get_options(TRUE);
opt.type->descriptions = M_get_option_desc(TRUE);
+ opt.type->guidependency = "pattern,exclude";
opt.pattern = G_define_option();
opt.pattern->key = "pattern";
opt.pattern->type = TYPE_STRING;
opt.pattern->required = NO;
opt.pattern->multiple = NO;
+ opt.pattern->gisprompt = "old,element,element";
opt.pattern->description = _("Map name search pattern (default: all)");
opt.pattern->guisection = _("Pattern");
@@ -100,6 +102,7 @@
opt.exclude->type = TYPE_STRING;
opt.exclude->required = NO;
opt.exclude->multiple = NO;
+ opt.exclude->gisprompt = "old,element,element";
opt.exclude->description = _("Map name exclusion pattern (default: none)");
opt.exclude->guisection = _("Pattern");
Modified: grass/trunk/general/g.remove/main.c
===================================================================
--- grass/trunk/general/g.remove/main.c 2014-10-06 03:33:01 UTC (rev 62190)
+++ grass/trunk/general/g.remove/main.c 2014-10-06 04:16:45 UTC (rev 62191)
@@ -73,11 +73,13 @@
opt.type->multiple = YES;
opt.type->options = M_get_options(TRUE);
opt.type->descriptions = M_get_option_desc(TRUE);
+ opt.type->guidependency = "pattern,exclude";
opt.pattern = G_define_option();
opt.pattern->key = "pattern";
opt.pattern->type = TYPE_STRING;
opt.pattern->required = YES;
+ opt.pattern->gisprompt = "old,element,element";
opt.pattern->description = _("Map name search pattern or map names separated by a comma");
opt.pattern->guisection = _("Pattern");
@@ -85,6 +87,7 @@
opt.exclude->key = "exclude";
opt.exclude->type = TYPE_STRING;
opt.exclude->required = NO;
+ opt.exclude->gisprompt = "old,element,element";
opt.exclude->description = _("Map name exclusion pattern (default: none)");
opt.exclude->guisection = _("Pattern");
Modified: grass/trunk/gui/wxpython/gui_core/forms.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/forms.py 2014-10-06 03:33:01 UTC (rev 62190)
+++ grass/trunk/gui/wxpython/gui_core/forms.py 2014-10-06 04:16:45 UTC (rev 62191)
@@ -188,13 +188,23 @@
if pBind:
pBind['value'] = ''
- # set appropriate types in t.* modules element selections
+ # set appropriate types in t.* modules and g.list/remove element selections
if name == 'Select':
- type_param = self.task.get_param('type', element = 'name', raiseError = False)
- maps_param = self.task.get_param('maps', element = 'name', raiseError = False)
- self.data[win.GetParent().SetType] = {'etype': type_param.get('value')}
+ type_param = self.task.get_param('type', element='name', raiseError=False)
+
+ if 'all' in type_param.get('value'):
+ etype = type_param.get('values')
+ if 'all' in etype:
+ etype.remove('all')
+ etype = ','.join(etype)
+ else:
+ etype = type_param.get('value')
+
+ self.data[win.GetParent().SetType] = {'etype': etype}
+
# t.(un)register has one type for 'input', 'maps'
- if maps_param is not None:
+ maps_param = self.task.get_param('maps', element='name', raiseError=False)
+ if self.task.get_name().startswith('t') and maps_param is not None:
if maps_param['wxId'][0] != uid:
element_dict = {'rast': 'strds', 'vect': 'stvds', 'rast3d': 'str3ds'}
self.data[win.GetParent().SetType] = {'etype': element_dict[type_param.get('value')]}
@@ -1003,6 +1013,7 @@
if val in isEnabled:
chkbox.SetValue(True)
hSizer.Add(item = chkbox, proportion = 0)
+ chkbox.Bind(wx.EVT_CHECKBOX, self.OnUpdateSelection)
chkbox.Bind(wx.EVT_CHECKBOX, self.OnCheckBoxMulti)
idx += 1
@@ -2118,6 +2129,7 @@
theParam['value'] = ','.join(currentValueList)
self.OnUpdateValues()
+ event.Skip()
def OnSetValue(self, event):
"""Retrieve the widget value and set the task value field
Modified: grass/trunk/gui/wxpython/gui_core/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/gselect.py 2014-10-06 03:33:01 UTC (rev 62190)
+++ grass/trunk/gui/wxpython/gui_core/gselect.py 2014-10-06 04:16:45 UTC (rev 62191)
@@ -450,9 +450,16 @@
'str3ds':'str3ds',
'stvds':'stvds'}
- if element not in elementdict:
- self.AddItem(_('Not selectable element'), node = False)
- return
+ # to support multiple elements
+ element_list = element.split(',')
+ print element
+ renamed_elements = []
+ for elem in element_list:
+ if elem not in elementdict:
+ self.AddItem(_('Not selectable element'), node = False)
+ return
+ else:
+ renamed_elements.append(elementdict[elem])
if element in ('stds', 'strds', 'str3ds', 'stvds'):
if self.tgis_error is False:
@@ -461,7 +468,7 @@
else:
filesdict = None
else:
- filesdict = grass.list_grouped(elementdict[element],
+ filesdict = grass.list_grouped(renamed_elements,
check_search_path=False)
# add extra items first
Modified: grass/trunk/lib/python/script/core.py
===================================================================
--- grass/trunk/lib/python/script/core.py 2014-10-06 03:33:01 UTC (rev 62190)
+++ grass/trunk/lib/python/script/core.py 2014-10-06 04:16:45 UTC (rev 62191)
@@ -26,6 +26,7 @@
import subprocess
import shutil
import codecs
+import types as python_types
from utils import KeyValue, parse_key_val, basename, encode
from grass.exceptions import ScriptError
@@ -1092,7 +1093,7 @@
def list_grouped(type, pattern=None, check_search_path=True, exclude=None,
- flag=''):
+ flag=''):
"""List of elements grouped by mapsets.
Returns the output from running g.list, as a dictionary where the
@@ -1102,7 +1103,7 @@
>>> list_grouped('vect', pattern='*roads*')['PERMANENT']
['railroads', 'roadsmajor']
- :param str type: element type (rast, vect, rast3d, region, ...)
+ :param str type: element type (rast, vect, rast3d, region, ...) or list of elements
:param str pattern: pattern string
:param str check_search_path: True to add mapsets for the search path
with no found elements
@@ -1112,27 +1113,48 @@
:return: directory of mapsets/elements
"""
- if type == 'raster' or type == 'cell':
- verbose(_('Element type should be "rast" and not "%s"') % type)
- type = 'rast'
+ if isinstance(type, python_types.StringTypes) or len(type) == 1:
+ types = [type]
+ store_types = False
+ else:
+ types = type
+ store_types = True
+ flag += 't'
+ for i in range(len(types)):
+ if types[i] == 'raster' or types[i] == 'cell':
+ verbose(_('Element type should be "rast" and not "%s"') % types[i])
+ types[i] = 'rast'
result = {}
if check_search_path:
for mapset in mapsets(search_path=True):
- result[mapset] = []
+ if store_types:
+ result[mapset] = {}
+ else:
+ result[mapset] = []
mapset = None
for line in read_command("g.list", quiet=True, flags="m" + flag,
- type=type, pattern=pattern, exclude=exclude).splitlines():
+ type=types, pattern=pattern, exclude=exclude).splitlines():
try:
name, mapset = line.split('@')
except ValueError:
warning(_("Invalid element '%s'") % line)
continue
- if mapset in result:
- result[mapset].append(name)
+ if store_types:
+ type_, name = name.split('/')
+ if mapset in result:
+ if type_ in result[mapset]:
+ result[mapset][type_].append(name)
+ else:
+ result[mapset][type_] = [name, ]
+ else:
+ result[mapset] = {type_: [name, ]}
else:
- result[mapset] = [name, ]
+ if mapset in result:
+ result[mapset].append(name)
+ else:
+ result[mapset] = [name, ]
return result
More information about the grass-commit
mailing list