浏览代码

wxGUI/modeler: set label and comment when adding new command to the model

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@58540 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 11 年之前
父节点
当前提交
0b70e0bc3d
共有 3 个文件被更改,包括 35 次插入5 次删除
  1. 28 4
      gui/wxpython/gmodeler/dialogs.py
  2. 2 1
      gui/wxpython/gmodeler/frame.py
  3. 5 0
      gui/wxpython/gui_core/prompt.py

+ 28 - 4
gui/wxpython/gmodeler/dialogs.py

@@ -15,7 +15,7 @@ Classes:
  - dialogs::ItemListCtrl
  - dialogs::ItemListCtrl
  - dialogs::ItemCheckListCtrl
  - dialogs::ItemCheckListCtrl
 
 
-(C) 2010-2011 by the GRASS Development Team
+(C) 2010-2013 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
 (>=v2). Read the file COPYING that comes with GRASS for details.
 (>=v2). Read the file COPYING that comes with GRASS for details.
@@ -138,7 +138,7 @@ class ModelDataDialog(SimpleDialog):
             self.Destroy()
             self.Destroy()
 
 
 class ModelSearchDialog(wx.Dialog):
 class ModelSearchDialog(wx.Dialog):
-    def __init__(self, parent, title = _("Add new GRASS module to the model"),
+    def __init__(self, parent, title = _("Add GRASS command to the model"),
                  style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
                  style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
         """!Graphical modeler module search window
         """!Graphical modeler module search window
         
         
@@ -158,12 +158,15 @@ class ModelSearchDialog(wx.Dialog):
         
         
         self.cmdBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
         self.cmdBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
                                    label=" %s " % _("Command"))
                                    label=" %s " % _("Command"))
+        self.labelBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
+                                   label=" %s " % _("Label and comment"))
         
         
         # menu data for search widget and prompt
         # menu data for search widget and prompt
         menuModel = LayerManagerMenuData()
         menuModel = LayerManagerMenuData()
         
         
         self.cmd_prompt = GPromptSTC(parent = self, menuModel = menuModel.GetModel(), updateCmdHistory = False)
         self.cmd_prompt = GPromptSTC(parent = self, menuModel = menuModel.GetModel(), updateCmdHistory = False)
         self.cmd_prompt.promptRunCmd.connect(self.OnCommand)
         self.cmd_prompt.promptRunCmd.connect(self.OnCommand)
+        self.cmd_prompt.commandSelected.connect(lambda command: self.label.SetValue(command))
         self.search = SearchModuleWidget(parent = self.panel,
         self.search = SearchModuleWidget(parent = self.panel,
                                          model = menuModel.GetModel(),
                                          model = menuModel.GetModel(),
                                          showTip = True)
                                          showTip = True)
@@ -171,6 +174,9 @@ class ModelSearchDialog(wx.Dialog):
                                            self.cmd_prompt.SetTextAndFocus(name + ' '))
                                            self.cmd_prompt.SetTextAndFocus(name + ' '))
         wx.CallAfter(self.cmd_prompt.SetFocus)
         wx.CallAfter(self.cmd_prompt.SetFocus)
         
         
+        self.label = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY)
+        self.comment = wx.TextCtrl(parent = self.panel, id = wx.ID_ANY, style =  wx.TE_MULTILINE)
+        
         self.btnCancel = wx.Button(self.panel, wx.ID_CANCEL)
         self.btnCancel = wx.Button(self.panel, wx.ID_CANCEL)
         self.btnOk     = wx.Button(self.panel, wx.ID_OK)
         self.btnOk     = wx.Button(self.panel, wx.ID_OK)
         self.btnOk.SetDefault()
         self.btnOk.SetDefault()
@@ -180,12 +186,24 @@ class ModelSearchDialog(wx.Dialog):
         
         
         self._layout()
         self._layout()
         
         
-        self.SetSize((500, 275))
+        self.SetSize((500, -1))
 
 
     def _layout(self):
     def _layout(self):
         cmdSizer = wx.StaticBoxSizer(self.cmdBox, wx.VERTICAL)
         cmdSizer = wx.StaticBoxSizer(self.cmdBox, wx.VERTICAL)
         cmdSizer.Add(item = self.cmd_prompt, proportion = 1,
         cmdSizer.Add(item = self.cmd_prompt, proportion = 1,
                      flag = wx.EXPAND)
                      flag = wx.EXPAND)
+        labelSizer = wx.StaticBoxSizer(self.labelBox, wx.VERTICAL)
+        gridSizer = wx.GridBagSizer (hgap = 5, vgap = 5)
+        gridSizer.AddGrowableCol(1)
+        gridSizer.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
+                                           label = _("Label:")),
+                      flag = wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
+        gridSizer.Add(item = self.label, pos = (0, 1), flag =  wx.EXPAND)
+        gridSizer.Add(item = wx.StaticText(parent = self.panel, id = wx.ID_ANY,
+                                           label = _("Comment:")),
+                      flag = wx.ALIGN_CENTER_VERTICAL, pos = (1, 0))
+        gridSizer.Add(item = self.comment, pos = (1, 1), flag =  wx.EXPAND)
+        labelSizer.Add(item = gridSizer, proportion = 1, flag = wx.EXPAND)
         
         
         btnSizer = wx.StdDialogButtonSizer()
         btnSizer = wx.StdDialogButtonSizer()
         btnSizer.AddButton(self.btnCancel)
         btnSizer.AddButton(self.btnCancel)
@@ -197,11 +215,13 @@ class ModelSearchDialog(wx.Dialog):
                       flag = wx.EXPAND | wx.ALL, border = 3)
                       flag = wx.EXPAND | wx.ALL, border = 3)
         mainSizer.Add(item = cmdSizer, proportion = 1,
         mainSizer.Add(item = cmdSizer, proportion = 1,
                       flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border = 3)
                       flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border = 3)
+        mainSizer.Add(item = labelSizer, proportion = 1,
+                      flag = wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, border = 3)
         mainSizer.Add(item = btnSizer, proportion = 0,
         mainSizer.Add(item = btnSizer, proportion = 0,
                       flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
                       flag = wx.EXPAND | wx.ALL | wx.ALIGN_CENTER, border = 5)
         
         
         self.panel.SetSizer(mainSizer)
         self.panel.SetSizer(mainSizer)
-        mainSizer.Fit(self.panel)
+        mainSizer.Fit(self)
         
         
         self.Layout()
         self.Layout()
 
 
@@ -224,6 +244,10 @@ class ModelSearchDialog(wx.Dialog):
         """!Get command"""
         """!Get command"""
         return self._command
         return self._command
 
 
+    def GetLabel(self):
+        """!Get label and comment"""
+        return self.label.GetValue(), self.comment.GetValue()
+    
     def ValidateCmd(self, cmd):
     def ValidateCmd(self, cmd):
         if len(cmd) < 1:
         if len(cmd) < 1:
             GError(parent = self,
             GError(parent = self,

+ 2 - 1
gui/wxpython/gmodeler/frame.py

@@ -650,10 +650,11 @@ class ModelFrame(wx.Frame):
         
         
         # add action to canvas
         # add action to canvas
         x, y = self.canvas.GetNewShapePos()
         x, y = self.canvas.GetNewShapePos()
+        label, comment = self.searchDialog.GetLabel()
         action = ModelAction(self.model, cmd = cmd,
         action = ModelAction(self.model, cmd = cmd,
                              x = x + self._randomShift(),
                              x = x + self._randomShift(),
                              y = y + self._randomShift(),
                              y = y + self._randomShift(),
-                             id = self.model.GetNextId())
+                             id = self.model.GetNextId(), label = label, comment = comment)
         overwrite = self.model.GetProperties().get('overwrite', None)
         overwrite = self.model.GetProperties().get('overwrite', None)
         if overwrite is not None:
         if overwrite is not None:
             action.GetTask().set_flag('overwrite', overwrite)
             action.GetTask().set_flag('overwrite', overwrite)

+ 5 - 0
gui/wxpython/gui_core/prompt.py

@@ -183,6 +183,9 @@ class GPromptSTC(GPrompt, wx.stc.StyledTextCtrl):
         # signal which requests showing of a notification
         # signal which requests showing of a notification
         self.showNotification = Signal('GPromptSTC.showNotification')
         self.showNotification = Signal('GPromptSTC.showNotification')
 
 
+        # signal to notify selected command
+        self.commandSelected = Signal('GPromptSTC.commandSelected')
+        
     def OnTextSelectionChanged(self, event):
     def OnTextSelectionChanged(self, event):
         """!Copy selected text to clipboard and skip event.
         """!Copy selected text to clipboard and skip event.
         The same function is in GStc class (goutput.py).
         The same function is in GStc class (goutput.py).
@@ -200,6 +203,7 @@ class GPromptSTC(GPrompt, wx.stc.StyledTextCtrl):
                 nodes = self._menuModel.SearchNodes(key='command', value=item)
                 nodes = self._menuModel.SearchNodes(key='command', value=item)
                 desc = ''
                 desc = ''
                 if nodes:
                 if nodes:
+                    self.commandSelected.emit(command=item)
                     desc = nodes[0].data['description']
                     desc = nodes[0].data['description']
             except KeyError:
             except KeyError:
                 desc = '' 
                 desc = '' 
@@ -269,6 +273,7 @@ class GPromptSTC(GPrompt, wx.stc.StyledTextCtrl):
 
 
     def SetTextAndFocus(self, text):
     def SetTextAndFocus(self, text):
         pos = len(text)
         pos = len(text)
+        self.commandSelected.emit(command=text)
         self.SetText(text)
         self.SetText(text)
         self.SetSelectionStart(pos)
         self.SetSelectionStart(pos)
         self.SetCurrentPos(pos)
         self.SetCurrentPos(pos)