Forráskód Böngészése

wxGUI/search tree: simplify graphical interface, add tooltips

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@57176 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 12 éve
szülő
commit
a24bcfdf12

+ 3 - 3
gui/wxpython/core/menutree.py

@@ -100,10 +100,10 @@ class MenuTreeModelBuilder:
                 desc = _(desc.text)
             else:
                 desc = ""
-            if keywords != None:
-                keywords = keywords.text
-            else:
+            if keywords is None or keywords.text is None:
                 keywords = ""
+            else:            
+                keywords = keywords.text
             if shortcut != None:
                 shortcut = shortcut.text
             else:

+ 5 - 4
gui/wxpython/gui_core/menu.py

@@ -129,9 +129,10 @@ class SearchModuleWindow(wx.Panel):
         
         # tree
         self._tree = CTreeView(model=model, parent=self)
+        self._tree.SetToolTipString(_("Double-click or Ctrl-Enter to run selected module"))
 
-        self._dataBox = wx.StaticBox(parent = self, id = wx.ID_ANY,
-                                     label = " %s " % _("Menu tree (double-click or Ctrl-Enter to run command)"))
+#        self._dataBox = wx.StaticBox(parent = self, id = wx.ID_ANY,
+#                                     label = " %s " % _("Module tree"))
 
         # search widget
         self._search = SearchModuleWidget(parent=self,
@@ -142,7 +143,7 @@ class SearchModuleWindow(wx.Panel):
         
         # buttons
         self._btnRun = wx.Button(self, id=wx.ID_OK, label=_("&Run"))
-        self._btnRun.SetToolTipString(_("Run selected command from the menu tree"))
+        self._btnRun.SetToolTipString(_("Run selected module from the tree"))
         
         # bindings
         self._btnRun.Bind(wx.EVT_BUTTON, lambda evt: self.Run())
@@ -160,7 +161,7 @@ class SearchModuleWindow(wx.Panel):
         sizer = wx.BoxSizer(wx.VERTICAL)
         
         # body
-        dataSizer = wx.StaticBoxSizer(self._dataBox, wx.HORIZONTAL)
+        dataSizer = wx.BoxSizer(wx.HORIZONTAL)
         dataSizer.Add(item = self._tree, proportion =1,
                       flag = wx.EXPAND)
         

+ 38 - 51
gui/wxpython/gui_core/widgets.py

@@ -782,6 +782,7 @@ class SearchModuleWidget(wx.Panel):
         self._model = model
         self._results = [] # list of found nodes
         self._resultIndex = -1
+        self._searchKeys = ['description', 'keywords', 'command']
         
         self.moduleSelected = Signal('SearchModuleWidget.moduleSelected')
         self.showSearchResult = Signal('SearchModuleWidget.showSearchResult')
@@ -789,28 +790,18 @@ class SearchModuleWidget(wx.Panel):
 
         wx.Panel.__init__(self, parent = parent, id = wx.ID_ANY, **kwargs)
 
-        self._searchDict = { _('description') : 'description',
-                             _('command') : 'command',
-                             _('keywords') : 'keywords' }
-
-
-        self._box = wx.StaticBox(parent = self, id = wx.ID_ANY,
-                                label = " %s " % _("Find module - (press Enter for next match)"))
-
-        self._searchBy = wx.Choice(parent = self, id = wx.ID_ANY)
-        items = [_('description'), _('keywords'), _('command')]
-        datas = ['description', 'keywords', 'command']
-        for item, data in zip(items, datas):
-            self._searchBy.Append(item = item, clientData = data)
-        self._searchBy.SetSelection(0)
-        self._searchBy.Bind(wx.EVT_CHOICE, self.OnSearchModule)
+#        self._box = wx.StaticBox(parent = self, id = wx.ID_ANY,
+#                                label = " %s " % _("Find module - (press Enter for next match)"))
 
         if sys.platform == 'win32':
-            ctrl = wx.TextCtrl
+            self._search = wx.TextCtrl(parent = self, id = wx.ID_ANY,
+                                       size = (-1, 25), style = wx.TE_PROCESS_ENTER)
         else:
-            ctrl = wx.SearchCtrl
-        self._search = ctrl(parent = self, id = wx.ID_ANY,
-                            size = (-1, 25), style = wx.TE_PROCESS_ENTER)
+            self._search = wx.SearchCtrl(parent = self, id = wx.ID_ANY,
+                                         size = (-1, 25), style = wx.TE_PROCESS_ENTER)
+            self._search.SetDescriptiveText(_('Fulltext search'))
+            self._search.SetToolTipString(_("Type to search in all modules. Press Enter for next match."))
+
         self._search.Bind(wx.EVT_TEXT, self.OnSearchModule)
         self._search.Bind(wx.EVT_KEY_UP,  self.OnKeyUp)
 
@@ -820,33 +811,31 @@ class SearchModuleWidget(wx.Panel):
 
         if self._showChoice:
             self._searchChoice = wx.Choice(parent = self, id = wx.ID_ANY)
-            self._searchChoice.SetItems(self._searchModule(key='command', value=''))
+            self._searchChoice.SetItems(self._searchModule(keys=['command'], value=''))
             self._searchChoice.Bind(wx.EVT_CHOICE, self.OnSelectModule)
 
         self._layout()
 
     def _layout(self):
         """!Do layout"""
-        sizer = wx.StaticBoxSizer(self._box, wx.HORIZONTAL)
-        gridSizer = wx.GridBagSizer(hgap = 3, vgap = 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))
-        row = 1
+        sizer = wx.BoxSizer(wx.HORIZONTAL)
+        boxSizer = wx.BoxSizer(wx.VERTICAL)
+
+        boxSizer.Add(item=self._search,
+                     flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND | wx.BOTTOM,
+                     border=5)
         if self._showChoice:
-            gridSizer.Add(item = self._searchChoice,
-                          flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, pos = (row, 0), span = (1, 2))
-            row += 1
+            hSizer = wx.BoxSizer(wx.HORIZONTAL)
+            hSizer.Add(item=self._searchChoice,
+                       flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND | wx.BOTTOM,
+                       border=5)
+            hSizer.AddStretchSpacer()
+            boxSizer.Add(item=hSizer, flag=wx.EXPAND)
         if self._showTip:
-            gridSizer.Add(item = self._searchTip,
-                          flag = wx.ALIGN_CENTER_VERTICAL | wx.EXPAND, pos = (row, 0), span = (1, 2))
-            row += 1
-
-        gridSizer.AddGrowableCol(1)
+            boxSizer.Add(item=self._searchTip,
+                          flag=wx.ALIGN_CENTER_VERTICAL | wx.EXPAND)
 
-        sizer.Add(item = gridSizer, proportion = 1)
+        sizer.Add(item = boxSizer, proportion = 1)
 
         self.SetSizer(sizer)
         sizer.Fit(self)
@@ -861,19 +850,13 @@ class SearchModuleWidget(wx.Panel):
                 self.showSearchResult.emit(result=self._results[self._resultIndex])
         event.Skip()
 
-    def GetSelection(self):
-        """!Get selected element"""
-        selection = self._searchBy.GetStringSelection()
-
-        return self._searchDict[selection]
-
-    def SetSelection(self, i):
-        """!Set selection element"""
-        self._searchBy.SetSelection(i)
-
     def OnSearchModule(self, event):
         """!Search module by keywords or description"""
-        commands = self._searchModule(key=self.GetSelection(), value=self._search.GetValue())
+        value = self._search.GetValue()
+        if len(value) <= 2:
+            self.showNotification.emit(message=_("Searching, please type more characters."))
+            return
+        commands = self._searchModule(keys=self._searchKeys, value=value)
         if self._showChoice:
             self._searchChoice.SetItems(commands)
             if commands:
@@ -887,8 +870,13 @@ class SearchModuleWidget(wx.Panel):
 
         event.Skip()
 
-    def _searchModule(self, key, value):
-        nodes = self._model.SearchNodes(key=key, value=value)
+    def _searchModule(self, keys, value):
+        nodes = set()
+        for key in keys:
+            nodes.update(self._model.SearchNodes(key=key, value=value))
+
+        nodes = list(nodes)
+        nodes.sort(key=lambda node: self._model.GetIndexOfNode(node))
         self._results = nodes
         self._resultIndex = -1
         return [node.data['command'] for node in nodes if node.data['command']]
@@ -906,7 +894,6 @@ class SearchModuleWidget(wx.Panel):
 
     def Reset(self):
         """!Reset widget"""
-        self._searchBy.SetSelection(0)
         self._search.SetValue('')
         if self._showTip:
             self._searchTip.SetLabel('')

+ 1 - 1
gui/wxpython/lmgr/frame.py

@@ -319,7 +319,7 @@ class GMFrame(wx.Frame):
         if not UserSettings.Get(group = 'manager', key = 'hideTabs', subkey = 'search'):
             self.search = SearchModuleWindow(parent = self, model=self._menuTreeBuilder.GetModel())
             self.search.showNotification.connect(lambda message: self.SetStatusText(message))
-            self.notebook.AddPage(page = self.search, text = _("Search module"), name = 'search')
+            self.notebook.AddPage(page = self.search, text = _("Search modules"), name = 'search')
         else:
             self.search = None