MenuManager
- class pygamepopup.menu_manager.MenuManager(screen)
This class represents a manager for the interfaces of a screen.
It displays all the menus currently registered in the manager.
Handle the opening of a new menu and the closing of the active one. Handle the triggering of user motion events and user click events on the active menu.
- Keyword Arguments:
screen (pygame.Surface) – the screen on which the menus should be displayed and on which the user events should be handled
- screen
the screen on which the menus should be displayed and on which the user events should be handled
- Type:
- active_menu
the current menu in the foreground, the only one that will react to user events
- Type:
Optional[InfoBox]
- clear_menus()
Close all the menus (in foreground and in background)
- click(button, position)
Handle the triggering of a click event. Delegate this event to the active menu if there is any and if it’s a left click.
- Keyword Arguments:
button (int) – a value representing which mouse button has been pressed (1 for left button, 2 for middle button, 3 for right button)
position (Position) – the position of the mouse
- close_active_menu()
Close the active menu by ‘destroying’ it.
Take the next menu in the background to move it to foreground if there is any.
- close_given_menu(menu_identifier, all_occurrences=False)
Close menu corresponding to the given identifier.
By default, only first occurrence is closed if many menus in the manager have the given identifier.
- Keyword Arguments:
menu_identifier (str) – the identifier of the menu to be closed
all_occurrences (bool) – whether all found occurrences should be closed or only the first one, defaults to False
- Returns:
whether at least one menu has been closed or not
- Return type:
bool
- display()
Display all the visible menus in the background in order first, then display the active menu
- motion(position)
Handle the triggering of a motion event. Delegate this event to the active menu if there is any.
- Keyword Arguments:
position (Position) – the position of the mouse
- open_menu(menu)
Open the given menu. Initialize the rendering of the menu, and set it as the new active menu.
Previous active menu is sent to the background.
- Keyword Arguments:
menu (InfoBox) – the popup that should be open
- reduce_active_menu()
Move the active menu to the background.
- replace_given_menu(menu_identifier, new_menu, all_occurrences=False)
Replace a menu by a new one according to its identifier.
By default, only first occurrence is replaced if many menus in the manager have the given identifier.
- Keyword Arguments:
menu_identifier (str) – the identifier of the menu to be replaced
new_menu (InfoBox) – the menu that should replace the given one
all_occurrences (bool) – whether all found occurrences should be replaced or only the first one
- Returns:
whether the replacement has succeeded or not
- Return type:
bool