-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_switcher.py
More file actions
61 lines (52 loc) · 2.33 KB
/
simple_switcher.py
File metadata and controls
61 lines (52 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from json import load
from time import monotonic
from obswebsocket import obsws, requests
from functools import partial
import tkinter as tk
from os import path
from argparse import ArgumentParser
from obswebsocket.exceptions import ConnectionFailure
from websocket._exceptions import WebSocketConnectionClosedException
def switch(ws: obsws, requested_name: str) -> None:
print(f"Call scene {requested_name}")
ws.call(requests.SetCurrentScene(requested_name))
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument('creds', nargs='?', help="Optional path to creditentials",
default=f"{path.dirname(__file__)}/creditentials.json")
args = parser.parse_args()
# Loading creditentials for OBSwebsocket
print("Loading creditentials...")
with open(args.creds, 'r') as creds:
creditentials: dict = load(creds)
ws = obsws(creditentials["host"],
creditentials["port"], creditentials["password"])
delay, future_delay = monotonic(), 2
try:
print("Connecting to OBS...")
ws.connect()
scenes_switcher: list = [scene['name']
for scene in ws.call(requests.GetSceneList()).getScenes()]
layout: int = 160
root = tk.Tk()
root.geometry(f"{layout}x{(len(scenes_switcher)*layout)//3}")
root.title('Switcher')
root.resizable(0, 0)
tk.Grid.columnconfigure(root, 0, weight=1)
for i in range(len(scenes_switcher)):
tk.Grid.rowconfigure(root, i, weight=1)
button_list = [tk.Button(master=root, text=scene, bg='#2f3136', fg='white', command=partial(
switch, ws=ws, requested_name=scene)) for scene in scenes_switcher]
[button.grid(sticky="nswe", column=0, row=i)
for i, button in enumerate(button_list)]
root.mainloop()
except KeyboardInterrupt:
ws.disconnect()
print("Connexion closed!")
except ConnectionFailure:
print(
"Could not connect to OBS ; please check creditentials file and if OBS is up and running.")
except WebSocketConnectionClosedException:
print("Connexion to OBS was prematurely closed ; aborting...")
except ConnectionRefusedError:
print("OBS refused connexion to the switcher.")