[GRASS-SVN] r41595 - in grass/branches/develbranch_6/gui: icons/grass2 wxpython/gui_modules wxpython/icons wxpython/xml

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Mar 28 11:59:23 EDT 2010


Author: martinl
Date: 2010-03-28 11:59:09 -0400 (Sun, 28 Mar 2010)
New Revision: 41595

Added:
   grass/branches/develbranch_6/gui/icons/grass2/map-add.png
Modified:
   grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py
   grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py
   grass/branches/develbranch_6/gui/wxpython/icons/grass2_icons.py
   grass/branches/develbranch_6/gui/wxpython/icons/grass_icons.py
   grass/branches/develbranch_6/gui/wxpython/icons/icon.py
   grass/branches/develbranch_6/gui/wxpython/icons/silk_icons.py
   grass/branches/develbranch_6/gui/wxpython/xml/menudata_modeler.xml
Log:
wxGUI/modeler: add data item partly implemented
(merge from r41594 from trunk)


Copied: grass/branches/develbranch_6/gui/icons/grass2/map-add.png (from rev 41594, grass/trunk/gui/icons/grass2/map-add.png)
===================================================================
(Binary files differ)

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py	2010-03-28 15:55:47 UTC (rev 41594)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py	2010-03-28 15:59:09 UTC (rev 41595)
@@ -18,6 +18,7 @@
 
 import os
 import shlex
+import time
 
 import globalvar
 if not os.getenv("GRASS_WXBUNDLED"):
@@ -44,8 +45,8 @@
         @param kwargs wx.Frames' arguments
         """
         self.parent = parent
-        
-        self.actions = list() # list of recoreded actions
+        self.searchDialog = None # module search dialog
+        self.actions = list()    # list of recoreded actions
 
         wx.Frame.__init__(self, parent = parent, id = id, title = title, **kwargs)
         self.SetName("Modeler")
@@ -102,17 +103,26 @@
 
     def OnAddAction(self, event):
         """!Add action to model"""
-        dlg = ModelSearchDialog(self)
-        dlg.CentreOnParent()
+        debug = False
+        if debug == False:
+            if self.searchDialog is None:
+                self.searchDialog = ModelSearchDialog(self)
+                self.searchDialog.CentreOnParent()
+            else:
+                self.searchDialog.Reset()
+            
+            if self.searchDialog.ShowModal() == wx.ID_CANCEL:
+                self.searchDialog.Hide()
+                return
+            
+            cmd = self.searchDialog.GetCmd()
+            self.searchDialog.Hide()
+        else:
+            cmd = ['r.buffer']
         
-        if dlg.ShowModal() == wx.CANCEL:
-            dlg.Destroy()
-            return
-        
-        cmd = dlg.GetCmd()
-        dlg.Destroy()
-        
-        action = ModelAction(self, cmd = cmd, x = 100, y = 100)
+        # add action to canvas
+        width, height = self.canvas.GetSize()
+        action = ModelAction(self, cmd = cmd, x = width/2, y = height/2)
         self.canvas.diagram.AddShape(action)
         action.Show(True)
         
@@ -125,11 +135,31 @@
         self.actions.append(action)
         
         self.canvas.Refresh()
+        time.sleep(.1)
         
+        # show properties dialog
+        win = action.GetPropDialog()
+        if not win:
+            module = menuform.GUI().ParseCommand(action.GetCmd(string = False),
+                                                 completed = (self.GetOptData, action, None),
+                                                 parentframe = self, show = True)
+        elif not win.IsShown():
+            win.Show()
+        if win:
+            win.Raise()
+
+    def OnAddData(self, event):
+        """!Add data item to model"""
+        
     def OnHelp(self, event):
         """!Display manual page"""
         grass.run_command('g.manual',
                           entry = 'wxGUI.Modeler')
+
+    def GetOptData(self, dcmd, layer, params, propwin):
+        """!Process action data"""
+        layer.SetProperties(dcmd, params, propwin)
+        self.SetStatusText(layer.GetCmd(), 0)
         
 class ModelCanvas(ogl.ShapeCanvas):
     """!Canvas where model is drawn"""
@@ -146,8 +176,11 @@
 class ModelAction(ogl.RectangleShape):
     """!Action class (GRASS module)"""
     def __init__(self, parent, x, y, cmd = None, width = 100, height = 50):
-        self.parent = parent
-        
+        self.parent  = parent
+        self.cmd     = cmd
+        self.params  = None
+        self.propWin = None
+
         ogl.RectangleShape.__init__(self, width, height)
         
         # self.Draggable(True)
@@ -156,11 +189,31 @@
         self.SetY(y)
         self.SetPen(wx.BLACK_PEN)
         self.SetBrush(wx.LIGHT_GREY_BRUSH)
-        if cmd and len(cmd) > 0:
-            self.AddText(cmd[0])
+        if self.cmd and len(self.cmd) > 0:
+            self.AddText(self.cmd[0])
         else:
             self.AddText('<<module>>')
-       
+
+    def SetProperties(self, dcmd, params, propwin):
+        """!Record properties dialog"""
+        self.cmd     = dcmd
+        self.params  = params
+        self.propWin = propwin
+
+    def GetPropDialog(self):
+        """!Get properties dialog"""
+        return self.propWin
+
+    def GetCmd(self, string = True):
+        """!Get command"""
+        if string:
+            if self.cmd is None:
+                return ''
+            else:
+                return ' '.join(self.cmd)
+        
+        return self.cmd
+    
 class ModelEvtHandler(ogl.ShapeEvtHandler):
     """!Model event handler class"""
     def __init__(self, log, frame):
@@ -171,15 +224,23 @@
     def OnLeftClick(self, x, y, keys = 0, attachment = 0):
         """!Left mouse button pressed -> update statusbar"""
         shape = self.GetShape()
+        self.log.SetStatusText(shape.GetCmd(), 0)
         
     def OnLeftDoubleClick(self, x, y, keys = 0, attachment = 0):
         """!Left mouse button pressed (double-click) -> show properties"""
         shape = self.GetShape()
-        module = menuform.GUI()
-        # module.ParseCommand(['r.buffer'],
-        # completed = (None , None, None),
-        # parentframe = self.frame, show = True)
-
+        win = shape.GetPropDialog()
+        if not win:
+            module = menuform.GUI().ParseCommand(shape.cmd,
+                                                 completed = (self.frame.GetOptData, shape, None),
+                                                 parentframe = self.frame, show = True)
+        
+        elif not win.IsShown():
+            win.Show()
+        
+        if win:
+            win.Raise()
+            
 class ModelSearchDialog(wx.Dialog):
     def __init__(self, parent, id = wx.ID_ANY, title = _("Find GRASS module"),
                  style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
@@ -260,8 +321,14 @@
         return cmd
 
     def OnOk(self, event):
-        self.Close()
-    
+        self.btnOk.SetFocus()
+        
+    def Reset(self):
+        """!Reset dialog"""
+        self.searchBy.SetSelection(0)
+        self.search.SetValue('')
+        self.cmd_prompt.OnCmdErase(None)
+        
 def main():
     app = wx.PySimpleApp()
     frame = ModelFrame(parent = None)

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py	2010-03-28 15:55:47 UTC (rev 41594)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/menuform.py	2010-03-28 15:59:09 UTC (rev 41595)
@@ -375,8 +375,7 @@
         param['value'] = aValue
                 
     def getCmd(self, ignoreErrors = False):
-        """
-        Produce an array of command name and arguments for feeding
+        """!Produce an array of command name and arguments for feeding
         into some execve-like command processor.
 
         If ignoreErrors==True then it will return whatever has been
@@ -397,7 +396,7 @@
             if p.get('value','') == '' and p.get('required','no') != 'no':
                 if p.get('default', '') != '':
                     cmd += [ '%s=%s' % ( p['name'], p['default'] ) ]
-                else:
+                elif ignoreErrors is False:
                     cmd += [ '%s=%s' % ( p['name'], _('<required>') ) ]
                     errStr += _("Parameter %(name)s (%(desc)s) is missing.\n") % \
                         {'name' : p['name'], 'desc' : p['description']}
@@ -405,6 +404,7 @@
             elif p.get('value','') != '' and p['value'] != p.get('default','') :
                 # Output only values that have been set, and different from defaults
                 cmd += [ '%s=%s' % ( p['name'], p['value'] ) ]
+        
         if errors and not ignoreErrors:
             raise ValueError, errStr
 
@@ -755,7 +755,7 @@
         guisizer.Add(item=btnsizer, proportion=0, flag=wx.ALIGN_CENTER | wx.LEFT | wx.RIGHT,
                      border = 30)
 
-        if self.parent is not None:
+        if self.parent and self.parent.GetName() != 'Modeler':
             self.outputType = None
             for p in self.task.params:
                 if p.get('name', '') == 'output':
@@ -856,8 +856,11 @@
 
     def OnApply(self, event):
         """!Apply the command"""
-        cmd = self.createCmd()
-
+        if self.parent.GetName() == 'Modeler':
+            cmd = self.createCmd(ignoreErrors = True)
+        else:
+            cmd = self.createCmd()
+            
         if cmd is not None and self.get_dcmd is not None:
             # return d.* command to layer tree for rendering
             self.get_dcmd(cmd, self.layer, {"params": self.task.params, 
@@ -1657,25 +1660,24 @@
                                             None,
                                             self.task)
             
-    def createCmd( self, ignoreErrors = False ):
-        """
-        Produce a command line string (list) or feeding into GRASS.
+    def createCmd(self, ignoreErrors = False):
+        """!Produce a command line string (list) or feeding into GRASS.
 
         If ignoreErrors==True then it will return whatever has been
         built so far, even though it would not be a correct command
         for GRASS.
         """
         try:
-            cmd = self.task.getCmd( ignoreErrors=ignoreErrors )
+            cmd = self.task.getCmd(ignoreErrors=ignoreErrors)
         except ValueError, err:
             dlg = wx.MessageDialog(parent=self,
-                                   message=unicode(err),
+                                   message=utils.UnicodeString(err),
                                    caption=_("Error in %s") % self.task.name,
                                    style=wx.OK | wx.ICON_ERROR | wx.CENTRE)
             dlg.ShowModal()
             dlg.Destroy()
             cmd = None
-
+        
         return cmd
     
     def OnSize(self, event):

Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py	2010-03-28 15:55:47 UTC (rev 41594)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py	2010-03-28 15:59:09 UTC (rev 41595)
@@ -1388,6 +1388,7 @@
         self.open = wx.NewId()
         self.save = wx.NewId()
         self.action = wx.NewId()
+        self.data = wx.NewId()
         self.quit = wx.NewId()
         
         # tool, label, bitmap, kind, shortHelp, longHelp, handler
@@ -1402,6 +1403,9 @@
              wx.ITEM_NORMAL, Icons['modelSave'].GetLabel(), Icons['modelSave'].GetDesc(),
              self.parent.OnModelSave),
             ('', '', '', '', '', '', ''),
+            (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),

Modified: grass/branches/develbranch_6/gui/wxpython/icons/grass2_icons.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/icons/grass2_icons.py	2010-03-28 15:55:47 UTC (rev 41594)
+++ grass/branches/develbranch_6/gui/wxpython/icons/grass2_icons.py	2010-03-28 15:59:09 UTC (rev 41595)
@@ -105,4 +105,5 @@
     "nvizSettings"   : 'settings.png',
     # modeler
     "modelActionAdd" : 'layer-add.png',
+    "modelDataAdd"   : 'map-add.png',
     }

Modified: grass/branches/develbranch_6/gui/wxpython/icons/grass_icons.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/icons/grass_icons.py	2010-03-28 15:55:47 UTC (rev 41594)
+++ grass/branches/develbranch_6/gui/wxpython/icons/grass_icons.py	2010-03-28 15:59:09 UTC (rev 41595)
@@ -107,4 +107,5 @@
     "nvizSettings" : 'edit-color.gif',  
     # modeler
     "modelActionAdd" : wx.ART_ERROR,
+    "modelDataAdd"   : wx.ART_ERROR,
     }

Modified: grass/branches/develbranch_6/gui/wxpython/icons/icon.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/icons/icon.py	2010-03-28 15:55:47 UTC (rev 41594)
+++ grass/branches/develbranch_6/gui/wxpython/icons/icon.py	2010-03-28 15:59:09 UTC (rev 41595)
@@ -343,6 +343,8 @@
                                 label=_("Save current model to file (Ctrl+S)")),
     "modelActionAdd" : MetaIcon (img=Icons["modelActionAdd"],
                                  label=_("Add action (GRASS module) to model")),
+    "modelDataAdd" : MetaIcon (img=Icons["modelDataAdd"],
+                                 label=_("Add data item to model")),
     }
 
 # testing ...

Modified: grass/branches/develbranch_6/gui/wxpython/icons/silk_icons.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/icons/silk_icons.py	2010-03-28 15:55:47 UTC (rev 41594)
+++ grass/branches/develbranch_6/gui/wxpython/icons/silk_icons.py	2010-03-28 15:59:09 UTC (rev 41595)
@@ -8,6 +8,8 @@
 
 import os
 
+import wx
+
 import globalvar
 
 iconpath = os.path.join(globalvar.ETCDIR, "gui", "icons", "silk")
@@ -106,4 +108,5 @@
     "nvizSettings"   : 'color_swatch.png',
     # modeler
     "modelActionAdd" : wx.ART_ERROR,
+    "modelDataAdd"   : wx.ART_ERROR,
     }


Property changes on: grass/branches/develbranch_6/gui/wxpython/icons/silk_icons.py
___________________________________________________________________
Modified: svn:mergeinfo
   - /grass/trunk/gui/wxpython/icons/silk_icons.py:41584,41586-41587,41590-41592
   + /grass/trunk/gui/wxpython/icons/silk_icons.py:41584,41586-41587,41590-41592,41594

Modified: grass/branches/develbranch_6/gui/wxpython/xml/menudata_modeler.xml
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/xml/menudata_modeler.xml	2010-03-28 15:55:47 UTC (rev 41594)
+++ grass/branches/develbranch_6/gui/wxpython/xml/menudata_modeler.xml	2010-03-28 15:59:09 UTC (rev 41595)
@@ -39,6 +39,11 @@
       <label>&amp;Model</label>
       <items>
 	<menuitem>
+	  <label>Add data</label>
+	  <help>Add data item to model</help>
+	  <handler>OnAddData</handler>
+	</menuitem>
+	<menuitem>
 	  <label>Add action</label>
 	  <help>Add action (GRASS module) to model</help>
 	  <handler>OnAddAction</handler>



More information about the grass-commit mailing list