[GRASS-SVN] r58521 - grass/trunk/gui/wxpython/gmodeler

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Dec 25 01:31:18 PST 2013


Author: martinl
Date: 2013-12-25 01:31:18 -0800 (Wed, 25 Dec 2013)
New Revision: 58521

Modified:
   grass/trunk/gui/wxpython/gmodeler/dialogs.py
   grass/trunk/gui/wxpython/gmodeler/model.py
Log:
wxGUI/modeler: fix handling model item labels
               write labels to model file


Modified: grass/trunk/gui/wxpython/gmodeler/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gmodeler/dialogs.py	2013-12-24 12:14:39 UTC (rev 58520)
+++ grass/trunk/gui/wxpython/gmodeler/dialogs.py	2013-12-25 09:31:18 UTC (rev 58521)
@@ -333,7 +333,7 @@
                                                label = _("Command:")),
                           pos = (0, 0))
             gridSizer.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
-                                               label = shape.GetName()),
+                                               label = shape.GetLabel()),
                           pos = (0, 1))
             gridSizer.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
                                                label = _("Option:")),
@@ -780,7 +780,7 @@
         
         if self.shape:
             if isinstance(self.shape, ModelCondition):
-                if self.GetName() == 'ElseBlockList':
+                if self.GetLabel() == 'ElseBlockList':
                     shapeItems = map(lambda x: x.GetId(), self.shape.GetItems()['else'])
                 else:
                     shapeItems = map(lambda x: x.GetId(), self.shape.GetItems()['if'])
@@ -799,7 +799,7 @@
                 continue
             
             if len(self.columns) == 2:
-                self.itemDataMap[i] = [action.GetName(),
+                self.itemDataMap[i] = [action.GetLabel(),
                                        action.GetLog()]
                 aId = action.GetBlockId()
                 if action.GetId() in shapeItems:
@@ -812,7 +812,7 @@
                     bId = _('No')
                 else:
                     bId = _("Yes")
-                self.itemDataMap[i] = [action.GetName(),
+                self.itemDataMap[i] = [action.GetLabel(),
                                        bId,
                                        action.GetLog()]
             
@@ -867,13 +867,13 @@
         """!Finish editing of item"""
         itemIndex = event.GetIndex()
         columnIndex = event.GetColumn()
-        
         self.itemDataMap[itemIndex][columnIndex] = event.GetText()
-        
-        action = self.frame.GetModel().GetItem(itemIndex)
+        action = self.frame.GetModel().GetItem(itemIndex + 1)
         if not action:
             event.Veto()
-        
+            return
+
+        action.SetLabel(label = event.GetText())
         self.frame.ModelChanged()
 
     def OnReload(self, event = None):
@@ -959,7 +959,7 @@
         
     def OnCheckItem(self, index, flag):
         """!Item checked/unchecked"""
-        name = self.GetName()
+        name = self.GetLabel()
         if name == 'IfBlockList' and self.window:
             self.window.OnCheckItemIf(index, flag)
         elif name == 'ElseBlockList' and self.window:

Modified: grass/trunk/gui/wxpython/gmodeler/model.py
===================================================================
--- grass/trunk/gui/wxpython/gmodeler/model.py	2013-12-24 12:14:39 UTC (rev 58520)
+++ grass/trunk/gui/wxpython/gmodeler/model.py	2013-12-25 09:31:18 UTC (rev 58521)
@@ -140,7 +140,8 @@
     def Normalize(self):
         iId = 1
         for item in self.items:
-            item.SetLabel(iId)
+            item.SetId(iId)
+            item.SetLabel()
             iId += 1
         
     def GetNextId(self):
@@ -303,7 +304,8 @@
                                      width = action['size'][0],
                                      height = action['size'][1],
                                      task = action['task'],
-                                     id = action['id'])
+                                     id = action['id'],
+                                     label = action['label'])
             
             if action['disabled']:
                 actionItem.Enable(False)
@@ -391,7 +393,8 @@
             self.items.append(newItem)
         i = 1
         for item in self.items:
-            item.SetLabel(i)
+            item.SetId(i)
+            item.SetLabel()
             i += 1
         
     def IsValid(self):
@@ -518,7 +521,7 @@
         @param onPrepare on-prepare method
         @param statusbar wx.StatusBar instance or None
         """
-        name = item.GetName()
+        name = item.GetLabel()
         if name in params:
             paramsOrig = item.GetParams(dcopy = True)
             item.MergeParams(params[name])
@@ -774,7 +777,7 @@
         for action in self.GetItems(objType = ModelAction):
             if not action.IsEnabled():
                 continue
-            name   = action.GetName()
+            name   = action.GetLabel()
             params = action.GetParams()
             for f in params['flags']:
                 if f.get('parameterized', False):
@@ -891,12 +894,14 @@
     
 class ModelAction(ModelObject, ogl.RectangleShape):
     """!Action class (GRASS module)"""
-    def __init__(self, parent, x, y, id = -1, cmd = None, task = None, width = None, height = None):
+    def __init__(self, parent, x, y, id = -1, cmd = None, task = None,
+                 width = None, height = None, label = None):
         ModelObject.__init__(self, id)
         
         self.parent  = parent
         self.task    = task
-        
+        self.label   = label
+
         if not width:
             width = UserSettings.Get(group='modeler', key='action', subkey=('size', 'width'))
         if not height:
@@ -961,14 +966,26 @@
         pen.SetWidth(width)
         self.SetPen(pen)
 
-    def SetLabel(self, idx=-1):
-        cmd = self.task.get_cmd(ignoreErrors = True)
-        self.ClearText()
-        if cmd and len(cmd) > 0:
-            self.AddText('(%d) %s' % (idx, cmd[0]))
+    def SetLabel(self, label=None):
+        """!Set label
+
+        @param label if None use command string instead
+        """
+        if label:
+            self.label = label 
+        elif self.label:
+            label = self.label
         else:
-            self.AddText('(%d) <<%s>>' % (idx, _("unknown")))
+            try:
+                label = self.task.get_cmd(ignoreErrors = True)[0]
+            except:
+                label = _("unknown")
         
+        idx = self.GetId()
+        
+        self.ClearText()
+        self.AddText('(%d) %s' % (idx, label))
+                
     def SetProperties(self, params, propwin):
         """!Record properties dialog"""
         self.task.params = params['params']
@@ -1028,8 +1045,11 @@
         
         return cmd
     
-    def GetName(self):
+    def GetLabel(self):
         """!Get name"""
+        if self.label:
+            return self.label
+        
         cmd = self.task.get_cmd(ignoreErrors = True)
         if cmd and len(cmd) > 0:
             return cmd[0]
@@ -1100,7 +1120,7 @@
         """!Find data item by name"""
         for rel in self.GetRelations():
             data = rel.GetData()
-            if name == rel.GetName() and name in data.GetName():
+            if name == rel.GetLabel() and name in data.GetLabel():
                 return data
         
         return None
@@ -1177,17 +1197,17 @@
         """!Get logging info"""
         name = list()
         for rel in self.GetRelations():
-            name.append(rel.GetName())
+            name.append(rel.GetLabel())
         if name:
             return '/'.join(name) + '=' + self.value + ' (' + self.prompt + ')'
         else:
             return self.value + ' (' + self.prompt + ')'
 
-    def GetName(self):
+    def GetLabel(self):
         """!Get list of names"""
         name = list()
         for rel in self.GetRelations():
-            name.append(rel.GetName())
+            name.append(rel.GetLabel())
         
         return name
     
@@ -1221,7 +1241,7 @@
                     action = rel.GetFrom()
                 
                 task = GUI(show = None).ParseCommand(cmd = action.GetLog(string = False))
-                task.set_param(rel.GetName(), self.value)
+                task.set_param(rel.GetLabel(), self.value)
                 action.SetParams(params = task.get_options())
         
     def GetPropDialog(self):
@@ -1277,7 +1297,7 @@
         self.ClearText()
         name = []
         for rel in self.GetRelations():
-            name.append(rel.GetName())
+            name.append(rel.GetLabel())
         self.AddText('/'.join(name))
         if self.value:
             self.AddText(self.value)
@@ -1330,7 +1350,7 @@
         
         return None
     
-    def GetName(self):
+    def GetLabel(self):
         """!Get parameter name"""
         return self.param
     
@@ -1462,7 +1482,7 @@
     def Update(self):
         self._setBrush()
         
-    def GetName(self):
+    def GetLabel(self):
         """!Get name"""
         return _("loop")
     
@@ -1509,7 +1529,7 @@
             else:
                 self.AddText('(' + str(self.id) + ')')
 
-    def GetName(self):
+    def GetLabel(self):
         """!Get name"""
         return _("if-else")
 
@@ -1645,12 +1665,14 @@
                 task = None
             
             aId = int(action.get('id', -1))
+            label = action.get('name')
             
             self.actions.append({ 'pos'      : pos,
                                   'size'     : size,
                                   'task'     : task,
                                   'id'       : aId,
-                                  'disabled' : disabled })
+                                  'disabled' : disabled,
+                                  'label'    : label})
             
     def _getDim(self, node):
         """!Get position and size of shape"""
@@ -1908,7 +1930,7 @@
     def _action(self, action):
         """!Write actions"""
         self.fd.write('%s<action id="%d" name="%s" pos="%d,%d" size="%d,%d">\n' % \
-                          (' ' * self.indent, action.GetId(), action.GetName(), action.GetX(), action.GetY(),
+                          (' ' * self.indent, action.GetId(), EncodeString(action.GetLabel()), action.GetX(), action.GetY(),
                            action.GetWidth(), action.GetHeight()))
         self.indent += 4
         self.fd.write('%s<task name="%s">\n' % (' ' * self.indent, action.GetLog(string = False)[0]))
@@ -1973,7 +1995,7 @@
                     else:
                         aid  = rel.GetFrom().GetId()
                     self.fd.write('%s<relation dir="%s" id="%d" name="%s">\n' % \
-                                      (' ' * self.indent, ft, aid, rel.GetName()))
+                                      (' ' * self.indent, ft, aid, rel.GetLabel()))
                     self.indent += 4
                     for point in rel.GetLineControlPoints()[1:-1]:
                         self.fd.write('%s<point>\n' % (' ' * self.indent))



More information about the grass-commit mailing list