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() |
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 |
|
|