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

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Apr 2 06:41:05 EDT 2010


Author: martinl
Date: 2010-04-02 06:41:04 -0400 (Fri, 02 Apr 2010)
New Revision: 41661

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/gcmd.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py
Log:
wxGUI/gmodeler: run/validate model
(merge r41659 from trunk)


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gcmd.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gcmd.py	2010-04-02 10:40:34 UTC (rev 41660)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gcmd.py	2010-04-02 10:41:04 UTC (rev 41661)
@@ -66,20 +66,32 @@
         if msgType == 'error':
             caption = _('Error')
             style = wx.OK | wx.ICON_ERROR | wx.CENTRE
+        elif msgType == 'info':
+            caption = _('Message')
+            style = wx.OK | wx.ICON_INFORMATION | wx.CENTRE
+        elif msgType == 'warning':
+            caption = _('Warning')
+            style = wx.OK | wx.ICON_WARNING | wx.CENTRE
         
-        exception = traceback.format_exc()
-        reason = exception.split('\n')[-2].split(':', 1)[-1].strip()
+        if msgType != 'error':
+            wx.MessageBox(parent = parent,
+                          message = message,
+                          caption = caption,
+                          style = style)
+        else:
+            exception = traceback.format_exc()
+            reason = exception.split('\n')[-2].split(':', 1)[-1].strip()
         
-        if Debug.get_level() > 0:
-            sys.stderr.write(exception)
+            if Debug.get_level() > 0:
+                sys.stderr.write(exception)
         
-        wx.MessageBox(parent = parent,
-                      message = message + '\n\n%s: %s\n\n%s' % \
-                          (_('Reason'),
-                           reason, exception),
-                      caption = caption,
-                      style = style)
-        
+            wx.MessageBox(parent = parent,
+                          message = message + '\n\n%s: %s\n\n%s' % \
+                              (_('Reason'),
+                               reason, exception),
+                          caption = caption,
+                          style = style)
+            
 class GException(Exception):
     """!Generic exception"""
     def __init__(self, message, title=_("Error"), parent=None):

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py	2010-04-02 10:40:34 UTC (rev 41660)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py	2010-04-02 10:41:04 UTC (rev 41661)
@@ -204,6 +204,24 @@
         
     def OnRunModel(self, event):
         """!Run entire model"""
+        if len(self.actions) < 1:
+            GMessage(parent = self, 
+                     message = _('Model is empty. Nothing to run.'),
+                     msgType = 'info')
+            return
+    
+        errList = self._validateModel()
+        if errList:
+            dlg = wx.MessageDialog(parent = self,
+                                   message = _('Model is not valid. Do you want to '
+                                               'run the model anyway?\n\n%s') % '\n'.join(errList),
+                                   caption=_("Run model?"),
+                                   style = wx.YES_NO | wx.NO_DEFAULT |
+                                   wx.ICON_QUESTION | wx.CENTRE)
+            ret = dlg.ShowModal()
+            if ret != wx.ID_YES:
+                return
+        
         for action in self.actions:
             self.SetStatusText(_('Running model...'), 0)
             self.goutput.RunCmd(command = action.GetLog(string = False),
@@ -213,11 +231,38 @@
         """!Computation finished"""
         self.SetStatusText('', 0)
         
-    def OnValidateModel(self, event):
+    def OnValidateModel(self, event, showMsg = True):
         """!Validate entire model"""
-        for s in self.actions:
-            print s
+        if len(self.actions) < 1:
+            GMessage(parent = self, 
+                     message = _('Model is empty. Nothing to validate.'),
+                     msgType = 'info')
+            return
         
+        errList = self._validateModel()
+        
+        if errList:
+            GMessage(parent = self,
+                     message = _('Model is not valid.\n\n%s') % '\n'.join(errList),
+                     msgType = 'warning')
+        else:
+            GMessage(parent = self,
+                     message = _('Model is valid.'),
+                     msgType = 'info')
+
+    def _validateModel(self):
+        """!Validate model"""
+        self.SetStatusText(_('Validating model...'), 0)
+        errList = list()
+        for action in self.actions:
+            task = menuform.GUI().ParseCommand(cmd = action.GetLog(string = False),
+                                               show = None)
+            errList += task.getCmdError()
+        
+        self.SetStatusText('', 0)
+        
+        return errList
+    
     def OnRemoveItem(self, event):
         """!Remove item from model"""
         pass

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py	2010-04-02 10:40:34 UTC (rev 41660)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py	2010-04-02 10:41:04 UTC (rev 41661)
@@ -381,7 +381,22 @@
             return
         
         param['value'] = aValue
-                
+        
+    def getCmdError(self):
+        """!Get error string produced by getCmd(ignoreErrors = False)
+
+        @return list of errors
+        """
+        errorList = list()
+        
+        for p in self.params:
+            if p.get('value', '') == '' and p.get('required', 'no') != 'no':
+                if p.get('default', '') == '':
+                    errorList.append(_("Parameter '%(name)s' (%(desc)s) is missing.") % \
+                                         {'name' : p['name'], 'desc' : p['description']})
+        
+        return errorList
+    
     def getCmd(self, ignoreErrors = False):
         """!Produce an array of command name and arguments for feeding
         into some execve-like command processor.
@@ -391,9 +406,7 @@
         for GRASS.
         """
         cmd = [self.name]
-        errors = 0
-        errStr = ""
-
+        
         for flag in self.flags:
             if 'value' in flag and flag['value']:
                 if len(flag['name']) > 1: # e.g. overwrite
@@ -406,16 +419,13 @@
                     cmd += [ '%s=%s' % ( p['name'], p['default'] ) ]
                 elif ignoreErrors is False:
                     cmd += [ '%s=%s' % ( p['name'], _('<required>') ) ]
-                    errStr += _("Parameter %(name)s (%(desc)s) is missing.\n") % \
-                        {'name' : p['name'], 'desc' : p['description']}
-                    errors += 1
             elif p.get('value','') != '' and p['value'] != p.get('default','') :
                 # Output only values that have been set, and different from defaults
                 cmd += [ '%s=%s' % ( p['name'], p['value'] ) ]
         
-        if errors and not ignoreErrors:
-            raise ValueError, errStr
-
+        if ignoreErrors is False:
+            raise ValueError, '\n'.join(self.getCmdError())
+        
         return cmd
 
     def set_options(self, opts):
@@ -864,7 +874,7 @@
 
     def OnApply(self, event):
         """!Apply the command"""
-        if self.parent.GetName() == 'Modeler':
+        if self.parent and self.parent.GetName() == 'Modeler':
             cmd = self.createCmd(ignoreErrors = True)
         else:
             cmd = self.createCmd()
@@ -1681,7 +1691,7 @@
             cmd = self.task.getCmd(ignoreErrors=ignoreErrors)
         except ValueError, err:
             dlg = wx.MessageDialog(parent=self,
-                                   message=utils.UnicodeString(err),
+                                   message=unicode(err),
                                    caption=_("Error in %s") % self.task.name,
                                    style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
             dlg.ShowModal()
@@ -1766,14 +1776,13 @@
     
     def ParseCommand(self, cmd, gmpath=None, completed=None, parentframe=None,
                      show=True, modal=False):
-        """
-        Parse command
+        """!Parse command
 
         Note: cmd is given as list
 
         If command is given with options, return validated cmd list:
-        * add key name for first parameter if not given
-        * change mapname to mapname at mapset
+         - add key name for first parameter if not given
+         - change mapname to mapname at mapset
         """
         start = time.time()
         dcmd_params = {}



More information about the grass-commit mailing list