[GRASS-SVN] r60326 - in grass/branches/releasebranch_7_0/gui/wxpython: gui_core mapswipe mapwin
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun May 18 11:30:16 PDT 2014
Author: annakrat
Date: 2014-05-18 11:30:16 -0700 (Sun, 18 May 2014)
New Revision: 60326
Modified:
grass/branches/releasebranch_7_0/gui/wxpython/gui_core/mapdisp.py
grass/branches/releasebranch_7_0/gui/wxpython/mapswipe/frame.py
grass/branches/releasebranch_7_0/gui/wxpython/mapswipe/toolbars.py
grass/branches/releasebranch_7_0/gui/wxpython/mapwin/base.py
Log:
wxGUI/mapswipe: add query tool (merge from trunk r60290)
Modified: grass/branches/releasebranch_7_0/gui/wxpython/gui_core/mapdisp.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/gui_core/mapdisp.py 2014-05-18 18:20:34 UTC (rev 60325)
+++ grass/branches/releasebranch_7_0/gui/wxpython/gui_core/mapdisp.py 2014-05-18 18:30:16 UTC (rev 60326)
@@ -587,6 +587,11 @@
self.GetFirstWindow().SetModePointer()
self.GetSecondWindow().SetModePointer()
+ def OnQuery(self, event):
+ """!Set query mode"""
+ self.GetFirstWindow().SetModeQuery()
+ self.GetSecondWindow().SetModeQuery()
+
def OnRender(self, event):
"""!Re-render map composition (each map layer)
"""
Modified: grass/branches/releasebranch_7_0/gui/wxpython/mapswipe/frame.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/mapswipe/frame.py 2014-05-18 18:20:34 UTC (rev 60325)
+++ grass/branches/releasebranch_7_0/gui/wxpython/mapswipe/frame.py 2014-05-18 18:30:16 UTC (rev 60326)
@@ -30,6 +30,7 @@
from core.gcmd import GError, GMessage
from core.utils import _
from core.layerlist import LayerListToRendererConverter
+from gui_core.query import QueryDialog, PrepareQueryResults
from mapswipe.toolbars import SwipeMapToolbar, SwipeMainToolbar, SwipeMiscToolbar
from mapswipe.mapwindow import SwipeBufferedWindow
@@ -71,6 +72,10 @@
self.secondMapWindow = SwipeBufferedWindow(parent = self.splitter, giface = self._giface,
properties=self.mapWindowProperties,
Map = self.secondMap)
+ # bind query signal
+ self.firstMapWindow.mapQueried.connect(self.Query)
+ self.secondMapWindow.mapQueried.connect(self.Query)
+
self.MapWindow = self.firstMapWindow # current by default
self.firstMapWindow.zoomhistory = self.secondMapWindow.zoomhistory
self.SetBindRegions(True)
@@ -100,6 +105,7 @@
self._inputDialog = None
self._preferencesDialog = None
+ self._queryDialog = None
# default action in map toolbar
self.GetMapToolbar().SelectDefault()
@@ -602,6 +608,75 @@
self.GetFirstWindow().SetRasterNameText('', 101)
self.GetSecondWindow().SetRasterNameText('', 102)
+ def Query(self, x, y):
+ """!Query active layers from both mapwindows.
+
+ @param x,y coordinates
+ """
+ rasters = ([layer.GetName() for layer in
+ self.GetFirstMap().GetListOfLayers(ltype='raster', active=True)],
+ [layer.GetName() for layer in
+ self.GetSecondMap().GetListOfLayers(ltype='raster', active=True)])
+ vectors = ([layer.GetName() for layer in
+ self.GetFirstMap().GetListOfLayers(ltype='vector', active=True)],
+ [layer.GetName() for layer in
+ self.GetSecondMap().GetListOfLayers(ltype='vector', active=True)])
+
+ if not (rasters[0] + rasters[1] + vectors[0] + vectors[1]):
+ GMessage(parent=self,
+ message=_('No raster or vector map layer selected for querying.'))
+ return
+
+ # set query snap distance for v.what at map unit equivalent of 10 pixels
+ qdist = 10.0 * ((self.GetFirstMap().region['e'] -
+ self.GetFirstMap().region['w']) / self.GetFirstMap().width)
+
+ east, north = self.GetFirstWindow().Pixel2Cell((x, y))
+
+ # use display region settings instead of computation region settings
+ self.tmpreg = os.getenv("GRASS_REGION")
+ os.environ["GRASS_REGION"] = self.GetFirstMap().SetRegion(windres=False)
+
+ result = []
+ if rasters[0]:
+ result.extend(grass.raster_what(map=rasters[0], coord=(east, north)))
+ if vectors[0]:
+ result.extend(grass.vector_what(map=vectors[0], coord=(east, north), distance=qdist))
+ if rasters[1]:
+ result.extend(grass.raster_what(map=rasters[1], coord=(east, north)))
+ if vectors[1]:
+ result.extend(grass.vector_what(map=vectors[1], coord=(east, north), distance=qdist))
+
+ self._QueryMapDone()
+
+ result = PrepareQueryResults(coordinates=(east, north), result=result)
+ if self._queryDialog:
+ self._queryDialog.Raise()
+ self._queryDialog.SetData(result)
+ else:
+ self._queryDialog = QueryDialog(parent=self, data=result)
+ self._queryDialog.Bind(wx.EVT_CLOSE, self._oncloseQueryDialog)
+ self._queryDialog.redirectOutput.connect(lambda output: self._giface.WriteLog(output))
+ self._queryDialog.Show()
+
+ def _oncloseQueryDialog(self, event):
+ self._queryDialog = None
+ event.Skip()
+
+ def _QueryMapDone(self):
+ """!Restore settings after querying (restore GRASS_REGION)
+ """
+ if hasattr(self, "tmpreg"):
+ if self.tmpreg:
+ os.environ["GRASS_REGION"] = self.tmpreg
+ elif 'GRASS_REGION' in os.environ:
+ del os.environ["GRASS_REGION"]
+ elif 'GRASS_REGION' in os.environ:
+ del os.environ["GRASS_REGION"]
+
+ if hasattr(self, "tmpreg"):
+ del self.tmpreg
+
def GetMapToolbar(self):
"""!Returns toolbar with zooming tools"""
return self.toolbars['swipeMap']
Modified: grass/branches/releasebranch_7_0/gui/wxpython/mapswipe/toolbars.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/mapswipe/toolbars.py 2014-05-18 18:20:34 UTC (rev 60325)
+++ grass/branches/releasebranch_7_0/gui/wxpython/mapswipe/toolbars.py 2014-05-18 18:30:16 UTC (rev 60326)
@@ -23,12 +23,15 @@
from core.utils import _
-swipeIcons = {
- 'tools': MetaIcon(img = 'tools', label = _("Tools")),
- 'quit' : BaseIcons['quit'].SetLabel(_("Quit Map Swipe")),
- 'addRast' : BaseIcons['addRast'].SetLabel(_("Select raster maps")),
- }
+swipeIcons = {'tools': MetaIcon(img='tools', label=_("Tools")),
+ 'quit': BaseIcons['quit'].SetLabel(_("Quit Map Swipe")),
+ 'addRast': BaseIcons['addRast'].SetLabel(_("Select raster maps")),
+ 'query': MetaIcon(img='info',
+ label=_('Query raster/vector map(s)'),
+ desc=_('Query selected raster/vector map(s)')),
+ }
+
class SwipeMapToolbar(BaseToolbar):
"""!Map toolbar (to control map zoom and rendering)
"""
@@ -36,18 +39,18 @@
"""!Map toolbar constructor
"""
BaseToolbar.__init__(self, parent, toolSwitcher)
-
+
self.InitToolbar(self._toolbarData())
self._default = self.pan
# realize the toolbar
self.Realize()
-
- for tool in (self.pointer, self.pan, self.zoomIn, self.zoomOut):
+
+ for tool in (self.pointer, self.query, self.pan, self.zoomIn, self.zoomOut):
self.toolSwitcher.AddToolToGroup(group='mouseUse', toolbar=self, tool=tool)
-
+
self.EnableTool(self.zoomBack, False)
-
+
def _toolbarData(self):
"""!Returns toolbar data (name, icon, handler)"""
# BaseIcons are a set of often used icons. It is possible
@@ -59,13 +62,16 @@
self.parent.OnRender),
("erase", icons["erase"],
self.parent.OnErase),
- (None, ), # creates separator
+ (None, ), # creates separator
("pointer", icons["pointer"],
self.parent.OnPointer,
wx.ITEM_CHECK),
+ ("query", swipeIcons["query"],
+ self.parent.OnQuery,
+ wx.ITEM_CHECK),
("pan", icons["pan"],
self.parent.OnPan,
- wx.ITEM_CHECK), # toggle tool
+ wx.ITEM_CHECK), # toggle tool
("zoomIn", icons["zoomIn"],
self.parent.OnZoomIn,
wx.ITEM_CHECK),
@@ -80,14 +86,15 @@
(None, ),
('saveFile', icons['saveFile'],
self.parent.SaveToFile),
- ))
-
+ ))
+
def SetActiveMap(self, index):
"""!Set currently selected map.
Unused, needed because of DoubleMapFrame API.
"""
pass
+
class SwipeMainToolbar(BaseToolbar):
"""!Toolbar with tools related to application functionality
"""
@@ -95,18 +102,18 @@
"""!Toolbar constructor
"""
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)
+ 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:
+ lambda event:
self.parent.SetViewMode(self.toggleMode.GetClientData(event.GetSelection())))
self.InsertControl(3, self.toggleMode)
@@ -114,7 +121,7 @@
self.SetToolShortHelp(self.toggleModeId, help)
# realize the toolbar
self.Realize()
-
+
def _toolbarData(self):
"""!Toolbar data"""
return self._getToolbarData((("addRaster", swipeIcons['addRast'],
@@ -122,7 +129,7 @@
(None, ),
("tools", swipeIcons['tools'],
self.OnToolMenu)
- ))
+ ))
def SetMode(self, mode):
for i in range(self.toggleMode.GetCount()):
@@ -132,19 +139,19 @@
def OnToolMenu(self, event):
"""!Menu for additional tools"""
toolMenu = wx.Menu()
-
+
for label, itype, handler, desc in (
(_("Switch orientation"),
wx.ITEM_NORMAL, self.parent.OnSwitchOrientation, "switchOrientation"),
(_("Switch maps"),
wx.ITEM_NORMAL, self.parent.OnSwitchWindows, "switchMaps")):
# Add items to the menu
- item = wx.MenuItem(parentMenu = toolMenu, id = wx.ID_ANY,
- text = label,
- kind = itype)
+ item = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
+ text=label,
+ kind=itype)
toolMenu.AppendItem(item)
self.parent.GetWindow().Bind(wx.EVT_MENU, handler, item)
-
+
# Popup the menu. If an item is selected then its handler
# will be called before PopupMenu returns.
self.parent.GetWindow().PopupMenu(toolMenu)
@@ -158,11 +165,11 @@
"""!Toolbar constructor
"""
BaseToolbar.__init__(self, parent)
-
+
self.InitToolbar(self._toolbarData())
# realize the toolbar
self.Realize()
-
+
def _toolbarData(self):
"""!Toolbar data"""
return self._getToolbarData((("settings", BaseIcons['settings'],
Modified: grass/branches/releasebranch_7_0/gui/wxpython/mapwin/base.py
===================================================================
--- grass/branches/releasebranch_7_0/gui/wxpython/mapwin/base.py 2014-05-18 18:20:34 UTC (rev 60325)
+++ grass/branches/releasebranch_7_0/gui/wxpython/mapwin/base.py 2014-05-18 18:30:16 UTC (rev 60326)
@@ -390,6 +390,13 @@
self.pen = wx.Pen(colour='Red', width=2, style=wx.SHORT_DASH)
self.SetNamedCursor('cross')
+ def SetModeQuery(self):
+ """!Query mode on"""
+ self.mouse['use'] = "query"
+ self.mouse['box'] = "point"
+ self.zoomtype = 0
+ self.SetNamedCursor('cross')
+
def DisactivateWin(self):
"""!Use when the class instance is hidden in MapFrame."""
raise NotImplementedError()
More information about the grass-commit
mailing list