[GRASS-SVN] r54884 - in grass/trunk/gui/wxpython: mapdisp mapswipe

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Feb 3 13:09:12 PST 2013


Author: annakrat
Date: 2013-02-03 13:09:12 -0800 (Sun, 03 Feb 2013)
New Revision: 54884

Modified:
   grass/trunk/gui/wxpython/mapdisp/mapwindow.py
   grass/trunk/gui/wxpython/mapswipe/frame.py
   grass/trunk/gui/wxpython/mapswipe/mapwindow.py
Log:
wxGUI/mapswipe: add cross mirroring cursor

Modified: grass/trunk/gui/wxpython/mapdisp/mapwindow.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/mapwindow.py	2013-02-03 21:02:11 UTC (rev 54883)
+++ grass/trunk/gui/wxpython/mapdisp/mapwindow.py	2013-02-03 21:09:12 UTC (rev 54884)
@@ -163,7 +163,7 @@
         self.PopupMenu(menu)
         menu.Destroy()
 
-    def Draw(self, pdc, img = None, drawid = None, pdctype = 'image', coords = [0, 0, 0, 0]):
+    def Draw(self, pdc, img = None, drawid = None, pdctype = 'image', coords = [0, 0, 0, 0], pen = None):
         """!Draws map and overlay decorations
         """
         if drawid == None:
@@ -174,6 +174,13 @@
             else:
                 drawid = wx.NewId()
         
+        # TODO: find better solution
+        if not pen:
+            if pdctype == 'polyline':
+                pen = self.polypen
+            else:
+                pen = self.pen
+
         if img and pdctype == 'image':
             # self.imagedict[img]['coords'] = coords
             self.select[self.imagedict[img]['id']] = False # ?
@@ -212,9 +219,9 @@
             pdc.SetIdBounds(drawid, wx.Rect(coords[0],coords[1], w, h))
         
         elif pdctype == 'box': # draw a box on top of the map
-            if self.pen:
+            if pen:
                 pdc.SetBrush(wx.Brush(wx.CYAN, wx.TRANSPARENT))
-                pdc.SetPen(self.pen)
+                pdc.SetPen(pen)
                 x2 = max(coords[0],coords[2])
                 x1 = min(coords[0],coords[2])
                 y2 = max(coords[1],coords[3])
@@ -226,16 +233,16 @@
                 pdc.SetIdBounds(drawid, rect)
                 
         elif pdctype == 'line': # draw a line on top of the map
-            if self.pen:
+            if pen:
                 pdc.SetBrush(wx.Brush(wx.CYAN, wx.TRANSPARENT))
-                pdc.SetPen(self.pen)
+                pdc.SetPen(pen)
                 pdc.DrawLinePoint(wx.Point(coords[0], coords[1]),wx.Point(coords[2], coords[3]))
                 pdc.SetIdBounds(drawid, wx.Rect(coords[0], coords[1], coords[2], coords[3]))
         
         elif pdctype == 'polyline': # draw a polyline on top of the map
-            if self.polypen:
+            if pen:
                 pdc.SetBrush(wx.Brush(wx.CYAN, wx.TRANSPARENT))
-                pdc.SetPen(self.polypen)
+                pdc.SetPen(pen)
                 if (len(coords) < 2):
                     return
                 i = 1
@@ -260,8 +267,8 @@
                     # self.ovlcoords[drawid] = [x1,y1,x2,y2]
         
         elif pdctype == 'point': # draw point
-            if self.pen:
-                pdc.SetPen(self.pen)
+            if pen:
+                pdc.SetPen(pen)
                 pdc.DrawPoint(coords[0], coords[1])
                 coordsBound = (coords[0] - 5,
                                coords[1] - 5,
@@ -914,7 +921,7 @@
         
         return -1
 
-    def DrawCross(self, pdc, coords, size, rotation = 0,
+    def DrawCross(self, pdc, coords, size, rotation = 0, pen = None,
                   text = None, textAlign = 'lr', textOffset = (5, 5)):
         """!Draw cross in PseudoDC
 
@@ -934,7 +941,7 @@
 
         self.lineid = wx.NewId()
         for lineCoords in coordsCross:
-            self.Draw(pdc, drawid = self.lineid, pdctype = 'line', coords = lineCoords)
+            self.Draw(pdc, drawid = self.lineid, pdctype = 'line', coords = lineCoords, pen = pen)
         
         if not text:
             return self.lineid
@@ -949,7 +956,7 @@
             coord = [coords[0] - textOffset[0], coords[1] + textOffset[1], 0, 0]
         
         self.Draw(pdc, img = text,
-                  pdctype = 'text', coords = coord)
+                  pdctype = 'text', coords = coord, pen = pen)
         
         return self.lineid
 

Modified: grass/trunk/gui/wxpython/mapswipe/frame.py
===================================================================
--- grass/trunk/gui/wxpython/mapswipe/frame.py	2013-02-03 21:02:11 UTC (rev 54883)
+++ grass/trunk/gui/wxpython/mapswipe/frame.py	2013-02-03 21:09:12 UTC (rev 54884)
@@ -99,6 +99,39 @@
 
         wx.CallAfter(self.CallAfterInit)
 
+    def TrackCursor(self, event, showInFirst):
+        """!Track cursor in one window and show cross in the other.
+
+        Only for mirror mode.
+        """
+        if self._mode == 'swipe':
+            return
+        coords = event.GetPosition()
+        if showInFirst:
+            self.firstMapWindow.DrawMouseCross(coords = coords)
+        else:
+            self.secondMapWindow.DrawMouseCross(coords = coords)
+
+        event.Skip()
+
+    def ActivateFirstMap(self, event = None):
+        """!Switch tracking direction"""
+        super(SwipeMapFrame, self).ActivateFirstMap(event)
+
+        self.firstMapWindow.Bind(wx.EVT_MOTION, lambda evt: self.TrackCursor(evt, showInFirst = False))
+        self.secondMapWindow.Unbind(wx.EVT_MOTION)
+        self.firstMapWindow.ClearLines()
+        self.firstMapWindow.Refresh()
+
+    def ActivateSecondMap(self, event = None):
+        """!Switch tracking direction"""
+        super(SwipeMapFrame, self).ActivateSecondMap(event)
+
+        self.secondMapWindow.Bind(wx.EVT_MOTION,  lambda evt: self.TrackCursor(evt, showInFirst = True))
+        self.firstMapWindow.Unbind(wx.EVT_MOTION)
+        self.secondMapWindow.ClearLines()
+        self.secondMapWindow.Refresh()
+
     def CallAfterInit(self):
         self.InitSliderBindings()
         if not (self.rasters['first'] and self.rasters['second']):

Modified: grass/trunk/gui/wxpython/mapswipe/mapwindow.py
===================================================================
--- grass/trunk/gui/wxpython/mapswipe/mapwindow.py	2013-02-03 21:02:11 UTC (rev 54883)
+++ grass/trunk/gui/wxpython/mapswipe/mapwindow.py	2013-02-03 21:09:12 UTC (rev 54884)
@@ -46,6 +46,7 @@
         self.imageId = 99
         self.movingSash = False
         self._mode = 'swipe'
+        self.lineid = wx.NewId()
 
     def _bindMouseEvents(self):
         """!Binds wx mouse events and custom mouse events"""
@@ -113,7 +114,7 @@
         if not self.movingSash:
             super(SwipeBufferedWindow, self).OnSize(event)
 
-    def Draw(self, pdc, img = None, drawid = None, pdctype = 'image', coords = [0, 0, 0, 0]):
+    def Draw(self, pdc, img = None, drawid = None, pdctype = 'image', coords = [0, 0, 0, 0], pen = None):
         """!Draws image (map) with translated coordinates.
         """
         Debug.msg(2, "SwipeBufferedWindow.Draw()")
@@ -121,7 +122,7 @@
         if pdctype == 'image':
             coords = self.GetImageCoords()
 
-        return super(SwipeBufferedWindow, self).Draw(pdc, img, drawid, pdctype, coords)
+        return super(SwipeBufferedWindow, self).Draw(pdc, img, drawid, pdctype, coords, pen)
         
     def OnLeftDown(self, event):
         """!Left mouse button pressed.
@@ -180,7 +181,12 @@
         end = (self.mouse['end'][0] + offsetX, self.mouse['end'][1] + offsetY)
         super(SwipeBufferedWindow, self).MouseDraw(pdc, begin, end)
 
+    def DrawMouseCross(self, coords):
+        """!Draw moving cross."""
+        self.pdcTmp.ClearId(self.lineid)
+        self.lineid = self.DrawCross(pdc = self.pdcTmp, coords = coords, size = 10, pen = wx.BLACK_PEN)
 
+
 class _MouseEvent(wx.PyCommandEvent):
     """!
     This event class takes a regular wxWindows mouse event as a parameter, 



More information about the grass-commit mailing list