composeui.core.model

The model: the app’s data beside its views, saved and opened with them in a study.

exception composeui.core.model.InvalidStateError[source]

Bases: ValueError

A saved study that can’t be opened; the views and the model are left unchanged.

class composeui.core.model.Model[source]

Bases: object

The app’s data beside its views, given to the callbacks asking for model.

A model with data of its own names its file in data_name. The study is then saved as an archive of the views’ state and that file (see composeui.core.study). New, Open and Save reach the model through the methods below. Without a data_name, Save and Open don’t call save_data and open_data, and the study stays the views’ JSON.

data_name: ClassVar[str | None] = None

the model’s file inside a saved study; None for a model with nothing to save

property signals: list[Signal[Unpack[tuple[Any, ...]]]]

Get the model’s signals: its attributes that are one, unless a subclass adds some.

The app gives them the main view and the model, as it does the views’ own signals. A callback that asks for main_view or model by name gets it.

new()[source]

Start the data of a new study.

Return type:

None

save_data(path)[source]

Write the data into the file path.

Parameters:

path (Path)

Return type:

None

open_data(path)[source]

Replace the data with the file path’s.

Raises InvalidStateError, leaving the data unchanged, for a file that doesn’t fit.

Parameters:

path (Path)

Return type:

None

loaded()[source]

React once New or Open has put both the views and the data in place.

MainView.loaded is emitted next, so the views’ callbacks read the data in place.

Return type:

None

close()[source]

Release what the data holds (files, connections); the app is done with it.

Return type:

None

exception composeui.core.model.RefusedError[source]

Bases: Exception

A change the model refused, changing nothing.

Its message tells the user why, as written in the code (View.refusing translates it), or translated already by a view’s tr.