SourceItem#

class deeptrack.sources.base.SourceItem(callbacks: Sequence[Callable[[SourceItem], None]], **kwargs: Any)#

Bases: dict

A dictionary-like object that triggers a list of callbacks when called.

SourceItem wraps a dictionary entry that activates one or more callbacks when accessed via calling. This mechanism ensures that all dependent `DeepTrackNode`s are updated when a particular item in the source is selected.

Parameters#

callbacks: Sequence[Callable[[SourceItem], None]]

A sequence of callback functions that are executed when the item is called. Each function receives the SourceItem itself as argument.

Attributes#

_callbacks: list[Callable[[SourceItem], None]]

Internal list of callbacks that are triggered on call.

Methods#

__call__() -> SourceItem

Executes all callbacks and returns the item.

__repr__() -> str

Returns a string representation including the dictionary content and number of callbacks.

Examples#

>>> from deeptrack.sources import SourceItem

Implement a callback function:

>>> def log_callback(item):
...     print(f"CALLBACK - Accessed item: {item}")

Create a SourceItem with dictionary contents and callbacks:

>>> item = SourceItem(callbacks=[log_callback], a=1, b=2)

Call the item to trigger the callbacks:

>>> item();
CALLBACK - Accessed item: SourceItem({'a': 1, 'b': 2}, 1 callback(s))

Methods Summary

__call__()

Call the item, triggering all associated callbacks.

Methods Documentation

__call__() SourceItem#

Call the item, triggering all associated callbacks.

Returns#

SourceItem

The item itself, after invoking all callbacks.