menus.base module

Contains base menu functionality.

Bases: menus.base._MenuData

Display plain text.

See _MenuData._render().

Bases: core.AutoUnload, list

The base menu. Every menu class should inherit from this class.

Initialize the menu.

Parameters:
  • data (iterable|None) – Data that should be added to the menu.
  • select_callback (callable|None) –

    A function that gets called whenever a selection was made.

    The callback will receive 3 parameters:
    1. The instance of this menu.
    2. The player’s index who made the selection.
    3. The player’s choice.
  • build_callback (callable|None) –

    A function that gets called before a menu is displayed.

    The callback will receive 2 parameters:
    1. The instance of this menu.
    2. The index of the player who will receive this menu.

Call the build callback and return all relevant menu data.

Parameters:player_index (int) – The index of the player whose menu should be built.

Close a menu for the player by sending an empty menu.

This method needs to be implemented by a subclass!

Parameters:player_index (int) – A player index.

Return the required data to send a menu.

This method needs to be implemented by a subclass!

Parameters:player_index (int) – A player index.

Return a _QueueHolder object.

This method needs to be implemented by a subclass!

Re-send the menu to a player.

Parameters:player_index (int) – The index of the player whose menu should be refreshed.

Handle a menu selection.

Parameters:
  • player_index (int) – The index of the player who made the selection.
  • choice_index (int) – Defines what was selected.

Send a menu to the player.

This method needs to be implemented by a subclass!

Parameters:player_index (int) – A player index.

Close this menu object for every player.

Remove every player specific information.

Parameters:player_index (int) – A player index.

Close the menu for the given player indexes.

If no indexes were given, the menu will be closed for all players.

Return the menu queue for the given player.

Parameters:player_index (int) – A player index.

Return True if this menu is the first menu in the user’s queue.

Parameters:player_index (int) – A player index.

Register a build callback for the menu.

Can and should be used as a decorator.

Parameters:callback (callable) –

A function that gets called before a menu is displayed.

The callback will receive 2 parameters:
  1. The instance of this menu.
  2. The index of the player who will receive this menu.

Register a select callback for the menu.

Can and should be used as a decorator.

Parameters:callback (callable) –

A function that gets called whenever a selection was made.

The callback will receive 3 parameters:
  1. The instance of this menu.
  2. The player’s index who made the selection.
  3. The player’s choice.

Send the menu to the given player indexes.

If no indexes were given, the menu will be sent to every player.

Parameters:
  • ply_indexes – Player indexes that should receive the menu.
  • tokens – Translation tokens for menu options, title and description.

Bases: menus.base._MenuData

This class is used to display an enumerated option.

Initialize the option.

Parameters:
  • text (str) – The text that should be displayed.
  • value – The value that should be passed to the menu’s selection callback.
  • hightlight (bool) – Set this to true if the text should be hightlighted.
  • selectable (bool) – Set this to True if the option should be selectable.

See _MenuData._render().

Bases: object

Base class for menu data.

All data types should inherit from this class.

Initialize the instance.

Parameters:text (str) – The text that should be displayed.

Render the data.

Parameters:
  • player_index (int) – A player index.
  • choice_index (int|None) – The number that was selected. It depends on the menu type if this parameter gets passed.

Bases: object

Implements the base of every page based menu.

Return the maximum possible item count per page.

Return a tuple containing the options for the given page index.

Parameters:page_index (int) – The index of the page.

Return the current player page index.

Parameters:player_index (int) – A player index.

Set the player’s current page index.

Parameters:
  • player_index (int) – A player index.
  • page_index (int) – The current active page index.

If page_index is lower than 0, the page index will be set to 0.

If page_index is greater than the last page index, it will be set to the last page index.

Return the index of the last page.

Return the number of pages the menu currently has.

Bases: object

Stores information about the player’s current active page.

Initialize the object.

Translate the given text.

Only translate if text is an instance of translations.strings.TranslationStrings. Otherwise the original text will be returned.