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(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 by screen.display_data() or screen.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()
  • 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 want to override it, make sure that user can still exit the Refresher.
  • name: Refresher name which can be used internally and for debugging.
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.

print_name()

A debug method. Useful for hooking up to an input event so that you can see which UI element is currently active.