forked from upgradeQ/Streaming-Software-Scripting-Reference
-
Notifications
You must be signed in to change notification settings - Fork 1
/
busy_thread.py
47 lines (33 loc) · 1.07 KB
/
busy_thread.py
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
import obspython as S
import threading
from time import sleep
def hook(obs_htk_id, htk_id, callback):
json_data = '{"%s":[{"key":"%s"}]}' % (htk_id, obs_htk_id)
s = S.obs_data_create_from_json(json_data)
a = S.obs_data_get_array(s, htk_id)
h = S.obs_hotkey_register_frontend(htk_id, obs_htk_id, callback)
S.obs_hotkey_load(h, a)
S.obs_data_array_release(a)
S.obs_data_release(s)
data = lambda: ...
data.thread_paused = True
data.status = "empty"
def toggle_thread():
data.thread_paused = not data.thread_paused
def callback(pressed):
if pressed:
toggle_thread()
def busy_thread():
while True:
if not data.thread_paused:
sleep(0.3)
data.status = "active"
# print to stdoud crashes OBS on exit
else:
sleep(0.5)
data.status = "inactive"
print('Press the "~" to toggle on/off')
hook("OBS_KEY_ASCIITILDE", "id_", callback)
S.timer_add(lambda: print(data.status), 500)
t = threading.Thread(target=busy_thread)
t.start()