Skip to content

ValueSource

Abstractions of managed atomic values.

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.

ValueSource is an wrapper around a single atomic value.

from toga.sources import ValueSource

source = ValueSource(42)

# Get the value managed by the source
print(f"Meaning of life, the universe, and everything is {source.value}")

Custom ValueSources

A custom ValueSource has 3 requirements:

  • It must have an accessor attribute that describes the name of the attribute that stores the data for the source.
  • It must have an attribute matching the name of the accessor that can be used to set and retrieve and the value.
  • When any change is made to the value, a change notification will be emitted.

Reference

toga.sources.ValueSource

ValueSource(value: object = None, accessor: str = 'value')

Bases: Source

PARAMETER DESCRIPTION
value

TYPE: object DEFAULT: None

accessor

TYPE: str DEFAULT: 'value'

toga.sources.ValueListener

Bases: Protocol, Generic[ItemT]

The protocol that must be implemented by objects that will act as a listener on a value data source.

source_change

source_change(*, item: ItemT) -> None

A change has occurred in an item.

PARAMETER DESCRIPTION
item

The data object that has changed.

TYPE: ItemT