[GRASS-SVN] r57436 - in grass/trunk/gui/wxpython: gcp gui_core iclass mapdisp mapswipe mapwin psmap rlisetup vdigit vnet
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Aug 8 06:45:54 PDT 2013
Author: annakrat
Date: 2013-08-08 06:45:54 -0700 (Thu, 08 Aug 2013)
New Revision: 57436
Modified:
grass/trunk/gui/wxpython/gcp/mapdisplay.py
grass/trunk/gui/wxpython/gcp/toolbars.py
grass/trunk/gui/wxpython/gui_core/forms.py
grass/trunk/gui/wxpython/gui_core/gselect.py
grass/trunk/gui/wxpython/gui_core/mapdisp.py
grass/trunk/gui/wxpython/gui_core/toolbars.py
grass/trunk/gui/wxpython/iclass/frame.py
grass/trunk/gui/wxpython/iclass/toolbars.py
grass/trunk/gui/wxpython/mapdisp/frame.py
grass/trunk/gui/wxpython/mapdisp/toolbars.py
grass/trunk/gui/wxpython/mapswipe/frame.py
grass/trunk/gui/wxpython/mapswipe/toolbars.py
grass/trunk/gui/wxpython/mapwin/decorations.py
grass/trunk/gui/wxpython/psmap/frame.py
grass/trunk/gui/wxpython/psmap/toolbars.py
grass/trunk/gui/wxpython/rlisetup/sampling_frame.py
grass/trunk/gui/wxpython/vdigit/toolbars.py
grass/trunk/gui/wxpython/vnet/dialogs.py
grass/trunk/gui/wxpython/vnet/toolbars.py
Log:
wxGUI: improved system of switching tools in toolbars
Modified: grass/trunk/gui/wxpython/gcp/mapdisplay.py
===================================================================
--- grass/trunk/gui/wxpython/gcp/mapdisplay.py 2013-08-08 11:26:44 UTC (rev 57435)
+++ grass/trunk/gui/wxpython/gcp/mapdisplay.py 2013-08-08 13:45:54 UTC (rev 57436)
@@ -33,6 +33,7 @@
from core.settings import UserSettings
from mapwin.buffered import BufferedMapWindow
from mapwin.base import MapWindowProperties
+from gui_core.toolbars import ToolSwitcher
import mapdisp.statusbar as sb
import gcp.statusbar as sbgcp
@@ -141,6 +142,8 @@
#
self._initMap(Map = self.SrcMap)
self._initMap(Map = self.TgtMap)
+
+ self.GetMapToolbar().SelectDefault()
#
# Bind various events
@@ -239,7 +242,7 @@
"""
# default toolbar
if name == "map":
- self.toolbars['map'] = MapToolbar(self, self.Map)
+ self.toolbars['map'] = MapToolbar(self, self._toolSwitcher)
self._mgr.AddPane(self.toolbars['map'],
wx.aui.AuiPaneInfo().
@@ -252,7 +255,7 @@
# GCP display
elif name == "gcpdisp":
- self.toolbars['gcpdisp'] = GCPDisplayToolbar(self)
+ self.toolbars['gcpdisp'] = GCPDisplayToolbar(self, self._toolSwitcher)
self._mgr.AddPane(self.toolbars['gcpdisp'],
wx.aui.AuiPaneInfo().
@@ -322,10 +325,7 @@
def OnPointer(self, event):
"""!Pointer button clicked
- """
- self.toolbars['gcpdisp'].OnTool(event)
- self.toolbars['gcpdisp'].action['desc'] = ''
-
+ """
# change the cursor
self.SrcMapWindow.SetNamedCursor('cross')
self.SrcMapWindow.mouse['use'] = "pointer"
@@ -338,10 +338,7 @@
"""
Zoom in the map.
Set mouse cursor, zoombox attributes, and zoom direction
- """
- self.toolbars['gcpdisp'].OnTool(event)
- self.toolbars['gcpdisp'].action['desc'] = ''
-
+ """
self.MapWindow.mouse['use'] = "zoom"
self.MapWindow.mouse['box'] = "box"
self.MapWindow.zoomtype = 1
@@ -368,9 +365,6 @@
Zoom out the map.
Set mouse cursor, zoombox attributes, and zoom direction
"""
- self.toolbars['gcpdisp'].OnTool(event)
- self.toolbars['gcpdisp'].action['desc'] = ''
-
self.MapWindow.mouse['use'] = "zoom"
self.MapWindow.mouse['box'] = "box"
self.MapWindow.zoomtype = -1
@@ -395,10 +389,7 @@
def OnPan(self, event):
"""
Panning, set mouse to drag
- """
- self.toolbars['gcpdisp'].OnTool(event)
- self.toolbars['gcpdisp'].action['desc'] = ''
-
+ """
self.MapWindow.mouse['use'] = "pan"
self.MapWindow.mouse['box'] = "pan"
self.MapWindow.zoomtype = 0
Modified: grass/trunk/gui/wxpython/gcp/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/gcp/toolbars.py 2013-08-08 11:26:44 UTC (rev 57435)
+++ grass/trunk/gui/wxpython/gcp/toolbars.py 2013-08-08 13:45:54 UTC (rev 57436)
@@ -78,12 +78,13 @@
class GCPDisplayToolbar(BaseToolbar):
"""!GCP Display toolbar
"""
- def __init__(self, parent):
+ def __init__(self, parent, toolSwitcher):
"""!GCP Display toolbar constructor
"""
- BaseToolbar.__init__(self, parent)
+ BaseToolbar.__init__(self, parent, toolSwitcher)
self.InitToolbar(self._toolbarData())
+ self._default = self.gcpset
# add tool to toggle active map window
self.togglemapid = wx.NewId()
@@ -96,15 +97,12 @@
BaseIcons["zoomBack"].GetLabel(),
_(' / Zoom to map')))
+ for tool in (self.gcpset, self.pan, self.zoomin, self.zoomout):
+ self.toolSwitcher.AddToolToGroup(group='mouseUse', toolbar=self, tool=tool)
+
# realize the toolbar
self.Realize()
-
- self.action = { 'id' : self.gcpset }
- self.defaultAction = { 'id' : self.gcpset,
- 'bind' : self.parent.OnPointer }
-
- self.OnTool(None)
-
+
self.EnableTool(self.zoomback, False)
def _toolbarData(self):
@@ -153,4 +151,3 @@
('quit', icons["quit"],
self.parent.OnQuit))
)
-
Modified: grass/trunk/gui/wxpython/gui_core/forms.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/forms.py 2013-08-08 11:26:44 UTC (rev 57435)
+++ grass/trunk/gui/wxpython/gui_core/forms.py 2013-08-08 13:45:54 UTC (rev 57436)
@@ -394,6 +394,8 @@
self.modeler = self.parent
else:
self.modeler = None
+
+ self.dialogClosing = Signal('TaskFrame.dialogClosing')
# module name + keywords
title = self.task.get_name()
@@ -738,7 +740,7 @@
def OnCancel(self, event):
"""!Cancel button pressed"""
self.MakeModal(False)
-
+ self.dialogClosing.emit()
if self.get_dcmd and \
self.parent and \
self.parent.GetName() in ('LayerTree',
@@ -1516,6 +1518,9 @@
param = p)
p['wxId'] = [win.GetTextWin().GetId()]
win.GetTextWin().Bind(wx.EVT_TEXT, self.OnSetValue)
+ # bind closing event because destructor is not working properly
+ if hasattr(self.parent, 'dialogClosing'):
+ self.parent.dialogClosing.connect(win.OnClose)
# normal text field
else:
Modified: grass/trunk/gui/wxpython/gui_core/gselect.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/gselect.py 2013-08-08 11:26:44 UTC (rev 57435)
+++ grass/trunk/gui/wxpython/gui_core/gselect.py 2013-08-08 13:45:54 UTC (rev 57436)
@@ -1993,6 +1993,10 @@
size = globalvar.DIALOG_COLOR_SIZE)
self.registered = False
self.buttonInsCoords.Bind(wx.EVT_BUTTON, self._onClick)
+ switcher = self._giface.GetMapDisplay().GetToolSwitcher()
+ switcher.AddCustomToolToGroup(group='mouseUse',
+ btnId=self.buttonInsCoords.GetId(),
+ toggleHandler=self.buttonInsCoords.SetValue)
self._doLayout()
def _doLayout(self):
@@ -2005,12 +2009,13 @@
def _onClick(self, event):
"""!Button for interacitve inserting of coordinates clicked"""
+ switcher = self._giface.GetMapDisplay().GetToolSwitcher()
+ switcher.ToolChanged(self.buttonInsCoords.GetId())
self.mapWin = self._giface.GetMapWindow()
if self.buttonInsCoords.GetToggle() and self.mapWin:
if self.mapWin.RegisterMouseEventHandler(wx.EVT_LEFT_DOWN,
self._onMapClickHandler,
'cross') == False:
- self.buttonInsCoords.SetToggle(False)
return
self.registered = True
@@ -2021,14 +2026,10 @@
self._onMapClickHandler):
self.registered = False
return
-
- self.buttonInsCoords.SetToggle(False)
-
+
def _onMapClickHandler(self, event):
"""!Gets coordinates from mapwindow"""
if event == "unregistered":
- if self.buttonInsCoords:
- self.buttonInsCoords.SetToggle(False)
return
e, n = self.mapWin.GetLastEN()
@@ -2041,9 +2042,11 @@
value = prevCoords + str(e) + "," + str(n)
self.coordsField.SetValue(value)
-
- def __del__(self):
+
+ def OnClose(self):
"""!Unregistrates _onMapClickHandler from mapWin"""
+ switcher = self._giface.GetMapDisplay().GetToolSwitcher()
+ switcher.RemoveCustomToolFromGroup(self.buttonInsCoords.GetId())
if self.mapWin and self.registered:
self.mapWin.UnregisterMouseEventHandler(wx.EVT_LEFT_DOWN,
self._onMapClickHandler)
Modified: grass/trunk/gui/wxpython/gui_core/mapdisp.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/mapdisp.py 2013-08-08 11:26:44 UTC (rev 57435)
+++ grass/trunk/gui/wxpython/gui_core/mapdisp.py 2013-08-08 13:45:54 UTC (rev 57436)
@@ -28,9 +28,11 @@
from core import globalvar
from core.debug import Debug
from core.utils import _
+from gui_core.toolbars import ToolSwitcher
from grass.script import core as grass
+
class MapFrameBase(wx.Frame):
"""!Base class for map display window
@@ -94,6 +96,10 @@
else:
self._mgr = auimgr
+ # handles switching between tools in different toolbars
+ self._toolSwitcher = ToolSwitcher()
+ self._toolSwitcher.toggleToolChanged.connect(self._onToggleTool)
+
def _initMap(self, Map):
"""!Initialize map display, set dimensions and map region
"""
@@ -106,6 +112,9 @@
Map.region = Map.GetRegion() # g.region -upgc
# self.Map.SetRegion() # adjust region to match display window
+ def _onToggleTool(self):
+ self.GetWindow().UnregisterAllHandlers()
+
def OnSize(self, event):
"""!Adjust statusbar on changing size"""
# reposition checkbox in statusbar
@@ -114,6 +123,9 @@
# update statusbar
self.StatusbarUpdate()
+ def GetToolSwitcher(self):
+ return self._toolSwitcher
+
def SetProperty(self, name, value):
"""!Sets property"""
self.statusbarManager.SetProperty(name, value)
@@ -288,20 +300,14 @@
def OnZoomIn(self, event):
"""!Zoom in the map.
Set mouse cursor, zoombox attributes, and zoom direction
- """
- toolbar = self.GetMapToolbar()
- self.SwitchTool(toolbar, event)
-
+ """
win = self.GetWindow()
self._prepareZoom(mapWindow = win, zoomType = 1)
def OnZoomOut(self, event):
"""!Zoom out the map.
Set mouse cursor, zoombox attributes, and zoom direction
- """
- toolbar = self.GetMapToolbar()
- self.SwitchTool(toolbar, event)
-
+ """
win = self.GetWindow()
self._prepareZoom(mapWindow = win, zoomType = -1)
@@ -329,27 +335,15 @@
# change the cursor
mapWindow.SetNamedCursor('cross')
-
- def SwitchTool(self, toolbar, event):
- """!Helper function to switch tools"""
- # unregistration of all registered mouse event handlers of
- # Mapwindow
- self.MapWindow.UnregisterAllHandlers()
-
- if toolbar:
- toolbar.OnTool(event)
- toolbar.action['desc'] = ''
def OnPointer(self, event):
"""!Sets mouse mode to pointer."""
self.MapWindow.mouse['use'] = 'pointer'
+ self.MapWindow.mouse['box'] = 'point'
def OnPan(self, event):
"""!Panning, set mouse to drag
"""
- toolbar = self.GetMapToolbar()
- self.SwitchTool(toolbar, event)
-
win = self.GetWindow()
self._preparePan(mapWindow = win)
@@ -359,7 +353,7 @@
@param mapWindow MapWindow to prepare
"""
mapWindow.mouse['use'] = "pan"
- mapWindow.mouse['box'] = "pan"
+ mapWindow.mouse['box'] = "box"
mapWindow.zoomtype = 0
# change the cursor
@@ -503,6 +497,10 @@
self.GetFirstWindow().Bind(wx.EVT_ENTER_WINDOW, self.ActivateFirstMap)
self.GetSecondWindow().Bind(wx.EVT_ENTER_WINDOW, self.ActivateSecondMap)
+ def _onToggleTool(self):
+ self.GetFirstWindow().UnregisterAllHandlers()
+ self.GetSecondWindow().UnregisterAllHandlers()
+
def GetFirstMap(self):
"""!Returns first Map instance
"""
@@ -606,10 +604,7 @@
def OnZoomIn(self, event):
"""!Zoom in the map.
Set mouse cursor, zoombox attributes, and zoom direction
- """
- toolbar = self.GetMapToolbar()
- self.SwitchTool(toolbar, event)
-
+ """
win = self.GetFirstWindow()
self._prepareZoom(mapWindow = win, zoomType = 1)
@@ -619,10 +614,7 @@
def OnZoomOut(self, event):
"""!Zoom out the map.
Set mouse cursor, zoombox attributes, and zoom direction
- """
- toolbar = self.GetMapToolbar()
- self.SwitchTool(toolbar, event)
-
+ """
win = self.GetFirstWindow()
self._prepareZoom(mapWindow = win, zoomType = -1)
@@ -631,10 +623,7 @@
def OnPan(self, event):
"""!Panning, set mouse to drag
- """
- toolbar = self.GetMapToolbar()
- self.SwitchTool(toolbar, event)
-
+ """
win = self.GetFirstWindow()
self._preparePan(mapWindow = win)
@@ -643,12 +632,11 @@
def OnPointer(self, event):
"""!Set pointer mode (dragging overlays)"""
- toolbar = self.GetMapToolbar()
- self.SwitchTool(toolbar, event)
-
self.GetFirstWindow().mouse['use'] = 'pointer'
+ self.GetFirstWindow().mouse['box'] = 'point'
self.GetFirstWindow().SetNamedCursor('default')
self.GetSecondWindow().mouse['use'] = 'pointer'
+ self.GetSecondWindow().mouse['box'] = 'point'
self.GetSecondWindow().SetNamedCursor('default')
def OnRender(self, event):
Modified: grass/trunk/gui/wxpython/gui_core/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/gui_core/toolbars.py 2013-08-08 11:26:44 UTC (rev 57435)
+++ grass/trunk/gui/wxpython/gui_core/toolbars.py 2013-08-08 13:45:54 UTC (rev 57436)
@@ -20,11 +20,15 @@
import wx
-from core import globalvar
-from core.debug import Debug
+from core import globalvar
+from core.debug import Debug
from core.utils import _
-from icons.icon import MetaIcon
+from icons.icon import MetaIcon
+from collections import defaultdict
+from grass.pydispatch.signal import Signal
+
+
BaseIcons = {
'display' : MetaIcon(img = 'show',
label = _('Display map'),
@@ -94,17 +98,18 @@
))
@endcode
"""
- def __init__(self, parent, style=wx.NO_BORDER|wx.TB_HORIZONTAL):
+ def __init__(self, parent, toolSwitcher=None, style=wx.NO_BORDER|wx.TB_HORIZONTAL):
self.parent = parent
wx.ToolBar.__init__(self, parent=self.parent, id=wx.ID_ANY,
style=style)
- self.action = dict()
+
+ self._default = None
+ self.SetToolBitmapSize(globalvar.toolbarSize)
- self.Bind(wx.EVT_TOOL, self.OnTool)
+ self.toolSwitcher = toolSwitcher
+ self.handlers = {}
- self.SetToolBitmapSize(globalvar.toolbarSize)
-
def InitToolbar(self, toolData):
"""!Initialize toolbar, add tools to the toolbar
"""
@@ -138,12 +143,14 @@
toolWin = self.InsertLabelTool(pos, tool, label, bitmap,
bmpDisabled, kind,
shortHelp, longHelp)
+ self.handlers[tool] = handler
self.Bind(wx.EVT_TOOL, handler, toolWin)
+ self.Bind(wx.EVT_TOOL, self.OnTool, toolWin)
else: # separator
self.AddSeparator()
-
+
return tool
-
+
def EnableLongHelp(self, enable = True):
"""!Enable/disable long help
@@ -152,7 +159,7 @@
for tool in self._data:
if tool[0] == '': # separator
continue
-
+
if enable:
self.SetToolLongHelp(vars(self)[tool[0]], tool[4])
else:
@@ -161,33 +168,20 @@
def OnTool(self, event):
"""!Tool selected
"""
+ if self.toolSwitcher:
+ Debug.msg(3, "BaseToolbar.OnTool(): id = %s" % event.GetId())
+ self.toolSwitcher.ToolChanged(event.GetId())
+ event.Skip()
+
+ def SelectTool(self, id):
+ self.ToggleTool(id, True)
+ self.toolSwitcher.ToolChanged(id)
- id = self.action.get('id', -1)
-
- if event:
- # deselect previously selected tool
- if id != -1 and id != event.GetId() :
- self.ToggleTool(self.action['id'], False)
- elif id != -1:
- self.ToggleTool(self.action['id'], True)
-
- self.action['id'] = event.GetId()
-
- event.Skip()
- elif id != -1:
- # initialize toolbar
- self.ToggleTool(self.action['id'], True)
-
- def GetAction(self, type = 'desc'):
- """!Get current action info"""
- return self.action.get(type, '')
-
- def SelectDefault(self, event):
+ self.handlers[id](event=None)
+
+ def SelectDefault(self):
"""!Select default tool"""
- self.ToggleTool(self.defaultAction['id'], True)
- self.defaultAction['bind'](event)
- self.action = { 'id' : self.defaultAction['id'],
- 'desc' : self.defaultAction.get('desc', '') }
+ self.SelectTool(self._default)
def FixSize(self, width):
"""!Fix toolbar width on Windows
@@ -253,3 +247,80 @@
self.PopupMenu(menu)
menu.Destroy()
+
+
+class ToolSwitcher:
+ """!Class handling switching tools in toolbar and custom toggle buttons."""
+ def __init__(self):
+ self._groups = defaultdict(lambda: defaultdict(list))
+ self._toolsGroups = defaultdict(list)
+
+ # emitted when tool is changed
+ self.toggleToolChanged = Signal('ToolSwitcher.toggleToolChanged')
+
+ def AddToolToGroup(self, group, toolbar, tool):
+ """!Adds tool from toolbar to group of exclusive tools.
+
+ @param group name of group (e.g. 'mouseUse')
+ @param toolbar instance of toolbar
+ @param tool id of a tool from the toolbar
+ """
+ self._groups[group][toolbar].append(tool)
+ self._toolsGroups[tool].append(group)
+
+ def AddCustomToolToGroup(self, group, btnId, toggleHandler):
+ """!Adds custom tool from to group of exclusive tools (some toggle button).
+
+ @param group name of group (e.g. 'mouseUse')
+ @param btnId id of a tool (typically button)
+ @param toggleHandler handler to be called to switch the button
+ """
+ self._groups[group]['custom'].append((btnId, toggleHandler))
+ self._toolsGroups[btnId].append(group)
+
+ def RemoveCustomToolFromGroup(self, tool):
+ """!Removes custom tool from group.
+
+ @param tool id of the button
+ """
+ if not tool in self._toolsGroups:
+ return
+ for group in self._toolsGroups[tool]:
+ self._groups[group]['custom'] = \
+ [(bid, hdlr) for (bid, hdlr)
+ in self._groups[group]['custom'] if bid != tool]
+
+ def RemoveToolbarFromGroup(self, group, toolbar):
+ """!Removes toolbar from group.
+
+ Before toolbar is destroyed, it must be removed from group, too.
+ Otherwise we can expect some DeadObject errors.
+
+ @param group name of group (e.g. 'mouseUse')
+ @param toolbar instance of toolbar
+ """
+ for tb in self._groups[group]:
+ if tb == toolbar:
+ del self._groups[group][tb]
+ break
+
+ def ToolChanged(self, tool):
+ """!When any tool/button is pressed, other tools from group must be unchecked.
+
+ @param tool id of a tool/button
+ """
+ for group in self._toolsGroups[tool]:
+ for tb in self._groups[group]:
+ if tb == 'custom':
+ for btnId, handler in self._groups[group][tb]:
+ if btnId != tool:
+ handler(False)
+ else:
+ for tl in self._groups[group][tb]:
+ if tb.FindById(tl): # check if still exists
+ if tl != tool:
+ tb.ToggleTool(tl, False)
+ else:
+ tb.ToggleTool(tool, True)
+
+ self.toggleToolChanged.emit(id=tool)
Modified: grass/trunk/gui/wxpython/iclass/frame.py
===================================================================
--- grass/trunk/gui/wxpython/iclass/frame.py 2013-08-08 11:26:44 UTC (rev 57435)
+++ grass/trunk/gui/wxpython/iclass/frame.py 2013-08-08 13:45:54 UTC (rev 57436)
@@ -53,6 +53,7 @@
from gui_core.dialogs import SetOpacityDialog
from mapwin.base import MapWindowProperties
from dbmgr.vinfo import VectorDBInfo
+from gui_core.toolbars import ToolSwitcher
import grass.script as grass
from iclass.digit import IClassVDigitWindow, IClassVDigit
@@ -186,7 +187,7 @@
self.previewMapManager.SetToolbar(self.toolbars['iClassPreviewMapManager'])
# default action
- self.OnPan(event = None)
+ self.GetMapToolbar().SelectDefault()
wx.CallAfter(self.AddTrainingAreaMap)
@@ -263,7 +264,7 @@
Toolbars 'iClassPreviewMapManager' are added in _addPanes().
"""
if name == "iClassMap":
- self.toolbars[name] = IClassMapToolbar(self)
+ self.toolbars[name] = IClassMapToolbar(self, self._toolSwitcher)
self._mgr.AddPane(self.toolbars[name],
wx.aui.AuiPaneInfo().
@@ -299,13 +300,13 @@
BestSize((self.toolbars[name].GetBestSize())))
if name == "vdigit":
- self.toolbars[name] = VDigitToolbar(parent = self, MapWindow = self.GetFirstWindow(),
- digitClass = IClassVDigit, giface = self._giface,
+ self.toolbars[name] = VDigitToolbar(parent=self, toolSwitcher=self._toolSwitcher,
+ MapWindow=self.GetFirstWindow(),
+ digitClass=IClassVDigit, giface=self._giface,
tools = ['addArea', 'moveVertex', 'addVertex',
'removeVertex', 'editLine', 'moveLine',
'deleteLine', 'deleteArea',
'undo', 'redo'])
-
self._mgr.AddPane(self.toolbars[name],
wx.aui.AuiPaneInfo().
Name(name).Caption(_("Digitization Toolbar")).
@@ -1119,24 +1120,6 @@
self.GetFirstWindow().mouse['use'] = 'pointer'
- def SwitchTool(self, toolbar, event):
- """!Calls UpdateTools to manage connected toolbars"""
- self.UpdateTools(event)
- super(IClassMapFrame, self).SwitchTool(toolbar, event)
-
- def UpdateTools(self, event):
- """!Method deals with relations of toolbars and other
- elements"""
- # untoggles button in other toolbars
- for toolbar in self.toolbars.itervalues():
- if hasattr(event, 'GetEventObject') == True:
- if event.GetEventObject() == toolbar:
- continue
- if toolbar.action:
- toolbar.ToggleTool(toolbar.action['id'], False)
- toolbar.action['id'] = -1
- toolbar.OnTool(None)
-
def OnScatterplot(self, event):
"""!Init interactive scatterplot tools
"""
Modified: grass/trunk/gui/wxpython/iclass/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/iclass/toolbars.py 2013-08-08 11:26:44 UTC (rev 57435)
+++ grass/trunk/gui/wxpython/iclass/toolbars.py 2013-08-08 13:45:54 UTC (rev 57436)
@@ -54,12 +54,13 @@
class IClassMapToolbar(BaseToolbar):
"""!IClass Map toolbar
"""
- def __init__(self, parent):
+ def __init__(self, parent, toolSwitcher):
"""!IClass Map toolbar constructor
"""
- BaseToolbar.__init__(self, parent)
+ BaseToolbar.__init__(self, parent, toolSwitcher)
self.InitToolbar(self._toolbarData())
+ self._default = self.pan
# add tool to toggle active map window
self.togglemapid = wx.NewId()
@@ -72,15 +73,11 @@
BaseIcons["zoomBack"].GetLabel(),
_('/ Zoom to map')))
+ for tool in (self.pan, self.zoomIn, self.zoomOut):
+ self.toolSwitcher.AddToolToGroup(group='mouseUse', toolbar=self, tool=tool)
# realize the toolbar
self.Realize()
- self.action = { 'id' : self.pan }
- self.defaultAction = { 'id' : self.pan,
- 'bind' : self.parent.OnPan }
-
- self.OnTool(None)
-
self.EnableTool(self.zoomBack, False)
def GetActiveMapTool(self):
Modified: grass/trunk/gui/wxpython/mapdisp/frame.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/frame.py 2013-08-08 11:26:44 UTC (rev 57435)
+++ grass/trunk/gui/wxpython/mapdisp/frame.py 2013-08-08 13:45:54 UTC (rev 57436)
@@ -49,6 +49,7 @@
from gui_core.mapdisp import SingleMapFrame
from mapwin.base import MapWindowProperties
from gui_core.query import QueryDialog, PrepareQueryResults
+from gui_core.toolbars import ToolSwitcher
from mapwin.buffered import BufferedMapWindow
from mapwin.decorations import DecorationDialog, TextLayerDialog, \
LegendController, BarscaleController, \
@@ -119,7 +120,7 @@
#
for toolb in toolbars:
self.AddToolbar(toolb)
-
+
#
# Add statusbar
#
@@ -179,10 +180,7 @@
self.MapWindow2D.mapQueried.connect(self.Query)
self.MapWindow2D.overlayActivated.connect(self._activateOverlay)
self._setUpMapWindow(self.MapWindow2D)
- # manage the state of toolbars connected to mouse cursor
- self.MapWindow2D.mouseHandlerRegistered.connect(
- lambda:
- self.UpdateTools(None))
+
self.MapWindow2D.mouseHandlerUnregistered.connect(self.ResetPointer)
self.MapWindow2D.InitZoomHistory()
@@ -202,6 +200,7 @@
#
self._initMap(Map = self.Map)
+ self.toolbars['map'].SelectDefault()
#
# Bind various events
#
@@ -281,7 +280,8 @@
elif self._mgr.GetPane('3d').IsShown():
self._mgr.GetPane('3d').Hide()
self._mgr.GetPane('vdigit').Show()
- self.toolbars['vdigit'] = VDigitToolbar(parent = self, MapWindow = self.MapWindow,
+ self.toolbars['vdigit'] = VDigitToolbar(parent=self, toolSwitcher=self._toolSwitcher,
+ MapWindow = self.MapWindow,
digitClass=VDigit, giface=self._giface,
layerTree=self.tree)
self.MapWindowVDigit.SetToolbar(self.toolbars['vdigit'])
@@ -320,8 +320,12 @@
# add rotate tool to map toolbar
self.toolbars['map'].InsertTool((('rotate', NvizIcons['rotate'],
self.OnRotate, wx.ITEM_CHECK, 7),)) # 7 is position
+ self._toolSwitcher.AddToolToGroup(group='mouseUse', toolbar=self.toolbars['map'],
+ tool=self.toolbars['map'].rotate)
self.toolbars['map'].InsertTool((('flyThrough', NvizIcons['flyThrough'],
- self.OnFlyThrough, wx.ITEM_CHECK, 8),))
+ self.OnFlyThrough, wx.ITEM_CHECK, 8),))
+ self._toolSwitcher.AddToolToGroup(group='mouseUse', toolbar=self.toolbars['map'],
+ tool=self.toolbars['map'].flyThrough)
self.toolbars['map'].ChangeToolsDesc(mode2d = False)
# update status bar
@@ -424,6 +428,7 @@
self.MapWindow.UpdateMap()
self._mgr.Update()
+ self.GetMapToolbar().SelectDefault()
def AddToolbar(self, name, fixed = False):
"""!Add defined toolbar to the window
@@ -437,7 +442,7 @@
"""
# default toolbar
if name == "map":
- self.toolbars['map'] = MapToolbar(self, self.Map)
+ self.toolbars['map'] = MapToolbar(self, toolSwitcher=self._toolSwitcher)
self._mgr.AddPane(self.toolbars['map'],
wx.aui.AuiPaneInfo().
@@ -468,6 +473,7 @@
return
self._mgr.DetachPane(self.toolbars[name])
+ self._toolSwitcher.RemoveToolbarFromGroup('mouseUse', self.toolbars[name])
self.toolbars[name].Destroy()
self.toolbars.pop(name)
@@ -511,43 +517,20 @@
def OnPointer(self, event):
"""!Pointer button clicked
- """
- if self.GetMapToolbar():
- if event:
- self.SwitchTool(self.toolbars['map'], event)
- self.toolbars['map'].action['desc'] = ''
-
+ """
self.MapWindow.mouse['use'] = "pointer"
self.MapWindow.mouse['box'] = "point"
# change the cursor
if self.GetToolbar('vdigit'):
- # digitization tool activated
- self.MapWindow.SetNamedCursor('cross')
+ self.toolbars['vdigit'].action['id'] = -1
+ self.toolbars['vdigit'].action['desc']=''
- # reset mouse['box'] if needed
- if self.toolbars['vdigit'].GetAction() in ['addLine']:
- if self.toolbars['vdigit'].GetAction('type') in ['point', 'centroid']:
- self.MapWindow.mouse['box'] = 'point'
- else: # line, boundary
- self.MapWindow.mouse['box'] = 'line'
- elif self.toolbars['vdigit'].GetAction() in ['addVertex', 'removeVertex', 'splitLine',
- 'editLine', 'displayCats', 'queryMap',
- 'copyCats']:
- self.MapWindow.mouse['box'] = 'point'
- else: # moveLine, deleteLine
- self.MapWindow.mouse['box'] = 'box'
-
- else:
- self.MapWindow.SetNamedCursor('default')
+ self.MapWindow.SetNamedCursor('default')
def OnRotate(self, event):
"""!Rotate 3D view
"""
- if self.GetMapToolbar():
- self.SwitchTool(self.toolbars['map'], event)
- self.toolbars['map'].action['desc'] = ''
-
self.MapWindow.mouse['use'] = "rotate"
# change the cursor
@@ -556,10 +539,6 @@
def OnFlyThrough(self, event):
"""!Fly-through mode
"""
- if self.GetMapToolbar():
- self.SwitchTool(self.toolbars['map'], event)
- self.toolbars['map'].action['desc'] = ''
-
self.MapWindow.mouse['use'] = "fly"
# change the cursor
@@ -803,10 +782,6 @@
def OnQuery(self, event):
"""!Query tools menu"""
- if self.GetMapToolbar():
- self.SwitchTool(self.toolbars['map'], event)
-
- self.toolbars['map'].action['desc'] = 'queryMap'
self.MapWindow.mouse['use'] = "query"
self.MapWindow.mouse['box'] = "point"
self.MapWindow.zoomtype = 0
@@ -1030,7 +1005,6 @@
def OnAddText(self, event):
"""!Handler for text decoration menu selection.
"""
- self.SwitchTool(self.toolbars['map'], event)
if self.MapWindow.dragid > -1:
id = self.MapWindow.dragid
self.MapWindow.dragid = -1
@@ -1210,47 +1184,11 @@
self.dialogs['vnet'] = VNETDialog(parent=self, giface=self._giface)
self.dialogs['vnet'].CenterOnScreen()
self.dialogs['vnet'].Show()
-
- def SwitchTool(self, toolbar, event):
- """!Calls UpdateTools to manage connected toolbars"""
- self.UpdateTools(event)
- SingleMapFrame.SwitchTool(self, toolbar, event)
- def UpdateTools(self, event):
- """!Method deals with relations of toolbars and other
- elements"""
- # untoggles button in other toolbars
- for toolbar in self.toolbars.itervalues():
- if hasattr(event, 'GetEventObject') == True:
- if event.GetEventObject() == toolbar:
- continue
- toolbar.ToggleTool(toolbar.action['id'], False)
- toolbar.action['id'] = -1
- toolbar.OnTool(None)
-
- # mouse settings
- self.MapWindow.mouse['box'] = 'point'
- self.MapWindow.mouse['use'] = 'pointer'
-
- # untoggles button in add legend dialog
- # FIXME: remove this mess
- if self.dialogs['legend']:
- btn = self.dialogs['legend'].resizeBtn
- if btn.GetValue():
- btn.SetValue(0)
- self.dialogs['legend'].DisconnectResizing()
- if self.measureDistController and self.measureDistController.IsActive():
- self.measureDistController.Stop(restore=False)
-
def ResetPointer(self):
"""Sets pointer mode.
Sets pointer and toggles it (e.g. after unregistration of mouse
handler).
- Somehow related to UpdateTools.
"""
- # sets pointer mode
- toolbar = self.toolbars['map']
- toolbar.action['id'] = vars(toolbar)["pointer"]
- toolbar.OnTool(None)
- self.OnPointer(event=None)
+ self.GetMapToolbar().SelectDefault()
Modified: grass/trunk/gui/wxpython/mapdisp/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/mapdisp/toolbars.py 2013-08-08 11:26:44 UTC (rev 57435)
+++ grass/trunk/gui/wxpython/mapdisp/toolbars.py 2013-08-08 13:45:54 UTC (rev 57436)
@@ -66,16 +66,15 @@
class MapToolbar(BaseToolbar):
"""!Map Display toolbar
"""
- def __init__(self, parent, mapcontent):
+ def __init__(self, parent, toolSwitcher):
"""!Map Display constructor
@param parent reference to MapFrame
- @param mapcontent reference to render.Map (registred by MapFrame)
"""
- self.mapcontent = mapcontent # render.Map
- BaseToolbar.__init__(self, parent = parent) # MapFrame
+ BaseToolbar.__init__(self, parent=parent, toolSwitcher=toolSwitcher) # MapFrame
self.InitToolbar(self._toolbarData())
+ self._default = self.pointer
# optional tools
choices = [ _('2D view'), ]
@@ -127,12 +126,9 @@
self.combo.Hide()
self.combo.Show()
- self.action = { 'id' : self.pointer }
- self.defaultAction = { 'id' : self.pointer,
- 'bind' : self.parent.OnPointer }
+ for tool in (self.pointer, self.query, self.pan, self.zoomIn, self.zoomOut):
+ self.toolSwitcher.AddToolToGroup(group='mouseUse', toolbar=self, tool=tool)
- self.OnTool(None)
-
self.EnableTool(self.zoomBack, False)
self.FixSize(width = 90)
Modified: grass/trunk/gui/wxpython/mapswipe/frame.py
===================================================================
--- grass/trunk/gui/wxpython/mapswipe/frame.py 2013-08-08 11:26:44 UTC (rev 57435)
+++ grass/trunk/gui/wxpython/mapswipe/frame.py 2013-08-08 13:45:54 UTC (rev 57436)
@@ -23,6 +23,7 @@
from gui_core.mapdisp import DoubleMapFrame
from gui_core.dialogs import GetImageHandlers
+from gui_core.toolbars import ToolSwitcher
from mapwin.base import MapWindowProperties
from core.render import Map
from mapdisp import statusbar as sb
@@ -98,7 +99,7 @@
self.rasters = {'first': None, 'second': None}
# default action in map toolbar
- self.OnPan(event = None)
+ self.GetMapToolbar().SelectDefault()
self.resize = False
@@ -256,7 +257,7 @@
- 'swipeMain' - swipe functionality
"""
if name == "swipeMap":
- self.toolbars[name] = SwipeMapToolbar(self)
+ self.toolbars[name] = SwipeMapToolbar(self, self._toolSwitcher)
self._mgr.AddPane(self.toolbars[name],
wx.aui.AuiPaneInfo().
Name(name).Caption(_("Map Toolbar")).
Modified: grass/trunk/gui/wxpython/mapswipe/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/mapswipe/toolbars.py 2013-08-08 11:26:44 UTC (rev 57435)
+++ grass/trunk/gui/wxpython/mapswipe/toolbars.py 2013-08-08 13:45:54 UTC (rev 57436)
@@ -32,19 +32,19 @@
class SwipeMapToolbar(BaseToolbar):
"""!Map toolbar (to control map zoom and rendering)
"""
- def __init__(self, parent):
+ def __init__(self, parent, toolSwitcher):
"""!Map toolbar constructor
"""
- BaseToolbar.__init__(self, parent)
+ BaseToolbar.__init__(self, parent, toolSwitcher)
self.InitToolbar(self._toolbarData())
+ self._default = self.pan
# realize the toolbar
self.Realize()
- self.action = { 'id' : self.pan }
- self.defaultAction = { 'id' : self.pan,
- 'bind' : self.parent.OnPan }
+ for tool in (self.pointer, self.pan, self.zoomIn, self.zoomOut):
+ self.toolSwitcher.AddToolToGroup(group='mouseUse', toolbar=self, tool=tool)
self.EnableTool(self.zoomBack, False)
Modified: grass/trunk/gui/wxpython/mapwin/decorations.py
===================================================================
--- grass/trunk/gui/wxpython/mapwin/decorations.py 2013-08-08 11:26:44 UTC (rev 57435)
+++ grass/trunk/gui/wxpython/mapwin/decorations.py 2013-08-08 13:45:54 UTC (rev 57436)
@@ -22,7 +22,9 @@
from core.utils import GetLayerNameFromCmd, _
from gui_core.forms import GUI
+from grass.pydispatch.errors import DispatcherKeyError
+
class OverlayController(object):
"""!Base class for decorations (barscale, legend) controller."""
@@ -187,9 +189,6 @@
self._ddstyle = ddstyle
self._giface = giface
- self._oldMouseUse = None
- self._oldCursor = None
-
sizer = wx.BoxSizer(wx.VERTICAL)
box = wx.BoxSizer(wx.HORIZONTAL)
@@ -218,7 +217,12 @@
self.resizeBtn.SetToolTipString(_("Click and drag on the map display to set legend "
"size and position and then press OK"))
self.resizeBtn.Disable()
- self.resizeBtn.Bind(wx.EVT_TOGGLEBUTTON, self.OnResize)
+ toolSwitcher = self._giface.GetMapDisplay().GetToolSwitcher()
+ toolSwitcher.AddCustomToolToGroup(group='mouseUse', btnId=self.resizeBtn.GetId(),
+ toggleHandler=self.resizeBtn.SetValue)
+ toolSwitcher.toggleToolChanged.connect(self._toolChanged)
+ self.resizeBtn.Bind(wx.EVT_TOGGLEBUTTON, lambda evt: toolSwitcher.ToolChanged(evt.GetId()))
+
box.Add(item=self.resizeBtn, proportion=0,
flag=wx.ALIGN_CENTRE | wx.ALL, border=5)
sizer.Add(item=box, proportion=0,
@@ -294,38 +298,37 @@
else:
self._overlay.propwin.Show()
- def OnResize(self, event):
- window = self._giface.GetMapWindow()
- if event.GetInt():
- self._oldMouseUse = window.mouse['use']
- self._oldCursor = window.GetNamedCursor()
- window.SetNamedCursor('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)
+ def _toolChanged(self, id):
+ """!Tool in toolbar or button itself were pressed"""
+ if id == self.resizeBtn.GetId():
+ if self.resizeBtn.GetValue():
+ # prepare for resizing
+ window = self._giface.GetMapWindow()
+ window.SetNamedCursor('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:
+ # stop resizing mode
+ self.DisconnectResizing()
+ self._giface.GetMapDisplay().GetMapToolbar().SelectDefault()
else:
- self.Restore()
+ # any other tool was pressed -> stop resizing mode
self.DisconnectResizing()
- def Restore(self):
- """!Restore conditions before resizing"""
- window = self._giface.GetMapWindow()
- if self._oldCursor:
- window.SetNamedCursor(self._oldCursor)
- if self._oldMouseUse:
- window.mouse['use'] = self._oldMouseUse
-
def DisconnectResizing(self):
- self._giface.GetMapWindow().mouseLeftUp.disconnect(self._resizeLegend)
+ try:
+ self._giface.GetMapWindow().mouseLeftUp.disconnect(self._resizeLegend)
+ except DispatcherKeyError:
+ pass
def _resizeLegend(self, x, y):
"""!Update legend after drawing new legend size (moved from BufferedWindow)"""
- self.resizeBtn.SetValue(False)
- window = self._giface.GetMapWindow()
+ self._giface.GetMapDisplay().GetMapToolbar().SelectDefault()
self.DisconnectResizing()
- self.Restore()
# resize legend
+ window = self._giface.GetMapWindow()
screenSize = window.GetClientSizeTuple()
self._overlay.ResizeLegend(window.mouse["begin"], window.mouse["end"], screenSize)
# redraw
@@ -334,8 +337,6 @@
def CloseDialog(self):
"""!Hide dialog"""
if self._ddstyle == DECOR_DIALOG_LEGEND and self.resizeBtn.GetValue():
- self.Restore()
- self.resizeBtn.SetValue(False)
self.DisconnectResizing()
self.Hide()
Modified: grass/trunk/gui/wxpython/psmap/frame.py
===================================================================
--- grass/trunk/gui/wxpython/psmap/frame.py 2013-08-08 11:26:44 UTC (rev 57435)
+++ grass/trunk/gui/wxpython/psmap/frame.py 2013-08-08 13:45:54 UTC (rev 57436)
@@ -40,6 +40,7 @@
from gui_core.dialogs import HyperlinkDialog
from gui_core.ghelp import ShowAboutDialog
from psmap.menudata import PsMapMenuData
+from gui_core.toolbars import ToolSwitcher
from psmap.dialogs import *
from psmap.instructions import *
@@ -65,10 +66,10 @@
self.SetMenuBar(self.menubar)
#toolbar
- self.toolbar = PsMapToolbar(parent = self)
+ self._toolSwitcher = ToolSwitcher()
+ self.toolbar = PsMapToolbar(parent=self, toolSwitcher=self._toolSwitcher)
self.SetToolBar(self.toolbar)
- self.actionOld = self.toolbar.action['id']
self.iconsize = (16, 16)
#satusbar
self.statusbar = self.CreateStatusBar(number = 1)
@@ -154,7 +155,9 @@
# set WIND_OVERRIDE
grass.use_temp_region()
-
+
+ self.toolbar.SelectDefault()
+
# create queues
self.requestQ = Queue.Queue()
self.resultQ = Queue.Queue()
@@ -457,25 +460,21 @@
dlg.Destroy()
def OnPointer(self, event):
- self.toolbar.OnTool(event)
self.mouse["use"] = "pointer"
self.canvas.SetCursor(self.cursors["default"])
self.previewCanvas.SetCursor(self.cursors["default"])
def OnPan(self, event):
- self.toolbar.OnTool(event)
self.mouse["use"] = "pan"
self.canvas.SetCursor(self.cursors["hand"])
self.previewCanvas.SetCursor(self.cursors["hand"])
def OnZoomIn(self, event):
- self.toolbar.OnTool(event)
self.mouse["use"] = "zoomin"
self.canvas.SetCursor(self.cursors["cross"])
self.previewCanvas.SetCursor(self.cursors["cross"])
def OnZoomOut(self, event):
- self.toolbar.OnTool(event)
self.mouse["use"] = "zoomout"
self.canvas.SetCursor(self.cursors["cross"])
self.previewCanvas.SetCursor(self.cursors["cross"])
@@ -500,14 +499,7 @@
def OnAddMap(self, event, notebook = False):
- """!Add or edit map frame"""
- if event is not None:
- if event.GetId() != self.toolbar.action['id']:
- self.actionOld = self.toolbar.action['id']
- self.mouseOld = self.mouse['use']
- self.cursorOld = self.canvas.GetCursor()
- self.toolbar.OnTool(event)
-
+ """!Add or edit map frame"""
if self.instruction.FindInstructionByType('map'):
mapId = self.instruction.FindInstructionByType('map').id
else: mapId = None
@@ -524,19 +516,9 @@
id[2] = vectorId
- if mapId: # map exists
-
- self.toolbar.ToggleTool(self.actionOld, True)
- self.toolbar.ToggleTool(self.toolbar.action['id'], False)
- self.toolbar.action['id'] = self.actionOld
- try:
- self.canvas.SetCursor(self.cursorOld)
- except AttributeError:
- pass
-
-## dlg = MapDialog(parent = self, id = id, settings = self.instruction,
-## notebook = notebook)
-## dlg.ShowModal()
+ if mapId: # map exists
+ self.toolbar.SelectDefault()
+
if notebook:
#check map, raster, vector and save, destroy them
if 'map' in self.openDialogs:
@@ -1450,12 +1432,7 @@
self.openDialogs['map'] = dlg
self.openDialogs['map'].Show()
- self.mouse['use'] = self.parent.mouseOld
-
- self.SetCursor(self.parent.cursorOld)
- self.parent.toolbar.ToggleTool(self.parent.actionOld, True)
- self.parent.toolbar.ToggleTool(self.parent.toolbar.action['id'], False)
- self.parent.toolbar.action['id'] = self.parent.actionOld
+ self.parent.toolbar.SelectDefault()
return
# resize resizable objects (map, line, rectangle)
Modified: grass/trunk/gui/wxpython/psmap/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/psmap/toolbars.py 2013-08-08 11:26:44 UTC (rev 57435)
+++ grass/trunk/gui/wxpython/psmap/toolbars.py 2013-08-08 13:45:54 UTC (rev 57436)
@@ -26,14 +26,19 @@
from core.globalvar import ETCIMGDIR
class PsMapToolbar(BaseToolbar):
- def __init__(self, parent):
+ def __init__(self, parent, toolSwitcher):
"""!Toolbar Cartographic Composer (psmap.py)
@param parent parent window
"""
- BaseToolbar.__init__(self, parent)
+ BaseToolbar.__init__(self, parent, toolSwitcher)
self.InitToolbar(self._toolbarData())
+ self._default = self.pointer
+
+ for tool in (self.pointer, self.pan, self.zoomin, self.zoomout,
+ self.drawGraphics, self.addMap):
+ self.toolSwitcher.AddToolToGroup(group='mouseUse', toolbar=self, tool=tool)
# custom button for graphics mode selection
# TODO: could this be somehow generalized?
@@ -46,11 +51,6 @@
self.Realize()
- self.action = { 'id' : self.pointer }
- self.defaultAction = { 'id' : self.pointer,
- 'bind' : self.parent.OnPointer }
- self.OnTool(None)
-
from psmap.frame import havePILImage
if not havePILImage:
self.EnableTool(self.preview, False)
@@ -169,7 +169,6 @@
def OnDrawGraphics(self, event):
"""!Graphics tool activated."""
- self.OnTool(event)
# we need the previous id
if self.drawGraphicsAction == 'pointAdd':
self.parent.OnAddPoint(event)
Modified: grass/trunk/gui/wxpython/rlisetup/sampling_frame.py
===================================================================
--- grass/trunk/gui/wxpython/rlisetup/sampling_frame.py 2013-08-08 11:26:44 UTC (rev 57435)
+++ grass/trunk/gui/wxpython/rlisetup/sampling_frame.py 2013-08-08 13:45:54 UTC (rev 57436)
@@ -33,7 +33,7 @@
from mapwin.base import MapWindowProperties
from mapwin.buffered import BufferedMapWindow
from core.render import Map
-from gui_core.toolbars import BaseToolbar, BaseIcons
+from gui_core.toolbars import BaseToolbar, BaseIcons, ToolSwitcher
from icons.icon import MetaIcon
from grass.pydispatch.signal import Signal
@@ -65,7 +65,9 @@
Dockable(True).BestSize((-1, -1)).Name('mapwindow').
CloseButton(False).DestroyOnClose(True).
Layer(0))
- self.toolbar = RLiSetupToolbar(self)
+ self._toolSwitcher = ToolSwitcher()
+ self._toolSwitcher.toggleToolChanged.connect(self._onToolChanged)
+ self.toolbar = RLiSetupToolbar(self, self._toolSwitcher)
self._mgr.AddPane(self.toolbar,
wx.aui.AuiPaneInfo().
@@ -75,18 +77,12 @@
BestSize((self.toolbar.GetBestSize())))
self._mgr.Update()
- self._initTool()
+ self.toolbar.SelectDefault()
self._registeredGraphics = self.mapWindow.RegisterGraphicsToDraw(graphicsType='rectangle')
self._registeredGraphics.AddPen('rlisetup', wx.Pen(wx.GREEN, width=3, style=wx.SOLID))
self._registeredGraphics.AddItem(coords=[[0, 0], [0, 0]], penName='rlisetup', hide=True)
- def _initTool(self):
- """!Initialize draw mode"""
- self.toolbar.ToggleTool(self.toolbar.draw, True)
- self.toolbar.action['id'] = self.toolbar.draw
- self.OnDraw(None)
-
def GetMap(self):
return self.map_
@@ -97,13 +93,11 @@
def OnZoomIn(self, event):
"""!Zoom in the map.
"""
- self.SwitchTool(event)
self._prepareZoom(mapWindow=self.mapWindow, zoomType=1)
def OnZoomOut(self, event):
"""!Zoom out the map.
"""
- self.SwitchTool(event)
self._prepareZoom(mapWindow=self.mapWindow, zoomType=-1)
def _prepareZoom(self, mapWindow, zoomType):
@@ -120,10 +114,8 @@
# change the cursor
mapWindow.SetNamedCursor('cross')
- def SwitchTool(self, event):
- """!Helper function to switch tools"""
- self.toolbar.OnTool(event)
- self.toolbar.action['desc'] = ''
+ def _onToolChanged(self):
+ """!Helper function to disconnect drawing"""
try:
self.mapWindow.mouseLeftUp.disconnect(self._rectangleDrawn)
except DispatcherKeyError:
@@ -132,8 +124,6 @@
def OnPan(self, event):
"""!Panning, set mouse to drag
"""
- self.SwitchTool(event)
-
self.mapWindow.mouse['use'] = "pan"
self.mapWindow.mouse['box'] = "pan"
self.mapWindow.zoomtype = 0
@@ -147,8 +137,6 @@
def OnDraw(self, event):
"""!Start draw mode"""
- self.SwitchTool(event)
-
self.mapWindow.mouse['use'] = None
self.mapWindow.mouse['box'] = "box"
self.mapWindow.pen = wx.Pen(colour=wx.RED, width=2, style=wx.SHORT_DASH)
@@ -182,12 +170,17 @@
class RLiSetupToolbar(BaseToolbar):
"""!IClass toolbar
"""
- def __init__(self, parent):
+ def __init__(self, parent, toolSwitcher):
"""!RLiSetup toolbar constructor
"""
- BaseToolbar.__init__(self, parent, style=wx.NO_BORDER | wx.TB_VERTICAL)
+ BaseToolbar.__init__(self, parent, toolSwitcher, style=wx.NO_BORDER | wx.TB_VERTICAL)
self.InitToolbar(self._toolbarData())
+ self._default = self.draw
+
+ for tool in (self.draw, self.pan, self.zoomIn, self.zoomOut):
+ self.toolSwitcher.AddToolToGroup(group='mouseUse', toolbar=self, tool=tool)
+
# realize the toolbar
self.Realize()
Modified: grass/trunk/gui/wxpython/vdigit/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/vdigit/toolbars.py 2013-08-08 11:26:44 UTC (rev 57435)
+++ grass/trunk/gui/wxpython/vdigit/toolbars.py 2013-08-08 13:45:54 UTC (rev 57436)
@@ -31,14 +31,14 @@
class VDigitToolbar(BaseToolbar):
"""!Toolbar for digitization
"""
- def __init__(self, parent, MapWindow, digitClass, giface,
+ def __init__(self, parent, toolSwitcher, MapWindow, digitClass, giface,
tools=[], layerTree=None):
self.MapWindow = MapWindow
self.Map = MapWindow.GetMap() # Map class instance
self.layerTree = layerTree # reference to layer tree associated to map display
self.tools = tools
self.digitClass = digitClass
- BaseToolbar.__init__(self, parent)
+ BaseToolbar.__init__(self, parent, toolSwitcher)
self.digit = None
self._giface = giface
@@ -53,11 +53,11 @@
# only one dialog can be open
self.settingsDialog = None
-
+
# create toolbars (two rows optionally)
self.InitToolbar(self._toolbarData())
- self.Bind(wx.EVT_TOOL, self._toolChosen)
+ self._default = -1
# default action (digitize new point, line, etc.)
self.action = { 'desc' : '',
'type' : '',
@@ -66,6 +66,13 @@
# list of available vector maps
self.UpdateListOfLayers(updateTool = True)
+ for tool in ('addPoint', 'addLine', 'addBoundary', 'addCentroid', 'addArea',
+ 'addVertex', 'deleteLine', 'deleteArea', 'displayAttr', 'displayCats',
+ 'editLine', 'moveLine', 'moveVertex', 'removeVertex', 'additionalTools'):
+ if hasattr(self, tool):
+ tool = getattr(self, tool)
+ self.toolSwitcher.AddToolToGroup(group='mouseUse', toolbar=self, tool=tool)
+
# realize toolbar
self.Realize()
# workaround for Mac bug. May be fixed by 2.8.8, but not before then.
@@ -78,12 +85,9 @@
self.EnableTool(self.undo, False)
if self.redo > 0:
self.EnableTool(self.redo, False)
-
- # toogle to pointer by default
- self.OnTool(None)
-
+
self.FixSize(width = 105)
-
+
def _toolbarData(self):
"""!Toolbar data
"""
@@ -235,27 +239,15 @@
self.OnExit))
return self._getToolbarData(data)
-
- def _toolChosen(self, event):
- """!Tool selected -> untoggles selected tools in other
- toolbars
- @todo implement iclass front-end
- """
- self.parent.MapWindow.UnregisterAllHandlers()
-
- if hasattr(self.parent, "UpdateTools"):
- self.parent.UpdateTools(event)
- self.OnTool(event)
-
def OnTool(self, event):
"""!Tool selected -> untoggles previusly selected tool in
toolbar"""
+ Debug.msg(3, "VDigitToolbar.OnTool(): id = %s" % event.GetId())
# set cursor
self.MapWindow.SetNamedCursor('cross')
-
- # pointer
- self.parent.OnPointer(None)
+ self.MapWindow.mouse['box'] = 'point'
+ self.MapWindow.mouse['use'] = 'pointer'
aId = self.action.get('id', -1)
BaseToolbar.OnTool(self, event)
@@ -316,7 +308,7 @@
def OnAddArea(self, event):
"""!Add area to the vector map layer"""
- Debug.msg (2, "VDigitToolbar.OnAddCentroid()")
+ Debug.msg (2, "VDigitToolbar.OnAddArea()")
self.action = { 'desc' : "addLine",
'type' : "area",
'id' : self.addArea }
@@ -333,8 +325,7 @@
self.settingsDialog.OnCancel(None)
# set default mouse settings
- self.MapWindow.mouse['use'] = "pointer"
- self.MapWindow.mouse['box'] = "point"
+ self.parent.GetMapToolbar().SelectDefault()
self.MapWindow.polycoords = []
# TODO: replace this by binding wx event in parent (or use signals...)
@@ -443,7 +434,11 @@
else:
if self.GetToolEnabled(tool) is True:
self.EnableTool(tool, False)
-
+
+ def GetAction(self, type = 'desc'):
+ """!Get current action info"""
+ return self.action.get(type, '')
+
def OnSettings(self, event):
"""!Show settings dialog"""
if self.digit is None:
Modified: grass/trunk/gui/wxpython/vnet/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/vnet/dialogs.py 2013-08-08 11:26:44 UTC (rev 57435)
+++ grass/trunk/gui/wxpython/vnet/dialogs.py 2013-08-08 13:45:54 UTC (rev 57436)
@@ -207,9 +207,11 @@
name = 'points')
self.list = PtsList(parent = pointsPanel, vnet_mgr = self.vnet_mgr)
- self.toolbars['pointsList'] = PointListToolbar(parent = pointsPanel,
- dialog = self,
- vnet_mgr = self.vnet_mgr)
+ toolSwitcher=self.giface.GetMapDisplay().GetToolSwitcher()
+ self.toolbars['pointsList'] = PointListToolbar(parent=pointsPanel,
+ toolSwitcher=toolSwitcher,
+ dialog=self,
+ vnet_mgr=self.vnet_mgr)
anSettingsPanel = wx.Panel(parent = pointsPanel)
Modified: grass/trunk/gui/wxpython/vnet/toolbars.py
===================================================================
--- grass/trunk/gui/wxpython/vnet/toolbars.py 2013-08-08 11:26:44 UTC (rev 57435)
+++ grass/trunk/gui/wxpython/vnet/toolbars.py 2013-08-08 13:45:54 UTC (rev 57436)
@@ -29,14 +29,15 @@
@param parent reference to VNETDialog
"""
- def __init__(self, parent, dialog, vnet_mgr):
- BaseToolbar.__init__(self, parent)
+ def __init__(self, parent, toolSwitcher, dialog, vnet_mgr):
+ BaseToolbar.__init__(self, parent, toolSwitcher)
self.vnet_mgr = vnet_mgr
self.vnet_pts_mgr = self.vnet_mgr.GetPointsManager()
self.dialog = dialog
self.InitToolbar(self._toolbarData())
+ self.toolSwitcher.AddToolToGroup('mouseUse', self, self.insertPoint)
# realize the toolbar
self.Realize()
More information about the grass-commit
mailing list