Checkbox UI element¶
from ui import Checkbox
contents = [
["Apples", 'apples'], #"Apples" will not be checked on activation
["Oranges", 'oranges', True], #"Oranges" will be checked on activation
["Bananas", 'bananas']]
selected_fruits = Checkbox(checkbox_contents, i, o).activate()
-
class
ui.checkbox.
Checkbox
(*args, **kwargs)[source]¶ Implements a checkbox which can be used to enable or disable some functions in your application.
Attributes:
contents
: list of checkbox entries which was passed either toCheckbox
constructor or tocheckbox.set_contents()
.- Checkbox entry structure is a list, where:
entry[0]
(entry label) is usually a string which will be displayed in the UI, such as “Option 1”. In case of entry_height > 1, can be a list of strings, each of which represents a corresponding display row occupied by the entry.entry[1]
(entry name) is a name returned by the checkbox upon its exit in a dictionary along with its boolean value.entry[2]
(entry state) is the default state of the entry (checked or not checked). If not present, assumed to be`` default_state``.
If you want to set contents after the initalisation, please, use set_contents() method.
pointer
: currently selected menu element’s number inself.contents
.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.
-
__init__
(*args, **kwargs)[source]¶ Args:
contents
: a list of element descriptions, which can be constructed as described in the Checkbox object’s docstring.i
,o
: input&output device objects
Kwargs:
name
: Checkbox name which can be used internally and for debugging.entry_height
: number of display rows that one checkbox element occupies.default_state
: default state for each entry that doesn’t have a state (entry[2]) specified incontents
(default:False
)final_button_name
: label for the last button that confirms the selection (default:"Accept"
)
-
activate
()¶ 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_foreground is False, while UI element callbacks are executed from the input listener thread.
-
deactivate
()¶ Sets a flag that signals the UI element’s
activate()
to return.
-
print_contents
()¶ A debug method. Useful for hooking up to an input event so that you can see the representation of current UI element’s contents.
-
print_name
()¶ A debug method. Useful for hooking up to an input event so that you can see which UI element is currently processing input events.
-
set_contents
(contents)¶ Sets the UI element contents and triggers pointer recalculation in the view.