[GRASS-SVN] r57383 - in grass/trunk/gui/wxpython: gui_core iclass mapdisp vdigit

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Aug 3 12:43:49 PDT 2013


Author: wenzeslaus
Date: 2013-08-03 12:43:48 -0700 (Sat, 03 Aug 2013)
New Revision: 57383

Modified:
   grass/trunk/gui/wxpython/gui_core/mapdisp.py
   grass/trunk/gui/wxpython/gui_core/mapwindow.py
   grass/trunk/gui/wxpython/iclass/frame.py
   grass/trunk/gui/wxpython/mapdisp/frame.py
   grass/trunk/gui/wxpython/mapdisp/mapwindow.py
   grass/trunk/gui/wxpython/mapdisp/statusbar.py
   grass/trunk/gui/wxpython/vdigit/mapwindow.py
Log:
wxGUI/mapwindow: removing mouse motion handlers, using signals for coordinates and for vdigit info

Modified: grass/trunk/gui/wxpython/gui_core/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/mapdisp.py	2013-08-03 10:00:53 UTC (rev 57382)
+++ grass/trunk/gui/wxpython/gui_core/mapdisp.py	2013-08-03 19:43:48 UTC (rev 57383)
@@ -264,10 +264,11 @@
         
     def CoordinatesChanged(self):
         """!Shows current coordinates on statusbar.
-        
-        Used in BufferedWindow to report change of map coordinates (under mouse cursor).
         """
-        self.statusbarManager.ShowItem('coordinates')
+        # assuming that the first mode is coordinates
+        # probably shold not be here but good solution is not available now
+        if self.statusbarManager.GetMode() == 0:
+            self.statusbarManager.ShowItem('coordinates')
         
     def StatusbarReposition(self):
         """!Reposition items in statusbar"""
@@ -326,6 +327,7 @@
         mapWindow.zoomHistoryUnavailable.connect(
             lambda:
             self.GetMapToolbar().Enable('zoomBack', enable=False))
+        mapWindow.mouseMoving.connect(self.CoordinatesChanged)
 
     def _prepareZoom(self, mapWindow, zoomType):
         """!Prepares MapWindow for zoom, toggles toolbar

Modified: grass/trunk/gui/wxpython/gui_core/mapwindow.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/mapwindow.py	2013-08-03 10:00:53 UTC (rev 57382)
+++ grass/trunk/gui/wxpython/gui_core/mapwindow.py	2013-08-03 19:43:48 UTC (rev 57383)
@@ -286,29 +286,23 @@
 
     def OnMotion(self, event):
         """!Tracks mouse motion and update statusbar
-        
+
+        @todo remove this method when lastEN is not used
+
         @see GetLastEN
         """
         try:
             self.lastEN = self.Pixel2Cell(event.GetPositionTuple())
         except (ValueError):
             self.lastEN = None
-        # FIXME: special case for vdigit and access to statusbarManager
-        if self.frame.statusbarManager.GetMode() == 0: # Coordinates            
-            updated = False
-            if hasattr(self, "digit"):
-                precision = int(UserSettings.Get(group = 'projection', key = 'format',
-                                             subkey = 'precision'))
-                updated = self._onMotion(self.lastEN, precision)
 
-            if not updated:
-                self.frame.CoordinatesChanged()
-        
         event.Skip()
 
     def GetLastEN(self):
         """!Returns last coordinates of mouse cursor.
-        
+
+        This method is depreciated.
+
         @see OnMotion
         """
         return self.lastEN

Modified: grass/trunk/gui/wxpython/iclass/frame.py
===================================================================
--- grass/trunk/gui/wxpython/iclass/frame.py	2013-08-03 10:00:53 UTC (rev 57382)
+++ grass/trunk/gui/wxpython/iclass/frame.py	2013-08-03 19:43:48 UTC (rev 57383)
@@ -106,7 +106,13 @@
         self._setUpMapWindow(self.secondMapWindow)
         self.firstMapWindow.InitZoomHistory()
         self.secondMapWindow.InitZoomHistory()
-
+        # TODO: for vdigit: it does nothing here because areas do not produce this info
+        self.firstMapWindow.digitizingInfo.connect(
+            lambda text:
+            self.statusbarManager.statusbarItems['coordinates'].SetAdditionalInfo(text))
+        self.firstMapWindow.digitizingInfoUnavailable.connect(
+            lambda:
+            self.statusbarManager.statusbarItems['coordinates'].SetAdditionalInfo(None))
         self.SetSize(size)
         #
         # Add toolbars

Modified: grass/trunk/gui/wxpython/mapdisp/frame.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/frame.py	2013-08-03 10:00:53 UTC (rev 57382)
+++ grass/trunk/gui/wxpython/mapdisp/frame.py	2013-08-03 19:43:48 UTC (rev 57383)
@@ -160,13 +160,7 @@
                                           properties=self.mapWindowProperties,
                                           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))
+        self._setUpMapWindow(self.MapWindow2D)
         # manage the state of toolbars connected to mouse cursor
         self.MapWindow2D.mouseHandlerRegistered.connect(
             lambda:
@@ -253,6 +247,13 @@
                                                 Map = self.Map, tree = self.tree,
                                                 properties=self.mapWindowProperties,
                                                 lmgr = self._layerManager)
+            self._setUpMapWindow(self.MapWindowVDigit)
+            self.MapWindowVDigit.digitizingInfo.connect(
+                lambda text:
+                self.statusbarManager.statusbarItems['coordinates'].SetAdditionalInfo(text))
+            self.MapWindowVDigit.digitizingInfoUnavailable.connect(
+                lambda:
+                self.statusbarManager.statusbarItems['coordinates'].SetAdditionalInfo(None))
             self.MapWindowVDigit.Show()
             self._mgr.AddPane(self.MapWindowVDigit, wx.aui.AuiPaneInfo().CentrePane().
                           Dockable(False).BestSize((-1,-1)).Name('vdigit').

Modified: grass/trunk/gui/wxpython/mapdisp/mapwindow.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/mapwindow.py	2013-08-03 10:00:53 UTC (rev 57382)
+++ grass/trunk/gui/wxpython/mapdisp/mapwindow.py	2013-08-03 19:43:48 UTC (rev 57383)
@@ -115,6 +115,9 @@
         self.mouseLeftUpPointer = Signal('BufferedWindow.mouseLeftUpPointer')
         # Emitted when left mouse button is released
         self.mouseLeftUp = Signal('BufferedWindow.mouseLeftUp')
+        # Emitted when mouse us moving (mouse motion event)
+        # Parametres are x and y of the mouse position in map (cell) units
+        self.mouseMoving = Signal('BufferedWindow.mouseMoving')
 
         # event bindings
         self.Bind(wx.EVT_PAINT,           self.OnPaint)
@@ -1045,6 +1048,9 @@
             self.OnMouseEnter(event)
         
         elif event.Moving():
+            pixelCoordinates = event.GetPositionTuple()[:]
+            coordinates = self.Pixel2Cell(pixelCoordinates)
+            self.mouseMoving.emit(x=coordinates[0], y=coordinates[1])
             self.OnMouseMoving(event)
                 
     def OnMouseWheel(self, event):

Modified: grass/trunk/gui/wxpython/mapdisp/statusbar.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/statusbar.py	2013-08-03 10:00:53 UTC (rev 57382)
+++ grass/trunk/gui/wxpython/mapdisp/statusbar.py	2013-08-03 19:43:48 UTC (rev 57383)
@@ -860,8 +860,14 @@
         SbTextItem.__init__(self, mapframe, statusbar, position)
         self.name = 'coordinates'
         self.label = _("Coordinates")
+        self._additionalInfo = None
+        self._basicValue = None
         
     def Show(self):
+        """Show the last map window coordinates.
+
+        @todo remove last EN call and use coordinates comming from signal
+        """
         precision = int(UserSettings.Get(group = 'projection', key = 'format',
                              subkey = 'precision'))
         format = UserSettings.Get(group = 'projection', key = 'format',
@@ -869,15 +875,35 @@
         projection = self.mapFrame.GetProperty('projection')
         try:
             e, n = self.mapFrame.GetWindow().GetLastEN()
-            self.SetValue(self.ReprojectENFromMap(e, n, projection, precision, format))
+            self._basicValue = self.ReprojectENFromMap(e, n, projection, precision, format)
+            if self._additionalInfo:
+                value = "{coords} ({additionalInfo})".format(coords=self._basicValue,
+                                                             additionalInfo=self._additionalInfo)
+            else:
+                value = self._basicValue
+            self.SetValue(value)
         except SbException, e:
             self.SetValue(e)
+        # TODO: remove these excepts, they just hide errors, solve problems differently
         except TypeError, e:
             self.SetValue("")
         except AttributeError:
             self.SetValue("") # during initialization MapFrame has no MapWindow
         SbTextItem.Show(self)
-        
+
+    def SetAdditionalInfo(self, text):
+        """Sets additional info to be shown together with coordinates.
+
+        The format is translation dependent but the default is
+        "coordinates (additional info)"
+
+        It does not show the changed text immediately, it waits for the Show()
+        method to be called.
+
+        @param text string to be shown
+        """
+        self._additionalInfo = text
+
     def ReprojectENFromMap(self, e, n, useDefinedProjection, precision, format):
         """!Reproject east, north to user defined projection.
         

Modified: grass/trunk/gui/wxpython/vdigit/mapwindow.py
===================================================================
--- grass/trunk/gui/wxpython/vdigit/mapwindow.py	2013-08-03 10:00:53 UTC (rev 57382)
+++ grass/trunk/gui/wxpython/vdigit/mapwindow.py	2013-08-03 19:43:48 UTC (rev 57383)
@@ -17,6 +17,8 @@
 import wx
 import tempfile
 
+from grass.pydispatch.signal import Signal
+
 from dbmgr.dialogs  import DisplayAttributesDialog
 from core.gcmd      import RunCommand, GMessage, GError
 from core.debug     import Debug
@@ -41,9 +43,23 @@
         self.pdcVector = wx.PseudoDC()
         self.toolbar   = self.parent.GetToolbar('vdigit')
         self.digit     = None # wxvdigit.IVDigit
+        self._digitizingInfo = False  # digitizing with info
 
+        # Emitted when info about digitizing updated
+        # Parameter text is a string with information
+        # currently used only for coordinates of mouse cursor + segmnt and
+        # total feature length
+        self.digitizingInfo = Signal('BufferedWindow.digitizingInfo')
+        # Emitted when some info about digitizing is or will be availbale
+        self.digitizingInfoAvailable = Signal('BufferedWindow.digitizingInfo')
+        # Emitted when some info about digitizing is or will be availbale
+        # digitizingInfo signal is emmited only between digitizingInfoAvailable
+        # and digitizingInfoUnavailable signals
+        self.digitizingInfoUnavailable = Signal('BufferedWindow.digitizingInfo')
+
         self.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
-        
+        self.mouseMoving.connect(self._mouseMovingToDigitizingInfo)
+
     def GetDisplay(self):
         if self.digit:
             return self.digit.GetDisplay()
@@ -53,35 +69,36 @@
         """!Set up related toolbar
         """
         self.toolbar = toolbar
-        
-    def _onMotion(self, coord, precision):
-        """!Track mouse motion and update statusbar (see self.Motion)
 
-        @parem coord easting, northing
-        @param precision formatting precision
-        """
-        e, n = coord
-        
+    def _mouseMovingToDigitizingInfo(self, x, y):
+        e, n = x, y
+        precision = int(UserSettings.Get(group='projection', key='format',
+                                         subkey='precision'))
         if self.toolbar.GetAction() != 'addLine' or \
                 self.toolbar.GetAction('type') not in ('line', 'boundary') or \
                 len(self.polycoords) == 0:
-            return False
-        
+            # we cannot provide info, so find out if it is something new
+            if self._digitizingInfo:
+                self._digitizingInfo = False
+                self.digitizingInfoUnavailable.emit()
+            return
+        # else, we can provide info, so find out if it is first time
+        if not self._digitizingInfo:
+            self._digitizingInfo = True
+            self.digitizingInfoAvailable.emit()
+
         # for linear feature show segment and total length
         distance_seg = self.Distance(self.polycoords[-1],
-                                     (e, n), screen = False)[0]
+                                     (e, n), screen=False)[0]
         distance_tot = distance_seg
         for idx in range(1, len(self.polycoords)):
             distance_tot += self.Distance(self.polycoords[idx-1],
                                           self.polycoords[idx],
-                                          screen = False)[0]
-        self.parent.SetStatusText("%.*f, %.*f (seg: %.*f; tot: %.*f)" % \
-                                                (precision, e, precision, n,
-                                                 precision, distance_seg,
-                                                 precision, distance_tot), 0)
-        
-        return True
-    
+                                          screen=False)[0]
+        text = "seg: %.*f; tot: %.*f" % (precision, distance_seg,
+                                         precision, distance_tot)
+        self.digitizingInfo.emit(text=text)
+
     def OnKeyDown(self, event):
         """!Key pressed"""
         shift = event.ShiftDown()



More information about the grass-commit mailing list