Skip to content

Source

Base abstraction of managed data.

Usage

Data sources are abstractions that allow you to define the data being managed by your application independent of the GUI representation of that data. For details on the use of data sources, see the topic guide.

The base class referenced on this page, Source, isn't useful on its own. It provides an implementation of the notification API that data sources must provide, and is subclassed by:

It can also be used by custom data source implementations.

Reference

toga.sources.Source

Source()

Bases: Generic[ListenerT]

A base class for data sources, providing an implementation of data notifications.

listeners property

listeners: list[ListenerT]

The listeners of this data source.

RETURNS DESCRIPTION
list[ListenerT]

A list of objects that are listening to this data source.

add_listener

add_listener(listener: ListenerT) -> None

Add a new listener to this data source.

If the listener is already registered on this data source, the request to add is ignored.

PARAMETER DESCRIPTION
listener

The listener to add

TYPE: ListenerT

notify

notify(notification: str, **kwargs: object) -> None

Notify all listeners an event has occurred.

PARAMETER DESCRIPTION
notification

The notification to emit.

TYPE: str

kwargs

The data associated with the notification.

TYPE: object DEFAULT: {}

remove_listener

remove_listener(listener: ListenerT) -> None

Remove a listener from this data source.

PARAMETER DESCRIPTION
listener

The listener to remove.

TYPE: ListenerT