|
@@ -102,6 +102,7 @@ class ModelFrame(wx.Frame):
|
|
|
|
|
|
self.modelPage = self.notebook.AddPage(self.canvas, text=_('Model'))
|
|
|
self.commandPage = self.notebook.AddPage(self.goutput, text=_('Command output'))
|
|
|
+ wx.CallAfter(self.notebook.SetSelection, 0)
|
|
|
|
|
|
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
|
|
|
|
|
@@ -566,7 +567,7 @@ if __name__ == "__main__":
|
|
|
if p.get('prompt', '') in ('raster', 'vector', 'raster3d'):
|
|
|
try:
|
|
|
name, mapset = p.get('value', '').split('@', 1)
|
|
|
- except IndexError:
|
|
|
+ except (ValueError, IndexError):
|
|
|
continue
|
|
|
|
|
|
if mapset != grass.gisenv()['MAPSET']:
|
|
@@ -1095,7 +1096,7 @@ class ModelEvtHandler(ogl.ShapeEvtHandler):
|
|
|
self.frame.canvas.Refresh()
|
|
|
|
|
|
class ModelSearchDialog(wx.Dialog):
|
|
|
- def __init__(self, parent, id = wx.ID_ANY, title = _("Find GRASS module"),
|
|
|
+ def __init__(self, parent, id = wx.ID_ANY, title = _("Select GRASS module"),
|
|
|
style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
|
|
|
"""!Graphical modeler module search window
|
|
|
|
|
@@ -1112,50 +1113,78 @@ class ModelSearchDialog(wx.Dialog):
|
|
|
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.findBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
|
|
|
+ label=" %s " % _("Find module(s) by"))
|
|
|
+ self.cmdBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
|
|
|
+ label=" %s " % _("Command"))
|
|
|
|
|
|
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.searchTip = menuform.StaticWrapText(parent = self.panel, id = wx.ID_ANY,
|
|
|
+ size = (-1, 35))
|
|
|
+
|
|
|
+ self.searchChoice = wx.Choice(parent = self.panel, id = wx.ID_ANY)
|
|
|
+
|
|
|
self.cmd_prompt = prompt.GPromptSTC(parent = self)
|
|
|
+
|
|
|
+ # get commands
|
|
|
+ items = self.cmd_prompt.GetCommandItems()
|
|
|
+ self.searchTip.SetLabel(_("%d modules found") % len(items))
|
|
|
+ self.searchChoice.SetItems(items)
|
|
|
|
|
|
self.btnCancel = wx.Button(self.panel, wx.ID_CANCEL)
|
|
|
self.btnOk = wx.Button(self.panel, wx.ID_OK)
|
|
|
self.btnOk.SetDefault()
|
|
|
-
|
|
|
+
|
|
|
+ self.search.Bind(wx.EVT_TEXT, self.OnSearchModule)
|
|
|
+ self.searchChoice.Bind(wx.EVT_CHOICE, self.OnSelectModule)
|
|
|
+
|
|
|
self._layout()
|
|
|
|
|
|
+ self.SetSize((500, 250))
|
|
|
+
|
|
|
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)
|
|
|
+ findSizer = wx.StaticBoxSizer(self.findBox, wx.HORIZONTAL)
|
|
|
+ gridSizer = wx.GridBagSizer(hgap = 3, vgap = 3)
|
|
|
+ gridSizer.AddGrowableCol(1)
|
|
|
+
|
|
|
+ cmdSizer = wx.StaticBoxSizer(self.cmdBox, wx.VERTICAL)
|
|
|
|
|
|
- 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)
|
|
|
+ gridSizer.Add(item = self.searchBy,
|
|
|
+ flag=wx.ALIGN_CENTER_VERTICAL, pos = (0, 0))
|
|
|
+ gridSizer.Add(item = self.search,
|
|
|
+ flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, pos = (0, 1))
|
|
|
+ gridSizer.Add(item = self.searchTip,
|
|
|
+ flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, pos = (1, 0), span = (1, 2))
|
|
|
+ gridSizer.Add(item = self.searchChoice,
|
|
|
+ flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, pos = (2, 0), span = (1, 2))
|
|
|
+ findSizer.Add(item = gridSizer, proportion = 1)
|
|
|
|
|
|
- bodySizer.Add(item=searchSizer, proportion=0,
|
|
|
+ cmdSizer.Add(item=self.cmd_prompt, proportion=1,
|
|
|
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,
|
|
|
+ mainSizer.Add(item=findSizer, proportion=0,
|
|
|
flag=wx.EXPAND | wx.ALL, border=5)
|
|
|
+ mainSizer.Add(item=cmdSizer, proportion=1,
|
|
|
+ flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, 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)
|
|
|
|
|
|
+ self.Layout()
|
|
|
+
|
|
|
def GetPanel(self):
|
|
|
"""!Get dialog panel"""
|
|
|
return self.panel
|
|
@@ -1173,6 +1202,52 @@ class ModelSearchDialog(wx.Dialog):
|
|
|
|
|
|
return cmd
|
|
|
|
|
|
+ def OnSearchModule(self, event):
|
|
|
+ """!Search module by keywords or description"""
|
|
|
+ text = event.GetString()
|
|
|
+ if not text:
|
|
|
+ self.cmd_prompt.SetFilter(None)
|
|
|
+ return
|
|
|
+
|
|
|
+ modules = dict()
|
|
|
+ iFound = 0
|
|
|
+ for module, data in self.cmd_prompt.moduleDesc.iteritems():
|
|
|
+ found = False
|
|
|
+ if self.searchBy.GetSelection() == 0: # -> description
|
|
|
+ if text in data['desc']:
|
|
|
+ found = True
|
|
|
+ else: # -> keywords
|
|
|
+ if self.cmd_prompt.CheckKey(text, data['keywords']):
|
|
|
+ found = True
|
|
|
+
|
|
|
+ if found:
|
|
|
+ iFound += 1
|
|
|
+ try:
|
|
|
+ group, name = module.split('.')
|
|
|
+ except ValueError:
|
|
|
+ continue # TODO
|
|
|
+
|
|
|
+ if not modules.has_key(group):
|
|
|
+ modules[group] = list()
|
|
|
+ modules[group].append(name)
|
|
|
+
|
|
|
+ self.cmd_prompt.SetFilter(modules)
|
|
|
+ self.searchTip.SetLabel(_("%d modules found") % iFound)
|
|
|
+ self.searchChoice.SetItems(self.cmd_prompt.GetCommandItems())
|
|
|
+
|
|
|
+ def OnSelectModule(self, event):
|
|
|
+ """!Module selected from choice, update command prompt"""
|
|
|
+ cmd = event.GetString().split(' ', 1)[0]
|
|
|
+ text = cmd + ' '
|
|
|
+ pos = len(text)
|
|
|
+ self.cmd_prompt.SetText(text)
|
|
|
+ self.cmd_prompt.SetSelectionStart(pos)
|
|
|
+ self.cmd_prompt.SetCurrentPos(pos)
|
|
|
+ self.cmd_prompt.SetFocus()
|
|
|
+
|
|
|
+ desc = self.cmd_prompt.GetCommandDesc(cmd)
|
|
|
+ self.searchTip.SetLabel(desc)
|
|
|
+
|
|
|
def OnOk(self, event):
|
|
|
self.btnOk.SetFocus()
|
|
|
|