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

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Oct 19 20:40:54 EDT 2011


Author: martinl
Date: 2011-10-19 17:40:53 -0700 (Wed, 19 Oct 2011)
New Revision: 48869

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py
Log:
wxGUI: add variable type: file
      check for missing variables
      (merge r48868 from trunk)


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py	2011-10-20 00:35:51 UTC (rev 48868)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py	2011-10-20 00:40:53 UTC (rev 48869)
@@ -409,8 +409,17 @@
         error string"""
         errList = list()
         for action in self.GetItems(objType = ModelAction):
-            task = menuform.GUI(show = None).ParseCommand(cmd = action.GetLog(string = False))
-            errList += task.get_cmd_error()
+            cmd = action.GetLog(string = False, substitute = True)
+            
+            task = menuform.GUI(show = None).ParseCommand(cmd = cmd)
+            errList += map(lambda x: cmd[0] + ': ' + x, task.get_cmd_error())
+            # check also variables
+            for opt in cmd[1:]:
+                if '=' not in opt:
+                    continue
+                key, value = opt.split('=', 1)
+                if '%' in value:
+                    errList.append(_("%s: undefined variable '%s'") % (cmd[0], value.strip()))
         
         return errList
 
@@ -430,7 +439,7 @@
         
         if statusbar:
             statusbar.SetStatusText(_('Running model...'), 0)
-        log.RunCmd(command = item.GetLog(string = False),
+        log.RunCmd(command = item.GetLog(string = False, substitute = True),
                    onDone = onDone)
         
         if name in params:
@@ -483,7 +492,7 @@
             
             err = dlg.GetErrors()
             if err:
-                GError(parent = self, message = unicode('\n'.join(err)))
+                GError(parent = parent, message = unicode('\n'.join(err)))
                 return
             
             # get variable values
@@ -547,7 +556,12 @@
                                 par[idx]['value'] = pattern.sub(var, par[idx]['value'])
                         self.RunAction(action, { action.GetName(): {'params': par } }, log, onDone)
         
+        # discard values
         if params:
+            for var in params['variables']['params']:
+                var['value'] = ''
+        
+        if params:
             dlg.Destroy()
         
     def DeleteIntermediateData(self, log):
@@ -614,7 +628,7 @@
                                     'idx' : idx }
             for name, values in self.variables.iteritems():
                 gtype = values.get('type', 'string')
-                if gtype in ('raster', 'vector', 'mapset'):
+                if gtype in ('raster', 'vector', 'mapset', 'file'):
                     gisprompt = True
                     prompt = gtype
                     if gtype == 'raster':
@@ -668,7 +682,7 @@
                                          'idx'   : idx }
                     result[name]['params'].append(p)
             idx += 1
-
+        
         self.variablesParams = result # record parameters
         
         return result
@@ -1829,37 +1843,44 @@
         """!Get properties dialog"""
         return self.propWin
 
-    def GetLog(self, string = True):
-        """!Get logging info"""
+    def GetLog(self, string = True, substitute = False):
+        """!Get logging info
+
+        @param string True to get cmd as a string otherwise a list
+        @param substitute True to substitute variables
+        """
         cmd = self.task.get_cmd(ignoreErrors = True, ignoreRequired = True)
         
         # substitute variables
-        variables = self.parent.GetVariables()
-        fparams = self.parent.GetVariables(params = True)
-        params = None
-        for values in fparams.itervalues():
-            params = values['params']
-            break
+        if substitute:
+            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 = None
-            if params:
-                for p in params:
-                    if variable == p.get('name', ''):
-                        value = p.get('value', '')
+            for variable in variables:
+                pattern= re.compile('%' + variable)
+                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:
+                            cmd[idx] = pattern.sub('', cmd[idx])
+                            self.isValid = False
                         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
-                idx += 1
+                    idx += 1
         
         if string:
             if cmd is None:
@@ -3933,7 +3954,8 @@
                                          _("string"),
                                          _("raster"),
                                          _("vector"),
-                                         _("mapset")])
+                                         _("mapset"),
+                                         _("file")])
         self.value = wx.TextCtrl(parent = self, id = wx.ID_ANY)
         self.desc = wx.TextCtrl(parent = self, id = wx.ID_ANY)
         



More information about the grass-commit mailing list