DialogBox UI element¶
This UI element allows you to make sure the user actually wants to proceed with some kind of action/decision.
from ui import DialogBox
...
choice = DialogBox("ync", i, o, name="My dialogbox of my app").activate()
if choice: "Yes" was selected
# do things
By default, you can pass string values like “ync” (or “yn”, or “yc”, or “cy”), where
the “y”, “n” and “c” characters will be parsed as “Yes” (True
), “No” (False
)
and “Cancel” (None
) options respectively (True
, False
and None
being
return values). Exiting by using LEFT will also result in None
being returned.
You can also pass custom labels/return values like this:
choice = DialogBox([["Abort", "abort"], ["Retry", "retry"], ["Ignore", "ignore"]], i, o, name="My dialogbox of my app").activate()
-
class
ui.
DialogBox
(values, i, o, message='Are you sure?', name='DialogBox', **kwargs)[source]¶ Bases:
ui.base_ui.BaseUIElement
Implements a dialog box with given values (or some default ones if chosen).
-
__init__
(values, i, o, message='Are you sure?', name='DialogBox', **kwargs)[source]¶ Initialises the DialogBox object.
Args:
values
: values to be used. Should be a list of[label, returned_value]
pairs.- You can also pass a string “yn” to get “Yes(True), No(False)” options, or “ync” to get “Yes(True), No(False), Cancel(None)” options.
- Values put together with spaces between them shouldn’t be longer than the screen’s width.
i
,o
: input&output device objects
Kwargs:
message
: Message to be shown on the first line of the screen when UI element is activatedname
: UI element name which can be used internally and for debugging.
-
set_start_option
(option_number)[source]¶ Allows you to set position of the option that’ll be selected upon DialogBox activation.
-
activate
()¶ A method which is called when the UI element needs to start operating. Is blocking, sets up input&output devices, refreshes the UI element, then calls the
idle_loop
method while the UI element is active.self.in_foreground
is True, while callbacks are executed from the input device thread.
-
deactivate
()¶ Deactivates the UI element, exiting it.
-