Backends

Each backend has an application class, and a model application class for an app with a model. composeui.core.application.run starts the classes of the backend that the command line selects.

Qt

The application classes of the Qt backend.

class composeui.qtcore.qtapplication.QtApplication[source]

Bases: Application[MainViewT]

The Qt app: it shows the main view in a window.

backend: ClassVar[RendererType | None] = ('composeui.qtcore.qtrenderer', 'composeui.qtcore.qtapplication', 'pyside6', ('PySide6', 'pyqtgraph', 'qtpy'))

the backend that shows the app, given by each backend’s app (current_backend)

__init__(*, build_main_view)[source]
Parameters:

build_main_view (Callable[[], MainViewT])

Return type:

None

run()[source]
Return type:

None

class composeui.qtcore.qtapplication.QtModelApplication[source]

Bases: ModelApplication[MainViewT, ModelT]

The Qt app with a model, which it closes once the window is closed.

backend: ClassVar[RendererType | None] = ('composeui.qtcore.qtrenderer', 'composeui.qtcore.qtapplication', 'pyside6', ('PySide6', 'pyqtgraph', 'qtpy'))

the backend that shows the app, given by each backend’s app (current_backend)

__init__(*, build_main_view, build_model, setup_model=None)[source]
Parameters:
  • build_main_view (Callable[[], MainViewT])

  • build_model (Callable[[], ModelT])

  • setup_model (Callable[[MainViewT, ModelT], None] | None)

Return type:

None

run()[source]
Return type:

None

composeui.qtcore.qtapplication.APPLICATION

the backend’s applications, for composeui.core.application.run

composeui.qtcore.qtapplication.MODEL_APPLICATION

alias of QtModelApplication

Textual

The application classes of the Textual backend.

class composeui.textualcore.textualapplication.TextualApplication[source]

Bases: Application[MainViewT]

The Textual app: it shows the main view in the terminal.

backend: ClassVar[RendererType | None] = ('composeui.textualcore.textualrenderer', 'composeui.textualcore.textualapplication', 'tui', ('textual', 'textual_fspicker', 'textual_plotext'))

the backend that shows the app, given by each backend’s app (current_backend)

__init__(*, build_main_view)[source]
Parameters:

build_main_view (Callable[[], MainViewT])

Return type:

None

run()[source]
Return type:

None

class composeui.textualcore.textualapplication.TextualModelApplication[source]

Bases: ModelApplication[MainViewT, ModelT]

The Textual app with a model, which it closes once the app exits.

backend: ClassVar[RendererType | None] = ('composeui.textualcore.textualrenderer', 'composeui.textualcore.textualapplication', 'tui', ('textual', 'textual_fspicker', 'textual_plotext'))

the backend that shows the app, given by each backend’s app (current_backend)

__init__(*, build_main_view, build_model, setup_model=None)[source]
Parameters:
  • build_main_view (Callable[[], MainViewT])

  • build_model (Callable[[], ModelT])

  • setup_model (Callable[[MainViewT, ModelT], None] | None)

Return type:

None

run()[source]
Return type:

None

composeui.textualcore.textualapplication.APPLICATION

the backend’s applications, for composeui.core.application.run

composeui.textualcore.textualapplication.MODEL_APPLICATION

alias of TextualModelApplication

Web

The application classes of the web backend.

composeui.webcore.webapplication.create_starlette_app(sessions, *, secret_key=None, reloading=False)[source]

Create the Starlette app serving one main view per browser session.

secret_key signs the session cookie, a new one by default. A --reload server’s process (reloading) saves the sessions as it stops (SessionStore.save_all), and its pages reload once another process serves (reload_poll).

Parameters:
  • sessions (SessionStore)

  • secret_key (str | None)

  • reloading (bool)

Return type:

Starlette

composeui.webcore.webapplication.create_reloaded_starlette_app()[source]

Build the app of the program named by _RELOAD_ENTRY_VARIABLE: --reload’s factory.

uvicorn’s reloader serves from a new process, started again after every change. That process doesn’t run the program that started the server. So this function runs the program again, with the command line the process inherited (-f, --debug, …). It keeps the app whose run the program reaches, instead of serving it. So an app built inline, connected or configured by the program’s main() comes back just as it was.

Return type:

Starlette

class composeui.webcore.webapplication.WebApplication[source]

Bases: Application[MainViewT]

The web app: it serves the main view over HTTP, one MainView per browser session.

main_view is only a template, for the command line (e.g. -f’s extension check). Every session gets its own instance from build_main_view. So connect(view=app.main_view..., ...) doesn’t wire the template. It records where the view and the signals sit in the template. Every new session then connects the callback to its own view and signals, with its own view and main_view. Connect before serving: a session already open keeps the connections it was built with.

backend: ClassVar[RendererType | None] = ('composeui.webcore.webrenderer', 'composeui.webcore.webapplication', 'web', ('itsdangerous', 'markdown_it', 'markupsafe', 'python_multipart', 'starlette', 'uvicorn'))

the backend that shows the app, given by each backend’s app (current_backend)

session_ttl: ClassVar[float] = 3600.0

seconds a session may stay idle before it is dropped

max_sessions: ClassVar[int] = 1000

most sessions live at once: past it, a new browser gets 503 until one is dropped (each holds a main view, and maybe a model, in memory)

__init__(*, build_main_view)[source]
Parameters:

build_main_view (Callable[[], MainViewT])

Return type:

None

connect(*, view, signals)[source]
Parameters:
  • view (ViewT)

  • signals (Sequence[Signal[Unpack[Ts]]])

Return type:

_ConnectDecorator[ViewT, MainViewT, Unpack[Ts]]

setup_session(main_view)[source]

Wire a new session’s main view; override to connect app-level behavior.

Parameters:

main_view (MainViewT)

Return type:

None

create_starlette_app(*, saved_sessions=None, secret_key=None)[source]

Create the Starlette app, building a fresh main view for each new session.

A page whose route takes one of the backend’s addresses stops it here, before serving, rather than failing every request. A --reload server’s process gets saved_sessions, the directory where its processes leave their sessions to the next, and secret_key, which they all sign the sessions’ cookies with.

Parameters:
  • saved_sessions (Path | None)

  • secret_key (str | None)

Return type:

Starlette

run()[source]

Build and serve the app.

Return type:

None

class composeui.webcore.webapplication.WebModelApplication[source]

Bases: WebApplication[MainViewT], Generic[MainViewT, ModelT]

A WebApplication whose every session also gets its own model from build_model.

Each session has its own model, as it has its own main view. A browser only ever sees the fragments its own requests return. So a model shared between sessions would leave every other browser showing stale views, and would need its own locking. Callbacks asking for model get their session’s model, whether a view’s own callbacks or those connected through connect. setup_model wires each session’s model to its main view.

__init__(*, build_main_view, build_model, setup_model=None)[source]
Parameters:
  • build_main_view (Callable[[], MainViewT])

  • build_model (Callable[[], ModelT])

  • setup_model (Callable[[MainViewT, ModelT], None] | None)

Return type:

None

connect(*, view, signals)[source]
Parameters:
  • view (ViewT)

  • signals (Sequence[Signal[Unpack[Ts]]])

Return type:

_ConnectModelDecorator[ViewT, MainViewT, ModelT, Unpack[Ts]]

setup_model(main_view, model)[source]

Wire a new session’s model to its main view: calls the setup_model given.

Runs after setup_session, e.g. to refresh views when a SqliteTable changes.

Parameters:
  • main_view (MainViewT)

  • model (ModelT)

Return type:

None

composeui.webcore.webapplication.APPLICATION

the backend’s applications, for composeui.core.application.run

composeui.webcore.webapplication.MODEL_APPLICATION

alias of WebModelApplication