Overview

This project uses the Observer Pattern as its primary means of integration with other code. This is handled by the python-dispatch library which provides methods of subscribing to events and property changes.

Tally Object

The primary object used for sending or receiving tally information is the Tally object.

When receiving, the Tally object will emit an Tally.on_update event on any change of state with the Tally instance as the first argument and the property names as the second:

>>> from tslumd import Tally, TallyColor
>>> def my_callback(tally: Tally, props_changed, **kwargs):
...     for name in props_changed:
...         value = getattr(tally, name)
...         print(f'my_callback: {tally!r}.{name} = {value}')
>>> tally = Tally(0)
>>> # bind `my_callback` to the `on_update` event
>>> tally.bind(on_update=my_callback)
>>> # rh_tally is initialized to "OFF"
>>> tally.rh_tally
<TallyColor.OFF: 0>
>>> tally.rh_tally = TallyColor.RED
my_callback: <Tally: (0 - "")>.rh_tally = RED

One can also subscribe to any of the properties individually:

>>> from tslumd import Tally, TallyColor
>>> def my_callback(tally: Tally, value, **kwargs):
...     prop = kwargs['property']
...     print(f'my_callback: {tally!r}.{prop.name} = {value}')
>>> tally = Tally(0, text='foo')
>>> tally
<Tally: (0 - "foo")>
>>> # bind `my_callback` to the `text` property
>>> tally.bind(text=my_callback)
>>> # does not reach the callback
>>> tally.rh_tally = TallyColor.RED
>>> # but this does
>>> tally.text = 'bar'
my_callback: <Tally: (0 - "bar")>.text = bar

Screen Object

Tally objects should never be created directly (as in the examples above). They are instead created by the Screen object and stored in its Screen.tallies dictionary, using the Tally’s index as the key.

When receiving, they are created automatically when necessary (when data is received). The Screen.on_tally_added event can be used to listen for new Tally objects.

Screens also propagate the “on_update” event for all of their Tally objects and emit their own Screen.on_tally_update event. This can reduce the amount of code and callbacks when handling multiple tallies.

When sending, Tally objects are created by using either the Screen.add_tally() and Screen.get_or_create_tally() methods.

Glossary

TallyKey

Combination of Screen.index and Tally.index used to uniquely identify a single tally (or Display) within a single Screen.

TallyKey is a 2-tuple of integers and is available as the Tally.id.

TallyType

TallyType is an enum used to aid in mapping the three Tally Tally Indicators to the Tally.lh_tally, Tally.txt_tally and Tally.rh_tally attributes

TallyColor

TallyColor is an enum defining the four allowable colors for an indicator (including “off”)