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

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Dec 25 09:20:55 PST 2013


Author: martinl
Date: 2013-12-25 09:20:55 -0800 (Wed, 25 Dec 2013)
New Revision: 58527

Modified:
   grass/trunk/gui/wxpython/gmodeler/dialogs.py
   grass/trunk/gui/wxpython/gmodeler/frame.py
   grass/trunk/gui/wxpython/gmodeler/model.py
Log:
wxGUI/modeler: synchronize model objects, text->label


Modified: grass/trunk/gui/wxpython/gmodeler/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gmodeler/dialogs.py	2013-12-25 16:59:06 UTC (rev 58526)
+++ grass/trunk/gui/wxpython/gmodeler/dialogs.py	2013-12-25 17:20:55 UTC (rev 58527)
@@ -404,7 +404,7 @@
         self.condBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
                                     label=" %s " % _("Condition"))
         self.condText = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY,
-                                    value = shape.GetText())
+                                    value = shape.GetLabel())
         
         self.itemList = ItemCheckListCtrl(parent = self.panel,
                                           columns = [_("Label"),
@@ -560,7 +560,7 @@
         if flag is False:
             return
         
-        aId = int(self.itemListIf.GetItem(index, 0).GetText())
+        aId = int(self.itemListIf.GetItem(index, 0).GetLabel())
         if aId in self.itemListElse.GetItems()['checked']:
             self.itemListElse.CheckItemById(aId, False)
             
@@ -569,7 +569,7 @@
         if flag is False:
             return
         
-        aId = int(self.itemListElse.GetItem(index, 0).GetText())
+        aId = int(self.itemListElse.GetItem(index, 0).GetLabel())
         if aId in self.itemListIf.GetItems()['checked']:
             self.itemListIf.CheckItemById(aId, False)
         
@@ -720,7 +720,7 @@
         """!Finish editing of item"""
         itemIndex = event.GetIndex()
         columnIndex = event.GetColumn()
-        nameOld = self.GetItem(itemIndex, 0).GetText()
+        nameOld = self.GetItem(itemIndex, 0).GetLabel()
 
         if columnIndex == 0: # TODO
             event.Veto()
@@ -981,7 +981,7 @@
     def CheckItemById(self, aId, flag):
         """!Check/uncheck given item by id"""
         for i in range(self.GetItemCount()):
-            iId = int(self.GetItem(i, 0).GetText())
+            iId = int(self.GetItem(i, 0).GetLabel())
             if iId == aId:
                 self.CheckItem(i, flag)
                 break

Modified: grass/trunk/gui/wxpython/gmodeler/frame.py
===================================================================
--- grass/trunk/gui/wxpython/gmodeler/frame.py	2013-12-25 16:59:06 UTC (rev 58526)
+++ grass/trunk/gui/wxpython/gmodeler/frame.py	2013-12-25 17:20:55 UTC (rev 58527)
@@ -1129,7 +1129,7 @@
             dlg = ModelLoopDialog(parent = self.frame, shape = shape)
             dlg.CentreOnParent()
             if dlg.ShowModal() == wx.ID_OK:
-                shape.SetText(dlg.GetCondition())
+                shape.SetLabel(dlg.GetCondition())
                 model = self.frame.GetModel()
                 ids = dlg.GetItems()
                 alist = list()
@@ -1152,7 +1152,7 @@
             dlg = ModelConditionDialog(parent = self.frame, shape = shape)
             dlg.CentreOnParent()
             if dlg.ShowModal() == wx.ID_OK:
-                shape.SetText(dlg.GetCondition())
+                shape.SetLabel(dlg.GetCondition())
                 model = self.frame.GetModel()
                 ids = dlg.GetItems()
                 for b in ids.keys():

Modified: grass/trunk/gui/wxpython/gmodeler/model.py
===================================================================
--- grass/trunk/gui/wxpython/gmodeler/model.py	2013-12-25 16:59:06 UTC (rev 58526)
+++ grass/trunk/gui/wxpython/gmodeler/model.py	2013-12-25 17:20:55 UTC (rev 58527)
@@ -349,7 +349,7 @@
                                  y = loop['pos'][1],
                                  width = loop['size'][0],
                                  height = loop['size'][1],
-                                 text = loop['text'],
+                                 label = loop['text'],
                                  id = loop['id'])
             self.AddItem(loopItem)
 
@@ -360,7 +360,7 @@
                                            y = condition['pos'][1],
                                            width = condition['size'][0],
                                            height = condition['size'][1],
-                                           text = condition['text'],
+                                           label = condition['text'],
                                            id = condition['id'])
             self.AddItem(conditionItem)
 
@@ -429,7 +429,7 @@
                     if var not in variables:
                         report = True
                         for item in filter(lambda x: isinstance(x, ModelLoop), action.GetBlock()):
-                            if var in item.GetText():
+                            if var in item.GetLabel():
                                 report = False
                                 break
                         if report:
@@ -612,7 +612,7 @@
                     continue
                 self.RunAction(item, params, log, onDone)
             elif isinstance(item, ModelLoop):
-                cond = item.GetText()
+                cond = item.GetLabel()
                 # substitute variables in condition
                 variables = self.GetVariables()
                 for variable in variables:
@@ -802,8 +802,9 @@
         return result
 
 class ModelObject(object):
-    def __init__(self, id = -1):
+    def __init__(self, id = -1, label = ''):
         self.id   = id     # internal id, should be not changed
+        self.label = ''
         self.rels = list() # list of ModelRelations
         
         self.isEnabled = True
@@ -811,7 +812,15 @@
         
     def __del__(self):
         pass
-    
+
+    def GetLabel(self):
+        """!Get label"""
+        return self.label
+
+    def SetLabel(self, label=''):
+        """!Set label"""
+        self.label = label
+        
     def GetId(self):
         """!Get id"""
         return self.id
@@ -897,11 +906,10 @@
     """!Action class (GRASS module)"""
     def __init__(self, parent, x, y, id = -1, cmd = None, task = None,
                  width = None, height = None, label = None, comment = ''):
-        ModelObject.__init__(self, id)
+        ModelObject.__init__(self, id, label)
         
         self.parent  = parent
         self.task    = task
-        self.label   = label
         self.comment = comment
 
         if not width:
@@ -1394,17 +1402,12 @@
         self.param = param
 
 class ModelItem(ModelObject):
-    def __init__(self, parent, x, y, id = -1, width = None, height = None, text = '', items = []):
+    def __init__(self, parent, x, y, id = -1, width = None, height = None, label = '', items = []):
         """!Abstract class for loops and conditions"""
-        ModelObject.__init__(self, id)
+        ModelObject.__init__(self, id, label)
         self.parent  = parent
-        self.text    = text
         self.itemIds = list() # unordered
         
-    def GetText(self):
-        """!Get loop text"""
-        return self.text
-
     def GetItems(self, items):
         """!Get sorted items by id"""
         result = list()
@@ -1418,16 +1421,16 @@
         """!Set loop id"""
         self.id = id
 
-    def SetText(self, cond):
+    def SetLabel(self, label):
         """!Set loop text (condition)"""
-        self.text = cond
+        self.label = label
         self.ClearText()
-        self.AddText('(' + str(self.id) + ') ' + self.text)
+        self.AddText('(' + str(self.id) + ') ' + self.label)
 
     def GetLog(self):
         """!Get log info"""
-        if self.text:
-            return _("Condition: ") + self.text
+        if self.label:
+            return _("Condition: ") + self.label
         else:
             return _("Condition: not defined")
 
@@ -1440,10 +1443,9 @@
         self.rels = list()
    
 class ModelLoop(ModelItem, ogl.RectangleShape):
-    def __init__(self, parent, x, y, id=-1, idx=-1, width = None, height = None, text = '', items = []):
+    def __init__(self, parent, x, y, id=-1, idx=-1, width = None, height = None, label = '', items = []):
         """!Defines a loop"""
-        ModelItem.__init__(self, parent, x, y, id, width, height, text, items)
-        self.cond = text
+        ModelItem.__init__(self, parent, x, y, id, width, height, label, items)
         
         if not width:
             width = UserSettings.Get(group='modeler', key='loop', subkey=('size', 'width'))
@@ -1473,12 +1475,13 @@
         wxColor = wx.Colour(color[0], color[1], color[2])
         self.SetBrush(wx.Brush(wxColor))
 
-    def SetLabel(self, idx=-1):
+    def SetLabel(self, label=''):
+        self.label = label
         self.ClearText()
-        if self.cond:
-            self.AddText('(%d) %s' % (idx, self.cond))
+        if self.label:
+            self.AddText('(%d) %s' % (self.id, self.label))
         else:
-            self.AddText('(%d)' % (idx))
+            self.AddText('(%d)' % (self.id))
                          
     def Enable(self, enabled = True):
         """!Enable/disable action"""
@@ -2035,7 +2038,7 @@
         self.fd.write('%s<loop id="%d" pos="%d,%d" size="%d,%d">\n' % \
                           (' ' * self.indent, loop.GetId(), loop.GetX(), loop.GetY(),
                            loop.GetWidth(), loop.GetHeight()))
-        text = loop.GetText()
+        text = loop.GetLabel()
         self.indent += 4
         if text:
             self.fd.write('%s<condition>%s</condition>\n' %
@@ -2052,7 +2055,7 @@
         self.fd.write('%s<if-else id="%d" pos="%d,%d" size="%d,%d">\n' % \
                           (' ' * self.indent, condition.GetId(), condition.GetX(), condition.GetY(),
                            bbox[0], bbox[1]))
-        text = condition.GetText()
+        text = condition.GetLabel()
         self.indent += 4
         if text:
             self.fd.write('%s<condition>%s</condition>\n' %
@@ -2165,7 +2168,7 @@
         elif isinstance(item, ModelLoop) or isinstance(item, ModelCondition):
             # substitute condition
             variables = self.model.GetVariables()
-            cond = item.GetText()
+            cond = item.GetLabel()
             for variable in variables:
                 pattern = re.compile('%' + variable)
                 if pattern.search(cond):



More information about the grass-commit mailing list