[GRASS-SVN] r33018 -
grass/branches/develbranch_6/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Sat Aug 23 08:46:47 EDT 2008
Author: martinl
Date: 2008-08-23 08:46:47 -0400 (Sat, 23 Aug 2008)
New Revision: 33018
Modified:
grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py
Log:
wxGUI: fix map toolbar radio items, trac #208
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py 2008-08-23 11:55:39 UTC (rev 33017)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/mapdisp.py 2008-08-23 12:46:47 UTC (rev 33018)
@@ -2835,10 +2835,12 @@
def OnPointer(self, event):
"""Pointer button clicked"""
-
+ self.toolbars['map'].OnTool(event)
+ self.toolbars['map'].action['desc'] = ''
+
self.MapWindow.mouse['use'] = "pointer"
self.MapWindow.mouse['box'] = "point"
-
+
# change the cursor
if self.toolbars['vdigit']:
# digitization tool activated
@@ -2866,11 +2868,14 @@
Zoom in the map.
Set mouse cursor, zoombox attributes, and zoom direction
"""
+ self.toolbars['map'].OnTool(event)
+ self.toolbars['map'].action['desc'] = ''
+
self.MapWindow.mouse['use'] = "zoom"
self.MapWindow.mouse['box'] = "box"
self.MapWindow.zoomtype = 1
self.MapWindow.pen = wx.Pen(colour='Red', width=2, style=wx.SHORT_DASH)
-
+
# change the cursor
self.MapWindow.SetCursor(self.cursors["cross"])
@@ -2879,11 +2884,14 @@
Zoom out the map.
Set mouse cursor, zoombox attributes, and zoom direction
"""
+ self.toolbars['map'].OnTool(event)
+ self.toolbars['map'].action['desc'] = ''
+
self.MapWindow.mouse['use'] = "zoom"
self.MapWindow.mouse['box'] = "box"
self.MapWindow.zoomtype = -1
self.MapWindow.pen = wx.Pen(colour='Red', width=2, style=wx.SHORT_DASH)
-
+
# change the cursor
self.MapWindow.SetCursor(self.cursors["cross"])
@@ -2897,11 +2905,13 @@
"""
Panning, set mouse to drag
"""
+ self.toolbars['map'].OnTool(event)
+ self.toolbars['map'].action['desc'] = ''
+
self.MapWindow.mouse['use'] = "pan"
self.MapWindow.mouse['box'] = "pan"
self.MapWindow.zoomtype = 0
-# event.Skip()
-
+
# change the cursor
self.MapWindow.SetCursor(self.cursors["hand"])
@@ -3211,6 +3221,12 @@
"""
Query currrent raster/vector map layers (display mode)
"""
+ if self.toolbars['map'].GetAction() == 'displayAttrb': # select previous action
+ self.toolbars['map'].SelectDefault(event)
+ return
+
+ self.toolbars['map'].action['desc'] = 'displayAttrb'
+
# switch GIS Manager to output console to show query results
self.gismanager.notebook.SetSelection(1)
@@ -3225,6 +3241,12 @@
"""
Query vector map layer (edit mode)
"""
+ if self.toolbars['map'].GetAction() == 'modifyAttrb': # select previous action
+ self.toolbars['map'].SelectDefault(event)
+ return
+
+ self.toolbars['map'].action['desc'] = 'modifyAttrb'
+
self.MapWindow.mouse['use'] = "queryVector"
self.MapWindow.mouse['box'] = "point"
self.MapWindow.zoomtype = 0
@@ -3355,16 +3377,27 @@
def OnQuery(self, event):
"""Query tools menu"""
+ self.toolbars['map'].OnTool(event)
+ action = self.toolbars['map'].GetAction()
+
point = wx.GetMousePosition()
toolsmenu = wx.Menu()
# Add items to the menu
- display = wx.MenuItem(toolsmenu, wx.ID_ANY, Icons["queryDisplay"].GetLabel())
+ display = wx.MenuItem(parentMenu=toolsmenu, id=wx.ID_ANY,
+ text=Icons["queryDisplay"].GetLabel(),
+ kind=wx.ITEM_CHECK)
toolsmenu.AppendItem(display)
self.Bind(wx.EVT_MENU, self.OnQueryDisplay, display)
-
- modify = wx.MenuItem(toolsmenu, wx.ID_ANY, Icons["queryModify"].GetLabel())
+ if action == "displayAttrb":
+ display.Check(True)
+
+ modify = wx.MenuItem(parentMenu=toolsmenu, id=wx.ID_ANY,
+ text=Icons["queryModify"].GetLabel(),
+ kind=wx.ITEM_CHECK)
toolsmenu.AppendItem(modify)
self.Bind(wx.EVT_MENU, self.OnQueryModify, modify)
+ if action == "modifyAttrb":
+ modify.Check(True)
self.PopupMenu(toolsmenu)
toolsmenu.Destroy()
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py 2008-08-23 11:55:39 UTC (rev 33017)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/toolbars.py 2008-08-23 12:46:47 UTC (rev 33018)
@@ -39,9 +39,9 @@
class AbstractToolbar(object):
"""Abstract toolbar class"""
- def __init__():
+ def __init__(self):
pass
-
+
def InitToolbar(self, parent, toolbar, toolData):
"""Initialize toolbar, i.e. add tools to the toolbar
@@ -56,7 +56,6 @@
def ToolbarData(self):
"""Toolbar data"""
-
return None
def CreateTool(self, parent, toolbar, tool, label, bitmap, kind,
@@ -95,13 +94,43 @@
self._toolbar.SetToolLongHelp(tool[0], tool[5])
else:
self._toolbar.SetToolLongHelp(tool[0], "")
-
+
+ def OnTool(self, event):
+ """Tool selected"""
+ if event:
+ # deselect previously selected tool
+ id = self.action.get('id', -1)
+ if id != event.GetId():
+ self._toolbar.ToggleTool(self.action['id'], False)
+ else:
+ self._toolbar.ToggleTool(self.action['id'], True)
+
+ self.action['id'] = event.GetId()
+
+ event.Skip()
+ else:
+ # initialize toolbar
+ self._toolbar.ToggleTool(self.action['id'], True)
+
+ def GetAction(self, type='desc'):
+ """Get current action info"""
+ return self.action.get(type, '')
+
+ def SelectDefault(self, event):
+ """Select default tool"""
+ self._toolbar.ToggleTool(self.defaultAction['id'], True)
+ self.defaultAction['bind'](event)
+ self.action = { 'id' : self.defaultAction['id'],
+ 'desc' : self.defaultAction.get('desc', '') }
+
class MapToolbar(AbstractToolbar):
"""
Main Map Display toolbar
"""
def __init__(self, mapdisplay, map):
+ AbstractToolbar.__init__(self)
+
self.mapcontent = map
self.mapdisplay = mapdisplay
@@ -120,10 +149,16 @@
# realize the toolbar
self.toolbar.Realize()
- #workaround for Mac bug. May be fixed by 2.8.8, but not before then.
+ # workaround for Mac bug. May be fixed by 2.8.8, but not before then.
self.combo.Hide()
self.combo.Show()
-
+
+ # default action
+ self.action = { 'id' : self.pointer }
+ self.defaultAction = { 'id' : self.pointer,
+ 'bind' : self.mapdisplay.OnPointer }
+ self.OnTool(None)
+
def ToolbarData(self):
"""Toolbar data"""
@@ -155,19 +190,19 @@
self.mapdisplay.OnErase),
("", "", "", "", "", "", ""),
(self.pointer, "pointer", Icons["pointer"].GetBitmap(),
- wx.ITEM_RADIO, Icons["pointer"].GetLabel(), Icons["pointer"].GetDesc(),
+ wx.ITEM_CHECK, Icons["pointer"].GetLabel(), Icons["pointer"].GetDesc(),
self.mapdisplay.OnPointer),
(self.query, "queryDisplay", Icons["queryDisplay"].GetBitmap(),
- wx.ITEM_RADIO, Icons["queryDisplay"].GetLabel(), Icons["queryDisplay"].GetDesc(),
+ wx.ITEM_CHECK, Icons["queryDisplay"].GetLabel(), Icons["queryDisplay"].GetDesc(),
self.mapdisplay.OnQuery),
(self.pan, "pan", Icons["pan"].GetBitmap(),
- wx.ITEM_RADIO, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
+ wx.ITEM_CHECK, Icons["pan"].GetLabel(), Icons["pan"].GetDesc(),
self.mapdisplay.OnPan),
(self.zoomin, "zoom_in", Icons["zoom_in"].GetBitmap(),
- wx.ITEM_RADIO, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
+ wx.ITEM_CHECK, Icons["zoom_in"].GetLabel(), Icons["zoom_in"].GetDesc(),
self.mapdisplay.OnZoomIn),
(self.zoomout, "zoom_out", Icons["zoom_out"].GetBitmap(),
- wx.ITEM_RADIO, Icons["zoom_out"].GetLabel(), Icons["zoom_out"].GetDesc(),
+ wx.ITEM_CHECK, Icons["zoom_out"].GetLabel(), Icons["zoom_out"].GetDesc(),
self.mapdisplay.OnZoomOut),
(self.zoomback, "zoom_back", Icons["zoom_back"].GetBitmap(),
wx.ITEM_NORMAL, Icons["zoom_back"].GetLabel(), Icons["zoom_back"].GetDesc(),
@@ -502,12 +537,16 @@
id = self.parent.toolbars['map'].pointer
self.parent.toolbars['map'].toolbar.ToggleTool(id, True)
self.parent.toolbars['map'].mapdisplay.OnPointer(event)
+
if event:
# deselect previously selected tool
- if self.action.has_key('id'):
+ id = self.action.get('id', -1)
+ if id != event.GetId():
self.toolbar[0].ToggleTool(self.action['id'], False)
-
+ else:
+ self.toolbar[0].ToggleTool(self.action['id'], True)
+
self.action['id'] = event.GetId()
event.Skip()
else:
@@ -683,7 +722,7 @@
kind=wx.ITEM_CHECK)
toolMenu.AppendItem(copy)
self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnCopy, copy)
- if self.action['desc'] == "copyLine":
+ if self.toolbars['map'].GetAction() == "copyLine":
copy.Check(True)
flip = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
@@ -691,7 +730,7 @@
kind=wx.ITEM_CHECK)
toolMenu.AppendItem(flip)
self.parent.MapWindow.Bind(wx.EVT_MENU, self.OnFlip, flip)
- if self.action['desc'] == "flipLine":
+ if self.toolbars['map'].GetAction() == "flipLine":
flip.Check(True)
merge = wx.MenuItem(parentMenu=toolMenu, id=wx.ID_ANY,
@@ -1058,10 +1097,6 @@
"""Get selected layer for editing -- MapLayer instance"""
return self.mapLayer
- def GetAction(self, type='desc'):
- """Get current action info"""
- return self.action[type]
-
class ProfileToolbar(AbstractToolbar):
"""
Toolbar for profiling raster map
More information about the grass-commit
mailing list