[GRASS-SVN] r54560 - in grass/trunk/gui/wxpython: gmodeler gui_core

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jan 7 09:21:25 PST 2013


Author: martinl
Date: 2013-01-07 09:21:24 -0800 (Mon, 07 Jan 2013)
New Revision: 54560

Modified:
   grass/trunk/gui/wxpython/gmodeler/model.py
   grass/trunk/gui/wxpython/gui_core/forms.py
   grass/trunk/gui/wxpython/gui_core/gselect.py
Log:
wxGUI: list extra map items for Graphical Modeler


Modified: grass/trunk/gui/wxpython/gmodeler/model.py
===================================================================
--- grass/trunk/gui/wxpython/gmodeler/model.py	2013-01-07 16:23:15 UTC (rev 54559)
+++ grass/trunk/gui/wxpython/gmodeler/model.py	2013-01-07 17:21:24 UTC (rev 54560)
@@ -183,6 +183,16 @@
         
         return None
 
+    def GetMaps(self, prompt):
+        """!Get list of maps of selected type
+
+        @param promt to filter maps"""
+        maps = list()
+        for data in self.GetData():
+            if prompt == data.GetPrompt():
+                maps.append(data.GetValue())
+        return maps
+
     def GetData(self):
         """!Get list of data items"""
         result = list()

Modified: grass/trunk/gui/wxpython/gui_core/forms.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/forms.py	2013-01-07 16:23:15 UTC (rev 54559)
+++ grass/trunk/gui/wxpython/gui_core/forms.py	2013-01-07 17:21:24 UTC (rev 54560)
@@ -1176,12 +1176,16 @@
                                     element_dict = {'rast': 'strds', 'vect': 'stvds', 'rast3d': 'str3ds'}
                                     elem = element_dict[type_param.get('default')]
                         
-
+                        if self.parent.modeler:
+                            extraItems = {_('Graphical Modeler') : self.parent.modeler.GetModel().GetMaps(p.get('prompt'))}
+                        else:
+                            extraItems = None
                         selection = gselect.Select(parent = which_panel, id = wx.ID_ANY,
                                                    size = globalvar.DIALOG_GSELECT_SIZE,
-                                                   type = elem,
-                                                   multiple = multiple, nmaps = len(p.get('key_desc', [])),
-                                                   mapsets = mapsets, fullyQualified = p.get('age', 'old') == 'old')
+                                                   type = elem, multiple = multiple, nmaps = len(p.get('key_desc', [])),
+                                                   mapsets = mapsets, fullyQualified = p.get('age', 'old') == 'old',
+                                                   extraItems = extraItems)
+                        
                         value = self._getValue(p)
                         if value:
                             selection.SetValue(value)

Modified: grass/trunk/gui/wxpython/gui_core/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/gselect.py	2013-01-07 16:23:15 UTC (rev 54559)
+++ grass/trunk/gui/wxpython/gui_core/gselect.py	2013-01-07 17:21:24 UTC (rev 54560)
@@ -66,7 +66,7 @@
     def __init__(self, parent, id = wx.ID_ANY, size = globalvar.DIALOG_GSELECT_SIZE,
                  type = None, multiple = False, nmaps = 1,
                  mapsets = None, updateOnPopup = True, onPopup = None,
-                 fullyQualified = True):
+                 fullyQualified = True, extraItems = {}):
         """!Custom control to create a ComboBox with a tree control to
         display and select GIS elements within acessible mapsets.
         Elements can be selected with mouse. Can allow multiple
@@ -80,6 +80,7 @@
         @param updateOnPopup True for updating list of elements on popup
         @param onPopup function to be called on Popup
         @param fullyQualified True to provide fully qualified names (map at mapset)
+        @param extraItems extra items to add (given as dictionary) - see gmodeler for usage
         """
         wx.combo.ComboCtrl.__init__(self, parent=parent, id=id, size=size)
         self.GetChildren()[0].SetName("Select")
@@ -92,7 +93,7 @@
             self.tcp.SetData(type = type, mapsets = mapsets,
                              multiple = multiple, nmaps = nmaps,
                              updateOnPopup = updateOnPopup, onPopup = onPopup,
-                             fullyQualified = fullyQualified)
+                             fullyQualified = fullyQualified, extraItems = extraItems)
         self.GetChildren()[0].Bind(wx.EVT_KEY_UP, self.OnKeyUp)
      
     def OnKeyUp(self, event):
@@ -165,6 +166,7 @@
         self.updateOnPopup = True
         self.onPopup = None
         self.fullyQualified = True
+        self.extraItems = dict()
         
         self.SetFilter(None)
         
@@ -342,12 +344,21 @@
                                                 check_search_path = False)
             else:
                 filesdict = grass.list_grouped(elementdict[element],
-                                           check_search_path = False)
+                                               check_search_path = False)
         
+        # add extra items first
+        if self.extraItems:
+            for group, items in self.extraItems.iteritems():
+                node = self.AddItem(group, node = True)
+                self.seltree.SetItemTextColour(node, wx.Colour(50, 50, 200))
+                for item in items:
+                    self.AddItem(item, node = False, parent = node)
+                self.seltree.ExpandAllChildren(node)
+        
         # list of mapsets in current location
         if mapsets is None:
             mapsets = grass.mapsets(search_path = True)
-        
+                        
         # current mapset first
         if curr_mapset in mapsets and mapsets[0] != curr_mapset:
             mapsets.remove(curr_mapset)
@@ -511,7 +522,7 @@
                 self.value = []
             else:
                 fullName = self.seltree.GetItemText(item)
-                if self.fullyQualified:
+                if self.fullyQualified and self.seltree.GetPyData(item)['mapset']:
                     fullName += '@' + self.seltree.GetPyData(item)['mapset']
                 
                 if self.multiple:
@@ -548,7 +559,7 @@
                 return
             
             fullName = self.seltree.GetItemText(item)
-            if self.fullyQualified:
+            if self.fullyQualified and self.seltree.GetPyData(item)['mapset']:
                 fullName += '@' + self.seltree.GetPyData(item)['mapset']
             
             if self.multiple:
@@ -584,6 +595,8 @@
             self.onPopup = kargs['onPopup']
         if 'fullyQualified' in kargs:
             self.fullyQualified = kargs['fullyQualified']
+        if 'extraItems' in kargs:
+            self.extraItems = kargs['extraItems']
         
     def GetType(self):
         """!Get element type



More information about the grass-commit mailing list