Checkbox UI element¶
from ui import Checkbox contents = [ ["Apples", 'apples'], ["Oranges", 'oranges'], ["Bananas", 'bananas']] selected_fruits = Checkbox(checkbox_contents, i, o).activate()
Checkbox(contents, i, o, name='Menu', entry_height=1, default_state=False, append_exit=True)¶
Implements a checkbox which can be used to enable or disable some functions in your application.
contents: list of checkbox elements which was passed either to
Checkboxconstructor or to
- Checkbox element structure is a list, where:
element(element’s representation) is either a string, which simply has the element’s value as it’ll be displayed, such as “Menu element 1”, or, in case of entry_height > 1, can be a list of strings, each of which represents a corresponding display row occupied by the element.
element(element’s name) is a name returned by the checkbox upon its exit in a dictionary along with its boolean value.
element(element’s state) is the default state assumed by the checkbox. If not present, assumed to be default_state.
If you want to set contents after the initalisation, please, use set_contents() method.
_contents: “Working copy” of checkbox contents, basically, a
contentsattribute which has been processed by
pointer: currently selected menu element’s number in
in_foreground: a flag which indicates if checkbox is currently displayed. If it’s not active, inhibits any of menu’s actions which can interfere with other menu or UI element being displayed.
first_displayed_entry: Internal flag which points to the number of
self._contentselement which is at the topmost position of the checkbox menu as it’s currently displayed on the screen
last_displayed_entry: Internal flag which points to the number of
self._contentselement which is at the lowest position of the checkbox menu as it’s currently displayed on the screen
__init__(contents, i, o, name='Menu', entry_height=1, default_state=False, append_exit=True)¶
Initialises the Checkbox object.
contents: a list of element descriptions, which can be constructed as described in the Checkbox object’s docstring.
o: input&output device objects
name: Checkbox name which can be used internally and for debugging.
entry_height: number of display rows one checkbox element occupies.
default_state: default state of the element if not supplied.
A method which is called when checkbox needs to start operating. Is blocking, sets up input&output devices, renders the checkbox and waits until self.in_background is False, while checkbox callbacks are executed from the input device thread.
A debug method. Useful for hooking up to an input event so that you can see the representation of checkbox’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 checkbox contents, as well as additionally re-sets
first_displayed_entrypointers and calculates the value for