Browse Source

wxGUI: setting zoom, pan, pointer mode moved from frame to window

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@57438 15284696-431f-4ddb-bdfa-cd5b030d7da7
Anna Petrášová 11 years ago
parent
commit
b1f09ea7f0

+ 12 - 75
gui/wxpython/gcp/mapdisplay.py

@@ -33,7 +33,6 @@ from gui_core.mapdisp  import SingleMapFrame
 from core.settings     import UserSettings
 from mapwin.buffered import BufferedMapWindow
 from mapwin.base import MapWindowProperties
-from gui_core.toolbars import ToolSwitcher
 
 import mapdisp.statusbar as sb
 import gcp.statusbar as sbgcp
@@ -326,88 +325,26 @@ class MapFrame(SingleMapFrame):
     def OnPointer(self, event):
         """!Pointer button clicked
         """        
-        # change the cursor
+        self.SrcMapWindow.SetModePointer()
+        self.TgtMapWindow.SetModePointer()
+        # change the default cursor
         self.SrcMapWindow.SetNamedCursor('cross')
-        self.SrcMapWindow.mouse['use'] = "pointer"
-        self.SrcMapWindow.mouse['box'] = "point"
         self.TgtMapWindow.SetNamedCursor('cross')
-        self.TgtMapWindow.mouse['use'] = "pointer"
-        self.TgtMapWindow.mouse['box'] = "point"
 
     def OnZoomIn(self, event):
-        """
-        Zoom in the map.
-        Set mouse cursor, zoombox attributes, and zoom direction
-        """        
-        self.MapWindow.mouse['use'] = "zoom"
-        self.MapWindow.mouse['box'] = "box"
-        self.MapWindow.zoomtype = 1
-        self.MapWindow.pen = wx.Pen(colour='Red', width=2, style=wx.SHORT_DASH)
-        
-        # change the cursor
-        self.MapWindow.SetNamedCursor('cross')
-
-        if self.MapWindow == self.SrcMapWindow:
-            win = self.TgtMapWindow
-        elif self.MapWindow == self.TgtMapWindow:
-            win = self.SrcMapWindow
-
-        win.mouse['use'] = "zoom"
-        win.mouse['box'] = "box"
-        win.zoomtype = 1
-        win.pen = wx.Pen(colour='Red', width=2, style=wx.SHORT_DASH)
-        
-        # change the cursor
-        win.SetNamedCursor('cross')
+        """Zoom in the map."""
+        self.SrcMapWindow.SetModeZoomIn()
+        self.TgtMapWindow.SetModeZoomIn()
 
     def OnZoomOut(self, event):
-        """
-        Zoom out the map.
-        Set mouse cursor, zoombox attributes, and zoom direction
-        """
-        self.MapWindow.mouse['use'] = "zoom"
-        self.MapWindow.mouse['box'] = "box"
-        self.MapWindow.zoomtype = -1
-        self.MapWindow.pen = wx.Pen(colour='Red', width=2, style=wx.SHORT_DASH)
-        
-        # change the cursor
-        self.MapWindow.SetNamedCursor('cross')
-
-        if self.MapWindow == self.SrcMapWindow:
-            win = self.TgtMapWindow
-        elif self.MapWindow == self.TgtMapWindow:
-            win = self.SrcMapWindow
-
-        win.mouse['use'] = "zoom"
-        win.mouse['box'] = "box"
-        win.zoomtype = -1
-        win.pen = wx.Pen(colour='Red', width=2, style=wx.SHORT_DASH)
-        
-        # change the cursor
-        win.SetNamedCursor('cross')
+        """Zoom out the map."""
+        self.SrcMapWindow.SetModeZoomOut()
+        self.TgtMapWindow.SetModeZoomOut()
 
     def OnPan(self, event):
-        """
-        Panning, set mouse to drag
-        """        
-        self.MapWindow.mouse['use'] = "pan"
-        self.MapWindow.mouse['box'] = "pan"
-        self.MapWindow.zoomtype = 0
-        
-        # change the cursor
-        self.MapWindow.SetNamedCursor('hand')
-
-        if self.MapWindow == self.SrcMapWindow:
-            win = self.TgtMapWindow
-        elif self.MapWindow == self.TgtMapWindow:
-            win = self.SrcMapWindow
-
-        win.mouse['use'] = "pan"
-        win.mouse['box'] = "pan"
-        win.zoomtype = 0
-        
-        # change the cursor
-        win.SetNamedCursor('hand')
+        """Panning, set mouse to drag"""
+        self.SrcMapWindow.SetModePan()
+        self.TgtMapWindow.SetModePan()
 
     def OnErase(self, event):
         """

+ 19 - 71
gui/wxpython/gui_core/mapdisp.py

@@ -298,18 +298,12 @@ class MapFrameBase(wx.Frame):
         self.MapWindow.EraseMap()
         
     def OnZoomIn(self, event):
-        """!Zoom in the map.
-        Set mouse cursor, zoombox attributes, and zoom direction
-        """        
-        win = self.GetWindow()
-        self._prepareZoom(mapWindow = win, zoomType = 1)
+        """!Zoom in the map."""
+        self.MapWindow.SetModeZoomIn()
         
     def OnZoomOut(self, event):
-        """!Zoom out the map.
-        Set mouse cursor, zoombox attributes, and zoom direction
-        """        
-        win = self.GetWindow()
-        self._prepareZoom(mapWindow = win, zoomType = -1)
+        """!Zoom out the map."""
+        self.MapWindow.SetModeZoomOut()
 
     def _setUpMapWindow(self, mapWindow):
         """Binds map windows' zoom history signals to map toolbar."""
@@ -322,43 +316,15 @@ class MapFrameBase(wx.Frame):
             self.GetMapToolbar().Enable('zoomBack', enable=False))
         mapWindow.mouseMoving.connect(self.CoordinatesChanged)
 
-    def _prepareZoom(self, mapWindow, zoomType):
-        """!Prepares MapWindow for zoom, toggles toolbar
-        
-        @param mapWindow MapWindow to prepare
-        @param zoomType 1 for zoom in, -1 for zoom out
-        """
-        mapWindow.mouse['use'] = "zoom"
-        mapWindow.mouse['box'] = "box"
-        mapWindow.zoomtype = zoomType
-        mapWindow.pen = wx.Pen(colour = 'Red', width = 2, style = wx.SHORT_DASH)
-        
-        # change the cursor
-        mapWindow.SetNamedCursor('cross')
-            
     def OnPointer(self, event):
         """!Sets mouse mode to pointer."""
-        self.MapWindow.mouse['use'] = 'pointer'
-        self.MapWindow.mouse['box'] = 'point'
+        self.MapWindow.SetModePointer()
 
     def OnPan(self, event):
         """!Panning, set mouse to drag
         """
-        win = self.GetWindow()
-        self._preparePan(mapWindow = win)
-    
-    def _preparePan(self, mapWindow):
-        """!Prepares MapWindow for pan, toggles toolbar
-        
-        @param mapWindow MapWindow to prepare
-        """
-        mapWindow.mouse['use'] = "pan"
-        mapWindow.mouse['box'] = "box"
-        mapWindow.zoomtype = 0
-        
-        # change the cursor
-        mapWindow.SetNamedCursor('hand')
-        
+        self.MapWindow.SetModePan()
+
     def OnZoomBack(self, event):
         """!Zoom last (previously stored position)
         """
@@ -602,42 +568,24 @@ class DoubleMapFrame(MapFrameBase):
         self.Render(mapToRender = self.GetFirstWindow())
 
     def OnZoomIn(self, event):
-        """!Zoom in the map.
-        Set mouse cursor, zoombox attributes, and zoom direction
-        """        
-        win = self.GetFirstWindow()
-        self._prepareZoom(mapWindow = win, zoomType = 1)
-        
-        win = self.GetSecondWindow()
-        self._prepareZoom(mapWindow = win, zoomType = 1)
+        """!Zoom in the map."""
+        self.GetFirstWindow().SetModeZoomIn()
+        self.GetSecondWindow().SetModeZoomIn()
 
     def OnZoomOut(self, event):
-        """!Zoom out the map.
-        Set mouse cursor, zoombox attributes, and zoom direction
-        """        
-        win = self.GetFirstWindow()
-        self._prepareZoom(mapWindow = win, zoomType = -1)
-        
-        win = self.GetSecondWindow()
-        self._prepareZoom(mapWindow = win, zoomType = -1)
+        """!Zoom out the map."""
+        self.GetFirstWindow().SetModeZoomOut()
+        self.GetSecondWindow().SetModeZoomOut()
         
     def OnPan(self, event):
-        """!Panning, set mouse to drag
-        """        
-        win = self.GetFirstWindow()
-        self._preparePan(mapWindow = win)
-        
-        win = self.GetSecondWindow()
-        self._preparePan(mapWindow = win)
-        
+        """!Panning, set mouse to pan"""
+        self.GetFirstWindow().SetModePan()
+        self.GetSecondWindow().SetModePan()
+
     def OnPointer(self, event):
         """!Set pointer mode (dragging overlays)"""
-        self.GetFirstWindow().mouse['use'] = 'pointer'
-        self.GetFirstWindow().mouse['box'] = 'point'
-        self.GetFirstWindow().SetNamedCursor('default')
-        self.GetSecondWindow().mouse['use'] = 'pointer'
-        self.GetSecondWindow().mouse['box'] = 'point'
-        self.GetSecondWindow().SetNamedCursor('default')
+        self.GetFirstWindow().SetModePointer()
+        self.GetSecondWindow().SetModePointer()
 
     def OnRender(self, event):
         """!Re-render map composition (each map layer)

+ 2 - 4
gui/wxpython/iclass/frame.py

@@ -53,7 +53,6 @@ from core.gcmd          import RunCommand, GMessage, GError, GWarning
 from gui_core.dialogs   import SetOpacityDialog
 from mapwin.base import MapWindowProperties
 from dbmgr.vinfo        import VectorDBInfo
-from gui_core.toolbars import ToolSwitcher
 import grass.script as grass
 
 from iclass.digit       import IClassVDigitWindow, IClassVDigit
@@ -1116,9 +1115,8 @@ class IClassMapFrame(DoubleMapFrame):
 
         @todo: pointers need refactoring
         """
-        toolbar = self.GetMapToolbar()
-
-        self.GetFirstWindow().mouse['use'] = 'pointer'
+        self.GetFirstWindow().SetModePointer()
+        self.GetSecondWindow().SetModePointer()
 
     def OnScatterplot(self, event):
         """!Init interactive scatterplot tools

+ 1 - 6
gui/wxpython/mapdisp/frame.py

@@ -49,7 +49,6 @@ from core.settings      import UserSettings
 from gui_core.mapdisp   import SingleMapFrame
 from mapwin.base import MapWindowProperties
 from gui_core.query     import QueryDialog, PrepareQueryResults
-from gui_core.toolbars import ToolSwitcher
 from mapwin.buffered import BufferedMapWindow
 from mapwin.decorations import DecorationDialog, TextLayerDialog, \
     LegendController, BarscaleController, \
@@ -518,16 +517,12 @@ class MapFrame(SingleMapFrame):
     def OnPointer(self, event):
         """!Pointer button clicked
         """        
-        self.MapWindow.mouse['use'] = "pointer"
-        self.MapWindow.mouse['box'] = "point"
+        self.MapWindow.SetModePointer()
 
-        # change the cursor
         if self.GetToolbar('vdigit'):
             self.toolbars['vdigit'].action['id'] = -1
             self.toolbars['vdigit'].action['desc']=''
 
-        self.MapWindow.SetNamedCursor('default')
-
     def OnRotate(self, event):
         """!Rotate 3D view
         """

+ 0 - 1
gui/wxpython/mapswipe/frame.py

@@ -23,7 +23,6 @@ import grass.script as grass
 
 from gui_core.mapdisp   import DoubleMapFrame
 from gui_core.dialogs   import GetImageHandlers
-from gui_core.toolbars import ToolSwitcher
 from mapwin.base import MapWindowProperties
 from core.render        import Map
 from mapdisp            import statusbar as sb

+ 26 - 0
gui/wxpython/mapwin/base.py

@@ -355,3 +355,29 @@ class MapWindowBase(object):
         return self._cursor
 
     cursor = property(fget=GetNamedCursor, fset=SetNamedCursor)
+
+    def SetModePointer(self):
+        """!Sets mouse mode to pointer."""
+        self.mouse['use'] = 'pointer'
+        self.mouse['box'] = 'point'
+        self.SetNamedCursor('default')
+
+    def SetModePan(self):
+        """!Sets mouse mode to pan."""
+        self.mouse['use'] = "pan"
+        self.mouse['box'] = "box"
+        self.zoomtype = 0
+        self.SetNamedCursor('hand')
+
+    def SetModeZoomIn(self):
+        self._setModeZoom(zoomType=1)
+
+    def SetModeZoomOut(self):
+        self._setModeZoom(zoomType=-1)
+
+    def _setModeZoom(self, zoomType):
+        self.mouse['use'] = "zoom"
+        self.mouse['box'] = "box"
+        self.zoomtype = zoomType
+        self.pen = wx.Pen(colour='Red', width=2, style=wx.SHORT_DASH)
+        self.SetNamedCursor('cross')

+ 15 - 37
gui/wxpython/rlisetup/sampling_frame.py

@@ -90,46 +90,17 @@ class RLiSetupMapPanel(wx.Panel):
         """!Returns currently drawn region in a dict"""
         return self._region
 
+    def OnPan(self, event):
+        """!Panning, set mouse to drag."""
+        self.mapWindow.SetModePan()
+
     def OnZoomIn(self, event):
-        """!Zoom in the map.
-        """
-        self._prepareZoom(mapWindow=self.mapWindow, zoomType=1)
+        """!Zoom in the map."""
+        self.mapWindow.SetModeZoomIn()
 
     def OnZoomOut(self, event):
-        """!Zoom out the map.
-        """
-        self._prepareZoom(mapWindow=self.mapWindow, zoomType=-1)
-
-    def _prepareZoom(self, mapWindow, zoomType):
-        """!Prepares MapWindow for zoom
-
-        @param mapWindow MapWindow to prepare
-        @param zoomType 1 for zoom in, -1 for zoom out
-        """
-        mapWindow.mouse['use'] = "zoom"
-        mapWindow.mouse['box'] = "box"
-        mapWindow.zoomtype = zoomType
-        mapWindow.pen = wx.Pen(colour='Red', width=2, style=wx.SHORT_DASH)
-
-        # change the cursor
-        mapWindow.SetNamedCursor('cross')
-
-    def _onToolChanged(self):
-        """!Helper function to disconnect drawing"""
-        try:
-            self.mapWindow.mouseLeftUp.disconnect(self._rectangleDrawn)
-        except DispatcherKeyError:
-            pass
-
-    def OnPan(self, event):
-        """!Panning, set mouse to drag
-        """
-        self.mapWindow.mouse['use'] = "pan"
-        self.mapWindow.mouse['box'] = "pan"
-        self.mapWindow.zoomtype = 0
-
-        # change the cursor
-        self.mapWindow.SetNamedCursor('hand')
+        """!Zoom out the map."""
+        self.mapWindow.SetModeZoomOut()
 
     def OnZoomToMap(self, event):
         layers = self.map_.GetListOfLayers()
@@ -144,6 +115,13 @@ class RLiSetupMapPanel(wx.Panel):
 
         self.mapWindow.mouseLeftUp.connect(self._rectangleDrawn)
 
+    def _onToolChanged(self):
+        """!Helper function to disconnect drawing"""
+        try:
+            self.mapWindow.mouseLeftUp.disconnect(self._rectangleDrawn)
+        except DispatcherKeyError:
+            pass
+
     def _rectangleDrawn(self):
         """!When drawing finished, get region values"""
         mouse = self.mapWindow.mouse