Skip to content

Commit 12421a2

Browse files
committed
0.5.0 new effect and readme update
1 parent d9aeee7 commit 12421a2

File tree

2 files changed

+52
-31
lines changed

2 files changed

+52
-31
lines changed

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ _Optionally create media source_
77
- Open `Tools>Scripts`
88
- select this script
99
- set settings for it, change duration and refresh rate
10-
- preview it if need,
10+
- preview it if needed,
11+
- reset if needed,
1112
- set hotkey in `File>Settings`
12-
# Current implemented text effects
13+
# Example text effects
1314
- static
1415
> just show text
1516
> cycle threw colors
@@ -18,10 +19,18 @@ _Optionally create media source_
1819
- ![preview](https://i.imgur.com/2M2wDUD.gif)
1920
> loading text
2021
- ![preview](https://i.imgur.com/H0pgtHf.gif)
21-
> tremor effect NEW
22+
> tremor effect
2223
- ![preview](https://i.imgur.com/8G3TVGp.gif)
23-
> sanic effect NEW
24-
- ![preview](https://i.imgur.com/pvaEWlE.gif)
24+
> sanic effect
25+
- ![preview](https://i.imgur.com/pvaEWlE.gif)
26+
# How it works
27+
There is two classes:
28+
- `TextContent` - updates text
29+
- `Driver` - interacts with obs properties and controls execution
30+
31+
Interaction with obs happens on instance of `Driver` - *scripted_text_driver* it will update source name, scirpted text, selected effect and more according to settings from UI. Hotkey handling via `script_save` and `script_load` with callback on *scripted_text_driver* `hotkey_hook`. Note this callback is also attached to `PREVIEW` button in settings. It will trigger `obs_timer` , set `lock` to `False` (to run single callback at time). `obs_timer` will execute `ticker` with `interval` aka `refresh_rate`. `ticker` will execute selected text effect from settings ,substract `refresh_rate` from `duration` , check if its <= 0,then reset everything to initial state,remove itself via `obs.remove_current_callback`.
32+
To create a text effect , this naming `someefect_effect` is required and also adding it to `effects_list` in `load`. Text effects use inherited method `update_text` to update text one tick at time.
33+
2534
# Contribute
2635
[Forks](https://help.github.com/articles/fork-a-repo) are a great way to contribute to a repository.
2736
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: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from random import seed
88

99
__author__ = "upgradeQ"
10-
__version__ = "0.4.0"
10+
__version__ = "0.5.0"
1111
HOTKEY_ID = obs.OBS_INVALID_HOTKEY_ID
1212

1313
# auto release context managers
@@ -55,6 +55,13 @@ def __init__(self, text_string="This is default text", source_name=None):
5555
self.source_name = source_name
5656
self.text_string = text_string
5757
self.location = (0, 0)
58+
self._text_chars = self._wpm_chars = []
59+
self.rand_index = self.lst_index = self.wpm_index = 0
60+
self.position_swap = cycle([True, False])
61+
self.last_jump_x = self.last_jump_y = 0
62+
self.blinking = cycle([True, False])
63+
self.palette = cycle([0xFFBE0B, 0xFB5607, 0xFF006E, 0x8338EC, 0x3A86FF])
64+
self.dots = cycle([" ", ".", "..", "..."])
5865

5966
def update_text(self, scripted_text, color=None):
6067
"""takes scripted_text , sets its value in obs """
@@ -79,19 +86,9 @@ def __init__(self, text_string, source_name):
7986
self.duration = 5 * 1000
8087
self.effect_duration = 3 * 1000
8188

82-
self._text_chars = []
83-
self.rand_index = 0
84-
self.lst_index = 0
85-
self.blinking_bar = cycle([True, False])
86-
self.position_swap = cycle([True, False])
87-
self.last_jump_x = self.last_jump_y = 0
88-
self.blinking = cycle([True, False])
89-
self.palette = cycle([0xFFBE0B, 0xFB5607, 0xFF006E, 0x8338EC, 0x3A86FF])
90-
self.dots = cycle([" ", ".", "..", "..."])
91-
9289
def load(self):
9390
mapping = dict()
94-
for i in [
91+
effects_list = [
9592
"rainbow",
9693
"static",
9794
"blink",
@@ -100,7 +97,9 @@ def load(self):
10097
"sanic",
10198
"typewriter",
10299
"scrmbl",
103-
]:
100+
"fastread",
101+
]
102+
for i in effects_list:
104103
mapping[i] = getattr(self, i + "_" + "effect")
105104
return mapping
106105

@@ -122,8 +121,7 @@ def check_duration():
122121
self.duration = 5 * 1000
123122
self.lock = True
124123
self.last_jump_y, self.last_jump_x = 0, 0
125-
self.lst_index = 0
126-
self.rand_index = 0
124+
self.lst_index = self.rand_index = self.wpm_index = 0
127125

128126
try:
129127
self.txt_efcts[text_effect]()
@@ -233,7 +231,6 @@ def sanic_effect(self):
233231
with data_ar(scroll) as filter_settings:
234232
obs.obs_data_set_int(filter_settings, "speed_x", 5000)
235233
obs.obs_source_update(scroll, filter_settings)
236-
# set to zero scrolling speed and it will not interfere with others effects
237234
if self.duration // self.refresh_rate <= 3:
238235
obs.obs_source_filter_remove(source, scroll)
239236
self.duration = 0
@@ -243,20 +240,18 @@ def typewriter_effect(self):
243240
l = len(self.scripted_text)
244241
result = self.scripted_text[: self.lst_index]
245242
space_count = l - len(result)
246-
bar = "_" if next(self.blinking_bar) else ""
247-
result += bar
248243
result += space_count * " "
249244
self.lst_index += 1
250245
self.update_text(result)
251246

252247
def scrmbl_effect(self):
253-
"""tweak refresh rate & duration """
248+
"""adjust refresh rate in settings"""
254249
try:
250+
self._text_chars = list(self.text_chars(self.scripted_text))
255251
self.update_text(self._text_chars[self.rand_index])
256252
self.rand_index += 1
257253
except IndexError:
258254
self.update_text(self.scripted_text)
259-
# self.rand_index = 0
260255

261256
def text_chars(self, scripted_str):
262257
"""inspired by https://github.com/etienne-napoleone/scrmbl """
@@ -280,6 +275,20 @@ def gen(scripted_str, iterations):
280275

281276
return gen(scripted_str, 3)
282277

278+
def fastread_effect(self):
279+
"""show one word at time centered with spaces"""
280+
try:
281+
self._wpm_chars = self.wpm_chars()
282+
self.update_text(self._wpm_chars[self.wpm_index])
283+
self.wpm_index += 1
284+
except IndexError:
285+
self.update_text("")
286+
287+
def wpm_chars(self):
288+
s = self.scripted_text.split(" ")
289+
m = len(max(s, key=len))
290+
return [i.center(m, " ") for i in s]
291+
283292
def hotkey_hook(self):
284293
""" trigger hotkey event"""
285294
self.play_sound()
@@ -291,14 +300,17 @@ def hotkey_hook(self):
291300
obs.timer_add(self.ticker, interval)
292301
self.lock = False
293302

303+
def reset_duration(self):
304+
self.duration = 0
305+
294306

295307
scripted_text_driver = Driver(
296308
text_string="default string", source_name="default source name"
297309
)
298310

299311

300312
def script_description():
301-
return " Scripted text \n with effects and media "
313+
return " Scripted text \n with effects and media ".upper()
302314

303315

304316
def script_defaults(settings):
@@ -321,14 +333,10 @@ def script_update(settings):
321333
settings, "playsound"
322334
)
323335
scripted_text_driver.effect = obs.obs_data_get_string(settings, "text_effect")
324-
scripted_text_driver._text_chars = list(
325-
scripted_text_driver.text_chars(scripted_text_driver.scripted_text)
326-
)
327336
scripted_text_driver.stop_sound()
328337

329338

330339
def script_properties():
331-
"https://obsproject.com/docs/reference-properties.html"
332340
props = obs.obs_properties_create()
333341

334342
obs.obs_properties_add_text(
@@ -380,7 +388,11 @@ def script_properties():
380388
obs.source_list_release(sources)
381389

382390
obs.obs_properties_add_button(
383-
props, "button1", "preview", lambda *props: scripted_text_driver.hotkey_hook()
391+
props, "button1", "PREVIEW", lambda *props: scripted_text_driver.hotkey_hook()
392+
)
393+
394+
obs.obs_properties_add_button(
395+
props, "button2", "RESET", lambda *props: scripted_text_driver.reset_duration()
384396
)
385397

386398
return props

0 commit comments

Comments
 (0)