earwax.menus.action_menu module¶
Provides the ActionMenu class.
-
class
earwax.menus.action_menu.ActionMenu(game: Game, title: Union[str, TitleFunction], dismissible: bool = True, item_select_sound_path: Optional[pathlib.Path] = None, item_activate_sound_path: Optional[pathlib.Path] = None, position: int = -1, search_timeout: float = 0.5, search_time: float = 0.0, input_mode: Optional[earwax.input_modes.InputModes] = NOTHING, all_triggers_label: Optional[str] = '<< Show all triggers >>')¶ Bases:
earwax.menus.menu.MenuA menu to show a list of actions and their associated triggers.
You can use this class with any game, like so:
from earwax import Game, Level, ActionMenu from pyglet.window import Window, key w = Window(caption='Test Game') g = Game() l = Level() @l.action('Show actions', symbol=key.SLASH, modifiers=key.MOD_SHIFT) def actions_menu(): '''Show an actions menu.''' a = ActionMenu(g, 'Actions') g.push_level(a) g.push_level(l) g.run(w)
Now, if you press shift and slash (a question mark on english keyboards), you will get an action menu.
This code can be shortened to:
@l.action('Show actions', symbol=key.SLASH, modifiers=key.MOD_SHIFT) def actions_menu(): '''Show an actions menu.''' game.push_action_menu()
If you want to override how triggers appear in the menu, then you can override
symbol_to_string()andmouse_to_string().Variables: - input_mode – The input mode this menu will show actions for.
- all_triggers_label –
The label for the “All triggers” entry.
If this value is
Noneno such entry will be shown.
-
action_menu(action: earwax.action.Action) → Callable[[], Optional[Generator[None, None, None]]]¶ Show a submenu of triggers.
Override this method to change how the submenu for actions is displayed.
Parameters: action – The action to generate the menu for.
-
action_title(action: earwax.action.Action, triggers: List[str]) → str¶ Return a suitable title for the given action.
This method is used when building the menu when
input_modeis notNone.Parameters: - action – The action whose name will be used.
- triggers – A list of triggers gleaned from the given action.
-
get_default_input_mode() → earwax.input_modes.InputModes¶ Get the default input mode.
-
handle_action(action: earwax.action.Action) → Callable[[], Optional[Generator[None, None, None]]]¶ Handle an action.
This method is used as the menu handler that is triggered when you select a trigger to activate the current action.
Parameters: action – The action to run.
-
hat_direction_to_string(direction: Tuple[int, int]) → str¶ Return the given hat direction as a string.
-
mouse_to_string(action: earwax.action.Action) → str¶ Describe how to trigger the given action with the mouse.
Returns a string representing the mouse button and modifiers needed to trigger the provided action.
You must be certain that
action.mouse_button is not None.Override this method to change how mouse triggers appear.
Parameters: action – The action whose mouse_buttonattribute this method will be working on.
-
show_all() → None¶ Show all triggers.
-
symbol_to_string(action: earwax.action.Action) → str¶ Describe how to trigger the given action with the keyboard.
Returns a string representing the symbol and modifiers needed to trigger the provided action.
You must be certain that
action.symbol is not None.Override this method to change how symbol triggers appear.
Parameters: action – The action whose symbolattribute this method will be working on.