Checkbox UI element¶
from ui import Checkbox
contents = [
["Apples", 'apples'],
["Oranges", 'oranges'],
["Bananas", 'bananas']]
selected_fruits = Checkbox(checkbox_contents, i, o).activate()
-
class
ui.checkbox.
Checkbox
(contents, i, o, name='Menu', entry_height=1, default_state=False, append_exit=True)[source]¶ Implements a checkbox which can be used to enable or disable some functions in your application.
Attributes:
contents
: list of checkbox elements which was passed either toCheckbox
constructor or tocheckbox.set_contents()
.- Checkbox element structure is a list, where:
element[0]
(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[1]
(element’s name) is a name returned by the checkbox upon its exit in a dictionary along with its boolean value.element[2]
(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, acontents
attribute which has been processed byself.process_contents
.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.first_displayed_entry
: Internal flag which points to the number ofself._contents
element which is at the topmost position of the checkbox menu as it’s currently displayed on the screenlast_displayed_entry
: Internal flag which points to the number ofself._contents
element 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)[source]¶ Initialises the Checkbox object.
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 one checkbox element occupies.default_state
: default state of the element if not supplied.
-
activate
()[source]¶ 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.
-
print_contents
()[source]¶ A debug method. Useful for hooking up to an input event so that you can see the representation of checkbox’s contents.