A few code examples are provided with the library code. Here you’ll find a step-by-step explanation of each one.

You can get the code for all the examples at the GitHub repo.

In this section

  • tally: Quick tally indicator.
  • tally-str: A different (maybe easier) way to access tally information.
  • ping: Check if your switcher is alive (ping-like).
  • scan: Scan a network for ATEM switchers.
  • scan-query: Scan a network for ATEM switchers and show some settings.
  • change-settings: Change some settings on a switcher.
  • change-settings-multi: Change some settings on multiple switchers at once.
  • events: Using PyATEMMax’s events.
  • scheduled-tasks: A more elaborate example, including scheduled tasks.

Running the examples

If you haven’t installed the library you will need to copy the library code into the examples folder before running the examples:

$ cp -r $(pwd)/PyATEMMax $(pwd)/examples/PyATEMMax

A better option, which you will need if you want to modify PyATEMMax’s code, is to create a symbolic link:

$ ln -s $(pwd)/PyATEMMax $(pwd)/examples/PyATEMMax

Hey! There’s strange code in the examples!

In order to provide some level of Type Checking and make it easier to not mix variable types, this code uses Python Type Hints (PEP 484).

This can make the code look a little strange if you’re used to the classic Python. As an example, in scheduled-tasks.py you can find this function:

def changeSwitcherSettings(switcher: PyATEMMax.ATEMMax) -> None:

This is equivalent to:

def changeSwitcherSettings(switcher):

… but includes a couple hints that can help your code editor warn you if you’re using a wrong variable type somewhere.

If you don’t know what linting is or you don’t want to know, you can safely ignore it, you don’t have to write your code like this.

Common structure in all/most examples

The usual format in these example scripts follows::

#!/usr/bin/env python3
# coding: utf-8
"""ping.py - PyATEMMax demo script.
   Part of the PyATEMMax library."""
  • the necessary import statements for the script
import argparse
import time
import PyATEMMax
  • welcome message
print(f"[{time.ctime()}] PyATEMMax demo script: ping")
  • constant initialization for the script
DEFAULT_INTERVAL = 1.0
  • read of command line arguments
parser = argparse.ArgumentParser()
parser.add_argument('ip', help='switcher IP address')
parser.add_argument('-i', '--interval',
                    help=f'wait INTERVAL seconds between pings, default: {DEFAULT_INTERVAL}',
                    default=DEFAULT_INTERVAL,
                    type=float)
args = parser.parse_args()
  • after all this initialization the ATEMMax object is usually created
switcher = PyATEMMax.ATEMMax()
  • at some point the script will tell the ATEMMax object to connect
switcher.connect(args.ip)
  • after calling connect() it’s usual to wait for the connection to be established
switcher.waitForConnection()
  • and then, after doing its stuff the script normally closes the ATEMMax object
switcher.disconnect()

Having this in mind, the step-by-step explanations will omit detail in these initialization sections, as

  • they are (more or less) the same in all the examples.
  • they do stuff with other Python libraries.

Stripped down (no-nonsense) versions

Some examples include a stripped down version which removes all non-essential clutter:

  • Command line argument management.
  • Console messages.
  • Fancy constants.
  • Shebangs and Python source encoding marks.
  • Docstrings.

While the full examples could even serve as a general CLI utilities, the stripped down versions are more likely what someone will build as a quickScript to solve a problem at hand. If you always connect to the same switcher (more likely than not) you will not need code to get the IP address from the command line, etc.