[GRASS-SVN] r55326 - in grass/trunk/gui/wxpython: core gmodeler gui_core lmgr mapdisp modules vnet

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Mar 11 13:29:47 PDT 2013


Author: wenzeslaus
Date: 2013-03-11 13:29:47 -0700 (Mon, 11 Mar 2013)
New Revision: 55326

Modified:
   grass/trunk/gui/wxpython/core/events.py
   grass/trunk/gui/wxpython/core/gconsole.py
   grass/trunk/gui/wxpython/core/giface.py
   grass/trunk/gui/wxpython/gmodeler/frame.py
   grass/trunk/gui/wxpython/gui_core/forms.py
   grass/trunk/gui/wxpython/gui_core/goutput.py
   grass/trunk/gui/wxpython/gui_core/mapdisp.py
   grass/trunk/gui/wxpython/gui_core/menu.py
   grass/trunk/gui/wxpython/gui_core/prompt.py
   grass/trunk/gui/wxpython/gui_core/widgets.py
   grass/trunk/gui/wxpython/lmgr/frame.py
   grass/trunk/gui/wxpython/lmgr/giface.py
   grass/trunk/gui/wxpython/lmgr/layertree.py
   grass/trunk/gui/wxpython/mapdisp/frame.py
   grass/trunk/gui/wxpython/mapdisp/main.py
   grass/trunk/gui/wxpython/mapdisp/mapwindow.py
   grass/trunk/gui/wxpython/modules/extensions.py
   grass/trunk/gui/wxpython/modules/mcalc_builder.py
   grass/trunk/gui/wxpython/vnet/dialogs.py
Log:
wxGUI: replacing wx events by pydispatcher signals, first steps (co-author: annakrat)

Modified: grass/trunk/gui/wxpython/core/events.py
===================================================================
--- grass/trunk/gui/wxpython/core/events.py	2013-03-11 20:25:45 UTC (rev 55325)
+++ grass/trunk/gui/wxpython/core/events.py	2013-03-11 20:29:47 UTC (rev 55326)
@@ -33,18 +33,6 @@
 from wx.lib.newevent import NewEvent
 
 
-# Notification event intended to update statusbar.
-# The message attribute contains the text of the message (plain text)
-gShowNotification, EVT_SHOW_NOTIFICATION = NewCommandEvent()
-
-
-# Occurs event when some map is created or updated by a module.
-# attributes: name: map name, ltype: map type,
-# add: if map should be added to layer tree (questionable attribute)
-gMapCreated, EVT_MAP_CREATED = NewCommandEvent()
-
-gZoomChanged, EVT_ZOOM_CHANGED = NewEvent()
-
 # Post it to BufferedWindow instance, which you want to update.
 # For relevant attributes for the event see 
 # mapdisp.mapwindow.BufferedWindow UpdateMap method arguments.

Modified: grass/trunk/gui/wxpython/core/gconsole.py
===================================================================
--- grass/trunk/gui/wxpython/core/gconsole.py	2013-03-11 20:25:45 UTC (rev 55325)
+++ grass/trunk/gui/wxpython/core/gconsole.py	2013-03-11 20:29:47 UTC (rev 55326)
@@ -35,9 +35,10 @@
 import grass.script as grass
 from   grass.script import task as gtask
 
+from grass.pydispatch.signal import Signal
+
 from core import globalvar
 from core.gcmd import CommandThread, GError, GException
-from core.events import gMapCreated
 from gui_core.forms import GUI
 from core.debug import Debug
 from core.settings import UserSettings
@@ -348,6 +349,10 @@
         """
         wx.EvtHandler.__init__(self)
 
+        # Signal when some map is created or updated by a module.
+        # attributes: name: map name, ltype: map type,
+        self.mapCreated = Signal('GConsole.mapCreated')
+
         self._guiparent = guiparent
         self._giface = giface
         self._ignoredCmdPattern = ignoredCmdPattern
@@ -595,7 +600,7 @@
     def OnCmdDone(self, event):
         """!Command done (or aborted)
 
-        Posts event EVT_MAP_CREATED.
+        Sends signal mapCreated if map is recognized in output parameters.
         """
         # Process results here
         try:
@@ -650,9 +655,7 @@
                 name = p.get('value')
                 if '@' not in name:
                     name = name + '@' + grass.gisenv()['MAPSET']
-                mapEvent = gMapCreated(self._guiparent.GetId(),
-                                       name=name, ltype=prompt, add=None)
-                wx.PostEvent(self._guiparent, mapEvent)
+                self.mapCreated.emit(name=name, ltype=prompt)
 
         event.Skip()
 

Modified: grass/trunk/gui/wxpython/core/giface.py
===================================================================
--- grass/trunk/gui/wxpython/core/giface.py	2013-03-11 20:25:45 UTC (rev 55325)
+++ grass/trunk/gui/wxpython/core/giface.py	2013-03-11 20:29:47 UTC (rev 55326)
@@ -22,6 +22,7 @@
 
 import grass.script as grass
 
+from grass.pydispatch.signal import Signal
 
 # to disable Abstract class not referenced
 #pylint: disable=R0921
@@ -136,6 +137,15 @@
 class StandaloneGrassInterface():
     """!@implements GrassInterface"""
     def __init__(self):
+
+        # Signal when some map is created or updated by a module.
+        # attributes: name: map name, ltype: map type,
+        # add: if map should be added to layer tree (questionable attribute)
+        self.mapCreated = Signal('StandaloneGrassInterface.mapCreated')
+
+        # Signal emitted to request updating of map
+        self.updateMap = Signal('StandaloneGrassInterface.updateMap')
+
         self._gconsole = GConsole()
         self._gconsole.Bind(EVT_CMD_PROGRESS, self._onCmdProgress)
         self._gconsole.Bind(EVT_CMD_OUTPUT, self._onCmdOutput)

Modified: grass/trunk/gui/wxpython/gmodeler/frame.py
===================================================================
--- grass/trunk/gui/wxpython/gmodeler/frame.py	2013-03-11 20:25:45 UTC (rev 55325)
+++ grass/trunk/gui/wxpython/gmodeler/frame.py	2013-03-11 20:29:47 UTC (rev 55326)
@@ -37,7 +37,6 @@
 from core.gconsole        import GConsole, \
     EVT_CMD_RUN, EVT_CMD_DONE, EVT_CMD_PREPARE, EVT_CMD_RUN, EVT_CMD_DONE
 from gui_core.goutput     import GConsoleWindow
-from core.events          import EVT_MAP_CREATED, EVT_SHOW_NOTIFICATION
 from core.debug           import Debug
 from core.gcmd            import GMessage, GException, GWarning, GError, RunCommand
 from gui_core.dialogs     import GetImageHandlers
@@ -110,6 +109,8 @@
         
         self._gconsole = GConsole(guiparent = self)
         self.goutput = GConsoleWindow(parent = self, gconsole = self._gconsole)
+        self.goutput.showNotification.connect(lambda message: self.SetStatusText(message))
+
         # here events are binded twice
         self._gconsole.Bind(EVT_CMD_RUN,
                                 lambda event:
@@ -120,9 +121,6 @@
         self.Bind(EVT_CMD_RUN, self.OnCmdRun)
         self.Bind(EVT_CMD_DONE, self.OnCmdDone)
         self.Bind(EVT_CMD_PREPARE, self.OnCmdPrepare)
-        self.Bind(EVT_MAP_CREATED, self.OnMapCreated)
-        self.Bind(EVT_SHOW_NOTIFICATION,
-                  lambda event: self.SetStatusText(event.message))
 
         self.notebook.AddPage(page = self.canvas, text=_('Model'), name = 'model')
         self.notebook.AddPage(page = self.itemPanel, text=_('Items'), name = 'items')
@@ -240,14 +238,6 @@
         except IndexError:
             pass
 
-    def OnMapCreated(self, event):
-        """!Map was created but we don't want to add it to layer tree.
-        """
-        # remove this method if you want to add it to layer tree
-        # or see gui_core.forms.TaskFrame.OnMapCreated
-        event.add = False
-        event.Skip()
-
     def OnCloseWindow(self, event):
         """!Close window"""
         if self.modelChanged and \

Modified: grass/trunk/gui/wxpython/gui_core/forms.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/forms.py	2013-03-11 20:25:45 UTC (rev 55325)
+++ grass/trunk/gui/wxpython/gui_core/forms.py	2013-03-11 20:29:47 UTC (rev 55326)
@@ -87,6 +87,8 @@
 except ImportError:
     import elementtree.ElementTree as etree # Python <= 2.4
 
+from grass.pydispatch.signal import Signal
+
 from grass.script import core as grass
 from grass.script import task as gtask
 
@@ -96,7 +98,6 @@
 from core             import gcmd
 from core             import utils
 from core.settings    import UserSettings
-from core.events      import EVT_MAP_CREATED
 from gui_core.widgets import FloatValidator, GNotebook, FormNotebook, FormListbook
 
 wxUpdateDialog, EVT_DIALOG_UPDATE = NewEvent()
@@ -456,6 +457,9 @@
                                       frame = self)
         self._gconsole = self.notebookpanel._gconsole
         self.goutput = self.notebookpanel.goutput
+        if self._gconsole:
+            self._gconsole.mapCreated.connect(self.OnMapCreated)
+
         self.notebookpanel.OnUpdateValues = self.updateValuesHook
         guisizer.Add(item = self.notebookpanel, proportion = 1, flag = wx.EXPAND)
         
@@ -558,7 +562,6 @@
         # bindings
         self.Bind(wx.EVT_CLOSE,  self.OnCancel)
         self.Bind(wx.EVT_KEY_UP, self.OnKeyUp)
-        self.Bind(EVT_MAP_CREATED, self.OnMapCreated)
         
         # do layout
         # called automatically by SetSizer()
@@ -650,12 +653,12 @@
             # was closed also when aborted but better is leave it open
             wx.FutureCall(2000, self.Close)
 
-    def OnMapCreated(self, event):
+    def OnMapCreated(self, name, ltype):
         if hasattr(self, "addbox") and self.addbox.IsChecked():
-            event.add = True
+            add = True
         else:
-            event.add = False
-        event.Skip()
+            add = False
+        self._giface.mapCreated.emit(name=name, ltype=ltype, add=add)
     
     def OnOK(self, event):
         """!OK button pressed"""
@@ -782,7 +785,9 @@
         self._giface = giface
         
         wx.Panel.__init__(self, parent, id = id, *args, **kwargs)
-        
+
+        self.mapCreated = Signal
+
         # Determine tab layout
         sections = []
         is_section = {}

Modified: grass/trunk/gui/wxpython/gui_core/goutput.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/goutput.py	2013-03-11 20:25:45 UTC (rev 55325)
+++ grass/trunk/gui/wxpython/gui_core/goutput.py	2013-03-11 20:29:47 UTC (rev 55326)
@@ -29,8 +29,9 @@
 from   wx import stc
 from wx.lib.newevent import NewEvent
 
+from grass.pydispatch.signal import Signal
+
 from core.gcmd       import GError, EncodeString
-from core.events     import gShowNotification
 from core.gconsole   import GConsole, \
     EVT_CMD_OUTPUT, EVT_CMD_PROGRESS, EVT_CMD_RUN, EVT_CMD_DONE, \
     EVT_WRITE_LOG, EVT_WRITE_CMD_LOG, EVT_WRITE_WARNING, EVT_WRITE_ERROR
@@ -80,6 +81,9 @@
         self._gcstyle = gcstyle
         self.lineWidth       = 80
 
+        # signal which requests showing of a notification
+        self.showNotification = Signal("GConsoleWindow.showNotification")
+
         # progress bar
         self.progressbar = wx.Gauge(parent = self.panelOutput, id = wx.ID_ANY,
                                     range = 100, pos = (110, 50), size = (-1, 25),
@@ -121,6 +125,7 @@
         self.cmdPrompt.Bind(EVT_GPROMPT_RUN_CMD, 
                             lambda event:
                                 self._gconsole.RunCmd(command = event.cmd))
+        self.cmdPrompt.showNotification.connect(self.showNotification)
 
         if not self._gcstyle & GC_PROMPT:
             self.cmdPrompt.Hide()
@@ -259,7 +264,9 @@
         
         self.search = SearchModuleWidget(parent = pane,
                                          modulesData = modulesData)
-        
+
+        self.search.showNotification.connect(self.showNotification)
+
         border.Add(item = self.search, proportion = 0,
                    flag = wx.EXPAND | wx.ALL, border = 1)
         
@@ -391,7 +398,7 @@
             finally:
                 output.close()
             message = _("Commands output saved into '%s'") % path
-            wx.PostEvent(self, gShowNotification(self.GetId(), message = message))
+            self.showNotification.emit(message = message)
         
         dlg.Destroy()
 
@@ -444,7 +451,7 @@
             output.close()
         
         message = _("Commands protocol saved into '%s'") % self.cmdFileProtocol
-        wx.PostEvent(self, gShowNotification(self.GetId(), message = message))
+        self.showNotification.emit(message = message)
         del self.cmdFileProtocol
         
     def OnCmdProtocol(self, event = None):

Modified: grass/trunk/gui/wxpython/gui_core/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/mapdisp.py	2013-03-11 20:25:45 UTC (rev 55325)
+++ grass/trunk/gui/wxpython/gui_core/mapdisp.py	2013-03-11 20:29:47 UTC (rev 55326)
@@ -27,7 +27,6 @@
 
 from core        import globalvar
 from core.debug  import Debug
-from core.events import EVT_ZOOM_CHANGED
 
 from grass.script import core as grass
 
@@ -56,7 +55,7 @@
                  style = wx.DEFAULT_FRAME_STYLE,
                  auimgr = None, name = None, **kwargs):
         """!
-        
+
         @warning Use \a auimgr parameter only if you know what you are doing.
         
         @param parent gui parent
@@ -529,28 +528,30 @@
     
     def ActivateFirstMap(self, event = None):
         """!Make first Map and MapWindow active and (un)bind regions of the two Maps."""
+        if self.MapWindow == self.firstMapWindow:
+            return
+
         self.Map = self.firstMap
         self.MapWindow = self.firstMapWindow
         self.GetMapToolbar().SetActiveMap(0)
 
         # bind/unbind regions
         if self._bindRegions:
-            self.firstMapWindow.Bind(EVT_ZOOM_CHANGED, self.OnZoomChangedFirstMap)
-        else:
-            self.firstMapWindow.Unbind(EVT_ZOOM_CHANGED)
-        self.secondMapWindow.Unbind(EVT_ZOOM_CHANGED)
+            self.firstMapWindow.zoomChanged.connect(self.OnZoomChangedFirstMap)
+            self.secondMapWindow.zoomChanged.disconnect(self.OnZoomChangedSecondMap)
 
     def ActivateSecondMap(self, event = None):
         """!Make second Map and MapWindow active and (un)bind regions of the two Maps."""
+        if self.MapWindow == self.secondMapWindow:
+            return        
+
         self.Map = self.secondMap
         self.MapWindow = self.secondMapWindow
         self.GetMapToolbar().SetActiveMap(1)
 
         if self._bindRegions:
-            self.secondMapWindow.Bind(EVT_ZOOM_CHANGED, self.OnZoomChangedSecondMap)
-        else:
-            self.secondMapWindow.Unbind(EVT_ZOOM_CHANGED)
-        self.firstMapWindow.Unbind(EVT_ZOOM_CHANGED)
+            self.secondMapWindow.zoomChanged.connect(self.OnZoomChangedSecondMap)
+            self.firstMapWindow.zoomChanged.disconnect(self.OnZoomChangedFirstMap)
 
     def SetBindRegions(self, on):
         """!Set or unset binding display regions."""
@@ -558,14 +559,16 @@
 
         if on:
             if self.MapWindow == self.firstMapWindow:
-                self.firstMapWindow.Bind(EVT_ZOOM_CHANGED, self.OnZoomChangedFirstMap)
+                self.firstMapWindow.zoomChanged.connect(self.OnZoomChangedFirstMap)
             else:
-                self.secondMapWindow.Bind(EVT_ZOOM_CHANGED, self.OnZoomChangedSecondMap)
+                self.secondMapWindow.zoomChanged.connect(self.OnZoomChangedSecondMap)
         else:
-            self.firstMapWindow.Unbind(EVT_ZOOM_CHANGED)
-            self.secondMapWindow.Unbind(EVT_ZOOM_CHANGED)
+            if self.MapWindow == self.firstMapWindow:
+                self.firstMapWindow.zoomChanged.disconnect(self.OnZoomChangedFirstMap)
+            else:
+                self.secondMapWindow.zoomChanged.disconnect(self.OnZoomChangedSecondMap)
 
-    def OnZoomChangedFirstMap(self, event):
+    def OnZoomChangedFirstMap(self):
         """!Display region of the first window (Map) changed.
 
         Synchronize the region of the second map and re-render it.
@@ -575,7 +578,7 @@
         self.GetSecondMap().region.update(region)
         self.Render(mapToRender = self.GetSecondWindow())
 
-    def OnZoomChangedSecondMap(self, event):
+    def OnZoomChangedSecondMap(self):
         """!Display region of the second window (Map) changed.
 
         Synchronize the region of the second map and re-render it.

Modified: grass/trunk/gui/wxpython/gui_core/menu.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/menu.py	2013-03-11 20:25:45 UTC (rev 55325)
+++ grass/trunk/gui/wxpython/gui_core/menu.py	2013-03-11 20:29:47 UTC (rev 55326)
@@ -27,7 +27,6 @@
 from core.modulesdata  import ModulesData
 from core.gcmd         import EncodeString
 from core.settings     import UserSettings
-from core.events       import EVT_SHOW_NOTIFICATION
 from gui_core.widgets  import ItemTree, SearchModuleWidget
 from lmgr.menudata     import LayerManagerMenuData
 
@@ -155,14 +154,13 @@
         self.tree.Bind(wx.EVT_TREE_SEL_CHANGED,    self.OnItemSelected)
         self.search.GetCtrl().Bind(wx.EVT_TEXT,    self.OnUpdateStatusBar)
         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)
-        
+        # TODO: use this event for updating statusbar
+        # TODO: some showNotification usage?
+
         self._layout()
         
         self.search.SetFocus()

Modified: grass/trunk/gui/wxpython/gui_core/prompt.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/prompt.py	2013-03-11 20:25:45 UTC (rev 55325)
+++ grass/trunk/gui/wxpython/gui_core/prompt.py	2013-03-11 20:29:47 UTC (rev 55326)
@@ -29,10 +29,11 @@
 from grass.script import core as grass
 from grass.script import task as gtask
 
+from grass.pydispatch.signal import Signal
+
 from core          import globalvar
 from core          import utils
 from core.gcmd     import EncodeString, DecodeString, GetRealCmd
-from core.events   import gShowNotification
 
 gPromptRunCmd, EVT_GPROMPT_RUN_CMD = NewEvent()
 
@@ -197,7 +198,10 @@
         self.Bind(wx.stc.EVT_STC_AUTOCOMP_SELECTION, self.OnItemSelected)
         self.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnItemChanged)
         self.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus)
-        
+
+        # signal which requests showing of a notification
+        self.showNotification = Signal('GPromptSTC.showNotification')
+
     def OnTextSelectionChanged(self, event):
         """!Copy selected text to clipboard and skip event.
         The same function is in GStc class (goutput.py).
@@ -586,12 +590,8 @@
             event.Skip()
 
     def ShowStatusText(self, text):
-        """!Sets statusbar text, if it's too long, it is cut off"""
-        # event is not propagated beyond dialog
-        # thus when GPrompt in Modeler is inside a dialog, 
-        # it does not show text in modeler statusbar which is probably
-        # the right behaviour. The dialog itself should display the text.
-        wx.PostEvent(self, gShowNotification(self.GetId(), message = text))
+        """!Requests showing of notification, e.g. showing in a statusbar."""
+        self.showNotification.emit(message=text)
         
     def GetTextLeft(self):
         """!Returns all text left of the caret"""

Modified: grass/trunk/gui/wxpython/gui_core/widgets.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/widgets.py	2013-03-11 20:25:45 UTC (rev 55325)
+++ grass/trunk/gui/wxpython/gui_core/widgets.py	2013-03-11 20:29:47 UTC (rev 55326)
@@ -49,10 +49,11 @@
 except ImportError:
     import wx.lib.customtreectrl as CT
 
+from grass.pydispatch.signal import Signal
+
 from core        import globalvar
 from core.gcmd   import GMessage
 from core.debug  import Debug
-from core.events import gShowNotification
 
 from wx.lib.newevent import NewEvent
 wxSymbolSelectionChanged, EVT_SYMBOL_SELECTION_CHANGED  = NewEvent()
@@ -861,7 +862,10 @@
         self._searchDict = { _('description') : 'description',
                              _('command') : 'command',
                              _('keywords') : 'keywords' }
-        
+
+        # signal which requests showing of a notification
+        self.showNotification = Signal('SearchModuleWidget.showNotification')
+
         self.box = wx.StaticBox(parent = self, id = wx.ID_ANY,
                                 label = " %s " % _("Find module - (press Enter for next match)"))
 
@@ -949,8 +953,7 @@
         if self.showTip:
             self.searchTip.SetLabel(label)
 
-        newEvent = gShowNotification(self.GetId(), message = label)
-        wx.PostEvent(self, newEvent)
+        self.showNotification.emit(message=label)
 
         event.Skip()
 

Modified: grass/trunk/gui/wxpython/lmgr/frame.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/frame.py	2013-03-11 20:25:45 UTC (rev 55325)
+++ grass/trunk/gui/wxpython/lmgr/frame.py	2013-03-11 20:29:47 UTC (rev 55326)
@@ -43,7 +43,6 @@
 from core.gcmd             import RunCommand, GError, GMessage, GException
 from core.settings         import UserSettings, GetDisplayVectSettings
 from core.utils            import SetAddOnPath, GetLayerNameFromCmd, command2ltype
-from core.events           import EVT_SHOW_NOTIFICATION, EVT_MAP_CREATED
 from gui_core.preferences  import MapsetAccess, PreferencesDialog, EVT_SETTINGS_CHANGED
 from lmgr.layertree        import LayerTree, LMIcons
 from lmgr.menudata         import LayerManagerMenuData
@@ -162,10 +161,9 @@
         # bindings
         self.Bind(wx.EVT_CLOSE,    self.OnCloseWindow)
         self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
-        self.Bind(EVT_SHOW_NOTIFICATION,
-                  lambda event: self.SetStatusText(event.message))
-        self.Bind(EVT_MAP_CREATED, self.OnMapCreated)
 
+        self._giface.mapCreated.connect(self.OnMapCreated)
+
         # minimal frame size
         self.SetMinSize((globalvar.GM_WINDOW_SIZE[0], 400))
 
@@ -278,6 +276,11 @@
         self.goutput = GConsoleWindow(parent = self, gconsole = self._gconsole,
                                       gcstyle = GC_SEARCH | GC_PROMPT)
         self.notebook.AddPage(page = self.goutput, text = _("Command console"), name = 'output')
+
+        self.goutput.showNotification.connect(lambda message: self.SetStatusText(message))
+
+        self._gconsole.mapCreated.connect(self.OnMapCreated)
+
         # EVT_CMD_OUTPUT and EVT_GC_CONTENT_CHANGED are similar but should be distinct
         # (logging/messages may be splited from GConsole commad running interface)
         # thus, leaving this bind here
@@ -1448,6 +1451,7 @@
                 cmd = ['r.mapcalc']
         
         win = MapCalcFrame(parent = self,
+                           giface = self._giface,
                            cmd = cmd[0])
         win.CentreOnScreen()
         win.Show()
@@ -1663,14 +1667,14 @@
                                        lcmd = cmd,
                                        lgroup = None)
 
-    def OnMapCreated(self, event):
+    def OnMapCreated(self, name, ltype, add=None):
         """!Decides wheter the map should be added to layer tree."""
-        if event.add is None:
+        if add is None:
             if UserSettings.Get(group = 'cmd',
                                 key = 'addNewLayer', subkey = 'enabled'):
-                self.AddOrUpdateMap(event.name, event.ltype)
-        elif event.add:
-            self.AddOrUpdateMap(event.name, event.ltype)
+                self.AddOrUpdateMap(name, ltype)
+        elif add:
+            self.AddOrUpdateMap(name, ltype)
 
     def AddOrUpdateMap(self, mapName, ltype):
         """!Add map layer or update"""

Modified: grass/trunk/gui/wxpython/lmgr/giface.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/giface.py	2013-03-11 20:25:45 UTC (rev 55325)
+++ grass/trunk/gui/wxpython/lmgr/giface.py	2013-03-11 20:29:47 UTC (rev 55326)
@@ -15,6 +15,7 @@
 @author Vaclav Petras <wenzeslaus gmail.com>
 """
 
+from grass.pydispatch.signal import Signal
 
 class Layer(object):
     """!@implements core::giface::Layer
@@ -64,6 +65,14 @@
         """
         self.lmgr = lmgr
 
+        # Signal when some map is created or updated by a module.
+        # attributes: name: map name, ltype: map type,
+        # add: if map should be added to layer tree (questionable attribute)
+        self.mapCreated = Signal('LayerManagerGrassInterface.mapCreated')
+
+        # Signal emitted to request updating of map
+        self.updateMap = Signal('LayerManagerGrassInterface.updateMap')
+
     def RunCmd(self, *args, **kwargs):
         self.lmgr._gconsole.RunCmd(*args, **kwargs)
 
@@ -107,18 +116,21 @@
         return self.lmgr.goutput.GetProgressBar()
 
 
-class LayerManagerGrassInterfaceForMapDisplay(LayerManagerGrassInterface):
+class LayerManagerGrassInterfaceForMapDisplay(object):
     """!Provides reference only to the given layer list (according to tree),
         not to the current.
     """
-    def __init__(self, lmgr, tree):
+    def __init__(self, giface, tree):
         """!
-        @lmgr layer manager
-        @tree tree which will be used instead of the lmgr.tree
+        @giface original grass interface
+        @tree tree which will be used instead of the tree from giface
         """
-        LayerManagerGrassInterface.__init__(self, lmgr)
+        self._giface = giface
         self.tree = tree
 
+        # Signal emitted to request updating of map
+        self.updateMap = Signal('LayerManagerGrassInterfaceForMapDisplay.updateMap')
+
     def GetLayerTree(self):
         return self.tree
 
@@ -127,3 +139,6 @@
 
     def GetMapWindow(self):
         return self.tree.GetMapDisplay()
+
+    def __getattr__(self, name):
+        return getattr(self._giface, name)

Modified: grass/trunk/gui/wxpython/lmgr/layertree.py
===================================================================
--- grass/trunk/gui/wxpython/lmgr/layertree.py	2013-03-11 20:25:45 UTC (rev 55325)
+++ grass/trunk/gui/wxpython/lmgr/layertree.py	2013-03-11 20:29:47 UTC (rev 55326)
@@ -155,7 +155,7 @@
         
         # init associated map display
         pos = wx.Point((self.displayIndex + 1) * 25, (self.displayIndex + 1) * 25)
-        gifaceForDisplay = LayerManagerGrassInterfaceForMapDisplay(self.lmgr,
+        gifaceForDisplay = LayerManagerGrassInterfaceForMapDisplay(self._giface,
                                                                    self)
         self.mapdisplay = MapFrame(self, giface = gifaceForDisplay,
                                    id = wx.ID_ANY, pos = pos,

Modified: grass/trunk/gui/wxpython/mapdisp/frame.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/frame.py	2013-03-11 20:25:45 UTC (rev 55325)
+++ grass/trunk/gui/wxpython/mapdisp/frame.py	2013-03-11 20:29:47 UTC (rev 55326)
@@ -1293,7 +1293,7 @@
             return
         
         from vnet.dialogs import VNETDialog
-        self.dialogs['vnet'] = VNETDialog(parent = self)
+        self.dialogs['vnet'] = VNETDialog(parent=self, giface=self._giface)
         self.dialogs['vnet'].CenterOnScreen()
         self.dialogs['vnet'].Show()
             

Modified: grass/trunk/gui/wxpython/mapdisp/main.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/main.py	2013-03-11 20:25:45 UTC (rev 55325)
+++ grass/trunk/gui/wxpython/mapdisp/main.py	2013-03-11 20:29:47 UTC (rev 55326)
@@ -38,7 +38,6 @@
 from core.giface   import StandaloneGrassInterface
 from core.gcmd     import RunCommand
 from core.render   import Map, MapLayer
-from core.events   import gUpdateMap
 from mapdisp.frame import MapFrame
 from grass.script  import core as grass
 from core.debug    import Debug
@@ -56,7 +55,7 @@
 
 
 class DMonMap(Map):
-    def __init__(self, cmdfile=None, mapfile=None):
+    def __init__(self, giface, cmdfile=None, mapfile=None):
         """!Map composition (stack of map layers and overlays)
 
         @param cmdline full path to the cmd file (defined by d.mon)
@@ -65,6 +64,8 @@
 
         Map.__init__(self)
 
+        self._giface = giface
+
         # environment settings
         self.env   = dict()
 
@@ -125,8 +126,7 @@
         fd.close()
 
         if nlayers:
-            event = gUpdateMap()
-            wx.PostEvent(self.receiver, event)
+            self._giface.updateMap.emit()
 
         Debug.msg(1, "Map.GetLayersFromCmdFile(): cmdfile=%s" % self.cmdfile)
         Debug.msg(1, "                            nlayers=%d" % nlayers)
@@ -232,15 +232,18 @@
     def OnInit(self):
         if not globalvar.CheckWxVersion([2, 9]):
             wx.InitAllImageHandlers()
+
+        # actual use of StandaloneGrassInterface not yet tested
+        # needed for adding functionality in future
+        giface = DMonGrassInterface(None)
+
         if __name__ == "__main__":
             self.cmdTimeStamp = os.path.getmtime(monFile['cmd'])
-            self.Map = DMonMap(cmdfile = monFile['cmd'], mapfile = monFile['map'])
+            self.Map = DMonMap(giface=giface, cmdfile=monFile['cmd'],
+                               mapfile = monFile['map'])
         else:
             self.Map = None
 
-        # actual use of StandaloneGrassInterface not yet tested
-        # needed for adding functionality in future
-        giface = DMonGrassInterface(None)
         self.mapFrm = DMonFrame(parent = None, id = wx.ID_ANY, Map = self.Map,
                                 giface = giface, size = monSize)
         # FIXME: hack to solve dependency

Modified: grass/trunk/gui/wxpython/mapdisp/mapwindow.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/mapwindow.py	2013-03-11 20:25:45 UTC (rev 55325)
+++ grass/trunk/gui/wxpython/mapdisp/mapwindow.py	2013-03-11 20:29:47 UTC (rev 55326)
@@ -28,13 +28,15 @@
 
 import wx
 
+from grass.pydispatch.signal import Signal
+
 import grass.script as grass
 
 from gui_core.dialogs   import SavedRegion
 from core.gcmd          import RunCommand, GException, GError, GMessage
 from core.debug         import Debug
 from core.settings      import UserSettings
-from core.events        import gZoomChanged, EVT_UPDATE_MAP
+from core.events        import EVT_UPDATE_MAP
 from gui_core.mapwindow import MapWindow
 from core.ws            import EVT_UPDATE_PRGBAR
 from core.utils         import GetGEventAttribsForHandler
@@ -77,7 +79,12 @@
         self.lineid = None
         # ID of poly line resulting from cumulative rubber band lines (e.g. measurement)
         self.plineid = None
-        
+
+        # Emitted when zoom of a window is changed
+        self.zoomChanged = Signal('BufferedWindow.zoomChanged')
+
+        self._giface.updateMap.connect(self.UpdateMap)
+
         # event bindings
         self.Bind(wx.EVT_PAINT,           self.OnPaint)
         self.Bind(wx.EVT_SIZE,            self.OnSize)
@@ -603,9 +610,9 @@
         underlaying images or to the geometry of the canvas.
         
         This method should not be called directly.
-        Post core.events.gUpdateMap event to instance of this class. 
 
-        @todo change direct calling of UpdateMap method to posting core.events.gUpdateMap
+        @todo change direct calling of UpdateMap method to emittig grass
+        interface updateMap signal
 
         @param render re-render map composition
         @param renderVector re-render vector map layer enabled for editing (used for digitizer)
@@ -1521,7 +1528,7 @@
         # update statusbar
         self.frame.StatusbarUpdate()
 
-        wx.PostEvent(self, gZoomChanged())
+        self.zoomChanged.emit()
 
     def ZoomHistory(self, n, s, e, w):
         """!Manages a list of last 10 zoom extents
@@ -1553,7 +1560,7 @@
         
         toolbar.Enable('zoomBack', enable)
 
-        wx.PostEvent(self, gZoomChanged())
+        self.zoomChanged.emit()
         
         return removed
 

Modified: grass/trunk/gui/wxpython/modules/extensions.py
===================================================================
--- grass/trunk/gui/wxpython/modules/extensions.py	2013-03-11 20:25:45 UTC (rev 55325)
+++ grass/trunk/gui/wxpython/modules/extensions.py	2013-03-11 20:29:47 UTC (rev 55326)
@@ -33,7 +33,6 @@
 from core             import globalvar
 from core.gcmd        import GError, RunCommand
 from core.utils       import SetAddOnPath
-from core.events      import EVT_SHOW_NOTIFICATION
 from gui_core.forms   import GUI
 from gui_core.widgets import ItemTree, GListCtrl, SearchModuleWidget, EVT_MODULE_SELECTED
 
@@ -150,7 +149,9 @@
                                          showChoice = False)
         self.search.SetSelection(0)
         self.search.Bind(EVT_MODULE_SELECTED, self.OnShowItem)
-        
+        # show text in statusbar when notification appears
+        self.search.showNotification.connect(lambda message: self.SetStatusText(message))
+
         self.optionBox = wx.StaticBox(parent = self.panel, id = wx.ID_ANY,
                                       label = " %s " % _("Options"))
         if sys.platform == 'win32':
@@ -193,13 +194,7 @@
         self.tree.Bind(wx.EVT_TREE_ITEM_ACTIVATED, self.OnItemActivated)
         self.tree.Bind(wx.EVT_TREE_SEL_CHANGED,    self.OnItemSelected)
         self.search.Bind(wx.EVT_TEXT_ENTER,        self.OnShowItem)
-        self.search.Bind(wx.EVT_TEXT,              self.OnUpdateStatusBar)
 
-        # show text in statusbar when notification command event occurs
-        # propagation stops here, no need to show text twice
-        self.Bind(EVT_SHOW_NOTIFICATION,
-                  lambda event: self.SetStatusText(event.message))
-        
         wx.CallAfter(self._fetch)
         
         self._layout()
@@ -271,7 +266,10 @@
                                           'svnurl=' + self.repo.GetValue().strip()]
     
     def OnUpdateStatusBar(self, event):
-        """!Update statusbar text"""
+        """!Update statusbar text
+
+        @todo This method is a dead code. Is it useful?
+        """
         element = self.search.GetSelection()
         if not self.tree.IsLoaded():
             self.SetStatusText(_("Fetch list of available extensions by clicking on 'Fetch' button"), 0)

Modified: grass/trunk/gui/wxpython/modules/mcalc_builder.py
===================================================================
--- grass/trunk/gui/wxpython/modules/mcalc_builder.py	2013-03-11 20:25:45 UTC (rev 55325)
+++ grass/trunk/gui/wxpython/modules/mcalc_builder.py	2013-03-11 20:29:47 UTC (rev 55326)
@@ -27,7 +27,6 @@
 
 from core             import globalvar
 from core.gcmd        import GError, RunCommand
-from core.events      import gMapCreated
 from gui_core.gselect import Select
 from gui_core.forms   import GUI
 from core.settings    import UserSettings
@@ -36,9 +35,11 @@
     """!Mapcalc Frame class. Calculator-style window to create and run
     r(3).mapcalc statements.
     """
-    def __init__(self, parent, cmd, id = wx.ID_ANY,
+    def __init__(self, parent, giface, cmd, id = wx.ID_ANY,
                  style = wx.DEFAULT_FRAME_STYLE | wx.RESIZE_BORDER, **kwargs):
         self.parent = parent
+        self._giface = giface
+
         if self.parent:
             self.log = self.parent.GetLogWindow()
         else:
@@ -59,7 +60,7 @@
         
         self.panel = wx.Panel(parent = self, id = wx.ID_ANY)
         self.CreateStatusBar()
-        
+
         #
         # variables
         #
@@ -503,16 +504,17 @@
                        overwrite = overwrite)
         
     def OnDone(self, cmd, returncode):
-        """!Add create map to the layer tree"""
+        """!Add create map to the layer tree
+
+        Sends the mapCreated signal from the grass interface.
+        """
         if returncode != 0:
             return
         name = self.newmaptxt.GetValue().strip(' "') + '@' + grass.gisenv()['MAPSET']
         ltype = 'rast'
         if self.rast3d:
             ltype = 'rast3d'
-        mapEvent = gMapCreated(self.GetId(),
-                               name=name, ltype=ltype, add=self.addbox.IsChecked())
-        wx.PostEvent(self, mapEvent)
+        self._giface.mapCreated.emit(name=name, ltype=ltype, add=self.addbox.IsChecked())
 
     def OnSaveExpression(self, event):
         """!Saves expression to file

Modified: grass/trunk/gui/wxpython/vnet/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/vnet/dialogs.py	2013-03-11 20:25:45 UTC (rev 55325)
+++ grass/trunk/gui/wxpython/vnet/dialogs.py	2013-03-11 20:29:47 UTC (rev 55326)
@@ -62,7 +62,7 @@
 #   it's destructor is not called
 
 class VNETDialog(wx.Dialog):
-    def __init__(self, parent,
+    def __init__(self, parent, giface,
                  id = wx.ID_ANY, title = _("GRASS GIS Vector Network Analysis Tool"),
                  style = wx.DEFAULT_DIALOG_STYLE | wx.RESIZE_BORDER, **kwargs):
         """!Dialog for vector network analysis"""
@@ -72,6 +72,7 @@
 
         self.parent  = parent  # mapdisp.frame MapFrame class
         self.mapWin = parent.MapWindow 
+        self._giface = giface
 
         # contains current analysis result (do not have to be last one, when history is browsed), 
         # it is instance of VectMap class



More information about the grass-commit mailing list