From 44cd13aa4834d8aa6d6cb21de020e1afb56e51eb Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Fri, 28 Oct 2022 20:19:05 +0100 Subject: [PATCH] refactor examples add scripts to pyproject --- examples/obs/__main__.py | 101 +++++++++++++++++----------------- examples/observer/__main__.py | 4 +- pyproject.toml | 4 ++ 3 files changed, 57 insertions(+), 52 deletions(-) diff --git a/examples/obs/__main__.py b/examples/obs/__main__.py index 72435a0..4eede23 100644 --- a/examples/obs/__main__.py +++ b/examples/obs/__main__.py @@ -3,60 +3,61 @@ import logging import obsws_python as obs import vban_cmd - -def on_start(): - vban.strip[0].mute = True - vban.strip[1].B1 = True - vban.strip[2].B2 = True +logging.basicConfig(level=logging.INFO) -def on_brb(): - vban.strip[7].fadeto(0, 500) - vban.bus[0].mute = True +class Observer: + def __init__(self, vban): + self.vban = vban + self.client = obs.EventClient() + self.client.callback.register(self.on_current_program_scene_changed) + + def on_start(self): + self.vban.strip[0].mute = True + self.vban.strip[1].B1 = True + self.vban.strip[2].B2 = True + + def on_brb(self): + self.vban.strip[7].fadeto(0, 500) + self.vban.bus[0].mute = True + + def on_end(self): + self.vban.apply( + { + "strip-0": {"mute": True}, + "strip-1": {"mute": True, "B1": False}, + "strip-2": {"mute": True, "B1": False}, + } + ) + + def on_live(self): + self.vban.strip[0].mute = False + self.vban.strip[7].fadeto(-6, 500) + self.vban.strip[7].A3 = True + + def on_current_program_scene_changed(self, data): + def fget(scene): + run = { + "START": self.on_start, + "BRB": self.on_brb, + "END": self.on_end, + "LIVE": self.on_live, + } + return run.get(scene) + + scene = data.scene_name + print(f"Switched to scene {scene}") + if fn := fget(scene): + fn() -def on_end(): - vban.apply( - { - "strip-0": {"mute": True}, - "strip-1": {"mute": True, "B1": False}, - "strip-2": {"mute": True, "B1": False}, - } - ) - - -def on_live(): - vban.strip[0].mute = False - vban.strip[7].fadeto(-6, 500) - vban.strip[7].A3 = True - - -def on_current_program_scene_changed(data): - scene = data.scene_name - print(f"Switched to scene {scene}") - - match scene: - case "START": - on_start() - case "BRB": - on_brb() - case "END": - on_end() - case "LIVE": - on_live() - case _: - pass +def main(): + with vban_cmd.api("potato", sync=True) as vban: + obs = Observer(vban) + while cmd := input(" to exit\n"): + if not cmd: + break if __name__ == "__main__": - logging.basicConfig(level=logging.INFO) - - kind_id = "potato" - - with vban_cmd.api(kind_id, sync=True) as vban: - cl = obs.EventClient() - cl.callback.register(on_current_program_scene_changed) - - while cmd := input("Press to exit\n"): - if not cmd: - break + main() diff --git a/examples/observer/__main__.py b/examples/observer/__main__.py index 8d95011..a39c988 100644 --- a/examples/observer/__main__.py +++ b/examples/observer/__main__.py @@ -2,6 +2,8 @@ import logging import vban_cmd +logging.basicConfig(level=logging.INFO) + class Observer: def __init__(self, vban): @@ -33,6 +35,4 @@ def main(): if __name__ == "__main__": - logging.basicConfig(level=logging.INFO) - main() diff --git a/pyproject.toml b/pyproject.toml index 7e972f5..776c3d0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -22,3 +22,7 @@ isort = "^5.10.1" [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" + +[tool.poetry.scripts] +obs = "examples.obs.__main__:main" +observer = "examples.observer.__main__:main"