composeui.core.renderer

The base classes of the renderers, which show a view with a widget of a toolkit.

class composeui.core.renderer.MainRenderer[source]

Bases: Renderer[TView, TObject]

A root-window renderer: the app-level operations a MainView relies on.

Lets MainView talk to whichever backend rendered it through isinstance checks against this class alone, without importing any backend package.

draws_on_main_thread: ClassVar[bool] = True

whether the app’s window is drawn on the main thread, which long work there freezes (Qt, Textual): a view then runs it in a job. The web’s requests have threads of their own

abstractmethod close()[source]

Close the application.

Return type:

None

abstractmethod open_file()[source]

Ask the user for an existing file path, blocking until answered.

Return type:

Path | None

abstractmethod save_file()[source]

Ask the user for a file path to save to, blocking until answered.

Return type:

Path | None

exception composeui.core.renderer.MissingRefreshAttributeFunctionError[source]

Bases: Exception

A changed field of a view that its renderer has no handler for.

__init__(renderer, attr_name)[source]
Parameters:
Return type:

None

exception composeui.core.renderer.NoRenderedObjectError[source]

Bases: Exception

A renderer used before Renderer.render built its widget.

__init__()[source]
Return type:

None

class composeui.core.renderer.Renderer[source]

Bases: ABC, Generic[TView, TObject]

The base of a backend’s renderers: one shows a view with a widget of its toolkit.

render builds the widget. refresh_attribute shows a new value of a field of the view, with the handler of _refresh_dispatcher for that field. The renderer sets the view’s fields from the widget’s signals, inside stop_refresh, so the view doesn’t show them back.

__init__(view)[source]
Parameters:

view (TView)

Return type:

None

has_attr(attr_name)[source]

Check if the attribute has an associated refresh function.

Parameters:

attr_name (str)

Return type:

bool

is_updating_state()[source]
Return type:

bool

call_on_main_thread(callback)[source]

Invoke callback on the thread that owns the GUI event loop.

Default: no real thread affinity to worry about outside a GUI toolkit, so just call it directly. Toolkit-bound renderers (e.g. Qt, whose widgets can only be touched from the thread that created them) must override this to marshal the call onto their main thread instead.

Parameters:

callback (Callable[[], None])

Return type:

None

abstractmethod render()[source]

Build the widget that shows the view.

Return type:

None

refresh()[source]

Show every field of the view that has a handler in _refresh_dispatcher.

Return type:

None

refresh_attribute(attr_name, value)[source]

Show value, the new value of the view’s field attr_name.

Raises MissingRefreshAttributeFunctionError when no handler shows the field.

Parameters:
Return type:

None

stop_refresh()[source]
Return type:

Generator[None]

class composeui.core.renderer.RendererContainer[source]

Bases: Generic[TView]

The renderers of a view shown by several widgets, e.g. a form row’s label and field.

__init__(view, renderers)[source]
Parameters:
  • view (TView)

  • renderers (Mapping[str, Renderer[TView, Any]])

Return type:

None

is_updating_state()[source]
Return type:

bool

call_on_main_thread(callback)[source]

Invoke callback on the thread that owns the GUI event loop.

Delegates to one of its renderers: they all share the same toolkit and thread.

Parameters:

callback (Callable[[], None])

Return type:

None

get_renderer(name)[source]
Parameters:

name (str)

Return type:

Renderer[TView, Any]

property renderers: list[Renderer[TView, Any]]
render()[source]

Build the widgets of every renderer.

Return type:

None

refresh()[source]

Show every field of the view that a renderer has a handler for.

Return type:

None

refresh_attribute(attr_name, value)[source]

Show value with each renderer that has a handler for the field attr_name.

Parameters:
Return type:

None

class composeui.core.renderer.ViewLike[source]

Bases: Protocol

What a renderer needs of every view: whether it is visible and enabled.

is_visible: bool
is_enabled: bool
__init__(*args, **kwargs)