Menu UI element¶
from ui import Menu ... menu_contents = [ ["Do this", do_this], ["Do this with 20", lambda: do_this(x=20)], ["Do nothing"], ["My submenu", submenu.activate] ] Menu(menu_contents, i, o, "My menu").activate()
This file exports app developer-accessible UI elements, so that they can be imported like:
from ui import UIElement
Implements a menu which can be used to navigate through your application, output a list of values or select actions to perform. Is one of the most used UI elements, used both in system core and in most of the applications.
number of currently selected menu entry, starting from 0.
flag which indicates whether menu is currently active, either being displayed or just waiting in background (for example, when you go into a sub-menu, the parent menu will still be considered active).
flag which indicates whether menu is currently displayed.
Initialises the Menu object.
contents: list of menu entries which was passed either to
Menuconstructor or to
- Menu entry is a list, where:
entry(entry label) is usually a string which will be displayed in the UI, such as “Menu entry 1”. If
entry_height> 1, can be a list of strings, each of those strings will be shown on a separate display row.
entry(entry callback) is a function which is called when the user presses Enter.
- Can be omitted if you don’t need to have any actions taken upon activation of the entry.
- You can supply ‘exit’ (a string, not a function) if you want a menu entry that exits the menu when the user presses Enter.
entry(entry second callback) is a callback for the right key press.
If you want to set contents after the initialisation, please, use set_contents() method.*
o: input&output device objects
name: Menu name which can be used internally and for debugging.
entry_height: number of display rows one menu entry occupies.
append_exit: Appends an “Exit” alement to menu contents.
MenuExitExceptionis received and catch_exit is False, it passes
MenuExitExceptionto the parent menu so that it exits, too. If catch_exit is True, MenuExitException is not passed along.
exitable: Decides if menu can exit by pressing
KEY_LEFT. Set by default and disables
KEY_LEFTcallback if unset. Is used for ZPUI main menu, not advised to be used in other settings.
contents_hook: A function that is called every time menu goes in foreground that returns new menu contents. Allows to almost-dynamically update menu contents.
A method which is called when UI element needs to start operating. Is blocking, sets up input&output devices, renders the UI element and waits until self.in_background is False, while UI element callbacks are executed from the input listener thread.
Sets a flag that signals the UI element’s
A debug method. Useful for hooking up to an input event so that you can see the representation of current UI element’s contents.
A debug method. Useful for hooking up to an input event so that you can see which UI element is currently processing input events.
Sets the UI element contents and triggers pointer recalculation in the view.
An exception that you can throw from a menu callback to exit the menu that the callback was called from (and underlying menus, if necessary)