+ Called when the current view must be updated. Never call
+ directly. Subclasses should extend this method, not update.
+ """
+ pass
+
+ def refresh_menu(self):
+ """
+ Refresh the menu and its bindings. Calls self.menu_items() to
+ get the new menu.
+ """
+ # Two helper functions
+ def shortcut_prefix(key_name):
+ short = key_shortname(key_name)
+ return '[%s]' % short if short else ' '
+
+ def do_entry((text, callback, key_name)):
+ key = get_key(key_name)
+ if key:
+ self.view.bind(key, callback)
+ self.menu_keys.append(key)
+ title = "%s %s" % (shortcut_prefix(key_name), text)
+ return(title, callback)
+
+ # Clear the bindings we previously added (we can't just clear
+ # all bindings, since other classes might have added other
+ # bindings)
+ for key in self.menu_keys:
+ self.view.bind(key, no_action)
+ self.menu_keys = []
+
+ # Set the menu, and let do_entry add binds at the same time.
+ appuifw.app.menu = [do_entry(item) for item in self.menu_items()]
+
+ def menu_items(self):
+ """
+ Should return a list of menu items. Each menu item is a tuple:
+ (text, callback, shortcut key name).