[GRASS-SVN] r54429 - in grass/trunk/gui/wxpython: core gui_core iclass mapdisp mapswipe

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Dec 27 10:46:15 PST 2012


Author: annakrat
Date: 2012-12-27 10:46:15 -0800 (Thu, 27 Dec 2012)
New Revision: 54429

Modified:
   grass/trunk/gui/wxpython/core/events.py
   grass/trunk/gui/wxpython/gui_core/mapdisp.py
   grass/trunk/gui/wxpython/iclass/frame.py
   grass/trunk/gui/wxpython/mapdisp/mapwindow.py
   grass/trunk/gui/wxpython/mapswipe/frame.py
   grass/trunk/gui/wxpython/mapswipe/mapwindow.py
Log:
wxGUI: synchronize displays in wxIClass; improve implementation

Modified: grass/trunk/gui/wxpython/core/events.py
===================================================================
--- grass/trunk/gui/wxpython/core/events.py	2012-12-27 17:23:12 UTC (rev 54428)
+++ grass/trunk/gui/wxpython/core/events.py	2012-12-27 18:46:15 UTC (rev 54429)
@@ -30,6 +30,7 @@
 
 
 from wx.lib.newevent import NewCommandEvent
+from wx.lib.newevent import NewEvent
 
 
 # Notification event intended to update statusbar.
@@ -41,3 +42,5 @@
 # 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()

Modified: grass/trunk/gui/wxpython/gui_core/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/mapdisp.py	2012-12-27 17:23:12 UTC (rev 54428)
+++ grass/trunk/gui/wxpython/gui_core/mapdisp.py	2012-12-27 18:46:15 UTC (rev 54429)
@@ -25,8 +25,9 @@
 import wx
 import wx.aui
 
-from core       import globalvar
-from core.debug import Debug
+from core        import globalvar
+from core.debug  import Debug
+from core.events import EVT_ZOOM_CHANGED
 
 from grass.script import core as grass
 
@@ -468,12 +469,13 @@
         self.firstMap = firstMap
         self.secondMap = secondMap
         self.Map = firstMap
-                
+
         #
         # initialize region values
         #
         self._initMap(Map = self.firstMap)
         self._initMap(Map = self.secondMap)
+        self._bindRegions = False
     
     def _bindWindowsActivation(self):
         self.GetFirstWindow().Bind(wx.EVT_ENTER_WINDOW, self.ActivateFirstMap)
@@ -514,17 +516,63 @@
         return self.MapWindow
     
     def ActivateFirstMap(self, event = None):
-        """!Make first Map and MapWindow active"""
+        """!Make first Map and MapWindow active and (un)bind regions of the two Maps."""
         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)
+
     def ActivateSecondMap(self, event = None):
-        """!Make second Map and MapWindow active"""
+        """!Make second Map and MapWindow active and (un)bind regions of the two Maps."""
         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)
+
+    def SetBindRegions(self, on):
+        """!Set or unset binding display regions."""
+        self._bindRegions = on
+
+        if on:
+            if self.MapWindow == self.firstMapWindow:
+                self.firstMapWindow.Bind(EVT_ZOOM_CHANGED, self.OnZoomChangedFirstMap)
+            else:
+                self.secondMapWindow.Bind(EVT_ZOOM_CHANGED, self.OnZoomChangedSecondMap)
+        else:
+            self.firstMapWindow.Unbind(EVT_ZOOM_CHANGED)
+            self.secondMapWindow.Unbind(EVT_ZOOM_CHANGED)
+
+    def OnZoomChangedFirstMap(self, event):
+        """!Display region of the first window (Map) changed.
+
+        Synchronize the region of the second map and re-render it.
+        This is the default implementation which can be overridden.
+        """
+        region = self.GetFirstMap().GetCurrentRegion()
+        self.GetSecondMap().region.update(region)
+        self.Render(mapToRender = self.GetSecondWindow())
+
+    def OnZoomChangedSecondMap(self, event):
+        """!Display region of the second window (Map) changed.
+
+        Synchronize the region of the second map and re-render it.
+        This is the default implementation which can be overridden.
+        """
+        region = self.GetSecondMap().GetCurrentRegion()
+        self.GetFirstMap().region.update(region)
+        self.Render(mapToRender = self.GetFirstWindow())
+
     def OnZoomIn(self, event):
         """!Zoom in the map.
         Set mouse cursor, zoombox attributes, and zoom direction

Modified: grass/trunk/gui/wxpython/iclass/frame.py
===================================================================
--- grass/trunk/gui/wxpython/iclass/frame.py	2012-12-27 17:23:12 UTC (rev 54428)
+++ grass/trunk/gui/wxpython/iclass/frame.py	2012-12-27 18:46:15 UTC (rev 54429)
@@ -342,7 +342,7 @@
     def IsStandalone(self):
         """!Check if Map display is standalone"""
         return True
-    
+
     def OnUpdateActive(self, event):
         """!
         @todo move to DoubleMapFrame?
@@ -370,7 +370,7 @@
         if mapTb.GetActiveMap() != (win == self.secondMapWindow):
             mapTb.SetActiveMap((win == self.secondMapWindow))
         self.StatusbarUpdate() 
-        
+
     def GetMapToolbar(self):
         """!Returns toolbar with zooming tools"""
         return self.toolbars['iClassMap']
@@ -399,6 +399,16 @@
         zoommenu.AppendItem(zoomtarget)
         self.Bind(wx.EVT_MENU, self.OnZoomToTraining, zoomtarget)
 
+        zoombind = wx.MenuItem(zoommenu, wx.ID_ANY, _("Display synchronization ON"))
+        zoommenu.AppendItem(zoombind)
+        self.Bind(wx.EVT_MENU, lambda event: self.SetBindRegions(True), zoombind)
+
+        zoomunbind = wx.MenuItem(zoommenu, wx.ID_ANY, _("Display synchronization OFF"))
+        zoommenu.AppendItem(zoomunbind)
+        self.Bind(wx.EVT_MENU, lambda event: self.SetBindRegions(False), zoomunbind)
+
+        zoomunbind.Enable(self._bindRegions)
+        zoombind.Enable(not self._bindRegions)
         # Popup the menu. If an item is selected then its handler
         # will be called before PopupMenu returns.
         self.PopupMenu(zoommenu)

Modified: grass/trunk/gui/wxpython/mapdisp/mapwindow.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/mapwindow.py	2012-12-27 17:23:12 UTC (rev 54428)
+++ grass/trunk/gui/wxpython/mapdisp/mapwindow.py	2012-12-27 18:46:15 UTC (rev 54429)
@@ -34,6 +34,7 @@
 from core.gcmd          import RunCommand, GException, GError, GMessage
 from core.debug         import Debug
 from core.settings      import UserSettings
+from core.events        import gZoomChanged
 from gui_core.mapwindow import MapWindow
 try:
     import grass.lib.gis as gislib
@@ -1536,6 +1537,8 @@
         # update statusbar
         self.frame.StatusbarUpdate()
 
+        wx.PostEvent(self, gZoomChanged())
+
     def ZoomHistory(self, n, s, e, w):
         """!Manages a list of last 10 zoom extents
 
@@ -1565,6 +1568,8 @@
         toolbar = self.frame.GetMapToolbar()
         
         toolbar.Enable('zoomBack', enable)
+
+        wx.PostEvent(self, gZoomChanged())
         
         return removed
 

Modified: grass/trunk/gui/wxpython/mapswipe/frame.py
===================================================================
--- grass/trunk/gui/wxpython/mapswipe/frame.py	2012-12-27 17:23:12 UTC (rev 54428)
+++ grass/trunk/gui/wxpython/mapswipe/frame.py	2012-12-27 18:46:15 UTC (rev 54429)
@@ -65,8 +65,8 @@
         self.secondMapWindow = SwipeBufferedWindow(parent = self.splitter, giface = self._giface,
                                                    Map = self.secondMap, frame = self)
         self.MapWindow = self.firstMapWindow # current by default
-        self.firstMap.region = self.secondMap.region
         self.firstMapWindow.zoomhistory = self.secondMapWindow.zoomhistory
+        self.SetBindRegions(True)
 
         self._mode = 'swipe'
 
@@ -270,18 +270,6 @@
                   LeftDockable(True).RightDockable(True).
                   Right().Layer(1).BestSize((self.sliderV.GetBestSize())))
 
-    def UpdateRegion(self):
-        """!
-        Rerender the second window
-        when the region of the first changed.
-        """
-        Debug.msg(3, "SwipeMapFrame.UpdateRegion()")
-
-        if self.GetWindow() == self.GetSecondWindow():
-            self.Render(self.GetFirstWindow())
-        else:
-            self.Render(self.GetSecondWindow())
-
     def ZoomToMap(self):
         """!
         Set display extents to match selected raster (including NULLs)
@@ -291,8 +279,6 @@
             self.GetFirstWindow().ZoomToMap(layers = self.firstMap.GetListOfLayers())
         if self.rasters['second']:
             self.GetSecondWindow().ZoomToMap(layers = self.secondMap.GetListOfLayers())
-        # needed again, don't know why
-        self.firstMap.region = self.secondMap.region
 
     def OnZoomToMap(self, event):
         """!Zoom to map"""

Modified: grass/trunk/gui/wxpython/mapswipe/mapwindow.py
===================================================================
--- grass/trunk/gui/wxpython/mapswipe/mapwindow.py	2012-12-27 17:23:12 UTC (rev 54428)
+++ grass/trunk/gui/wxpython/mapswipe/mapwindow.py	2012-12-27 18:46:15 UTC (rev 54429)
@@ -113,16 +113,6 @@
         if not self.movingSash:
             super(SwipeBufferedWindow, self).OnSize(event)
 
-    def ZoomToMap(self, layers = None, ignoreNulls = False, render = True):
-        super(SwipeBufferedWindow, self).ZoomToMap(layers, ignoreNulls, render)
-        self.frame.UpdateRegion()
-
-    def ZoomBack(self):
-        """!Zoom last (previously stored position)
-        """
-        super(SwipeBufferedWindow, self).ZoomBack()
-        self.frame.UpdateRegion()
-
     def Draw(self, pdc, img = None, drawid = None, pdctype = 'image', coords = [0, 0, 0, 0]):
         """!Draws image (map) with translated coordinates.
         """
@@ -180,17 +170,6 @@
                                  'rotation': 0, 'text': name,
                                  'active': True}
 
-    def MouseActions(self, event):
-        """!Handle mouse events and if needed let parent frame know"""
-        super(SwipeBufferedWindow, self).MouseActions(event)
-        if event.GetWheelRotation() != 0 or \
-           event.LeftUp() or \
-           event.MiddleUp():
-
-            self.frame.UpdateRegion()
-
-        event.Skip()
-        
     def MouseDraw(self, pdc = None, begin = None, end = None):
         """!Overriden method to recompute coordinates back to original values
         so that e.g. drawing of zoom box is done properly"""



More information about the grass-commit mailing list