tslumd.sender
The UmdSender
class is used to send tally information as UMD packets to clients on the network.
The remote addresses can be specified on initialization by giving a Sequence of tuples containing the address and port (Client
). The UmdSender.clients
container may also be modified on the instance if clients need to be added or removed while running.
Note
Modifying UmdSender.clients
is not a thread-safe operation and should only be done from within the same thread the instance belongs to.
UmdSender does not begin communication when first created.
Starting and stopping can be done by calling the UmdSender.open
and UmdSender.close
methods manually
UmdSender-open-close
>>> import asyncio >>> from tslumd import UmdSender >>> async def run(): ... sender = UmdSender(clients=[('127.0.0.1', 65000)]) ... await sender.open() ... ... ... await sender.close() >>> asyncio.run(run())
or it can be used as an asynchronous context manager
in an async with
block
UmdSender-async-with
>>> import asyncio >>> from tslumd import UmdSender >>> async def run(): ... sender = UmdSender(clients=[('127.0.0.1', 65000)]) ... async with sender: ... ... >>> asyncio.run(run())
UmdSender creates Screens <screen-object>
and Tallies <tally-object>
using one of the following methods:
UmdSender.add_tally
UmdSender.get_or_create_tally
UmdSender.get_or_create_screen
Additionally, it will create objects as needed when one of the Shortcut Methods are used.
Screens are stored in the UmdSender.screens
dictionary using their ~tslumd.tallyobj.Screen.index
as keys.
While each Screen object contains its own Tally instances, UmdSender stores all Tally objects from all Screens in its own ~UmdSender.tallies
dictionary by their Tally.id <tslumd.tallyobj.Tally.id>
(TallyKey
)
In UmdSender
, there are several shortcut methods defined to create and update tallies without needing to operate on ~tslumd.tallyobj.Tally
objects directly.
All of these methods operate using a TallyKey
to specify the Screen <screen-object>
and Tally <tally-object>
.
For UmdSender.set_tally_text
, the TallyKey
and the text are the only two arguments.
For UmdSender.set_tally_color
, the TallyKey
, TallyType
and TallyColor
arguments are used.
UmdSender-shortcuts
>>> from pprint import pprint >>> from tslumd import UmdSender, TallyType, TallyColor >>> sender = UmdSender(clients=[('127.0.0.1', 65000)]) >>> loop.run_until_complete(sender.open()) >>> for cam_num in range(1, 5): ... sender.set_tally_text((1, cam_num), f'Camera {cam_num}') # Creates a new Tally >>> pprint(sender.tallies) {(1, 1): <Tally: ((1, 1) - "Camera 1")>, (1, 2): <Tally: ((1, 2) - "Camera 2")>, (1, 3): <Tally: ((1, 3) - "Camera 3")>, (1, 4): <Tally: ((1, 4) - "Camera 4")>} >>> sender.set_tally_color((1, 1), TallyType.rh_tally, TallyColor.RED) >>> cam1_tally = sender.tallies[(1, 1)] >>> pprint(cam1_tally.rh_tally) <TallyColor.RED: 1> >>> # Rename "Camera 4" so you remember not to take their shot for too long >>> sender.set_tally_text((1, 4), 'Handheld') >>> pprint(sender.tallies) {(1, 1): <Tally: ((1, 1) - "Camera 1")>, (1, 2): <Tally: ((1, 2) - "Camera 2")>, (1, 3): <Tally: ((1, 3) - "Camera 3")>, (1, 4): <Tally: ((1, 4) - "Handheld")>} >>> loop.run_until_complete(sender.close())
In the example above, all of the changes would be sent automatically if the UmdSender were open (and the event loop running). To accomplish this, it listens for property changes on each ~tslumd.tallyobj.Tally
and ~tslumd.tallyobj.Screen
it contains. This also means that one can operate on a ~tslumd.tallyobj.Tally
object directly.
UmdSender-tally-props
>>> cam2_tally = sender.tallies[(1, 2)] >>> cam2_tally.text = 'Jim' >>> pprint(sender.tallies) {(1, 1): <Tally: ((1, 1) - "Camera 1")>, (1, 2): <Tally: ((1, 2) - "Jim")>, (1, 3): <Tally: ((1, 3) - "Camera 3")>, (1, 4): <Tally: ((1, 4) - "Handheld")>} >>> cam2_tally.txt_tally = TallyColor.GREEN >>> pprint(sender.tallies[cam2_tally.id].txt_tally) <TallyColor.GREEN: 2>
In some cases, it may be desirable for all tally lights to be remain in their last state when UmdSender closes. It could also be preferable to ensure all of them are "off".
This behavior can be set for either case by setting UmdSender.all_off_on_close
either upon creation (as an init argument), or by setting the instance attribute (must be done before ~UmdSender.close
is called).
The default behavior is to leave all tallies in their last state. If ~UmdSender.all_off_on_close
is set True however, messages will be sent for all tallies across all screens to be "OFF" right before shutdown.