[GRASS-SVN] r47287 -
grass/branches/develbranch_6/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jul 27 16:46:04 EDT 2011
Author: martinl
Date: 2011-07-27 13:46:03 -0700 (Wed, 27 Jul 2011)
New Revision: 47287
Modified:
grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py
Log:
annakrat: wxGUI: interactive setting of legend size and position
(merge r47233 from trunk)
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py 2011-07-27 18:02:34 UTC (rev 47286)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gdialogs.py 2011-07-27 20:46:03 UTC (rev 47287)
@@ -446,6 +446,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,
@@ -483,6 +494,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)
@@ -509,17 +522,19 @@
def _CreateOverlay(self):
if not self.parent.Map.GetOverlay(self.ovlId):
- overlay = self.parent.Map.AddOverlay(id=self.ovlId, type=self.name,
+ self.newOverlay = self.parent.Map.AddOverlay(id=self.ovlId, type=self.name,
command=self.cmd,
l_active=False, l_render=False, l_hidden=True)
-
- self.parent.MapWindow.overlays[self.ovlId] = {}
- self.parent.MapWindow.overlays[self.ovlId] = { 'layer' : overlay,
- 'params' : None,
- 'propwin' : None,
- 'cmd' : self.cmd,
- 'coords': (10, 10),
- 'pdcType': 'image' }
+
+ prop = { 'layer' : self.newOverlay,
+ 'params' : None,
+ 'propwin' : None,
+ 'cmd' : self.cmd,
+ 'coords': (0, 0),
+ 'pdcType': 'image' }
+ self.parent.MapWindow2D.overlays[self.ovlId] = prop
+ if self.parent.MapWindow3D:
+ self.parent.MapWindow3D.overlays[self.ovlId] = prop
else:
if self.parent.MapWindow.overlays[self.ovlId]['propwin'] == None:
return
@@ -543,11 +558,28 @@
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
-
+
+ if event and hasattr(self, 'newOverlay'):
+ self.parent.Map.DeleteOverlay(self.newOverlay)
+
self.Destroy()
def OnOK(self, event):
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py 2011-07-27 18:02:34 UTC (rev 47286)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp_window.py 2011-07-27 20:46:03 UTC (rev 47287)
@@ -1131,7 +1131,7 @@
else:
self.mouse['begin'] = self.mouse['end']
- elif self.mouse['use'] == 'zoom':
+ elif self.mouse['use'] in ('zoom', 'legend'):
pass
# vector digizer
@@ -1265,7 +1265,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
"""
@@ -1445,6 +1454,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/branches/develbranch_6/gui/wxpython/gui_modules/render.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py 2011-07-27 18:02:34 UTC (rev 47286)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/render.py 2011-07-27 20:46:03 UTC (rev 47287)
@@ -1200,7 +1200,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