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

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Dec 25 08:23:15 PST 2013


Author: martinl
Date: 2013-12-25 08:23:15 -0800 (Wed, 25 Dec 2013)
New Revision: 58522

Modified:
   grass/trunk/gui/wxpython/gmodeler/frame.py
   grass/trunk/gui/wxpython/gmodeler/model.py
Log:
wxGUI/modeler: implement comments #2148


Modified: grass/trunk/gui/wxpython/gmodeler/frame.py
===================================================================
--- grass/trunk/gui/wxpython/gmodeler/frame.py	2013-12-25 09:31:18 UTC (rev 58521)
+++ grass/trunk/gui/wxpython/gmodeler/frame.py	2013-12-25 16:23:15 UTC (rev 58522)
@@ -100,7 +100,7 @@
         self.canvas = ModelCanvas(self)
         self.canvas.SetBackgroundColour(wx.WHITE)
         self.canvas.SetCursor(self.cursors["default"])
-        
+
         self.model = Model(self.canvas)
         
         self.variablePanel = VariablePanel(parent = self)
@@ -121,7 +121,7 @@
         self.Bind(EVT_CMD_RUN, self.OnCmdRun)
         self.Bind(EVT_CMD_DONE, self.OnCmdDone)
         self.Bind(EVT_CMD_PREPARE, self.OnCmdPrepare)
-
+        
         self.notebook.AddPage(page = self.canvas, text=_('Model'), name = 'model')
         self.notebook.AddPage(page = self.itemPanel, text=_('Items'), name = 'items')
         self.notebook.AddPage(page = self.variablePanel, text=_('Variables'), name = 'variables')
@@ -1001,7 +1001,7 @@
         self.SetScrollbars(20, 20, 2000/20, 2000/20)
         
         self.Bind(wx.EVT_CHAR,  self.OnChar)
-        
+
     def OnChar(self, event):
         """!Key pressed"""
         kc = event.GetKeyCode()
@@ -1201,7 +1201,8 @@
         if not hasattr (self, "popupID"):
             self.popupID = dict()
             for key in ('remove', 'enable', 'addPoint',
-                        'delPoint', 'intermediate', 'props', 'id'):
+                        'delPoint', 'intermediate', 'props', 'id',
+                        'label', 'comment'):
                 self.popupID[key] = wx.NewId()
         
         # record coordinates
@@ -1222,7 +1223,12 @@
             else:
                 popupMenu.Append(self.popupID['enable'], text=_('Enable'))
                 self.frame.Bind(wx.EVT_MENU, self.OnEnable, id = self.popupID['enable'])
-        
+            popupMenu.AppendSeparator()
+            popupMenu.Append(self.popupID['label'], text=_('Set label'))
+            self.frame.Bind(wx.EVT_MENU, self.OnSetLabel, id = self.popupID['label'])
+            popupMenu.Append(self.popupID['comment'], text=_('Set comment'))
+            self.frame.Bind(wx.EVT_MENU, self.OnSetComment, id = self.popupID['comment'])
+
         if isinstance(shape, ModelRelation):
             popupMenu.AppendSeparator()
             popupMenu.Append(self.popupID['addPoint'], text=_('Add control point'))
@@ -1264,7 +1270,29 @@
         shape.Enable(enable)
         self.frame.ModelChanged()
         self.frame.canvas.Refresh()
-        
+
+    def OnSetLabel(self, event):
+        shape = self.GetShape()
+        dlg = wx.TextEntryDialog(parent = self.frame, message = _("Label:"), caption = _("Set label"),
+                                 defaultValue = shape.GetLabel())
+        if dlg.ShowModal() == wx.ID_OK:
+            label = dlg.GetValue()
+            shape.SetLabel(label)
+            self.frame.ModelChanged()
+            self.frame.itemPanel.Update()
+            self.frame.canvas.Refresh()
+        dlg.Destroy()
+    
+    def OnSetComment(self, event):
+        shape = self.GetShape()
+        dlg = wx.TextEntryDialog(parent = self.frame, message = _("Comment:"), caption = _("Set comment"),
+                                 defaultValue = shape.GetComment(), style = wx.OK | wx.CANCEL | wx.CENTRE | wx.TE_MULTILINE)
+        if dlg.ShowModal() == wx.ID_OK:
+            comment = dlg.GetValue()
+            shape.SetComment(comment)
+            self.frame.ModelChanged()
+        dlg.Destroy()
+
     def _onSelectShape(self, shape):
         canvas = shape.GetCanvas()
         dc = wx.ClientDC(canvas)

Modified: grass/trunk/gui/wxpython/gmodeler/model.py
===================================================================
--- grass/trunk/gui/wxpython/gmodeler/model.py	2013-12-25 09:31:18 UTC (rev 58521)
+++ grass/trunk/gui/wxpython/gmodeler/model.py	2013-12-25 16:23:15 UTC (rev 58522)
@@ -305,7 +305,8 @@
                                      height = action['size'][1],
                                      task = action['task'],
                                      id = action['id'],
-                                     label = action['label'])
+                                     label = action['label'],
+                                     comment = action['comment'])
             
             if action['disabled']:
                 actionItem.Enable(False)
@@ -895,12 +896,13 @@
 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, label = None):
+                 width = None, height = None, label = None, comment = ''):
         ModelObject.__init__(self, id)
         
         self.parent  = parent
         self.task    = task
         self.label   = label
+        self.comment = comment
 
         if not width:
             width = UserSettings.Get(group='modeler', key='action', subkey=('size', 'width'))
@@ -985,7 +987,15 @@
         
         self.ClearText()
         self.AddText('(%d) %s' % (idx, label))
-                
+
+    def SetComment(self, comment):
+        """!Set comment"""
+        self.comment = comment
+
+    def GetComment(self):
+        """!Get comment"""
+        return self.comment
+
     def SetProperties(self, params, propwin):
         """!Record properties dialog"""
         self.task.params = params['params']
@@ -1666,13 +1676,19 @@
             
             aId = int(action.get('id', -1))
             label = action.get('name')
+            comment = action.find('comment')
+            if comment is not None:
+                commentString = comment.text
+            else:
+                commentString = ''
             
             self.actions.append({ 'pos'      : pos,
                                   'size'     : size,
                                   'task'     : task,
                                   'id'       : aId,
                                   'disabled' : disabled,
-                                  'label'    : label})
+                                  'label'    : label,
+                                  'comment'  : commentString})
             
     def _getDim(self, node):
         """!Get position and size of shape"""
@@ -1933,6 +1949,9 @@
                           (' ' * self.indent, action.GetId(), EncodeString(action.GetLabel()), action.GetX(), action.GetY(),
                            action.GetWidth(), action.GetHeight()))
         self.indent += 4
+        comment = action.GetComment()
+        if comment:
+            self.fd.write('%s<comment>%s</comment>\n' % (' ' * self.indent, EncodeString(comment)))
         self.fd.write('%s<task name="%s">\n' % (' ' * self.indent, action.GetLog(string = False)[0]))
         self.indent += 4
         if not action.IsEnabled():



More information about the grass-commit mailing list