[GRASS-SVN] r42564 - grass/branches/develbranch_6/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jun 14 09:57:44 EDT 2010


Author: martinl
Date: 2010-06-14 13:57:44 +0000 (Mon, 14 Jun 2010)
New Revision: 42564

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py
Log:
wxGUI/modeler: fix runing model with variables
(merge r42563 from trunk)


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py	2010-06-14 13:49:22 UTC (rev 42563)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py	2010-06-14 13:57:44 UTC (rev 42564)
@@ -84,6 +84,7 @@
                             'author'      : getpass.getuser() }
         # model variables
         self.variables = dict()
+        self.variablesParams = dict()
         
         self.canvas  = canvas
         
@@ -103,8 +104,11 @@
         """!Get model properties"""
         return self.properties
 
-    def GetVariables(self):
+    def GetVariables(self, params = False):
         """!Get model variables"""
+        if params:
+            return self.variablesParams
+        
         return self.variables
     
     def SetVariables(self, data):
@@ -317,12 +321,12 @@
 
     def IsParameterized(self):
         """!Return True if model is parameterized"""
-        if self.Parametrize():
+        if self.Parameterize():
             return True
         
         return False
     
-    def Parametrize(self):
+    def Parameterize(self):
         """!Return parameterized options"""
         result = dict()
         idx = 0
@@ -332,23 +336,37 @@
                                        'params' : params,
                                        'idx' : idx }
             for name, values in self.variables.iteritems():
-                params.append({ 'gisprompt' : False,
+                gtype = values.get('type', 'string')
+                if gtype in ('raster', 'vector'):
+                    gisprompt = True
+                    prompt = gtype
+                    if gtype == 'raster':
+                        element = 'cell'
+                    else:
+                        element = 'vector'
+                    ptype = 'string'
+                else:
+                    gisprompt = False
+                    prompt = None
+                    element = None
+                    ptype = gtype
+                params.append({ 'gisprompt' : gisprompt,
                                 'multiple'  : 'no',
                                 'description' : values.get('description', ''),
                                 'guidependency' : '',
-                                'default' : values.get('value', ''),
+                                'default' : '',
                                 'age' : None,
                                 'required' : 'yes',
-                                'value' : '',
+                                'value' : values.get('value', ''),
                                 'label' : '',
                                 'guisection' : '',
                                 'key_desc' : '',
                                 'values' : list(),
                                 'parameterized' : False,
                                 'values_desc' : list(),
-                                'prompt' : None,
-                                'element' : None,
-                                'type' : values.get('type', 'string'),
+                                'prompt' : prompt,
+                                'element' : element,
+                                'type' : ptype,
                                 'name' : name })
             
             idx += 1
@@ -373,6 +391,8 @@
                                          'idx'   : idx }
                     result[name]['params'].append(p)
             idx += 1
+
+        self.variablesParams = result # record parameters
         
         return result
     
@@ -748,7 +768,7 @@
                 return
         
         # parametrization
-        params = self.model.Parametrize()
+        params = self.model.Parameterize()
         if params:
             dlg = ModelParamDialog(parent = self,
                                    params = params)
@@ -759,6 +779,12 @@
                 dlg.Destroy()
                 return
         
+        err = dlg.GetErrors()
+        if err:
+            GMessage(parent = self,
+                     message = unicode('\n'.join(err)))
+            return
+        
         self.goutput.cmdThread.SetId(-1)
         for action in self.model.GetActions():
             if not action.IsEnabled():
@@ -1445,17 +1471,32 @@
         cmd = self.task.getCmd(ignoreErrors = True)
         # substitute variables
         variables = self.parent.GetVariables()
+        fparams = self.parent.GetVariables(params = True)
+        params = None
+        for values in fparams.itervalues():
+            params = values['params']
+            break
+        
         for variable in variables:
             pattern= re.compile('%' + variable)
-            value = variables[variable].get('value', '')
+            value = None
+            if params:
+                for p in params:
+                    if variable == p.get('name', ''):
+                        value = p.get('value', '')
+                        break
+            if not value:
+                value = variables[variable].get('value', '')
+            
             for idx in range(len(cmd)):
                 if pattern.search(cmd[idx]):
                     if value:
                         cmd[idx] = pattern.sub(value, cmd[idx])
                     else:
                         self.isValid = False
-                        break
+                    break
                 idx += 1
+        
         if string:
             if cmd is None:
                 return ''
@@ -2912,6 +2953,7 @@
         """
         self.parent = parent
         self.params = params
+        self.tasks  = list() # list of tasks/pages
         
         wx.Dialog.__init__(self, parent = parent, id = id, title = title, style = style, **kwargs)
         
@@ -2981,9 +3023,18 @@
         task.params = params['params']
         
         panel = menuform.cmdPanel(parent = self, id = wx.ID_ANY, task = task)
+        self.tasks.append(task)
         
         return panel
 
+    def GetErrors(self):
+        """!Check for errors, get list of messages"""
+        errList = list()
+        for task in self.tasks:
+            errList += task.getCmdError()
+        
+        return errList
+    
 class VariablesDialog(wx.Dialog, listmix.ColumnSorterMixin):
     def __init__(self, parent, id = wx.ID_ANY, title = _("Manage model variables"),
                  style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER,
@@ -3020,7 +3071,9 @@
         self.type = wx.Choice(parent = self, id = wx.ID_ANY,
                               choices = [_("integer"),
                                          _("float"),
-                                         _("string")])
+                                         _("string"),
+                                         _("raster"),
+                                         _("vector")])
         self.value = wx.TextCtrl(parent = self, id = wx.ID_ANY, size = (150, -1))
         self.desc = wx.TextCtrl(parent = self, id = wx.ID_ANY, size = (350, -1))
         

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py	2010-06-14 13:49:22 UTC (rev 42563)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py	2010-06-14 13:57:44 UTC (rev 42564)
@@ -1501,7 +1501,7 @@
                     title_txt.SetToolTipString(tooltip)
 
             if p == first_param:
-                if type(p['wxId']) == type(1):
+                if p.has_key('wxId') and len(p['wxId']) > 0:
                     self.FindWindowById(p['wxId'][0]).SetFocus()
         
         #
@@ -1748,7 +1748,7 @@
                     porf['parameterized'] = me.IsChecked()
                 else:
                     porf['value'] = me.GetValue()
-        
+                
         self.OnUpdateValues(event)
         
         event.Skip()
@@ -1756,6 +1756,10 @@
     def OnUpdateSelection(self, event):
         """!Update dialog (layers, tables, columns, etc.)
         """
+        if not hasattr(self.parent, "updateThread"):
+            if event:
+                event.Skip()
+            return
         if event:
             self.parent.updateThread.Update(UpdateDialog,
                                             self,



More information about the grass-commit mailing list