[GRASS-SVN] r42728 - in grass/branches/develbranch_6/gui/wxpython: . gui_modules xml

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Jul 8 15:30:53 EDT 2010


Author: martinl
Date: 2010-07-08 19:30:53 +0000 (Thu, 08 Jul 2010)
New Revision: 42728

Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/location_wizard.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py
   grass/branches/develbranch_6/gui/wxpython/wxgui.py
   grass/branches/develbranch_6/gui/wxpython/xml/menudata_modeler.xml
Log:
wxGUI/modeler: progress in looping
(merge r42727 from trunk)


Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py	2010-07-08 19:29:09 UTC (rev 42727)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py	2010-07-08 19:30:53 UTC (rev 42728)
@@ -178,6 +178,24 @@
         
         return None
 
+    def FindData(self, value, prompt):
+        """!Find data item in the model
+
+        @param value value
+        @param prompt prompt
+
+        @return ModelData instance
+        @return None if not found
+        """
+        for action in self.GetActions():
+            for rel in action.GetRelations():
+                dataItem = rel.GetData()
+                if dataItem.GetValue() == value and \
+                        dataItem.GetPrompt() == prompt:
+                    return dataItem
+        
+        return None
+                
     def LoadModel(self, filename):
         """!Load model definition stored in GRASS Model XML file (gxm)
         
@@ -256,8 +274,8 @@
                 else:
                     relation = ModelRelation(actionItem, dataItem, rel['name'])
                 relation.SetControlPoints(rel['points'])
+                actionItem.AddRelation(relation)
                 dataItem.AddRelation(relation)
-                actionItem.AddRelation(relation)
             
             dataItem.Update()
                    
@@ -566,7 +584,9 @@
         
     def OnCanvasRefresh(self, event):
         """!Refresh canvas"""
+        self.SetStatusText(_("Redrawing model..."), 0)
         self.GetCanvas().Refresh()
+        self.SetStatusText("", 0)
 
     def OnCloseWindow(self, event):
         """!Close window"""
@@ -841,15 +861,28 @@
         
         self.goutput.cmdThread.SetId(-1)
         for item in self.model.GetItems():
-            print item
             if not item.IsEnabled():
                 continue
             if isinstance(item, ModelAction):
                 self._runAction(item, params)
             elif isinstance(item, ModelLoop):
-                print item.GetText()
+                cond = item.GetText()
+                # substitute variables in condition
+                variables = self.model.GetVariables()
+                for variable in variables:
+                    pattern = re.compile('%' + variable)
+                    if pattern.search(cond):
+                        value = variables[variable].get('value', '')
+                        vtype = variables[variable].get('type', 'string')
+                        if vtype == 'string':
+                            value = '"' + value + '"'
+                        cond = pattern.sub(value, cond)
+                # split condition
+                condVar, condText = re.split('\s*in\s*', cond)
+                
                 for action in item.GetActions():
-                    self._runAction(action, params)
+                    for vars()[condVar] in eval(condText):
+                        self._runAction(action, params)
         
         if params:
             dlg.Destroy()
@@ -1160,6 +1193,7 @@
         self._addEvent(action)
         self.model.AddItem(action)
         
+        self.actionPanel.Update()
         self.canvas.Refresh()
         time.sleep(.1)
         
@@ -1174,7 +1208,7 @@
         
         if win:
             win.Raise()
-
+        
     def OnAddData(self, event):
         """!Add data item to model"""
         # add action to canvas
@@ -1239,37 +1273,32 @@
                         continue
                     
                     data = self.model.FindData(p.get('value', ''),
-                                              p.get('prompt', ''))
+                                               p.get('prompt', ''))
                     if data:
                         if p.get('age', 'old') == 'old':
                             rel = ModelRelation(data, layer, p.get('name', ''))
-                            data.AddRelation(rel, direction = 'from')
-                            self.AddLine(rel)
                         else:
                             rel = ModelRelation(layer, data, p.get('name', ''))
-                            data.AddRelation(rel, direction = 'to')
-                            self.AddLine(rel)
+                        layer.AddRelation(rel)
+                        data.AddRelation(rel)
+                        self.AddLine(rel)
                         data.Update()
                         continue
                     
                     data = ModelData(self, value = p.get('value', ''),
                                      prompt = p.get('prompt', ''),
                                      x = x.pop(), y = height/2)
-                    layer.AddData(data)
+                    self._addEvent(data)
                     self.canvas.diagram.AddShape(data)
                     data.Show(True)
-                    
-                    self._addEvent(data)
-                    self.model.AddData(data)
-                    
+                                                            
                     if p.get('age', 'old') == 'old':
                         rel = ModelRelation(data, layer, p.get('name', ''))
-                        data.AddRelation(rel, direction = 'from')
-                        self.AddLine(rel)
                     else:
                         rel = ModelRelation(layer, data, p.get('name', ''))
-                        data.AddRelation(rel, direction = 'to')
-                        self.AddLine(rel)
+                    layer.AddRelation(rel)
+                    data.AddRelation(rel)
+                    self.AddLine(rel)
                     data.Update()
             
             # valid ?
@@ -2011,8 +2040,13 @@
             ### shape.SetPropDialog(dlg)
             dlg.CentreOnParent()
             if dlg.ShowModal() == wx.ID_OK:
-                shape.SetActions(dlg.GetActions())
+                shape.SetText(dlg.GetCondition())
+                alist = list()
+                for aId in dlg.GetActions():
+                    alist.append(self.frame.GetModel().GetAction(aId))
+                shape.SetActions(alist)
                 self.frame.DefineLoop(shape)
+            self.frame.GetCanvas().Refresh()
             
             dlg.Destroy()
         
@@ -2175,18 +2209,22 @@
         self.SetSize((500, 275))
         
     def _layout(self):
+        cmdSizer = wx.StaticBoxSizer(self.cmdBox, wx.VERTICAL)
+        cmdSizer.Add(item = self.cmd_prompt, proportion = 1,
+                     flag = wx.EXPAND)
+        
         btnSizer = wx.StdDialogButtonSizer()
         btnSizer.AddButton(self.btnCancel)
         btnSizer.AddButton(self.btnOk)
         btnSizer.Realize()
         
         mainSizer = wx.BoxSizer(wx.VERTICAL)
-        mainSizer.Add(item=self.search, proportion=0,
-                      flag=wx.EXPAND | wx.ALL, border=3)
-        mainSizer.Add(item=self.cmd_prompt, proportion=1,
-                      flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border=3)
-        mainSizer.Add(item=btnSizer, proportion=0,
-                      flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
+        mainSizer.Add(item = self.search, proportion = 0,
+                      flag = wx.EXPAND | wx.ALL, border = 3)
+        mainSizer.Add(item = cmdSizer, proportion = 1,
+                      flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border = 3)
+        mainSizer.Add(item = btnSizer, proportion = 0,
+                      flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
         
         self.panel.SetSizer(mainSizer)
         mainSizer.Fit(self.panel)
@@ -2269,6 +2307,19 @@
     def GetTo(self):
         """!Get id of 'to' shape"""
         return self.toShape
+
+    def GetData(self):
+        """!Get related ModelData instance
+
+        @return ModelData instance
+        @return None if not found
+        """
+        if isinstance(self.fromShape, ModelData):
+            return self.fromShape
+        elif isinstance(self.toShape, ModelData):
+            return self.toShape
+        
+        return None
     
     def GetName(self):
         """!Get parameter name"""
@@ -2556,14 +2607,11 @@
         dataList = list()
         for action in model.GetActions():
             for rel in action.GetRelations():
-                if rel.GetFrom() == action:
-                    dataItem = rel.GetTo()
-                else:
-                    dataItem = rel.GetFrom()
+                dataItem = rel.GetData()
                 if dataItem not in dataList:
                     dataList.append(dataItem)
         self._data(dataList)
-                
+        
         self._footer()
 
     def _filterValue(self, value):
@@ -2615,6 +2663,8 @@
 
     def _variables(self):
         """!Write model variables"""
+        if not self.variables:
+            return
         self.fd.write('%s<variables>\n' % (' ' * self.indent))
         self.indent += 4
         for name, values in self.variables.iteritems():
@@ -2634,14 +2684,12 @@
         
     def _items(self):
         """!Write actions/loops"""
-        self.indent += 4
         for item in self.items:
             if isinstance(item, ModelAction):
                 self._action(item)
             elif isinstance(item, ModelLoop):
                 self._loop(item)
-        self.indent -= 4
-
+        
     def _action(self, action):
         """!Write actions"""
         self.fd.write('%s<action id="%d" name="%s" pos="%d,%d" size="%d,%d">\n' % \
@@ -2686,7 +2734,6 @@
                 
     def _data(self, dataList):
         """!Write data"""
-        self.indent += 4
         for data in dataList:
             self.fd.write('%s<data pos="%d,%d" size="%d,%d">\n' % \
                               (' ' * self.indent, data.GetX(), data.GetY(),
@@ -2739,9 +2786,8 @@
                           (' ' * self.indent, self._filterValue(text)))
         for action in loop.GetActions():
             self.fd.write('%s<loop-action>%d</loop-action>\n' %
-                          (' ' * self.indent, action))
+                          (' ' * self.indent, action.GetId()))
         self.indent -= 4
-        
         self.fd.write('%s</loop>\n' % (' ' * self.indent))
             
 class PreferencesDialog(PreferencesBaseDialog):
@@ -3577,7 +3623,13 @@
     def SetActions(self, actions):
         """!Set actions (id)"""
         self.actions = actions
-        
+
+    def SetText(self, cond):
+        """!Set loop text (condition)"""
+        self.text = cond
+        self.ClearText()
+        self.AddText('(' + str(self.id) + ') ' + self.text)
+    
 class ModelLoopDialog(wx.Dialog):
     """!Loop properties dialog"""
     def __init__(self, parent, shape, id = wx.ID_ANY, title = _("Loop properties"),
@@ -3595,9 +3647,9 @@
                                     value = shape.GetText())
         self.listBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
                                     label=" %s " % _("List of actions in loop"))
-        self.actionList = ActionListCtrl(parent = self.panel,
-                                         columns = [_("ID"), _("Name"),
-                                                    _("Command")])
+        self.actionList = ActionCheckListCtrl(parent = self.panel,
+                                              columns = [_("ID"), _("Name"),
+                                                         _("Command")])
         
         self.actionList.Populate(self.parent.GetModel().GetActions())
         
@@ -3649,6 +3701,10 @@
         
         return ids
         
+    def GetCondition(self):
+        """!Get loop condition"""
+        return self.condText.GetValue()
+    
 class ActionPanel(wx.Panel):
     def __init__(self, parent, id = wx.ID_ANY,
                  **kwargs):
@@ -3685,8 +3741,10 @@
         self.list.OnReload(None)
         
 class ActionListCtrl(ModelListCtrl):
-    def __init__(self, parent, columns, **kwargs):
+    def __init__(self, parent, columns, disablePopup = False, **kwargs):
         """!List of model actions"""
+        self.disablePopup = disablePopup
+        
         ModelListCtrl.__init__(self, parent, columns, **kwargs)
         self.SetColumnWidth(1, 100)
         self.SetColumnWidth(2, 65)
@@ -3785,6 +3843,9 @@
 
     def OnRightUp(self, event):
         """!Mouse right button up"""
+        if self.disablePopup:
+            return
+        
         if not hasattr(self, "popupID1"):
             self.popupID1 = wx.NewId()
             self.popupID2 = wx.NewId()
@@ -3816,14 +3877,23 @@
         
         aId = 1
         for item in model.GetItems():
-            print item
             item.SetId(aId)
             aId += 1
         
         self.OnReload(None)
         self.frame.GetCanvas().Refresh()
         self.frame.ModelChanged()
-    
+
+class ActionCheckListCtrl(ActionListCtrl, listmix.CheckListCtrlMixin):
+    def __init__(self, parent, columns, **kwargs):
+        ActionListCtrl.__init__(self, parent, columns, disablePopup = True, **kwargs)
+        listmix.CheckListCtrlMixin.__init__(self)
+        self.SetColumnWidth(0, 50)
+        
+    def OnBeginEdit(self, event):
+        """!Disable editing"""
+        event.Veto()
+        
 def main():
     app = wx.PySimpleApp()
     wx.InitAllImageHandlers()

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/location_wizard.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/location_wizard.py	2010-07-08 19:29:09 UTC (rev 42727)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/location_wizard.py	2010-07-08 19:30:53 UTC (rev 42728)
@@ -33,7 +33,6 @@
 """
 import os
 import shutil
-import re
 import string
 import sys
 import locale

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py	2010-07-08 19:29:09 UTC (rev 42727)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py	2010-07-08 19:30:53 UTC (rev 42728)
@@ -1426,12 +1426,12 @@
              wx.ITEM_NORMAL, Icons['modelToPython'].GetLabel(), Icons['modelToPython'].GetDesc(),
              self.parent.OnExportPython),
             ('', '', '', '', '', '', ''),
+            (self.action, 'action', Icons['modelActionAdd'].GetBitmap(),
+             wx.ITEM_NORMAL, Icons['modelActionAdd'].GetLabel(), Icons['modelActionAdd'].GetDesc(),
+             self.parent.OnAddAction),
             (self.data, 'data', Icons['modelDataAdd'].GetBitmap(),
              wx.ITEM_NORMAL, Icons['modelDataAdd'].GetLabel(), Icons['modelDataAdd'].GetDesc(),
              self.parent.OnAddData),
-            (self.action, 'action', Icons['modelActionAdd'].GetBitmap(),
-             wx.ITEM_NORMAL, Icons['modelActionAdd'].GetLabel(), Icons['modelActionAdd'].GetDesc(),
-             self.parent.OnAddAction),
             (self.relation, 'relation', Icons['modelRelation'].GetBitmap(),
              wx.ITEM_NORMAL, Icons['modelRelation'].GetLabel(), Icons['modelRelation'].GetDesc(),
              self.parent.OnDefineRelation),
@@ -1439,12 +1439,12 @@
             (self.redraw, 'redraw', Icons['modelRedraw'].GetBitmap(),
              wx.ITEM_NORMAL, Icons['modelRedraw'].GetLabel(), Icons['modelRedraw'].GetDesc(),
              self.parent.OnCanvasRefresh),
+            (self.validate, 'validate', Icons['modelValidate'].GetBitmap(),
+             wx.ITEM_NORMAL, Icons['modelValidate'].GetLabel(), Icons['modelValidate'].GetDesc(),
+             self.parent.OnValidateModel),
             (self.run, 'run', Icons['modelRun'].GetBitmap(),
              wx.ITEM_NORMAL, Icons['modelRun'].GetLabel(), Icons['modelRun'].GetDesc(),
              self.parent.OnRunModel),
-            (self.validate, 'validate', Icons['modelValidate'].GetBitmap(),
-             wx.ITEM_NORMAL, Icons['modelValidate'].GetLabel(), Icons['modelValidate'].GetDesc(),
-             self.parent.OnValidateModel),
             ('', '', '', '', '', '', ''),
             (self.settings, "settings", Icons["modelSettings"].GetBitmap(),
              wx.ITEM_NORMAL, Icons["modelSettings"].GetLabel(), Icons["modelSettings"].GetDesc(),

Modified: grass/branches/develbranch_6/gui/wxpython/wxgui.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/wxgui.py	2010-07-08 19:29:09 UTC (rev 42727)
+++ grass/branches/develbranch_6/gui/wxpython/wxgui.py	2010-07-08 19:30:53 UTC (rev 42728)
@@ -22,7 +22,6 @@
 import sys
 import os
 import time
-import re
 import string
 import getopt
 import platform

Modified: grass/branches/develbranch_6/gui/wxpython/xml/menudata_modeler.xml
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/xml/menudata_modeler.xml	2010-07-08 19:29:09 UTC (rev 42727)
+++ grass/branches/develbranch_6/gui/wxpython/xml/menudata_modeler.xml	2010-07-08 19:30:53 UTC (rev 42728)
@@ -65,18 +65,18 @@
       <label>&amp;Model</label>
       <items>
 	<menuitem>
+	  <label>Add action</label>
+	  <help>Add action (GRASS module) to model</help>
+	  <handler>OnAddAction</handler>
+	  <shortcut>Ctrl+A</shortcut>
+	</menuitem>
+	<menuitem>
 	  <label>Add data</label>
 	  <help>Add data item to model</help>
 	  <handler>OnAddData</handler>
 	  <shortcut>Ctrl+D</shortcut>
 	</menuitem>
 	<menuitem>
-	  <label>Add action</label>
-	  <help>Add action (GRASS module) to model</help>
-	  <handler>OnAddAction</handler>
-	  <shortcut>Ctrl+A</shortcut>
-	</menuitem>
-	<menuitem>
 	  <label>Define relation</label>
 	  <help>Define relation between data and action items</help>
 	  <handler>OnDefineRelation</handler>



More information about the grass-commit mailing list