Last active
May 14, 2021 16:04
-
-
Save alexdean/87cb0c087b85cb529559086b319c832f to your computer and use it in GitHub Desktop.
demonstrating a problem with the OBS python method signal_handler_disconnect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import obspython as obs | |
obs_signal_handler = obs.obs_get_signal_handler() | |
# tested in OBS 25.0.6 on OSX. July 26, 2020. | |
def script_description(): | |
return """ | |
Debug signal_handler_disconnect. | |
Steps: | |
1. open script log. | |
2. click 'call add_handlers' button. | |
3. observe message in script log: "added 'source_activate' handler." | |
4. make a source active. | |
5. observe message in script log: "source_activated() called." | |
6. click 'call remove_handlers' button. | |
7. observe message in script log: "removed 'source_activate' handler." | |
8. make a source active. | |
* expected: nothing should be printed to the script log | |
* actual: "source_activated() called." is printed to the log | |
This shows that `obs.signal_handler_disconnect` is not behaving as expected | |
or as documented in https://obsproject.com/docs/scripting.html?highlight=disconnect#signal_handler_disconnect | |
""" | |
def script_properties(): | |
props = obs.obs_properties_create() | |
obs.obs_properties_add_button(props, "add_button", "call add_handlers", add_handlers) | |
obs.obs_properties_add_button(props, "remove_button", "call remove_handlers", remove_handlers) | |
return props | |
# this is the signal handler which will be called. | |
def source_activated(obs_calldata): | |
obs.script_log(obs.LOG_INFO, 'source_activated() called.') | |
# called when user clicks the 'call add_handlers' button. | |
# | |
# it adds a signal handler. whenever a source is activated, the source_activated | |
# method will be invoked. | |
def add_handlers(props, prop): | |
global obs_signal_handler | |
obs.signal_handler_connect( | |
obs_signal_handler, | |
'source_activate', | |
source_activated | |
) | |
obs.script_log(obs.LOG_INFO, "added 'source_activate' handler.") | |
# called when user clicks the 'call add_handlers' button. | |
# | |
# this should remove the handler added by add_handlers(). | |
# after this is called, no log messages should be written when a source is made | |
# active. that is not what happens on OBS 25.0.6 on OSX. | |
def remove_handlers(props, prop): | |
global obs_signal_handler | |
obs.signal_handler_disconnect( | |
obs_signal_handler, | |
'source_activate', | |
source_activated | |
) | |
obs.script_log(obs.LOG_INFO, "removed 'source_activate' handler.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Okay so how to disconnect instead?