Преглед изворни кода

wxGUI/modeler: add action implemented

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@41590 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa пре 15 година
родитељ
комит
2d3e3afcbb

+ 2 - 2
gui/wxpython/gui_modules/gdialogs.py

@@ -947,9 +947,9 @@ class MultiImportDialog(wx.Dialog):
             self.inputTitle = _("Input directory")
             self.inputTitle = _("Input directory")
         
         
         self.inputBox = wx.StaticBox(parent=self.panel, id=wx.ID_ANY,
         self.inputBox = wx.StaticBox(parent=self.panel, id=wx.ID_ANY,
-                                label=" %s " % self.inputTitle)
+                                     label=" %s " % self.inputTitle)
         self.layerBox = wx.StaticBox(parent=self.panel, id=wx.ID_ANY,
         self.layerBox = wx.StaticBox(parent=self.panel, id=wx.ID_ANY,
-                                label=_(" List of %s layers ") % self.inputType.upper())
+                                     label=_(" List of %s layers ") % self.inputType.upper())
 
 
         #
         #
         # input
         # input

+ 155 - 4
gui/wxpython/gui_modules/gmodeler.py

@@ -6,6 +6,8 @@
 Classes:
 Classes:
  - ModelFrame
  - ModelFrame
  - ModelCanvas
  - ModelCanvas
+ - ModelAction
+ - ModelSearchDialog
 
 
 (C) 2010 by the GRASS Development Team
 (C) 2010 by the GRASS Development Team
 This program is free software under the GNU General Public License
 This program is free software under the GNU General Public License
@@ -15,6 +17,7 @@ This program is free software under the GNU General Public License
 """
 """
 
 
 import os
 import os
+import shlex
 
 
 import globalvar
 import globalvar
 if not os.getenv("GRASS_WXBUNDLED"):
 if not os.getenv("GRASS_WXBUNDLED"):
@@ -25,6 +28,8 @@ import wx.lib.ogl as ogl
 import menu
 import menu
 import menudata
 import menudata
 import toolbars
 import toolbars
+import menuform
+import prompt
 
 
 from grass.script import core as grass
 from grass.script import core as grass
 
 
@@ -40,7 +45,10 @@ class ModelFrame(wx.Frame):
         """
         """
         self.parent = parent
         self.parent = parent
         
         
+        self.actions = list() # list of recoreded actions
+
         wx.Frame.__init__(self, parent = parent, id = id, title = title, **kwargs)
         wx.Frame.__init__(self, parent = parent, id = id, title = title, **kwargs)
+        self.SetName("Modeler")
         self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO))
         self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO))
         
         
         self.menubar = menu.Menu(parent = self, data = menudata.ModelerData())
         self.menubar = menu.Menu(parent = self, data = menudata.ModelerData())
@@ -57,7 +65,7 @@ class ModelFrame(wx.Frame):
         self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
         self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
         
         
         self._layout()
         self._layout()
-        self.SetMinSize((400, 300))
+        self.SetMinSize((640, 480))
         
         
     def _layout(self):
     def _layout(self):
         """!Do layout"""
         """!Do layout"""
@@ -94,8 +102,30 @@ class ModelFrame(wx.Frame):
 
 
     def OnAddAction(self, event):
     def OnAddAction(self, event):
         """!Add action to model"""
         """!Add action to model"""
-        pass
-
+        dlg = ModelSearchDialog(self)
+        dlg.CentreOnParent()
+        
+        if dlg.ShowModal() == wx.CANCEL:
+            dlg.Destroy()
+            return
+        
+        cmd = dlg.GetCmd()
+        dlg.Destroy()
+        
+        action = ModelAction(self, cmd = cmd, x = 100, y = 100)
+        self.canvas.diagram.AddShape(action)
+        action.Show(True)
+        
+        evthandler = ModelEvtHandler(self.statusbar,
+                                     self)
+        evthandler.SetShape(action)
+        evthandler.SetPreviousHandler(action.GetEventHandler())
+        action.SetEventHandler(evthandler)
+        
+        self.actions.append(action)
+        
+        self.canvas.Refresh()
+        
     def OnHelp(self, event):
     def OnHelp(self, event):
         """!Display manual page"""
         """!Display manual page"""
         grass.run_command('g.manual',
         grass.run_command('g.manual',
@@ -111,10 +141,131 @@ class ModelCanvas(ogl.ShapeCanvas):
         self.SetDiagram(self.diagram)
         self.SetDiagram(self.diagram)
         self.diagram.SetCanvas(self)
         self.diagram.SetCanvas(self)
         
         
+        self.SetScrollbars(20, 20, 1000/20, 1000/20)
+        
+class ModelAction(ogl.RectangleShape):
+    """!Action class (GRASS module)"""
+    def __init__(self, parent, x, y, cmd = None, width = 100, height = 50):
+        self.parent = parent
+        
+        ogl.RectangleShape.__init__(self, width, height)
+        
+        # self.Draggable(True)
+        self.SetCanvas(self.parent)
+        self.SetX(x)
+        self.SetY(y)
+        self.SetPen(wx.BLACK_PEN)
+        self.SetBrush(wx.LIGHT_GREY_BRUSH)
+        if cmd and len(cmd) > 0:
+            self.AddText(cmd[0])
+        else:
+            self.AddText('<<module>>')
+       
+class ModelEvtHandler(ogl.ShapeEvtHandler):
+    """!Model event handler class"""
+    def __init__(self, log, frame):
+        ogl.ShapeEvtHandler.__init__(self)
+        self.log = log
+        self.frame = frame
+        
+    def OnLeftClick(self, x, y, keys = 0, attachment = 0):
+        """!Left mouse button pressed -> update statusbar"""
+        shape = self.GetShape()
+        
+    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)
+
+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):
+        """!Graphical modeler module search window
+        
+        @param parent parent window
+        @param id window id
+        @param title window title
+
+        @param kwargs wx.Dialogs' arguments
+        """
+        self.parent = parent
+        
+        wx.Dialog.__init__(self, parent = parent, id = id, title = title, **kwargs)
+        self.SetName("ModelerDialog")
+        self.SetIcon(wx.Icon(os.path.join(globalvar.ETCICONDIR, 'grass.ico'), wx.BITMAP_TYPE_ICO))
+        
+        self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
+        
+        self.searchBy = wx.Choice(parent = self.panel, id = wx.ID_ANY,
+                                  choices = [_("description"),
+                                             _("keywords")])
+        self.search = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY,
+                                  value = "", size = (-1, 25))
+        self.cmd_prompt = prompt.GPromptSTC(parent = self)
+        
+        self.btnCancel = wx.Button(self.panel, wx.ID_CANCEL)
+        self.btnOk     = wx.Button(self.panel, wx.ID_OK)
+        self.btnOk.SetDefault()
+
+        self._layout()
+        
+    def _layout(self):
+        btnSizer = wx.StdDialogButtonSizer()
+        btnSizer.AddButton(self.btnCancel)
+        btnSizer.AddButton(self.btnOk)
+        btnSizer.Realize()
+
+        bodyBox = wx.StaticBox(parent=self.panel, id=wx.ID_ANY,
+                               label=" %s " % _("Find GRASS module"))
+        bodySizer = wx.StaticBoxSizer(bodyBox, wx.VERTICAL)
+        searchSizer = wx.BoxSizer(wx.HORIZONTAL)
+        
+        searchSizer.Add(item = self.searchBy,
+                        proportion = 0, flag = wx.LEFT, border = 3)
+        searchSizer.Add(item = self.search,
+                        proportion = 1, flag = wx.LEFT | wx.EXPAND, border = 3)
+        
+        bodySizer.Add(item=searchSizer, proportion=0,
+                      flag=wx.EXPAND | wx.ALL, border=1)
+        bodySizer.Add(item=self.cmd_prompt, proportion=1,
+                      flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border=3)
+        
+        mainSizer = wx.BoxSizer(wx.VERTICAL)
+        mainSizer.Add(item=bodySizer, proportion=1,
+                      flag=wx.EXPAND | wx.ALL, border=5)
+        mainSizer.Add(item=btnSizer, proportion=0,
+                      flag=wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border=5)
+        
+        self.panel.SetSizer(mainSizer)
+        mainSizer.Fit(self.panel)
+        
+    def GetPanel(self):
+        """!Get dialog panel"""
+        return self.panel
+
+    def GetCmd(self):
+        """!Get command"""
+        line = self.cmd_prompt.GetCurLine()[0].strip()
+        if len(line) == 0:
+            list()
+        
+        try:
+            cmd = shlex.split(str(line))
+        except UnicodeError:
+            cmd = shlex.split(utils.EncodeString((line)))
+            
+        return cmd
+
+    def OnOk(self, event):
+        self.Close()
+    
 def main():
 def main():
     app = wx.PySimpleApp()
     app = wx.PySimpleApp()
     frame = ModelFrame(parent = None)
     frame = ModelFrame(parent = None)
-    frame.CenterOnScreen()
+    # frame.CentreOnScreen()
     frame.Show()
     frame.Show()
     
     
     app.MainLoop()
     app.MainLoop()

+ 13 - 5
gui/wxpython/gui_modules/prompt.py

@@ -473,14 +473,17 @@ class GPrompt(object):
         self.parent = parent                 # GMConsole
         self.parent = parent                 # GMConsole
         self.panel  = self.parent.GetPanel()
         self.panel  = self.parent.GetPanel()
         
         
-        if self.parent.parent.GetName() != "LayerManager":
+        if self.parent.parent.GetName() == "LayerManager":
             self.standAlone = True
             self.standAlone = True
         else:
         else:
             self.standAlone = False
             self.standAlone = False
         
         
         # dictionary of modules (description, keywords, ...)
         # dictionary of modules (description, keywords, ...)
         if not self.standAlone:
         if not self.standAlone:
-            self.moduleDesc = parent.parent.menubar.GetData().GetModules()
+            if self.parent.parent.GetName() == 'Modeler':
+                self.moduleDesc = menudata.ManagerData().GetModules()
+            else:
+                self.moduleDesc = parent.parent.menubar.GetData().GetModules()
             self.moduleList = self._getListOfModules()
             self.moduleList = self._getListOfModules()
             self.mapList = self._getListOfMaps()
             self.mapList = self._getListOfMaps()
         else:
         else:
@@ -748,7 +751,7 @@ class GPromptSTC(GPrompt, wx.stc.StyledTextCtrl):
             
             
             usage, description = self.GetCommandUsage(cmd)
             usage, description = self.GetCommandUsage(cmd)
                                         
                                         
-            self.CallTipSetBackground("PALE GREEN")
+            self.CallTipSetBackground("#f4f4d1")
             self.CallTipSetForeground("BLACK")
             self.CallTipSetForeground("BLACK")
             self.CallTipShow(pos, usage + '\n\n' + description)
             self.CallTipShow(pos, usage + '\n\n' + description)
             
             
@@ -838,7 +841,12 @@ class GPromptSTC(GPrompt, wx.stc.StyledTextCtrl):
             self.InsertText(pos,txt)
             self.InsertText(pos,txt)
             self.LineEnd()
             self.LineEnd()
             
             
-        elif event.GetKeyCode() == wx.WXK_RETURN and self.AutoCompActive() == False:
+        elif event.GetKeyCode() == wx.WXK_RETURN and \
+                self.AutoCompActive() == False:
+            if self.parent.GetName() != "ModelDialog":
+                self.parent.OnOk(None)
+                return
+            
             # Run command on line when <return> is pressed    
             # Run command on line when <return> is pressed    
             
             
             # find the command to run
             # find the command to run
@@ -852,7 +860,7 @@ class GPromptSTC(GPrompt, wx.stc.StyledTextCtrl):
             except UnicodeError:
             except UnicodeError:
                 cmd = shlex.split(utils.EncodeString((line)))
                 cmd = shlex.split(utils.EncodeString((line)))
             
             
-            #send the command list to the processor 
+            # send the command list to the processor 
             self.parent.RunCmd(cmd)
             self.parent.RunCmd(cmd)
             
             
             # add command to history    
             # add command to history    

+ 5 - 0
gui/wxpython/gui_modules/toolbars.py

@@ -1391,6 +1391,7 @@ class ModelToolbar(AbstractToolbar):
         self.new = wx.NewId()
         self.new = wx.NewId()
         self.open = wx.NewId()
         self.open = wx.NewId()
         self.save = wx.NewId()
         self.save = wx.NewId()
+        self.action = wx.NewId()
         self.quit = wx.NewId()
         self.quit = wx.NewId()
         
         
         # tool, label, bitmap, kind, shortHelp, longHelp, handler
         # tool, label, bitmap, kind, shortHelp, longHelp, handler
@@ -1405,6 +1406,10 @@ class ModelToolbar(AbstractToolbar):
              wx.ITEM_NORMAL, Icons['modelSave'].GetLabel(), Icons['modelSave'].GetDesc(),
              wx.ITEM_NORMAL, Icons['modelSave'].GetLabel(), Icons['modelSave'].GetDesc(),
              self.parent.OnModelSave),
              self.parent.OnModelSave),
             ('', '', '', '', '', '', ''),
             ('', '', '', '', '', '', ''),
+            (self.action, 'action', Icons['modelActionAdd'].GetBitmap(),
+             wx.ITEM_NORMAL, Icons['modelActionAdd'].GetLabel(), Icons['modelActionAdd'].GetDesc(),
+             self.parent.OnAddAction),
+            ('', '', '', '', '', '', ''),
             (self.quit, 'quit', Icons['quit'].GetBitmap(),
             (self.quit, 'quit', Icons['quit'].GetBitmap(),
              wx.ITEM_NORMAL, Icons['quit'].GetLabel(), Icons['quit'].GetDesc(),
              wx.ITEM_NORMAL, Icons['quit'].GetLabel(), Icons['quit'].GetDesc(),
              self.parent.OnCloseWindow),
              self.parent.OnCloseWindow),

+ 3 - 0
gui/wxpython/icons/grass2_icons.py

@@ -1,6 +1,7 @@
 """
 """
 New GRASS icon set
 New GRASS icon set
 http://robert.szczepanek.pl/icons.php
 http://robert.szczepanek.pl/icons.php
+https://svn.osgeo.org/osgeo/graphics/toolbar-icons/24x24/
 """
 """
 __author__ = "Robert Szczepanek"
 __author__ = "Robert Szczepanek"
 
 
@@ -103,4 +104,6 @@ IconsGrass2 = {
     "grSettings"   : 'settings.png',
     "grSettings"   : 'settings.png',
     # nviz
     # nviz
     "nvizSettings"   : 'settings.png',
     "nvizSettings"   : 'settings.png',
+    # modeler
+    "modelActionAdd" : 'layer-add.png',
     }
     }

+ 3 - 1
gui/wxpython/icons/grass_icons.py

@@ -105,5 +105,7 @@ IconsGrass = {
     "grGcpReload"  : 'gui-redraw.gif',
     "grGcpReload"  : 'gui-redraw.gif',
     "grSettings"   : 'edit-color.gif', 
     "grSettings"   : 'edit-color.gif', 
     # nviz 
     # nviz 
-    "nvizSettings" : 'edit-color.gif',   
+    "nvizSettings" : 'edit-color.gif',  
+    # modeler
+    "modelActionAdd" : wx.ART_ERROR,
     }
     }

+ 2 - 0
gui/wxpython/icons/icon.py

@@ -343,6 +343,8 @@ Icons = {
                                 label=_("Load model from file (Ctrl+O)")),
                                 label=_("Load model from file (Ctrl+O)")),
     "modelSave" : MetaIcon (img=Icons["fileSave"],
     "modelSave" : MetaIcon (img=Icons["fileSave"],
                                 label=_("Save current model to file (Ctrl+S)")),
                                 label=_("Save current model to file (Ctrl+S)")),
+    "modelActionAdd" : MetaIcon (img=Icons["modelActionAdd"],
+                                 label=_("Add action (GRASS module) to model")),
     }
     }
 
 
 # testing ...
 # testing ...

+ 2 - 0
gui/wxpython/icons/silk_icons.py

@@ -105,4 +105,6 @@ IconsSilk = {
     "grSettings"   : 'color_swatch.png',
     "grSettings"   : 'color_swatch.png',
     # nviz
     # nviz
     "nvizSettings"   : 'color_swatch.png',
     "nvizSettings"   : 'color_swatch.png',
+    # modeler
+    "modelActionAdd" : wx.ART_ERROR,
     }
     }