From 362ec22257e9bbc1ae756eed54785d3814c7c790 Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Tue, 26 Jul 2022 21:47:41 +0100 Subject: [PATCH] no longer sending event name to callback update tests accordingly --- examples/events/__main__.py | 12 +++++++----- examples/scene_rotate/__main__.py | 6 +++--- obsstudio_sdk/callback.py | 7 ++----- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/examples/events/__main__.py b/examples/events/__main__.py index a95770c..83cdac1 100644 --- a/examples/events/__main__.py +++ b/examples/events/__main__.py @@ -15,17 +15,19 @@ class Observer: print(f"Registered events: {self._cl.callback.get()}") def on_current_program_scene_changed(self, data): + """The current program scene has changed.""" print(f"Switched to scene {data['sceneName']}") - def on_scene_created(self, event, data): + def on_scene_created(self, data): """A new scene has been created.""" - print(f"{event}: {data}") + print(f"scene {data['sceneName']} has been created") - def on_input_mute_state_changed(self, event, data): + def on_input_mute_state_changed(self, data): """An input's mute state has changed.""" - print(f"{event}: {data}") + print(f"{data['inputName']} mute toggled") - def on_exit_started(self): + def on_exit_started(self, data): + """OBS has begun the shutdown process.""" print(f"OBS closing!") self._cl.unsubscribe() diff --git a/examples/scene_rotate/__main__.py b/examples/scene_rotate/__main__.py index 23f71bb..9994d05 100644 --- a/examples/scene_rotate/__main__.py +++ b/examples/scene_rotate/__main__.py @@ -4,12 +4,12 @@ import obsstudio_sdk as obs def main(): - res = cl.GetSceneList() - scenes = reversed(tuple(d["sceneName"] for d in res["d"]["responseData"]["scenes"])) + resp = cl.get_scene_list() + scenes = reversed(tuple(di["sceneName"] for di in resp["scenes"])) for sc in scenes: print(f"Switching to scene {sc}") - cl.SetCurrentProgramScene(sc) + cl.set_current_program_scene(sc) time.sleep(0.5) diff --git a/obsstudio_sdk/callback.py b/obsstudio_sdk/callback.py index fc2c445..8cc4a61 100644 --- a/obsstudio_sdk/callback.py +++ b/obsstudio_sdk/callback.py @@ -23,15 +23,12 @@ class Callback: return [self.to_camel_case(fn.__name__) for fn in self._callbacks] - def trigger(self, event, data=None): + def trigger(self, event, data): """trigger callback on update""" for fn in self._callbacks: if fn.__name__ == self.to_snake_case(event): - if "eventData" in data: - fn(event, data["eventData"]) - else: - fn(event) + fn(data.get("eventData")) def register(self, fns: Union[Iterable, Callable]): """registers callback functions"""