[GRASS-SVN] r62427 - in grass/branches/releasebranch_7_0: gui/wxpython/gui_core lib/python/script

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Oct 27 20:59:29 PDT 2014


Author: annakrat
Date: 2014-10-27 20:59:28 -0700 (Mon, 27 Oct 2014)
New Revision: 62427

Modified:
   grass/branches/releasebranch_7_0/gui/wxpython/gui_core/forms.py
   grass/branches/releasebranch_7_0/gui/wxpython/gui_core/gselect.py
   grass/branches/releasebranch_7_0/lib/python/script/core.py
Log:
g.remove: backport changes in gui interface (multiple elements selection)

Modified: grass/branches/releasebranch_7_0/gui/wxpython/gui_core/forms.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/gui_core/forms.py	2014-10-27 22:33:31 UTC (rev 62426)
+++ grass/branches/releasebranch_7_0/gui/wxpython/gui_core/forms.py	2014-10-28 03:59:28 UTC (rev 62427)
@@ -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().SetElementList] = {'type': 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
                         
@@ -2110,6 +2121,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/branches/releasebranch_7_0/gui/wxpython/gui_core/gselect.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/gui_core/gselect.py	2014-10-27 22:33:31 UTC (rev 62426)
+++ grass/branches/releasebranch_7_0/gui/wxpython/gui_core/gselect.py	2014-10-28 03:59:28 UTC (rev 62427)
@@ -452,11 +452,17 @@
                        'strds':'strds',
                        '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(',')
+        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:
                 import grass.temporal as tgis
@@ -464,9 +470,9 @@
             else:
                 filesdict = None
         else:
-            filesdict = grass.list_grouped(elementdict[element],
-                                            check_search_path = False)
-        
+            filesdict = grass.list_grouped(renamed_elements,
+                                           check_search_path=False)
+
         # add extra items first
         if self.extraItems:
             for group, items in self.extraItems.iteritems():

Modified: grass/branches/releasebranch_7_0/lib/python/script/core.py
===================================================================
--- grass/branches/releasebranch_7_0/lib/python/script/core.py	2014-10-27 22:33:31 UTC (rev 62426)
+++ grass/branches/releasebranch_7_0/lib/python/script/core.py	2014-10-28 03:59:28 UTC (rev 62427)
@@ -31,6 +31,7 @@
 import subprocess
 import shutil
 import codecs
+import types as python_types
 
 from utils import KeyValue, parse_key_val, basename, encode
 
@@ -1083,7 +1084,7 @@
 # interface to g.list
 
 
-def list_strings(type, pattern=None, mapset=None, flag=''):
+def list_strings(type, pattern=None, mapset=None, exclude=None, flag=''):
     """!List of elements as strings.
 
     Returns the output from running g.list, as a list of qualified
@@ -1106,14 +1107,15 @@
                              flags='m' + flag,
                              type=type,
                              pattern=pattern,
+                             exclude=exclude,
                              mapset=mapset).splitlines():
         result.append(line.strip())
 
     return result
 
 
-def list_pairs(type, pattern=None, mapset=None, flag=''):
-    """!List of elements as pairs
+def list_pairs(type, pattern=None, mapset=None, exclude=None, flag=''):
+    """List of elements as pairs
 
     Returns the output from running g.list, as a list of
     (name, mapset) pairs
@@ -1121,17 +1123,20 @@
     @param type element type (rast, vect, rast3d, region, ...)
     @param pattern pattern string
     @param mapset mapset name (if not given use search path)
+    @param exclude pattern string to exclude maps from the research
     @param flag pattern type: 'r' (basic regexp), 'e' (extended regexp), or ''
                 (glob pattern)
 
     @return list of elements
     """
-    return [tuple(map.split('@', 1)) for map in mlist_strings(type, pattern,
-                                                              mapset, flag)]
+    return [tuple(map.split('@', 1)) for map in list_strings(type, pattern,
+                                                              mapset, exclude,
+                                                              flag)]
 
 
-def list_grouped(type, pattern=None, check_search_path=True, flag=''):
-    """!List of elements grouped by mapsets.
+def list_grouped(type, pattern=None, check_search_path=True, exclude=None,
+                 flag=''):
+    """List of elements grouped by mapsets.
 
     Returns the output from running g.list, as a dictionary where the
     keys are mapset names and the values are lists of maps in that
@@ -1147,32 +1152,54 @@
     @param pattern pattern string
     @param check_search_path True to add mapsets for the search path with no
                              found elements
+    @param exclude pattern string to exclude maps from the research
     @param flag pattern type: 'r' (basic regexp), 'e' (extended regexp), or ''
                 (glob pattern)
 
     @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).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