Refresher UI element¶
from ui import Refresher
counter = 0
def get_data():
counter += 1
return [str(counter), str(1000-counter)] #Return value will be sent directly to output.display_data
Refresher(get_data, i, o, 1, name="Counter view").activate()
-
class
ui.refresher.
Refresher
(refresh_function, i, o, refresh_interval=1, keymap=None, name='Refresher')[source]¶ A Refresher allows you to update the screen on a regular interval. All you need is to provide a function that’ll return the text/image you want to display; that function will then be called with the desired frequency and the display will be updated with whatever it returns.
-
__init__
(refresh_function, i, o, refresh_interval=1, keymap=None, name='Refresher')[source]¶ Initialises the Refresher object.
Args:
refresh_function
: a function which returns data to be displayed on the screen upon being called, in the format accepted byscreen.display_data()
orscreen.display_image()
. To be exact, supported return values are:- Tuples and lists - are converted to lists and passed to
display_data()
- Strings - are converted to a single-element list and passed to
display_data()
- PIL.Image objects - are passed to
display_image()
- Tuples and lists - are converted to lists and passed to
i
,o
: input&output device objects
Kwargs:
refresh_interval
: Time between display refreshes (and, accordingly,refresh_function
calls).keymap
: Keymap entries you want to set while Refresher is active. By default, KEY_LEFT deactivates the Refresher, if you wan tto override it, do it carefully.name
: Refresher name which can be used internally and for debugging.
-
activate
()[source]¶ A method which is called when refresher needs to start operating. Is blocking, sets up input&output devices, renders the refresher, periodically calls the refresh function&refreshes the screen while self.in_foreground is True, while refresher callbacks are executed from the input device thread.
-