Skip to content

Commit 21c51e1

Browse files
committed
fix startup , add loading_effect
1 parent 61e3d16 commit 21c51e1

File tree

2 files changed

+55
-43
lines changed

2 files changed

+55
-43
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ _Optionally create media source_
1212
# Current implemented text effects
1313
- static
1414
> just show text
15-
> cycle threw colors
16-
![preview](https://i.imgur.com/GmhEDv4.gif)
17-
18-
> blinking text
19-
![preview](https://i.imgur.com/2M2wDUD.gif)
15+
> cycle threw colors
16+
- ![preview](https://i.imgur.com/GmhEDv4.gif)
17+
> blinking text
18+
- ![preview](https://i.imgur.com/2M2wDUD.gif)
19+
> loading text NEW
20+
- ![preview](https://i.imgur.com/H0pgtHf.gif)
2021
# Contribute
21-
Report bugs or suggestions in issues.
22+
[Forks](https://help.github.com/articles/fork-a-repo) are a great way to contribute to a repository.
23+
After forking a repository, you can send the original author a [pull request](https://help.github.com/articles/using-pull-requests)

scripted_text.py

Lines changed: 47 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import string
66

77
__author__ = "upgradeQ"
8-
__version__ = "0.1.1"
9-
8+
__version__ = "0.2.0"
9+
HOTKEY_ID = obs.OBS_INVALID_HOTKEY_ID
1010

1111
class TextContent:
1212
def __init__(self, text_string="This is default text", source_name=None):
@@ -31,18 +31,16 @@ def __init__(self, text_string, source_name):
3131
super().__init__(text_string, source_name)
3232
self.scripted_text = "default value"
3333
self.sound_source_name = None
34-
self.hotkey_id_scripted_text = obs.OBS_INVALID_HOTKEY_ID
3534
self.effect = "static" # take value from property
3635

37-
self.preview = True
38-
self.hide = False
39-
36+
self.lock = True
4037
self.refresh_rate = 250
4138
self.duration = 5 * 1000
4239
self.effect_duration = 3 * 1000
4340

4441
self.blinking = cycle([True, False])
45-
self.palette = cycle([0xFFBE0B, 0xFB5607, 0xFF006E, 0x8338EC, 0x3A86FF])
42+
self.palette = cycle([0xFFBE0B, 0xFB5607, 0xFF006E, 0x8338EC, 0x3A86FF])
43+
self.dots = cycle([" ", ".", "..", "..."])
4644

4745
def play_sound(self):
4846
source = obs.obs_get_source_by_name(self.sound_source_name)
@@ -64,15 +62,16 @@ def ticker(self, text_effect):
6462
self.blink_effect()
6563
if text_effect == "rainbow":
6664
self.rainbow_effect()
65+
if text_effect == "loading":
66+
self.loading_effect()
6767

6868
self.duration -= self.refresh_rate
6969
print(self.duration)
7070
if self.duration <= 0:
7171
self.update_text("")
7272
obs.remove_current_callback()
7373
self.duration = 5 * 1000
74-
self.preview = True
75-
self.hide = True
74+
self.lock = True
7675

7776
def static_effect(self):
7877
self.update_text(self.scripted_text)
@@ -87,29 +86,37 @@ def blink_effect(self):
8786
else:
8887
self.update_text("")
8988

89+
def loading_effect(self):
90+
self.update_text(self.scripted_text + next(self.dots))
91+
9092
def hotkey_hook(self):
9193
""" trigger hotkey event"""
9294
self.play_sound()
9395
print("effect duration ", self.effect_duration)
9496
self.duration = self.effect_duration
9597
print("effect duration ", self.duration)
9698
interval = self.refresh_rate
97-
if self.preview:
99+
if self.lock:
98100
self.ticker = partial(self.ticker, text_effect=self.effect)
99101
obs.timer_add(self.ticker, interval)
100-
self.preview = False
102+
self.lock = False
101103

102104

103105
scripted_text_driver = Driver(
104106
text_string="default string", source_name="default source name"
105107
)
106108

107-
108-
109109
def script_description():
110110
return " Scripted text \n with effects and media "
111111

112112

113+
def script_defaults(settings):
114+
obs.obs_data_set_default_int(
115+
settings, "refresh_rate", scripted_text_driver.refresh_rate
116+
)
117+
obs.obs_data_set_default_int(settings, "duration", scripted_text_driver.duration)
118+
119+
113120
def script_update(settings):
114121
scripted_text_driver.source_name = obs.obs_data_get_string(settings, "source")
115122

@@ -119,9 +126,7 @@ def script_update(settings):
119126
scripted_text_driver.refresh_rate = obs.obs_data_get_int(settings, "refresh_rate")
120127

121128
print("setting duration")
122-
scripted_text_driver.effect_duration = obs.obs_data_get_int(
123-
settings, "duration"
124-
)
129+
scripted_text_driver.effect_duration = obs.obs_data_get_int(settings, "duration")
125130
scripted_text_driver.sound_source_name = obs.obs_data_get_string(
126131
settings, "playsound"
127132
)
@@ -130,25 +135,19 @@ def script_update(settings):
130135
scripted_text_driver.stop_sound()
131136

132137

133-
def script_save(settings):
134-
hotkey_save_array_scripted_text = obs.obs_hotkey_save(
135-
scripted_text_driver.hotkey_id_scripted_text
136-
)
137-
obs.obs_data_set_array(
138-
settings, "scripted_text_hotkey", hotkey_save_array_scripted_text
139-
)
140-
obs.obs_data_array_release(hotkey_save_array_scripted_text)
141-
142-
143138
def script_properties():
144139
"https://obsproject.com/docs/reference-properties.html"
145140
props = obs.obs_properties_create()
146141

147142
obs.obs_properties_add_text(
148143
props, "scripted_text", "Scripted text", obs.OBS_TEXT_DEFAULT
149144
)
150-
obs.obs_properties_add_int(props, "refresh_rate", "Refresh rate(ms)", 50, 5*1000, 1)
151-
obs.obs_properties_add_int(props, "duration", "Duration shown(ms)", 1*1000, 3600*1000, 1)
145+
obs.obs_properties_add_int(
146+
props, "refresh_rate", "Refresh rate(ms)", 50, 5 * 1000, 1
147+
)
148+
obs.obs_properties_add_int(
149+
props, "duration", "Duration shown(ms)", 1 * 1000, 3600 * 1000, 1
150+
)
152151

153152
p = obs.obs_properties_add_list(
154153
props,
@@ -172,7 +171,7 @@ def script_properties():
172171
obs.OBS_COMBO_FORMAT_STRING,
173172
)
174173

175-
for i in ["rainbow", "static", "blink"]:
174+
for i in ["rainbow", "static", "blink", "loading"]:
176175
obs.obs_property_list_add_string(tp, i, i)
177176

178177
sources = obs.obs_enum_sources()
@@ -189,21 +188,32 @@ def script_properties():
189188

190189
obs.source_list_release(sources)
191190

192-
obs.obs_properties_add_button(props, "button1", "preview",lambda *props:scripted_text_driver.hotkey_hook())
191+
obs.obs_properties_add_button(
192+
props, "button1", "preview", lambda *props: scripted_text_driver.hotkey_hook()
193+
)
193194

194195
return props
195196

196197

198+
def script_save(settings):
199+
global HOTKEY_ID
200+
hotkey_save_array = obs.obs_hotkey_save(HOTKEY_ID)
201+
print('htksave',hotkey_save_array)
202+
obs.obs_data_set_array(settings, "scripted_text_hotkey", hotkey_save_array)
203+
obs.obs_data_array_release(hotkey_save_array)
204+
205+
197206
def script_load(settings):
207+
global HOTKEY_ID
208+
198209
def callback_up(pressed):
199210
if pressed:
200211
return scripted_text_driver.hotkey_hook()
201212

202-
hotkey_id_scripted_text = obs.obs_hotkey_register_frontend(
203-
"Trigger sripted text", "Trigger sripted text", callback_up
204-
)
205-
hotkey_save_array_scripted_text = obs.obs_data_get_array(
206-
settings, "scripted_text_hotkey"
213+
HOTKEY_ID = obs.obs_hotkey_register_frontend(
214+
"scripted_text_hotkey", "Trigger sripted text", callback_up
207215
)
208-
obs.obs_hotkey_load(hotkey_id_scripted_text, hotkey_save_array_scripted_text)
209-
obs.obs_data_array_release(hotkey_save_array_scripted_text)
216+
obs.obs_data_get_array(settings, "scripted_text_hotkey")
217+
hotkey_save_array = obs.obs_data_get_array(settings, "scripted_text_hotkey")
218+
obs.obs_hotkey_load(HOTKEY_ID, hotkey_save_array)
219+
obs.obs_data_array_release(hotkey_save_array)

0 commit comments

Comments
 (0)