Skip to content

Commit 11a25e5

Browse files
committed
Add debug notes
1 parent f8fcafe commit 11a25e5

File tree

3 files changed

+92
-3
lines changed

3 files changed

+92
-3
lines changed

README.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# OBS Studio Python Scripting Cheatsheet
2-
`obspython` OBS Studio API.Obs scripts examples in /src. Each obs script example mostly will operate on *existsing* `TEXT SOURCE`
2+
- `obspython` OBS Studio API.Obs scripts examples in `/src`
3+
- Each obs script example mostly will operate on *existsing* text source
4+
- It is possible to duplicate scripts and re-add them to OBS ( names must be different)
35
# Table of content
46
- [Using classes](#using-classes)
57
- [with statement](#with-statement)
@@ -18,6 +20,7 @@
1820
- [Timing (sequential primitives) ](#timing-sequential-primitives)
1921
- [Hotkey](#hotkey)
2022
- [Links](#links)
23+
- [Debug](#debug)
2124
- [Contribute](#contribute)
2225

2326
## Using classes
@@ -324,10 +327,24 @@ def script_save(settings):
324327
```
325328
- [Full example](src/obs_httkeys.py)
326329
- [Example with global ](src/hotkey_exmpl.py)
330+
331+
# Debug
332+
There is no stdin therefore you can't use pdb , options are:
333+
- using `print`
334+
- using pycharm remote debugging (localhost)
335+
- using [vscode](https://code.visualstudio.com/docs/python/debugging) attach to the process:
336+
- Load python extension
337+
- open script file , `pip install debugpy` , place `debugpy.breakpoint()` somewhere
338+
- Run (F5) select configuration ( Attach using Process ID)
339+
- select obs (on windows `obs64.exe`)
340+
- View select Debug Console (ctrl+shift+y)
341+
- [Example debugpy obs ](src/debug_exmpl.py)
342+
343+
![screenshot](src/debug.png)
344+
327345
# Links
328346
- [Scripts](https://obsproject.com/forum/resources/categories/scripts.5/)
329347
- [Repo](https://github.com/obsproject/obs-studio)
330348
- [Docs](https://obsproject.com/docs/) , [Docs/scripting](https://obsproject.com/docs/scripting.html) , [Docs index](https://obsproject.com/docs/genindex.html)
331349
# Contribute
332-
[Forks](https://help.github.com/articles/fork-a-repo) are a great way to contribute to a repository.
333-
After forking a repository, you can send the original author a [pull request](https://help.github.com/articles/using-pull-requests)
350+
Contributions are welcome!

src/debug.png

213 KB
Loading

src/debug_exmpl.py

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import obspython as obs
2+
import debugpy
3+
4+
5+
class Hotkey:
6+
def __init__(self, callback, obs_settings, _id):
7+
self.obs_data = obs_settings
8+
self.hotkey_id = obs.OBS_INVALID_HOTKEY_ID
9+
self.hotkey_saved_key = None
10+
self.callback = callback
11+
self._id = _id
12+
13+
self.load_hotkey()
14+
self.register_hotkey()
15+
self.save_hotkey()
16+
17+
def register_hotkey(self):
18+
description = "Htk " + str(self._id)
19+
self.hotkey_id = obs.obs_hotkey_register_frontend(
20+
"htk_id" + str(self._id), description, self.callback
21+
)
22+
obs.obs_hotkey_load(self.hotkey_id, self.hotkey_saved_key)
23+
24+
def load_hotkey(self):
25+
self.hotkey_saved_key = obs.obs_data_get_array(
26+
self.obs_data, "htk_id" + str(self._id)
27+
)
28+
obs.obs_data_array_release(self.hotkey_saved_key)
29+
30+
def save_hotkey(self):
31+
self.hotkey_saved_key = obs.obs_hotkey_save(self.hotkey_id)
32+
obs.obs_data_set_array(
33+
self.obs_data, "htk_id" + str(self._id), self.hotkey_saved_key
34+
)
35+
obs.obs_data_array_release(self.hotkey_saved_key)
36+
37+
38+
class h:
39+
htk_copy = None # this attribute will hold instance of Hotkey
40+
41+
42+
def cb1(pressed):
43+
debugpy.breakpoint()
44+
if pressed:
45+
print("callback1: " + e1.txt)
46+
47+
48+
class e:
49+
txt = "default txt"
50+
51+
52+
e1 = e()
53+
h1 = h()
54+
55+
56+
def script_properties():
57+
props = obs.obs_properties_create()
58+
obs.obs_properties_add_text(props, "_text1", "_text1:", obs.OBS_TEXT_DEFAULT)
59+
return props
60+
61+
62+
def script_update(settings):
63+
_text1 = obs.obs_data_get_string(settings, "_text1")
64+
e1.txt = _text1
65+
66+
67+
def script_load(settings):
68+
h1.htk_copy = Hotkey(cb1, settings, "h1_id")
69+
70+
71+
def script_save(settings):
72+
h1.htk_copy.save_hotkey()

0 commit comments

Comments
 (0)