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

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Oct 25 08:51:37 EDT 2011


Author: martinl
Date: 2011-10-25 05:51:37 -0700 (Tue, 25 Oct 2011)
New Revision: 48931

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py
Log:
wxGUI/modeler: merge SetValid() with SetParameterized()
	       (merge r48930 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-25 12:47:12 UTC (rev 48930)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py	2011-10-25 12:51:37 UTC (rev 48931)
@@ -290,23 +290,7 @@
             
             self.AddItem(actionItem)
             
-            task = actionItem.GetTask()
-            parameterized = False
-            valid = True
-            for f in task.get_options()['flags']:
-                if f.get('parameterized', False):
-                    parameterized = True
-                    break
-            for p in task.get_options()['params']:
-                if p.get('required', 'no') != 'no' and \
-                        p.get('value', '') == '' and \
-                        p.get('default', '') == '':
-                    valid = False
-                if p.get('parameterized', False):
-                    parameterized = True
-            
-            actionItem.SetValid(valid)
-            actionItem.SetParameterized(parameterized)
+            actionItem.SetValid(actionItem.GetTask().get_options())
             actionItem.GetLog() # substitute variables (-> valid/invalid)
         
         # load data & relations
@@ -1284,7 +1268,7 @@
         # show properties dialog
         win = action.GetPropDialog()
         if not win:
-            if len(action.GetLog(string = False)) > 1:
+            if action.IsValid():
                 self.GetOptData(dcmd = action.GetLog(string = False), layer = action,
                                 params = action.GetParams(), propwin = None)
             else:
@@ -1390,28 +1374,8 @@
                     self.AddLine(rel)
                     data.Update()
             
-            # valid ?
-            valid = True
-            for p in params['params']:
-                if p.get('required', False) and \
-                        p.get('value', '') == '' and \
-                        p.get('default', '') == '':
-                    valid = False
-                    break
-            layer.SetValid(valid)
-
-            # parameterized ?
-            parameterized = False
-            for f in params['flags']:
-                if f.get('parameterized', False):
-                    parameterized = True
-                    break
-            if not parameterized:
-                for p in params['params']:
-                    if p.get('parameterized', False):
-                        parameterized = True
-                        break
-            layer.SetParameterized(parameterized)
+            # valid / parameterized ?
+            layer.SetValid(params)
             
             self.canvas.Refresh()
         
@@ -1503,15 +1467,7 @@
         
         # final updates
         for action in self.model.GetItems(objType = ModelAction):
-            valid = True
-            params = action.GetParams()
-            for p in params['params']:
-                if p.get('required', False) and \
-                        p.get('value', '') == '' and \
-                        p.get('default', '') == '':
-                    valid = False
-                    break
-            action.SetValid(valid)
+            action.SetValid(action.GetParams())
             action.Update()
         
         self.canvas.Refresh(True)
@@ -1794,7 +1750,10 @@
             self._setPen()
             self._setBrush()
             self.SetId(id)
-            
+        
+        if self.task:
+            self.SetValid(self.task.get_options())
+        
     def _setBrush(self, running = False):
         """!Set brush"""
         if running:
@@ -1923,17 +1882,35 @@
                 self.task.set_param(p['name'],
                                     p.get('value', ''))
         
-    def SetValid(self, isvalid):
-        """!Set instance to be valid/invalid"""
-        self.isValid = isvalid
-        self._setBrush()
+    def SetValid(self, options):
+        """!Set validity for action
         
-    def SetParameterized(self, isparameterized):
-        """!Set action parameterized"""
-        self.isParameterized = isparameterized
-        if self.parent.GetCanvas():                
+        @param options dictionary with flags and params (gtask)
+        """
+        self.isValid = True
+        self.isParameterized = False
+        
+        for f in options['flags']:
+            if f.get('parameterized', False):
+                self.IsParameterized = True
+                break
+        
+        for p in options['params']:
+            if self.isValid and p.get('required', False) and \
+                    p.get('value', '') == '' and \
+                    p.get('default', '') == '':
+                self.isValid = False
+            if not self.isParameterized and p.get('parameterized', False):
+                self.isParameterized = True
+        
+        if self.parent.GetCanvas():
+            self._setBrush()
             self._setPen()
         
+    def IsValid(self):
+        """!Check validity (all required parameters set)"""
+        return self.isValid
+    
     def IsParameterized(self):
         """!Check if action is parameterized"""
         return self.isParameterized
@@ -1960,7 +1937,7 @@
         self._setBrush()
         self._setPen()
         ogl.RectangleShape.OnDraw(self, dc)
-    
+
 class ModelData(ModelObject, ogl.EllipseShape):
     def __init__(self, parent, x, y, value = '', prompt = '', width = None, height = None):
         """Data item class



More information about the grass-commit mailing list