2 @package gui_core.toolbars
4 @brief Base classes toolbar widgets
7 - toolbars::BaseToolbar
9 (C) 2007-2011 by the GRASS Development Team
11 This program is free software under the GNU General Public License
12 (>=v2). Read the file COPYING that comes with GRASS for details.
14 @author Michael Barton
15 @author Jachym Cepicky
16 @author Martin Landa <landa.martin gmail.com>
25 from core
import globalvar
27 from icons.icon
import MetaIcon
30 'display' : MetaIcon(img =
'show',
31 label = _(
'Display map'),
32 desc = _(
'Re-render modified map layers only')),
33 'render' : MetaIcon(img =
'layer-redraw',
34 label = _(
'Render map'),
35 desc = _(
'Force re-rendering all map layers')),
36 'erase' : MetaIcon(img =
'erase',
37 label = _(
'Erase display'),
38 desc = _(
'Erase display canvas with given background color')),
39 'pointer' : MetaIcon(img =
'pointer',
40 label = _(
'Pointer')),
41 'zoomIn' : MetaIcon(img =
'zoom-in',
43 desc = _(
'Drag or click mouse to zoom')),
44 'zoomOut' : MetaIcon(img =
'zoom-out',
45 label = _(
'Zoom out'),
46 desc = _(
'Drag or click mouse to unzoom')),
47 'zoomBack' : MetaIcon(img =
'zoom-last',
48 label = _(
'Return to previous zoom')),
49 'zoomMenu' : MetaIcon(img =
'zoom-more',
50 label = _(
'Various zoom options'),
51 desc = _(
'Zoom to computational, default, saved region, ...')),
52 'zoomExtent' : MetaIcon(img =
'zoom-extent',
53 label = _(
'Zoom to selected map layer(s)')),
54 'pan' : MetaIcon(img =
'pan',
56 desc = _(
'Drag with mouse to pan')),
57 'saveFile' : MetaIcon(img =
'map-export',
58 label = _(
'Save display to graphic file')),
59 'print' : MetaIcon(img =
'print',
60 label = _(
'Print display')),
61 'font' : MetaIcon(img =
'font',
62 label = _(
'Select font')),
63 'help' : MetaIcon(img =
'help',
64 label = _(
'Show manual')),
65 'quit' : MetaIcon(img =
'quit',
67 'addRast' : MetaIcon(img =
'layer-raster-add',
68 label = _(
'Add raster map layer')),
69 'addVect' : MetaIcon(img =
'layer-vector-add',
70 label = _(
'Add vector map layer')),
71 'overlay' : MetaIcon(img =
'overlay-add',
72 label = _(
'Add map elements'),
73 desc = _(
'Overlay elements like scale and legend onto map')),
74 'histogramD' : MetaIcon(img =
'layer-raster-histogram',
75 label = _(
'Create histogram with d.histogram')),
76 'settings' : MetaIcon(img =
'settings',
77 label = _(
"Settings")),
81 """!Abstract toolbar class"""
84 wx.ToolBar.__init__(self, parent = self.
parent, id = wx.ID_ANY)
88 self.Bind(wx.EVT_TOOL, self.
OnTool)
90 self.SetToolBitmapSize(globalvar.toolbarSize)
93 """!Initialize toolbar, add tools to the toolbar
100 def _toolbarData(self):
101 """!Toolbar data (virtual)"""
105 shortHelp, longHelp, handler, pos = -1):
106 """!Add tool to the toolbar
108 @param pos if -1 add tool, if > 0 insert at given pos
111 bmpDisabled = wx.NullBitmap
114 tool = vars(self)[label] = wx.NewId()
115 Debug.msg(3,
"CreateTool(): tool=%d, label=%s bitmap=%s" % \
116 (tool, label, bitmap))
118 toolWin = self.AddLabelTool(tool, label, bitmap,
122 toolWin = self.InsertLabelTool(pos, tool, label, bitmap,
125 self.Bind(wx.EVT_TOOL, handler, toolWin)
132 """!Enable/disable long help
134 @param enable True for enable otherwise disable
136 for tool
in self.
_data:
141 self.SetToolLongHelp(vars(self)[tool[0]], tool[4])
143 self.SetToolLongHelp(vars(self)[tool[0]],
"")
149 if hasattr(self.
parent,
'toolbars'):
150 if self.parent.GetToolbar(
'vdigit'):
152 id = self.parent.toolbars[
'vdigit'].
GetAction(type =
'id')
153 self.parent.toolbars[
'vdigit'].ToggleTool(id,
False)
157 id = self.action.get(
'id', -1)
158 if id != event.GetId():
159 self.ToggleTool(self.
action[
'id'],
False)
161 self.ToggleTool(self.
action[
'id'],
True)
163 self.
action[
'id'] = event.GetId()
168 self.ToggleTool(self.
action[
'id'],
True)
171 """!Get current action info"""
172 return self.action.get(type,
'')
175 """!Select default tool"""
176 self.ToggleTool(self.defaultAction[
'id'],
True)
177 self.defaultAction[
'bind'](event)
178 self.
action = {
'id' : self.defaultAction[
'id'],
179 'desc' : self.defaultAction.get(
'desc',
'') }
182 """!Fix toolbar width on Windows
184 @todo Determine why combobox causes problems here
186 if platform.system() ==
'Windows':
187 size = self.GetBestSize()
188 self.SetSize((size[0] + width, size[1]))
191 """!Enable defined tool
194 @param enable True to enable otherwise disable tool
197 id = getattr(self, tool)
198 except AttributeError:
201 self.EnableTool(id, enable)
203 def _getToolbarData(self, data):
211 def _defineTool(self, name = None, icon = None, handler = None, item = wx.ITEM_NORMAL, pos = -1):
215 return (name, icon.GetBitmap(),
216 item, icon.GetLabel(), icon.GetDesc(),
218 return (
"",
"",
"",
"",
"",
"")
220 def _onMenu(self, data):
221 """!Toolbar pop-up menu"""
224 for icon, handler
in data:
225 item = wx.MenuItem(menu, wx.ID_ANY, icon.GetLabel())
226 item.SetBitmap(icon.GetBitmap(self.parent.iconsize))
227 menu.AppendItem(item)
228 self.Bind(wx.EVT_MENU, handler, item)