[GRASS-SVN] r54232 - grass/trunk/gui/wxpython/mapswipe
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Dec 7 00:59:28 PST 2012
Author: annakrat
Date: 2012-12-07 00:59:28 -0800 (Fri, 07 Dec 2012)
New Revision: 54232
Modified:
grass/trunk/gui/wxpython/mapswipe/frame.py
grass/trunk/gui/wxpython/mapswipe/g.gui.mapswipe.py
grass/trunk/gui/wxpython/mapswipe/mapwindow.py
grass/trunk/gui/wxpython/mapswipe/toolbars.py
Log:
wxGUI/mapswipe: add mirror map functionality
Modified: grass/trunk/gui/wxpython/mapswipe/frame.py
===================================================================
--- grass/trunk/gui/wxpython/mapswipe/frame.py 2012-12-06 22:06:58 UTC (rev 54231)
+++ grass/trunk/gui/wxpython/mapswipe/frame.py 2012-12-07 08:59:28 UTC (rev 54232)
@@ -68,6 +68,8 @@
self.firstMap.region = self.secondMap.region
self.firstMapWindow.zoomhistory = self.secondMapWindow.zoomhistory
+ self._mode = 'swipe'
+
self.splitter.SplitVertically(self.firstMapWindow, self.secondMapWindow, 0)
self._addPanes()
@@ -153,6 +155,7 @@
self.GetFirstWindow().movingSash = True
self.GetSecondWindow().movingSash = True
pos = event.GetPosition()
+
if pos > 0:
self.splitter.SetSashPosition(pos)
self.splitter.OnSashChanging(None)
@@ -375,28 +378,46 @@
@todo specify size of the new image (problem is inaccurate scaling)
@todo make dividing line width and color optional
"""
- # get size paramteres
- x, y = self.secondMapWindow.GetImageCoords()
- width, height = self.splitter.GetClientSize()
+ w1 = self.splitter.GetWindow1()
+ w2 = self.splitter.GetWindow2()
lineWidth = 1
# render to temporary files
filename1 = grass.tempfile(False) + '1'
filename2 = grass.tempfile(False) + '2'
- self.firstMapWindow.SaveToFile(filename1, fileType, width, height)
- self.secondMapWindow.SaveToFile(filename2, fileType, width, height)
+ width, height = self.splitter.GetClientSize()
+ if self._mode == 'swipe':
+ x, y = w2.GetImageCoords()
+ w1.SaveToFile(filename1, fileType, width, height)
+ w2.SaveToFile(filename2, fileType, width, height)
+ else:
+ fw, fh = w1.GetClientSize()
+ w1.SaveToFile(filename1, fileType, fw, fh)
+ sw, sh = w2.GetClientSize()
+ w2.SaveToFile(filename2, fileType, sw, sh)
+
# create empty white image - needed for line
im = wx.EmptyImage(width, height)
im.Replace(0, 0, 0, 255, 255, 255)
# paste images
- if self.splitter.GetSplitMode() == wx.SPLIT_HORIZONTAL:
- im1 = wx.Image(filename1).GetSubImage((0, 0, width, -y))
- im.Paste(im1, 0, 0)
- im.Paste(wx.Image(filename2), -x, -y + lineWidth)
+ if self._mode == 'swipe':
+ if self.splitter.GetSplitMode() == wx.SPLIT_HORIZONTAL:
+ im1 = wx.Image(filename1).GetSubImage((0, 0, width, -y))
+ im.Paste(im1, 0, 0)
+ im.Paste(wx.Image(filename2), -x, -y + lineWidth)
+ else:
+ im1 = wx.Image(filename1).GetSubImage((0, 0, -x, height))
+ im.Paste(im1, 0, 0)
+ im.Paste(wx.Image(filename2), -x + lineWidth, -y)
else:
- im1 = wx.Image(filename1).GetSubImage((0, 0, -x, height))
- im.Paste(im1, 0, 0)
- im.Paste(wx.Image(filename2), -x + lineWidth, -y)
+ if self.splitter.GetSplitMode() == wx.SPLIT_HORIZONTAL:
+ im1 = wx.Image(filename1)
+ im.Paste(im1, 0, 0)
+ im.Paste(wx.Image(filename2), 0, fh + lineWidth)
+ else:
+ im1 = wx.Image(filename1)
+ im.Paste(im1, 0, 0)
+ im.Paste(wx.Image(filename2), fw + lineWidth, 0)
im.SaveFile(fileName, fileType)
# remove temporary files
@@ -445,13 +466,15 @@
if splitter.GetSplitMode() == wx.SPLIT_HORIZONTAL:
splitter.SplitVertically(self.firstMapWindow, self.secondMapWindow, 0)
self.slider = self.sliderH
- self._mgr.GetPane('sliderH').Show()
- self._mgr.GetPane('sliderV').Hide()
+ if self._mode == 'swipe':
+ self._mgr.GetPane('sliderH').Show()
+ self._mgr.GetPane('sliderV').Hide()
else:
splitter.SplitHorizontally(self.firstMapWindow, self.secondMapWindow, 0)
self.slider = self.sliderV
- self._mgr.GetPane('sliderV').Show()
- self._mgr.GetPane('sliderH').Hide()
+ if self._mode == 'swipe':
+ self._mgr.GetPane('sliderV').Show()
+ self._mgr.GetPane('sliderH').Hide()
self._mgr.Update()
splitter.OnSashChanged(None)
self.OnSize(None)
@@ -464,6 +487,35 @@
"""
pass
+ def SetViewMode(self, mode):
+ """!Sets view mode.
+
+ @param mode view mode ('swipe', 'mirror')
+ """
+ if self._mode == mode:
+ return
+ self._mode = mode
+ self.toolbars['swipeMain'].SetMode(mode)
+ # set window mode
+ self.GetFirstWindow().SetMode(mode)
+ self.GetSecondWindow().SetMode(mode)
+ # hide/show slider
+ if self.splitter.GetSplitMode() == wx.SPLIT_HORIZONTAL:
+ self._mgr.GetPane('sliderV').Show(mode == 'swipe')
+ size = self.splitter.GetSize()[1] / 2
+ else:
+ self._mgr.GetPane('sliderH').Show(mode == 'swipe')
+ size = self.splitter.GetSize()[0] / 2
+ # set sash in the middle
+ self.splitter.SetSashPosition(size)
+ self.slider.SetValue(size)
+ self._mgr.Update()
+ # enable / disable sash
+ self.splitter.EnableSash(mode == 'swipe')
+ # hack to make it work
+ self.splitter.OnSashChanged(None)
+ self.SendSizeEvent()
+
def SetRasterNames(self):
if self.rasters['first']:
self.GetFirstWindow().SetRasterNameText(self.rasters['first'], 101)
@@ -501,9 +553,12 @@
self.sashWidthMax = 10
self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGED, self.OnSashChanged)
self.Bind(wx.EVT_SPLITTER_SASH_POS_CHANGING, self.OnSashChanging)
-
+ self._moveSash = True
wx.CallAfter(self.Init)
+ def EnableSash(self, enable):
+ self._moveSash = enable
+
def Init(self):
self.OnSashChanged(evt = None)
self.SetMinimumPaneSize(0)
@@ -535,7 +590,8 @@
def OnSashChanged(self, evt):
Debug.msg(5, "MapSplitter.OnSashChanged()")
-
+ if not self._moveSash:
+ return
w1, w2 = self.GetWindow1(), self.GetWindow2()
w1.movingSash = False
w2.movingSash = False
@@ -562,7 +618,9 @@
def OnSashChanging(self, event):
Debug.msg(5, "MapSplitter.OnSashChanging()")
-
+ if not self._moveSash:
+ event.SetSashPosition(-1)
+ return
if not (self.GetWindowStyle() & wx.SP_LIVE_UPDATE):
if event:
event.Skip()
Modified: grass/trunk/gui/wxpython/mapswipe/g.gui.mapswipe.py
===================================================================
--- grass/trunk/gui/wxpython/mapswipe/g.gui.mapswipe.py 2012-12-06 22:06:58 UTC (rev 54231)
+++ grass/trunk/gui/wxpython/mapswipe/g.gui.mapswipe.py 2012-12-07 08:59:28 UTC (rev 54232)
@@ -32,6 +32,14 @@
#% description: Second (bottom/left) raster map
#% required: no
#%end
+#%option
+#% key: mode
+#% description: View mode
+#% options: swipe,mirror
+#% descriptions:swipe;swiping the upper map layer to show the map layer below ;mirror;synchronized maps side by side
+#% answer: swipe
+#% required: no
+#%end
import os
@@ -63,6 +71,7 @@
first = options['first']
second = options['second']
+ mode = options['mode']
for mapName in [first, second]:
if mapName:
@@ -81,6 +90,8 @@
frame.SetSecondRaster(second)
if first or second:
frame.SetRasterNames()
+
+ frame.SetViewMode(mode)
frame.ZoomToMap()
frame.Show()
Modified: grass/trunk/gui/wxpython/mapswipe/mapwindow.py
===================================================================
--- grass/trunk/gui/wxpython/mapswipe/mapwindow.py 2012-12-06 22:06:58 UTC (rev 54231)
+++ grass/trunk/gui/wxpython/mapswipe/mapwindow.py 2012-12-07 08:59:28 UTC (rev 54232)
@@ -45,6 +45,7 @@
self.specialCoords = [0, 0]
self.imageId = 99
self.movingSash = False
+ self._mode = 'swipe'
def _bindMouseEvents(self):
"""!Binds wx mouse events and custom mouse events"""
@@ -76,7 +77,10 @@
def GetClientSize(self):
"""!Overriden method which returns simulated window size.
"""
- return self.specialSize
+ if self._mode == 'swipe':
+ return self.specialSize
+ else:
+ return super(SwipeBufferedWindow, self).GetClientSize()
def SetClientSize(self, size):
"""!Overriden method which sets simulated window size.
@@ -84,9 +88,19 @@
Debug.msg(3, "SwipeBufferedWindow.SetClientSize(): size = %s" % size)
self.specialSize = size
+ def SetMode(self, mode):
+ """!Sets mode of the window.
+
+ @param mode mode can be 'swipe' or 'mirror'
+ """
+ self._mode = mode
+
def GetImageCoords(self):
"""!Returns coordinates of rendered image"""
- return self.specialCoords
+ if self._mode == 'swipe':
+ return self.specialCoords
+ else:
+ return (0, 0)
def SetImageCoords(self, coords):
"""!Sets coordinates of rendered image"""
Modified: grass/trunk/gui/wxpython/mapswipe/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/mapswipe/toolbars.py 2012-12-06 22:06:58 UTC (rev 54231)
+++ grass/trunk/gui/wxpython/mapswipe/toolbars.py 2012-12-07 08:59:28 UTC (rev 54232)
@@ -95,7 +95,21 @@
BaseToolbar.__init__(self, parent)
self.InitToolbar(self._toolbarData())
-
+
+ # add tool to toggle active map window
+ self.toggleModeId = wx.NewId()
+ self.toggleMode = wx.Choice(parent = self, id = self.toggleModeId)
+ for label, cdata in zip([_('Swipe mode'), _('Mirror mode')], ['swipe', 'mirror']):
+ self.toggleMode.Append(label, cdata)
+ self.toggleMode.SetSelection(0)
+ self.toggleMode.SetSize(self.toggleMode.GetBestSize())
+ self.toggleMode.Bind(wx.EVT_CHOICE,
+ lambda event:
+ self.parent.SetViewMode(self.toggleMode.GetClientData(event.GetSelection())))
+ self.InsertControl(3, self.toggleMode)
+
+ help = _("Choose view mode")
+ self.SetToolShortHelp(self.toggleModeId, help)
# realize the toolbar
self.Realize()
@@ -108,6 +122,11 @@
self.OnToolMenu)
))
+ def SetMode(self, mode):
+ for i in range(self.toggleMode.GetCount()):
+ if mode == self.toggleMode.GetClientData(i):
+ self.toggleMode.SetSelection(i)
+
def OnToolMenu(self, event):
"""!Menu for additional tools"""
toolMenu = wx.Menu()
More information about the grass-commit
mailing list