[GRASS-SVN] r57078 - grass/trunk/gui/wxpython/mapdisp

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jul 13 08:47:04 PDT 2013


Author: wenzeslaus
Date: 2013-07-13 08:47:04 -0700 (Sat, 13 Jul 2013)
New Revision: 57078

Modified:
   grass/trunk/gui/wxpython/mapdisp/frame.py
   grass/trunk/gui/wxpython/mapdisp/mapwindow.py
Log:
wxGUI/mapdisp: using signals to decouple mapwindow and frame (query, zoom history and mouse handlers signals)

Modified: grass/trunk/gui/wxpython/mapdisp/frame.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/frame.py	2013-07-13 14:20:35 UTC (rev 57077)
+++ grass/trunk/gui/wxpython/mapdisp/frame.py	2013-07-13 15:47:04 UTC (rev 57078)
@@ -148,6 +148,20 @@
         self.MapWindow2D = BufferedWindow(self, giface = self._giface, id = wx.ID_ANY,
                                           Map = self.Map, frame = self, tree = self.tree,
                                           lmgr = self._layerManager, overlays = self.decorations)
+        self.MapWindow2D.mapQueried.connect(self.Query)
+        # enable or disable zoom history tool
+        self.MapWindow2D.zoomHistoryAvailable.connect(
+            lambda:
+            self.GetMapToolbar().Enable('zoomBack', enable=True))
+        self.MapWindow2D.zoomHistoryUnavailable.connect(
+            lambda:
+            self.GetMapToolbar().Enable('zoomBack', enable=False))
+        # manage the state of toolbars connected to mouse cursor
+        self.MapWindow2D.mouseHandlerRegistered.connect(
+            lambda:
+            self.UpdateTools(None))
+        self.MapWindow2D.mouseHandlerUnregistered.connect(self.ResetPointer)
+
         self._giface.updateMap.connect(self.MapWindow2D.UpdateMap)
         # default is 2D display mode
         self.MapWindow = self.MapWindow2D
@@ -1331,3 +1345,16 @@
                         self.dialogs['legend'].resizeBtn.GetId():
                     return
             self.dialogs['legend'].resizeBtn.SetValue(0)
+
+    def ResetPointer(self):
+        """Sets pointer mode.
+
+        Sets pointer and toggles it (e.g. after unregistration of mouse
+        handler).
+        Somehow related to UpdateTools.
+        """
+        # sets pointer mode
+        toolbar = self.toolbars['map']
+        toolbar.action['id'] = vars(toolbar)["pointer"]
+        toolbar.OnTool(None)
+        self.OnPointer(event=None)

Modified: grass/trunk/gui/wxpython/mapdisp/mapwindow.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/mapwindow.py	2013-07-13 14:20:35 UTC (rev 57077)
+++ grass/trunk/gui/wxpython/mapdisp/mapwindow.py	2013-07-13 15:47:04 UTC (rev 57078)
@@ -83,6 +83,20 @@
         # Emitted when zoom of a window is changed
         self.zoomChanged = Signal('BufferedWindow.zoomChanged')
 
+        # Emitted when map was queried, parameters x, y are mouse coordinates
+        # TODO: change pixel coordinates to map coordinates (using Pixel2Cell)
+        self.mapQueried = Signal('BufferedWindow.mapQueried')
+
+        # Emitted when the zoom history stack is emptied
+        self.zoomHistoryUnavailable = Signal('BufferedWindow.zoomHistoryUnavailable')
+        # Emitted when the zoom history stack is not empty
+        self.zoomHistoryAvailable = Signal('BufferedWindow.zoomHistoryAvailable')
+
+        # Emitted when someone registers as mouse event handler
+        self.mouseHandlerRegistered = Signal('BufferedWindow.mouseHandlerRegistered')
+        # Emitted when mouse event handler is unregistered
+        self.mouseHandlerUnregistered = Signal('BufferedWindow.mouseHandlerUnregistered')
+
         # event bindings
         self.Bind(wx.EVT_PAINT,           self.OnPaint)
         self.Bind(wx.EVT_SIZE,            self.OnSize)
@@ -1164,6 +1178,8 @@
         
     def OnLeftUp(self, event):
         """!Left mouse button released
+
+        Emits mapQueried signal when mouse use is 'query'.
         """
         Debug.msg (5, "BufferedWindow.OnLeftUp(): use=%s" % \
                        self.mouse["use"])
@@ -1189,8 +1205,8 @@
             self.frame.StatusbarUpdate()
             
         elif self.mouse["use"] == "query":
-            self.frame.Query(self.mouse['end'][0], self.mouse['end'][1])
-        
+            self.mapQueried.emit(x=self.mouse['end'][0], y=self.mouse['end'][1])
+
         elif self.mouse["use"] in ["measure", "profile"]:
             # measure or profile
             if self.mouse["use"] == "measure":
@@ -1504,18 +1520,19 @@
         
     def ZoomBack(self):
         """!Zoom to previous extents in zoomhistory list
+
+        Emits zoomChanged signal.
+        Emits zoomHistoryUnavailable signal when stack is empty.
         """
         zoom = list()
         
         if len(self.zoomhistory) > 1:
             self.zoomhistory.pop()
             zoom = self.zoomhistory[-1]
-        
-        # disable tool if stack is empty
-        if len(self.zoomhistory) < 2: # disable tool
-            toolbar = self.frame.GetMapToolbar()
-            toolbar.Enable('zoomBack', enable = False)
-        
+
+        if len(self.zoomhistory) < 2:
+            self.zoomHistoryUnavailable.emit()
+
         # zoom to selected region
         self.Map.GetRegion(n = zoom[0], s = zoom[1],
                            e = zoom[2], w = zoom[3],
@@ -1531,6 +1548,10 @@
     def ZoomHistory(self, n, s, e, w):
         """!Manages a list of last 10 zoom extents
 
+        Emits zoomChanged signal.
+        Emits zoomHistoryAvailable signal when stack is not empty.
+        Emits zoomHistoryUnavailable signal when stack is empty.
+
         @param n,s,e,w north, south, east, west
 
         @return removed history item if exists (or None)
@@ -1550,13 +1571,9 @@
         
         # update toolbar
         if len(self.zoomhistory) > 1:
-            enable = True
+            self.zoomHistoryAvailable.emit()
         else:
-            enable = False
-        
-        toolbar = self.frame.GetMapToolbar()
-        
-        toolbar.Enable('zoomBack', enable)
+            self.zoomHistoryUnavailable.emit()
 
         self.zoomChanged.emit()
         
@@ -1817,20 +1834,21 @@
         return self.Map
 
     def RegisterMouseEventHandler(self, event, handler, cursor = None):
-        """!Calls UpdateTools to manage connected toolbars"""
-        self.frame.UpdateTools(None)
+        """Registeres mouse event handler.
+
+        Emits mouseHandlerRegistered signal before handler is registered.
+        """
+        self.mouseHandlerRegistered.emit()
         MapWindow.RegisterMouseEventHandler(self, event, handler, cursor)
 
     def UnregisterMouseEventHandler(self, event, handler):
-        """!Sets pointer and toggles it after unregistration"""
+        """Unregisteres mouse event handler.
+
+        Emits mouseHandlerUnregistered signal after handler is unregistered.
+        """
         MapWindow.UnregisterMouseEventHandler(self, event, handler)
+        self.mouseHandlerUnregistered.emit()
         
-        # sets pointer mode
-        toolbar = self.frame.toolbars['map']
-        toolbar.action['id'] = vars(toolbar)["pointer"]
-        toolbar.OnTool(None)
-        self.frame.OnPointer(event = None)
-        
     def RegisterGraphicsToDraw(self, graphicsType, setStatusFunc = None, drawFunc = None):
         """! This method registers graphics to draw.
         



More information about the grass-commit mailing list