瀏覽代碼

wxGUI/SearchModuleWidget: general notification event, removing GConsole-statusbar dependency (co-author: annakrat)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@53916 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras 12 年之前
父節點
當前提交
d7c1b36732

+ 24 - 0
gui/wxpython/core/events.py

@@ -0,0 +1,24 @@
+"""!
+@package core.events
+
+@brief General events
+
+Put here only truly general events. Once you find that your event can be
+generated in more than one class, put your event here. Otherwise,
+leave it in your class file.
+        
+(C) 2012 by the GRASS Development Team
+
+This program is free software under the GNU General Public License
+(>=v2). Read the file COPYING that comes with GRASS for details.
+
+@author Vaclav Petras <wenzeslaus gmail.com>
+"""
+
+
+from wx.lib.newevent import NewCommandEvent
+
+
+# Notification event intended to update statusbar.
+gShowNotification, EVT_SHOW_NOTIFICATION = NewCommandEvent()
+

+ 4 - 0
gui/wxpython/core/modulesdata.py

@@ -30,6 +30,10 @@ class ModulesData(object):
     """!Holds information about modules.
     """!Holds information about modules.
 
 
     @todo add doctest
     @todo add doctest
+    @todo analyze what exactly this class is doing
+    @todo split this class into two classes
+
+    @see modules::extensions::ExtensionModulesData
     """
     """
     def __init__(self, modulesDesc = None):
     def __init__(self, modulesDesc = None):
 
 

+ 0 - 11
gui/wxpython/gui_core/goutput.py

@@ -273,7 +273,6 @@ class GConsole(wx.SplitterWindow):
             self.MakeSearchPaneContent(self.searchPane.GetPane(), modulesData)
             self.MakeSearchPaneContent(self.searchPane.GetPane(), modulesData)
             self.searchPane.Collapse(True)
             self.searchPane.Collapse(True)
             self.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.OnSearchPaneChanged, self.searchPane) 
             self.Bind(wx.EVT_COLLAPSIBLEPANE_CHANGED, self.OnSearchPaneChanged, self.searchPane) 
-            self.search.Bind(wx.EVT_TEXT,             self.OnUpdateStatusBar)
             self.search.Bind(EVT_MODULE_SELECTED,
             self.search.Bind(EVT_MODULE_SELECTED,
                              lambda event:
                              lambda event:
                                  self.cmdPrompt.SetTextAndFocus(event.name + ' '))
                                  self.cmdPrompt.SetTextAndFocus(event.name + ' '))
@@ -738,16 +737,6 @@ class GConsole(wx.SplitterWindow):
         else:
         else:
             self.cmdPrompt.Unbind(stc.EVT_STC_PAINTED)
             self.cmdPrompt.Unbind(stc.EVT_STC_PAINTED)
             self.cmdOutput.Unbind(stc.EVT_STC_PAINTED)
             self.cmdOutput.Unbind(stc.EVT_STC_PAINTED)
-        
-    def OnUpdateStatusBar(self, event):
-        """!Update statusbar text"""
-        if event.GetString():
-            nItems = len(self.cmdPrompt.GetCommandItems())
-            self.frame.SetStatusText(_('%d modules match') % nItems, 0)
-        else:
-            self.frame.SetStatusText('', 0)
-        
-        event.Skip()
 
 
     def OnCmdOutput(self, event):
     def OnCmdOutput(self, event):
         """!Print command output"""
         """!Print command output"""

+ 8 - 0
gui/wxpython/gui_core/menu.py

@@ -27,6 +27,7 @@ from core              import utils
 from core.modulesdata  import ModulesData
 from core.modulesdata  import ModulesData
 from core.gcmd         import EncodeString
 from core.gcmd         import EncodeString
 from core.settings     import UserSettings
 from core.settings     import UserSettings
+from core.events       import EVT_SHOW_NOTIFICATION
 from gui_core.widgets  import ItemTree, SearchModuleWidget
 from gui_core.widgets  import ItemTree, SearchModuleWidget
 from lmgr.menudata     import LayerManagerMenuData
 from lmgr.menudata     import LayerManagerMenuData
 
 
@@ -155,6 +156,13 @@ class SearchModuleWindow(wx.Panel):
         self.search.GetCtrl().Bind(wx.EVT_TEXT,    self.OnUpdateStatusBar)
         self.search.GetCtrl().Bind(wx.EVT_TEXT,    self.OnUpdateStatusBar)
         self.search.GetCtrl().Bind(wx.EVT_KEY_UP,  self.OnKeyUp)
         self.search.GetCtrl().Bind(wx.EVT_KEY_UP,  self.OnKeyUp)
         
         
+        # stop propagation of event
+        # because number of matched items differs
+        # from number of matched items in tree
+        # TODO: find the reason for this difference
+        # TODO: use this event for updating statusbar (i.e., don't do this bind)
+        self.Bind(EVT_SHOW_NOTIFICATION, lambda event: None)
+        
         self._layout()
         self._layout()
         
         
         self.search.SetFocus()
         self.search.SetFocus()

+ 14 - 11
gui/wxpython/gui_core/widgets.py

@@ -49,6 +49,7 @@ except ImportError:
 
 
 from core        import globalvar
 from core        import globalvar
 from core.debug  import Debug
 from core.debug  import Debug
+from core.events import gShowNotification
 
 
 from wx.lib.newevent import NewEvent
 from wx.lib.newevent import NewEvent
 wxSymbolSelectionChanged, EVT_SYMBOL_SELECTION_CHANGED  = NewEvent()
 wxSymbolSelectionChanged, EVT_SYMBOL_SELECTION_CHANGED  = NewEvent()
@@ -800,19 +801,21 @@ class SearchModuleWidget(wx.Panel):
             mList = self.modulesData.GetCommandItems()
             mList = self.modulesData.GetCommandItems()
             if self.showChoice:
             if self.showChoice:
                 self.searchChoice.SetItems(mList)
                 self.searchChoice.SetItems(mList)
-            if self.showTip:
-                self.searchTip.SetLabel(_("%d modules found") % len(mList))
-            event.Skip()
-            return
+            label = _("%d modules found") % len(mList)
+        else:
+            findIn = self.searchBy.GetClientData(self.searchBy.GetSelection())
+            modules, nFound = self.modulesData.FindModules(text = text, findIn = findIn)
+            self.modulesData.SetFilter(modules)
+            if self.showChoice:
+                self.searchChoice.SetItems(self.modulesData.GetCommandItems())
+                self.searchChoice.SetSelection(0)
+            label = _("%d modules match") % nFound
 
 
-        findIn = self.searchBy.GetClientData(self.searchBy.GetSelection())
-        modules, nFound = self.modulesData.FindModules(text = text, findIn = findIn)
-        self.modulesData.SetFilter(modules)
-        if self.showChoice:
-            self.searchChoice.SetItems(self.modulesData.GetCommandItems())
-            self.searchChoice.SetSelection(0)
         if self.showTip:
         if self.showTip:
-            self.searchTip.SetLabel(_("%d modules match") % nFound)
+            self.searchTip.SetLabel(label)
+
+        newEvent = gShowNotification(self.GetId(), message = label)
+        wx.PostEvent(self, newEvent)
 
 
         event.Skip()
         event.Skip()
 
 

+ 3 - 0
gui/wxpython/lmgr/frame.py

@@ -42,6 +42,7 @@ from grass.script          import core as grass
 from core.gcmd             import RunCommand, GError, GMessage
 from core.gcmd             import RunCommand, GError, GMessage
 from core.settings         import UserSettings, GetDisplayVectSettings
 from core.settings         import UserSettings, GetDisplayVectSettings
 from core.utils            import SetAddOnPath
 from core.utils            import SetAddOnPath
+from core.events           import EVT_SHOW_NOTIFICATION
 from gui_core.preferences  import MapsetAccess, PreferencesDialog, EVT_SETTINGS_CHANGED
 from gui_core.preferences  import MapsetAccess, PreferencesDialog, EVT_SETTINGS_CHANGED
 from lmgr.layertree        import LayerTree, LMIcons
 from lmgr.layertree        import LayerTree, LMIcons
 from lmgr.menudata         import LayerManagerMenuData
 from lmgr.menudata         import LayerManagerMenuData
@@ -154,6 +155,8 @@ class GMFrame(wx.Frame):
         # bindings
         # bindings
         self.Bind(wx.EVT_CLOSE,    self.OnCloseWindow)
         self.Bind(wx.EVT_CLOSE,    self.OnCloseWindow)
         self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
         self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
+        self.Bind(EVT_SHOW_NOTIFICATION,
+                  lambda event: self.SetStatusText(event.message))
 
 
         # minimal frame size
         # minimal frame size
         self.SetMinSize((globalvar.GM_WINDOW_SIZE[0], 400))
         self.SetMinSize((globalvar.GM_WINDOW_SIZE[0], 400))

+ 2 - 1
gui/wxpython/modules/extensions.py

@@ -40,7 +40,8 @@ from gui_core.widgets import ItemTree, GListCtrl, SearchModuleWidget, EVT_MODULE
 class ExtensionModulesData(object):
 class ExtensionModulesData(object):
     """!Holds information about modules.
     """!Holds information about modules.
 
 
-    @todo add doctest
+    @todo add some test
+    @todo this class has some common methods with core::modulesdata::ModulesData
     """
     """
     def __init__(self, modulesDesc):
     def __init__(self, modulesDesc):