Explorar o código

wxGUI/mapwindow: implementing mouse moving signal (https://trac.osgeo.org/grass/changeset/57383) and zoom history signals (https://trac.osgeo.org/grass/changeset/57078) for nviz

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@57396 15284696-431f-4ddb-bdfa-cd5b030d7da7
Vaclav Petras %!s(int64=11) %!d(string=hai) anos
pai
achega
d0f753205f

+ 3 - 1
gui/wxpython/gui_core/toolbars.py

@@ -206,7 +206,9 @@ class BaseToolbar(wx.ToolBar):
         try:
             id = getattr(self, tool)
         except AttributeError:
-            # this should raise an error
+            # TODO: test everything that this is not raised
+            # this error was ignored for a long time
+            raise AttributeError("Toolbar does not have a tool %s." % tool)
             return
         
         self.EnableTool(id, enable)

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

@@ -329,6 +329,7 @@ class MapFrame(SingleMapFrame):
         if not self.MapWindow3D:
             self.MapWindow3D = GLWindow(self, giface = self._giface, id = wx.ID_ANY, frame = self,
                                         Map = self.Map, tree = self.tree, lmgr = self._layerManager)
+            self._setUpMapWindow(self.MapWindow3D)
             self.MapWindow = self.MapWindow3D
             self.MapWindow.SetCursor(self.cursors["default"])
             

+ 29 - 11
gui/wxpython/nviz/mapwindow.py

@@ -33,6 +33,7 @@ from   wx              import glcanvas
 from wx.glcanvas       import WX_GL_DEPTH_SIZE
 
 import grass.script as grass
+from grass.pydispatch.signal import Signal
 
 from core.gcmd          import GMessage, GException, GError
 from core.debug         import Debug
@@ -89,7 +90,20 @@ class GLWindow(MapWindow, glcanvas.GLCanvas):
 
         MapWindow.__init__(self, parent=parent, giface=giface, Map=Map)
         self.Hide()
-        
+
+        # TODO: same signals as in BufferedWindow
+        # same interface is good, but how to ensure same names
+        # or avoid duplication, define in map window base class?
+
+        # Emitted when mouse us moving (mouse motion event)
+        # Parametres are x and y of the mouse position in map (cell) units
+        self.mouseMoving = Signal('GLWindow.mouseMoving')
+
+        # Emitted when the zoom history stack is emptied
+        self.zoomHistoryUnavailable = Signal('GLWindow.zoomHistoryUnavailable')
+        # Emitted when the zoom history stack is not empty
+        self.zoomHistoryAvailable = Signal('GLWindow.zoomHistoryAvailable')
+
         self.init = False
         self.initView = False
         self.context = None
@@ -658,7 +672,15 @@ class GLWindow(MapWindow, glcanvas.GLCanvas):
         # double click    
         elif event.ButtonDClick():
             self.OnDClick(event)
-        
+
+        elif event.Moving():
+            pixelCoordinates = event.GetPositionTuple()[:]
+            coordinates = self.Pixel2Cell(pixelCoordinates)
+            # coordinates are none when no map is loaded
+            # TODO: handle in more clever way: check the state
+            if coordinates is not None:
+                self.mouseMoving.emit(x=coordinates[0], y=coordinates[1])
+
         event.Skip()
 
     def OnMouseWheel(self, event):
@@ -670,7 +692,7 @@ class GLWindow(MapWindow, glcanvas.GLCanvas):
             return
             
         wheel = event.GetWheelRotation()
-        Debug.msg (5, "GLWindow.OnMouseMotion(): wheel = %d" % wheel)
+        Debug.msg (5, "GLWindow.OnMouseWheel(): wheel = %d" % wheel)
         if self.timerFly.IsRunning() and self.fly['mouseControl']:
             if wheel > 0:
                 self.ChangeFlySpeed(increase = True)
@@ -972,8 +994,7 @@ class GLWindow(MapWindow, glcanvas.GLCanvas):
         
         # disable tool if stack is empty
         if len(self.viewhistory) < 2: # disable tool
-            toolbar = self.parent.GetMapToolbar()
-            toolbar.Enable('zoomback', enable = False)
+            self.zoomHistoryUnavailable.emit()
             
         # set view and update nviz view page
         self.lmgr.nviz.UpdateState(view = view[0], iview = view[1])
@@ -1008,13 +1029,10 @@ class GLWindow(MapWindow, glcanvas.GLCanvas):
         
         # update toolbar
         if len(self.viewhistory) > 1:
-            enable = True
+            self.zoomHistoryAvailable.emit()
         else:
-            enable = False
-        
-        toolbar = self.parent.GetMapToolbar()
-        toolbar.Enable('zoomback', enable)
-        
+            self.zoomHistoryUnavailable.emit()
+
         return removed     
     
     def ResetViewHistory(self):