refactor examples

add scripts to pyproject
This commit is contained in:
onyx-and-iris 2022-10-28 20:19:05 +01:00
parent 87eb61170e
commit 44cd13aa48
3 changed files with 57 additions and 52 deletions

View File

@ -3,20 +3,26 @@ 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_end():
vban.apply(
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},
@ -24,39 +30,34 @@ def on_end():
}
)
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_live():
vban.strip[0].mute = False
vban.strip[7].fadeto(-6, 500)
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)
def on_current_program_scene_changed(data):
scene = data.scene_name
print(f"Switched to scene {scene}")
if fn := fget(scene):
fn()
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("<Enter> 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 <Enter> to exit\n"):
if not cmd:
break
main()

View File

@ -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()

View File

@ -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"