54 |
|
|
55 |
self.init_ids() |
self.init_ids() |
56 |
|
|
57 |
#main_menu.print_menu() |
# creat the menubar from the main_menu description |
58 |
self.SetMenuBar(self.build_menu_bar(main_menu)) |
self.SetMenuBar(self.build_menu_bar(main_menu)) |
59 |
|
|
60 |
# toolbar |
# Similarly, create the toolbar from main_toolbar |
61 |
toolbar = self.CreateToolBar(wxTB_3DBUTTONS) |
toolbar = self.build_toolbar(main_toolbar) |
|
|
|
|
# set the size of the tools' bitmaps. Not needed on wxGTK, but |
|
|
# on Windows. We probably shouldn't hardwire the bitmap size |
|
|
# here |
|
|
toolbar.SetToolBitmapSize(wxSize(24, 24)) |
|
|
|
|
|
for name in ["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool", |
|
|
"map_identify_tool", "map_label_tool", "map_full_extent"]: |
|
|
self.add_toolbar_command(toolbar, name) |
|
62 |
# call Realize to make sure that the tools appear. |
# call Realize to make sure that the tools appear. |
63 |
toolbar.Realize() |
toolbar.Realize() |
64 |
|
|
78 |
self.current_id = 6000 |
self.current_id = 6000 |
79 |
self.id_to_name = {} |
self.id_to_name = {} |
80 |
self.name_to_id = {} |
self.name_to_id = {} |
81 |
|
self.events_bound = {} |
82 |
|
|
83 |
def get_id(self, name): |
def get_id(self, name): |
84 |
"""Return the wxWindows id for the command named name. |
"""Return the wxWindows id for the command named name. |
92 |
self.id_to_name[ID] = name |
self.id_to_name[ID] = name |
93 |
return ID |
return ID |
94 |
|
|
95 |
|
def bind_command_events(self, command, ID): |
96 |
|
"""Bind the necessary events for the given command and ID""" |
97 |
|
if not self.events_bound.has_key(ID): |
98 |
|
# the events haven't been bound yet |
99 |
|
EVT_MENU(self, ID, self.invoke_command) |
100 |
|
if command.IsDynamic(): |
101 |
|
EVT_UPDATE_UI(self, ID, self.update_command_ui) |
102 |
|
|
103 |
def build_menu_bar(self, menudesc): |
def build_menu_bar(self, menudesc): |
104 |
"""Build and return the menu bar from the menu description""" |
"""Build and return the menu bar from the menu description""" |
105 |
menu_bar = wxMenuBar() |
menu_bar = wxMenuBar() |
130 |
last = item |
last = item |
131 |
return wxmenu |
return wxmenu |
132 |
|
|
133 |
|
def build_toolbar(self, toolbardesc): |
134 |
|
"""Build and return the main toolbar window from a toolbar description |
135 |
|
|
136 |
|
The parameter should be an instance of the Menu class but it |
137 |
|
should not contain submenus. |
138 |
|
""" |
139 |
|
toolbar = self.CreateToolBar(wxTB_3DBUTTONS) |
140 |
|
|
141 |
|
# set the size of the tools' bitmaps. Not needed on wxGTK, but |
142 |
|
# on Windows, although it doesn't work very well there. It seems |
143 |
|
# that only 16x16 icons are really supported on windows. |
144 |
|
# We probably shouldn't hardwire the bitmap size here. |
145 |
|
toolbar.SetToolBitmapSize(wxSize(24, 24)) |
146 |
|
|
147 |
|
for item in toolbardesc.items: |
148 |
|
if item is None: |
149 |
|
toolbar.AddSeparator() |
150 |
|
else: |
151 |
|
# assume it's a string. |
152 |
|
self.add_toolbar_command(toolbar, item) |
153 |
|
|
154 |
|
return toolbar |
155 |
|
|
156 |
def add_menu_command(self, menu, name): |
def add_menu_command(self, menu, name): |
157 |
"""Add the command with name name to the menu menu. |
"""Add the command with name name to the menu menu. |
158 |
|
|
166 |
ID = self.get_id(name) |
ID = self.get_id(name) |
167 |
menu.Append(ID, command.Title(), command.HelpText(), |
menu.Append(ID, command.Title(), command.HelpText(), |
168 |
command.IsCheckCommand()) |
command.IsCheckCommand()) |
169 |
EVT_MENU(self, ID, self.invoke_command) |
self.bind_command_events(command, ID) |
|
if command.IsDynamic(): |
|
|
EVT_UPDATE_UI(self, ID, self.update_command_ui) |
|
170 |
else: |
else: |
171 |
print "Unknown command %s" % name |
print "Unknown command %s" % name |
172 |
|
|
188 |
toolbar.AddTool(ID, bitmap, |
toolbar.AddTool(ID, bitmap, |
189 |
shortHelpString = command.HelpText(), |
shortHelpString = command.HelpText(), |
190 |
isToggle = command.IsCheckCommand()) |
isToggle = command.IsCheckCommand()) |
191 |
|
self.bind_command_events(command, ID) |
192 |
else: |
else: |
193 |
print "Unknown command %s" % name |
print "Unknown command %s" % name |
194 |
|
|
614 |
"layer_show_table"]), |
"layer_show_table"]), |
615 |
Menu("help", "&Help", |
Menu("help", "&Help", |
616 |
["help_about"])]) |
["help_about"])]) |
617 |
|
|
618 |
|
# the main toolbar |
619 |
|
|
620 |
|
main_toolbar = Menu("<toolbar>", "<toolbar>", |
621 |
|
["map_zoom_in_tool", "map_zoom_out_tool", "map_pan_tool", |
622 |
|
"map_identify_tool", "map_label_tool", "map_full_extent"]) |