is an abstract base class for screens that respond to keyboard commands. It allows declaratively
describing a set of commands, with menu titles, keyboard equivalents
and associated actions. A menu of buttons may optionally be added to the screen to invoke the commands.
Each menu item is specified by a descriptor
(title, action_name, keys)
The title is a string to use as a button label.
The action_name is a string used to derive the names of two methods of the Shell object:
|action_name + '_enable'||Method
returning a boolean indicating whether the command should be enabled.
If the method does not exist, the command is always enabled.|
|action_name + '_cmd'||Method to call when the command is invoked.|
is a sequence of PyGame key codes specifying alternative keyboard
equivalents for the command. For non-function keys, the Control or
Command modifier is implicitly required along with the key. For function keys (K_F1 to K_F12) or the Escape key, no modifiers are required.
- String to use as a screen title, if a menu is being created.
- title_class = MenuTitle
- Widget class to use for the screen title, if a menu is being created. Should be a subclass of Label or something with a compatible constructor.
- button_class = MenuButton
- Widget class to use for the menu buttons, if a menu is being created. Should be a subclass of Button or something with a compatible constructor.
- with_menu = False
- Whether to create a title and menu.
- A sequence of menu item descriptors as defined above.
- CommandScreen(shell, with_menu = False)
- Associates the screen with the given shell. If with_menu is true, a title and menu will be created and displayed.
- create_button(title, action_name)
- Creates a button with the given title that invokes the specified action. The button_class is used as the class of the button.
You can customize the appearance of the title and menu at various levels by overriding the following methods.
- If the command specified by action_name is enabled, calls the corresponding action method of the Shell.
- Creates and return a widget to use for the title of the menu. The default implementation calls the title_class passing it the title.
and returns a widget implementing a menu for the screen. The default
implementation returns a column of buttons created by calling the button_class.
- Returns true if a button for the indicated action should be included in the menu.
- add_title_and_buttons(title, buttons)
- Given a title widget and a list of button widgets, adds them to the screen, appropriately arranged.
- add_title_and_menu(title, menu)
- Given a title widget and a menu widget, adds them to the screen, appropriately arranged.
Themable ClassesYou can customize the default appearance of a CommandScreen menu by providing Albow themes
for the following classes defined in the main_commands module.
- class MenuTitle(albow.controls.Label)
- Default class for the menu title.
- class MenuButton(albow.controls.Button)
- Default class for menu buttons.