appdev.app

App: devices, events, display refresh and lifecycle, on multimer’s timers.

An App owns no timer machinery of its own. app.every(ms, fn) is multimer.every; the device service tick and each display’s refresh are ordinary timers you can see in multimer.report(); and staying alive past the end of the script body is multimer.keepalive, which the App sets when it has a display or a subscription. So a script that builds its UI and ends keeps running, at the prompt under -i and in the exit hook otherwise, with or without LVGL, and app.run() is only for a program that wants to block.

class appdev.app.App(board_config=None, *, displays=None, host_read=None, touch_read=None, touch_rotation_table=None, refresh_period=None)[source]

Bases: object

Application coordinator: devices, event dispatch, display refresh, lifecycle.

events = <module 'events' from '/home/docs/checkouts/pydevices/checkouts/177/docs-site/_repos/omnipython/lib/events.py'>
keys = <module 'keys' from '/home/docs/checkouts/pydevices/checkouts/177/docs-site/_repos/omnipython/lib/keys.py'>
classmethod current()[source]

Return the currently active App instance, or None.

property strategy

How the program stays alive past the script body (see multimer.strategy).

on_quit(callback)[source]

Call callback() at quit, after before_quit, in the order added.

Unlike before_quit, any number of callbacks can be added, and adding one never replaces another. Returns callback, so it works as a decorator. An exception in one is printed and the rest still run.

property timers

The App’s own timers: service, refresh and every() subscriptions.

on(event_type_or_list, callback=None)[source]

Subscribe callback to one or more event types, or use as a decorator.

off(event_type_or_list, callback)[source]

Unsubscribe callback from one or more event types.

every(ms=None, callback=None, *, period=None, name=None)[source]

A periodic multimer.Timer calling callback(timer) every ms.

The callback receives the timer, so a method needs the signature def step(self, timer=None). Usable as a decorator (@app.every(1000)). The App keeps the process alive while any subscription runs; timer.deinit() (or cancel()) ends one.

on_tick(callback, period=10, **_ignored)[source]

Schedule a periodic callback (alias of every).

stop_timers()[source]

Stop the service tick, every refresh and every subscription.

stop_timer()

Stop the service tick, every refresh and every subscription.

pause_refresh()[source]

Pause display refresh while a GUI renders frames.

resume_refresh()[source]

Resume display refresh after pausing.

refresh_paused()[source]

Context manager to pause display refresh within a block.

pause_polling()[source]

Stop the service tick reading the devices: the caller reads them.

A GUI that polls the input devices itself (LVGL reads its indevs from its own timers) claims the devices with this, or the service tick consumes the events first. release() the claim to resume.

poll()[source]

Poll registered devices and dispatch any pending events.

A program that calls this from its own loop takes over from the service timer; delivery of every other timer happens here too.

run(tick_ms=10)[source]

Block until quit, delivering timers and events. Optional.

Returns at once where the host already owns a loop that keeps the program running (a REPL under -i, a browser page, a notebook).

run_async(coro_or_fn)[source]

Run a coroutine (or a factory of one) under the host’s asyncio loop.

Schedules it as a task where a loop is already running (Jupyter, PyScript) and returns the task; otherwise asyncio.run blocks.

request_quit(code=None)[source]

Request a clean application shutdown.