[GRASS-SVN] r57361 - in grass/trunk/gui/wxpython: gui_core mapdisp

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Aug 2 02:11:59 PDT 2013


Author: annakrat
Date: 2013-08-02 02:11:59 -0700 (Fri, 02 Aug 2013)
New Revision: 57361

Modified:
   grass/trunk/gui/wxpython/gui_core/dialogs.py
   grass/trunk/gui/wxpython/mapdisp/frame.py
   grass/trunk/gui/wxpython/mapdisp/mapwindow.py
Log:
wxGUI: move legend related code from BufferedWindow

Modified: grass/trunk/gui/wxpython/gui_core/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/dialogs.py	2013-08-02 08:25:59 UTC (rev 57360)
+++ grass/trunk/gui/wxpython/gui_core/dialogs.py	2013-08-02 09:11:59 UTC (rev 57361)
@@ -518,7 +518,7 @@
     """!Controls setting options and displaying/hiding map overlay
     decorations
     """
-    def __init__(self, parent, title, overlayController,
+    def __init__(self, parent, title, giface, overlayController,
                  ddstyle, **kwargs):
         
         wx.Dialog.__init__(self, parent, wx.ID_ANY, title, **kwargs)
@@ -526,7 +526,11 @@
         self.parent  = parent  # MapFrame
         self._overlay = overlayController
         self._ddstyle = ddstyle
+        self._giface = giface
         
+        self._oldMouseUse = None
+        self._oldCursor = None
+        
         sizer = wx.BoxSizer(wx.VERTICAL)
         
         box = wx.BoxSizer(wx.HORIZONTAL)
@@ -630,23 +634,50 @@
                 self._overlay.propwin.SetFocus()
             else:
                 self._overlay.propwin.Show()
-        
+
     def OnResize(self, event):
+        window = self._giface.GetMapWindow()
         if event.GetInt(): 
-            self.parent.SwitchTool(self.parent.toolbars['map'], event)
-            self.parent.MapWindow.SetCursor(self.parent.cursors["cross"])
-            self.parent.MapWindow.mouse['use'] = 'legend'
-            self.parent.MapWindow.mouse['box'] = 'box'
-            self.parent.MapWindow.pen = wx.Pen(colour = 'Black', width = 2, style = wx.SHORT_DASH)
+            self._oldMouseUse = window.mouse['use']
+            self._oldCursor = window.GetCursor()
+            window.SetCursor(self.parent.cursors["cross"])
+            window.mouse['use'] = None
+            window.mouse['box'] = 'box'
+            window.pen = wx.Pen(colour = 'Black', width = 2, style = wx.SHORT_DASH)
+            window.mouseLeftUp.connect(self._resizeLegend)
         else:
-            self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
-            self.parent.MapWindow.mouse['use'] = 'pointer'
-            
+            self.Restore()
+            self.DisconnectResizing()
+
+    def Restore(self):
+        """!Restore conditions before resizing"""
+        window = self._giface.GetMapWindow()
+        if self._oldCursor:
+            window.SetCursor(self._oldCursor)
+        if self._oldMouseUse:
+            window.mouse['use'] = self._oldMouseUse
+
+    def DisconnectResizing(self):
+        self._giface.GetMapWindow().mouseLeftUp.disconnect(self._resizeLegend)
+
+    def _resizeLegend(self, x, y):
+        """!Update legend after drawing new legend size (moved from BufferedWindow)"""
+        self.resizeBtn.SetValue(False)
+        window = self._giface.GetMapWindow()
+        self.DisconnectResizing()
+        self.Restore()
+        # resize legend
+        screenSize = window.GetClientSizeTuple()
+        self._overlay.ResizeLegend(window.mouse["begin"], window.mouse["end"], screenSize)
+        # redraw
+        self._giface.updateMap.emit()
+
     def CloseDialog(self):
         """!Hide dialog"""
         if self._ddstyle == DECOR_DIALOG_LEGEND and self.resizeBtn.GetValue():
+            self.Restore()
             self.resizeBtn.SetValue(False)
-            self.OnResize(None)
+            self.DisconnectResizing()
 
         self.Hide()
 
@@ -654,16 +685,16 @@
         """!Button 'OK' pressed"""
         # enable or disable overlay
         self._overlay.Show(self.chkbox.IsChecked())
-        
+
         # update map
         if self.parent.IsPaneShown('3d'):
             self.parent.MapWindow.UpdateOverlays()
-        
-        self.parent.MapWindow.UpdateMap()
-        
+
+        self._giface.updateMap.emit()
+
         # hide dialog
         self.CloseDialog()
-        
+
     def GetOptData(self, dcmd, layer, params, propwin):
         """!Process decoration layer data"""
         if dcmd:

Modified: grass/trunk/gui/wxpython/mapdisp/frame.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/frame.py	2013-08-02 08:25:59 UTC (rev 57360)
+++ grass/trunk/gui/wxpython/mapdisp/frame.py	2013-08-02 09:11:59 UTC (rev 57361)
@@ -1096,11 +1096,12 @@
 
             # decoration overlay control dialog
             self.dialogs['barscale'] = \
-                DecorationDialog(parent = self, title = _('Scale and North arrow'),
-                                     overlayController = self.barscale,
-                                     ddstyle = DECOR_DIALOG_BARSCALE,
-                                     size = (350, 200),
-                                     style = wx.DEFAULT_DIALOG_STYLE | wx.CENTRE)
+                DecorationDialog(parent=self, title=_('Scale and North arrow'),
+                                 giface=self._giface,
+                                 overlayController=self.barscale,
+                                 ddstyle=DECOR_DIALOG_BARSCALE,
+                                 size=(350, 200),
+                                 style=wx.DEFAULT_DIALOG_STYLE | wx.CENTRE)
 
             self.dialogs['barscale'].CentreOnParent()
             ### dialog cannot be show as modal - in the result d.barscale is not selectable
@@ -1133,11 +1134,12 @@
                 self.dialogs['legend'].Show()
         else:
             self.dialogs['legend'] = \
-                DecorationDialog(parent = self, title = _("Legend"),
-                                 overlayController = self.legend,
-                                 ddstyle = DECOR_DIALOG_LEGEND,
-                                 size = (350, 200),
-                                 style = wx.DEFAULT_DIALOG_STYLE | wx.CENTRE)
+                DecorationDialog(parent=self, title=_("Legend"),
+                                 overlayController=self.legend,
+                                 giface=self._giface, 
+                                 ddstyle=DECOR_DIALOG_LEGEND,
+                                 size=(350, 200),
+                                 style=wx.DEFAULT_DIALOG_STYLE | wx.CENTRE)
 
             self.dialogs['legend'].CentreOnParent() 
             ### dialog cannot be show as modal - in the result d.legend is not selectable
@@ -1339,11 +1341,10 @@
         # untoggles button in add legend dialog
         # FIXME: remove this mess
         if self.dialogs['legend']:
-            if hasattr(event ,'GetEventObject') and hasattr(event.GetEventObject() ,'GetId'):
-                if event.GetEventObject().GetId() == \
-                        self.dialogs['legend'].resizeBtn.GetId():
-                    return
-            self.dialogs['legend'].resizeBtn.SetValue(0)
+            btn = self.dialogs['legend'].resizeBtn
+            if btn.GetValue():
+                btn.SetValue(0)
+                self.dialogs['legend'].DisconnectResizing()
 
     def ResetPointer(self):
         """Sets pointer mode.

Modified: grass/trunk/gui/wxpython/mapdisp/mapwindow.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/mapwindow.py	2013-08-02 08:25:59 UTC (rev 57360)
+++ grass/trunk/gui/wxpython/mapdisp/mapwindow.py	2013-08-02 09:11:59 UTC (rev 57361)
@@ -113,6 +113,8 @@
         # it could replace register and unregister mechanism
         # and partially maybe also internal mouse use dictionary
         self.mouseLeftUpPointer = Signal('BufferedWindow.mouseLeftUpPointer')
+        # Emitted when left mouse button is released
+        self.mouseLeftUp = Signal('BufferedWindow.mouseLeftUp')
 
         # event bindings
         self.Bind(wx.EVT_PAINT,           self.OnPaint)
@@ -1143,9 +1145,6 @@
             else:
                 self.mouse['begin'] = self.mouse['end']
         
-        elif self.mouse['use'] in ('zoom', 'legend'):
-            pass
-        
         # vector digizer
         elif self.mouse["use"] == "pointer" and \
                 hasattr(self, "digit"):
@@ -1179,6 +1178,7 @@
                        self.mouse["use"])
         
         self.mouse['end'] = event.GetPositionTuple()[:]
+        coordinates = self.Pixel2Cell(self.mouse['end'])
         
         if self.mouse['use'] in ["zoom", "pan"]:
             # set region in zoom or pan
@@ -1224,19 +1224,11 @@
             self.dragid = None
             self.currtxtid = None
 
-            coordinates = self.Pixel2Cell(self.mouse['end'])
             self.mouseLeftUpPointer.emit(x=coordinates[0], y=coordinates[1])
 
-        elif self.mouse['use'] == 'legend':
-            self.frame.dialogs['legend'].resizeBtn.SetValue(False)
-            screenSize = self.GetClientSizeTuple()
-            self.overlays[1].ResizeLegend(self.mouse["begin"], self.mouse["end"], screenSize)
+       # TODO: decide which coordinates to send (e, n, mouse['begin'], mouse['end'])
+        self.mouseLeftUp.emit(x=coordinates[0], y=coordinates[1])
 
-            self.frame.MapWindow.SetCursor(self.frame.cursors["default"])
-            self.frame.MapWindow.mouse['use'] = 'pointer'
-            
-            self.UpdateMap()
-            
     def OnButtonDClick(self, event):
         """!Mouse button double click
         """



More information about the grass-commit mailing list