|
| 1 | +import obspython as S |
| 2 | +from itertools import cycle |
| 3 | + |
| 4 | +datacycle = cycle([1, 2, 3, 4, 5]) |
| 5 | + |
| 6 | +class Example: |
| 7 | + def __init__(self,source_name=None): |
| 8 | + self.source_name = source_name |
| 9 | + |
| 10 | + def update_text(self): |
| 11 | + source = S.obs_get_source_by_name(self.source_name) |
| 12 | + if source is not None: |
| 13 | + data = str(next(datacycle)) |
| 14 | + settings = S.obs_data_create() |
| 15 | + S.obs_data_set_string(settings, "text", data) |
| 16 | + S.obs_source_update(source, settings) |
| 17 | + S.obs_data_release(settings) |
| 18 | + S.obs_source_release(source) |
| 19 | + |
| 20 | + |
| 21 | +eg = Example() # class created ,obs part starts |
| 22 | + |
| 23 | + |
| 24 | +def refresh_pressed(props, prop): |
| 25 | + print("refresh pressed") |
| 26 | + eg.update_text() |
| 27 | + |
| 28 | + |
| 29 | +def script_description(): |
| 30 | + return "Using classes example" |
| 31 | + |
| 32 | + |
| 33 | +def script_update(settings): |
| 34 | + eg.source_name = S.obs_data_get_string(settings, "source") |
| 35 | + S.timer_remove(eg.update_text) |
| 36 | + if eg.source_name != "": |
| 37 | + S.timer_add(eg.update_text, 1 * 1000) |
| 38 | + |
| 39 | + |
| 40 | +def script_properties(): # ui |
| 41 | + props = S.obs_properties_create() |
| 42 | + p = S.obs_properties_add_list( |
| 43 | + props, |
| 44 | + "source", |
| 45 | + "Text Source", |
| 46 | + S.OBS_COMBO_TYPE_EDITABLE, |
| 47 | + S.OBS_COMBO_FORMAT_STRING, |
| 48 | + ) |
| 49 | + sources = S.obs_enum_sources() |
| 50 | + if sources is not None: |
| 51 | + for source in sources: |
| 52 | + source_id = S.obs_source_get_unversioned_id(source) |
| 53 | + if source_id == "text_gdiplus" or source_id == "text_ft2_source": |
| 54 | + name = S.obs_source_get_name(source) |
| 55 | + S.obs_property_list_add_string(p, name, name) |
| 56 | + |
| 57 | + S.source_list_release(sources) |
| 58 | + S.obs_properties_add_button(props, "button", "Refresh", refresh_pressed) |
| 59 | + return props |
0 commit comments