[GRASS-SVN] r47233 - grass/trunk/gui/wxpython/gui_modules

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jul 23 12:47:42 EDT 2011


Author: annakrat
Date: 2011-07-23 09:47:41 -0700 (Sat, 23 Jul 2011)
New Revision: 47233

Modified:
   grass/trunk/gui/wxpython/gui_modules/gdialogs.py
   grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py
   grass/trunk/gui/wxpython/gui_modules/render.py
Log:
wxGUI: interactive setting of legend size and position

Modified: grass/trunk/gui/wxpython/gui_modules/gdialogs.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/gdialogs.py	2011-07-23 08:46:52 UTC (rev 47232)
+++ grass/trunk/gui/wxpython/gui_modules/gdialogs.py	2011-07-23 16:47:41 UTC (rev 47233)
@@ -448,6 +448,17 @@
         box.Add(item=optnbtn, proportion=0, flag=wx.ALIGN_CENTRE|wx.ALL, border=5)
         sizer.Add(item=box, proportion=0,
                   flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
+        if self.name == 'legend':
+            box = wx.BoxSizer(wx.HORIZONTAL)
+            resize = wx.ToggleButton(parent=self, id=wx.ID_ANY, label=_("Set size and position"))
+            resize.SetToolTipString(_("Click and drag on the map display to set legend"
+                                        " size and position and then press OK"))
+            resize.SetName('resize')
+            if self.parent.toolbars['nviz']:
+                resize.Disable()
+            box.Add(item=resize, proportion=0, flag=wx.ALIGN_CENTRE|wx.ALL, border=5)
+            sizer.Add(item=box, proportion=0,
+                      flag=wx.GROW|wx.ALIGN_CENTER_VERTICAL|wx.ALL, border=5)
 
         box = wx.BoxSizer(wx.HORIZONTAL)
         label = wx.StaticText(parent=self, id=wx.ID_ANY,
@@ -485,6 +496,8 @@
         # bindings
         #
         self.Bind(wx.EVT_BUTTON,   self.OnOptions, optnbtn)
+        if self.name == 'legend':
+            self.Bind(wx.EVT_TOGGLEBUTTON,   self.OnResize, resize)
         self.Bind(wx.EVT_BUTTON,   self.OnCancel,  btnCancel)
         self.Bind(wx.EVT_BUTTON,   self.OnOK,      self.btnOK)
 
@@ -518,7 +531,7 @@
                      'params' : None,
                      'propwin' : None,
                      'cmd' : self.cmd,
-                     'coords': (10, 10),
+                     'coords': (0, 0),
                      'pdcType': 'image' }
             self.parent.MapWindow2D.overlays[self.ovlId] = prop
             if self.parent.MapWindow3D:
@@ -547,11 +560,26 @@
                 self.parent.MapWindow.overlays[self.ovlId]['propwin'].SetFocus()
             else:
                 self.parent.MapWindow.overlays[self.ovlId]['propwin'].Show()
-
+    
+    def OnResize(self, event):
+        if self.FindWindowByName('resize').GetValue():
+            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)
+        else:
+            self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
+            self.parent.MapWindow.mouse['use'] = 'pointer'
+            
     def OnCancel(self, event):
         """!Cancel dialog"""
+        if self.name == 'legend' and self.FindWindowByName('resize').GetValue():
+            self.FindWindowByName('resize').SetValue(False)
+            self.OnResize(None)
+            
         self.parent.dialogs['barscale'] = None
-        self.parent.Map.DeleteOverlay(self.newOverlay)
+        if event and hasattr(self, 'newOverlay'):
+            self.parent.Map.DeleteOverlay(self.newOverlay)
         self.Destroy()
 
     def OnOK(self, event):

Modified: grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py	2011-07-23 08:46:52 UTC (rev 47232)
+++ grass/trunk/gui/wxpython/gui_modules/mapdisp_window.py	2011-07-23 16:47:41 UTC (rev 47233)
@@ -1158,7 +1158,7 @@
             else:
                 self.mouse['begin'] = self.mouse['end']
         
-        elif self.mouse['use'] == 'zoom':
+        elif self.mouse['use'] in ('zoom', 'legend'):
             pass
         
         # vector digizer
@@ -1294,7 +1294,16 @@
                 pass
             self.dragid = None
             self.currtxtid = None
-        
+            
+        elif self.mouse['use'] == 'legend':
+            self.ResizeLegend(self.mouse["begin"], self.mouse["end"])
+            self.parent.dialogs['legend'].FindWindowByName("resize").SetValue(False)
+            self.Map.GetOverlay(1).SetActive(True)
+            self.parent.MapWindow.SetCursor(self.parent.cursors["default"])
+            self.parent.MapWindow.mouse['use'] = 'pointer'
+            
+            self.UpdateMap()
+            
     def OnButtonDClick(self, event):
         """!Mouse button double click
         """
@@ -1475,6 +1484,29 @@
         
         return (x, y)
     
+    def ResizeLegend(self, begin, end):
+        w = abs(begin[0] - end[0])
+        h = abs(begin[1] - end[1])
+        if begin[0] < end[0]:
+            x = begin[0]
+        else:
+            x = end[0]
+        if begin[1] < end[1]:
+            y = begin[1]
+        else:
+            y = end[1]
+        screenRect = wx.Rect(x, y, w, h)
+        screenSize = self.GetClientSizeTuple()
+        at = [(screenSize[1] - (y + h)) / float(screenSize[1]) * 100,
+              (screenSize[1] - y) / float(screenSize[1]) * 100,
+              x / float(screenSize[0]) * 100,
+              (x + w) / float(screenSize[0]) * 100]
+        for i, subcmd in enumerate(self.overlays[1]['cmd']):
+            if subcmd.startswith('at='):
+                self.overlays[1]['cmd'][i] = "at=%d,%d,%d,%d" % (at[0], at[1], at[2], at[3])
+        self.Map.ChangeOverlay(1, True, command = self.overlays[1]['cmd'])
+        self.overlays[1]['coords'] = (0,0)
+        
     def Zoom(self, begin, end, zoomtype):
         """!Calculates new region while (un)zoom/pan-ing
         """

Modified: grass/trunk/gui/wxpython/gui_modules/render.py
===================================================================
--- grass/trunk/gui/wxpython/gui_modules/render.py	2011-07-23 08:46:52 UTC (rev 47232)
+++ grass/trunk/gui/wxpython/gui_modules/render.py	2011-07-23 16:47:41 UTC (rev 47233)
@@ -1262,7 +1262,7 @@
         if 'opacity' in kargs:
             overlay.SetOpacity(kargs['opacity'])
         
-        if render and command != [] and not overlay.Render():
+        if render and overlay.GetCmd() != [] and not overlay.Render():
             raise gcmd.GException(_("Unable render overlay <%s>") % 
                                   name)
         



More information about the grass-commit mailing list