[GRASS-SVN] r70146 - in grass/trunk/gui/wxpython: gui_core lmgr

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Dec 27 09:21:02 PST 2016


Author: wenzeslaus
Date: 2016-12-27 09:21:02 -0800 (Tue, 27 Dec 2016)
New Revision: 70146

Modified:
   grass/trunk/gui/wxpython/gui_core/menu.py
   grass/trunk/gui/wxpython/lmgr/frame.py
Log:
wxGUI: Help and Advanced search in Modules tab

Help button to show documentation (manual page) for modules
which also tells that in status bar (otherwise same as Run button).

Advanced search does not interact with the window but opens
g.search.modules form window instead (similar concept
to the Simple editor button in the Python tab).


Modified: grass/trunk/gui/wxpython/gui_core/menu.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/menu.py	2016-12-27 16:57:37 UTC (rev 70145)
+++ grass/trunk/gui/wxpython/gui_core/menu.py	2016-12-27 17:21:02 UTC (rev 70146)
@@ -27,6 +27,7 @@
 from core.utils import _
 from gui_core.widgets import SearchModuleWidget
 from gui_core.treeview import CTreeView
+from gui_core.wrap import Button
 from gui_core.wrap import Menu as MenuWidget
 from icons.icon import MetaIcon
 
@@ -137,9 +138,11 @@
         showNotification - attribute 'message'
     """
 
-    def __init__(self, parent, handlerObj, model, id=wx.ID_ANY, **kwargs):
+    def __init__(self, parent, handlerObj, giface, model, id=wx.ID_ANY,
+                 **kwargs):
         self.parent = parent
-        self.handlerObj = handlerObj
+        self._handlerObj = handlerObj
+        self._giface = giface
 
         self.showNotification = Signal('SearchModuleWindow.showNotification')
         wx.Panel.__init__(self, parent=parent, id=id, **kwargs)
@@ -168,11 +171,21 @@
                 wx.SYS_COLOUR_GRAYTEXT))
 
         # buttons
-        self._btnRun = wx.Button(self, id=wx.ID_OK, label=_("&Run"))
-        self._btnRun.SetToolTipString(_("Run selected module from the tree"))
+        self._btnRun = Button(self, id=wx.ID_OK, label=_("&Run"))
+        self._btnRun.SetToolTip(_("Run selected module from the tree"))
+        self._btnHelp = Button(self, id=wx.ID_ANY, label=_("H&elp"))
+        self._btnHelp.SetToolTip(
+            _("Show manual for selected module from the tree"))
+        self._btnAdvancedSearch = Button(self, id=wx.ID_ANY,
+                                         label=_("Adva&nced search..."))
+        self._btnAdvancedSearch.SetToolTip(
+            _("Do advanced search using %s module") % 'g.search.module')
 
         # bindings
         self._btnRun.Bind(wx.EVT_BUTTON, lambda evt: self.Run())
+        self._btnHelp.Bind(wx.EVT_BUTTON, lambda evt: self.Help())
+        self._btnAdvancedSearch.Bind(wx.EVT_BUTTON,
+                                     lambda evt: self.AdvancedSearch())
         self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
 
         self._tree.selectionChanged.connect(self.OnItemSelected)
@@ -193,6 +206,9 @@
 
         # buttons
         btnSizer = wx.BoxSizer(wx.HORIZONTAL)
+        btnSizer.Add(self._btnAdvancedSearch, proportion=0)
+        btnSizer.AddStretchSpacer()
+        btnSizer.Add(self._btnHelp, proportion=0)
         btnSizer.Add(self._btnRun, proportion=0)
 
         sizer.Add(dataSizer, proportion=1,
@@ -201,8 +217,8 @@
         sizer.Add(self._search, proportion=0,
                   flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=5)
 
-        sizer.Add(btnSizer, proportion=0,
-                  flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.RIGHT, border=5)
+        sizer.Add(item=btnSizer, proportion=0,
+                  flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=5)
 
         sizer.Add(self._helpText,
                   proportion=0, flag=wx.EXPAND | wx.LEFT, border=5)
@@ -216,27 +232,61 @@
         self.SetAutoLayout(True)
         self.Layout()
 
-    def Run(self, module=None):
+    def _GetSelectedNode(self):
+        selection = self._tree.GetSelected()
+        if not selection:
+            return None
+        return selection[0]
+
+    def Run(self, node=None):
         """Run selected command.
 
-        :param module: module (represented by tree node)
+        :param node: a tree node associated with the module or other item
         """
-        if module is None:
-            if not self._tree.GetSelected():
-                return
-
-            module = self._tree.GetSelected()[0]
-        data = module.data
+        if not node:
+            node = self._GetSelectedNode()
+        # nothing selected
+        if not node:
+            return
+        data = node.data
+        # non-leaf nodes
         if not data:
             return
 
-        handler = 'self.handlerObj.' + data['handler'].lstrip('self.')
+        # extract name of the handler and create a new call
+        handler = 'self._handlerObj.' + data['handler'].lstrip('self.')
 
         if data['command']:
             eval(handler)(event=None, cmd=data['command'].split())
         else:
             eval(handler)(event=None)
 
+    def Help(self, node=None):
+        """Show documentation for a module"""
+        if not node:
+            node = self._GetSelectedNode()
+        # nothing selected
+        if not node:
+            return
+        data = node.data
+        # non-leaf nodes
+        if not data:
+            return
+
+        if not data['command']:
+            # showing nothing for non-modules
+            return
+        # strip parameters from command if present
+        name = data['command'].split()[0]
+        self._giface.Help(name)
+        self.showNotification.emit(
+            message=_("Documentation for %s is now open in the web browser")
+            % name)
+
+    def AdvancedSearch(self):
+        """Show advanced search window"""
+        self._handlerObj.RunMenuCmd(cmd=['g.search.modules'])
+
     def OnKeyUp(self, event):
         """Key or key combination pressed"""
         if event.ControlDown() and \

Modified: grass/trunk/gui/wxpython/lmgr/frame.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/frame.py	2016-12-27 16:57:37 UTC (rev 70145)
+++ grass/trunk/gui/wxpython/lmgr/frame.py	2016-12-27 17:21:02 UTC (rev 70146)
@@ -358,6 +358,7 @@
                 group='manager', key='hideTabs', subkey='search'):
             self.search = SearchModuleWindow(
                 parent=self.notebook, handlerObj=self,
+                giface=self._giface,
                 model=self._moduleTreeBuilder.GetModel())
             self.search.showNotification.connect(
                 lambda message: self.SetStatusText(message))



More information about the grass-commit mailing list