Skip to content

Implicit Settings on Button Callback #13

Description

@jdbodyfelt

Hi, sorry to bother it's me again. I have another question popping up in the property_modification.py example. Namely, in callback you mention that settings are passed implicitly, however, how do you access them within the callback? I've tried a for key, val in kwargs.items(): print(key, val), but it does not produce anything. Thank you!

Activity

  1. jdbodyfelt commented on Feb 9, 2021

    @jdbodyfelt
    Author

    As an update, I can see that args[0] holds an obs_data_t object initially (assuming it's settings), but after pushing the button, it's emptied (as well as kwargs).

  2. upgradeQ commented on Feb 10, 2021

    @upgradeQ
    Owner

    What are you trying to do? Have you found a post from @bfxdev about properties ? Maybe this is what are you looking for.
    img
    Also a page on the wiki


    The property_modification.py example snippet was written in June 2020, and there was no intention to access settings in callback. They are passed implicitly using star arguments because later you cannot access it ( as you confirmed it ). **kwargs were passed just to make sure nothing breaks.
    Take a look to a new example:

    import obspython as obs
    from itertools import count
    
    G = lambda: ...
    G.settings = None
    G.n = 0
    G.counter = count()
    
    
    def refresh_pressed(props, prop, *args):  # pass settings implicitly
        print("refresh pressed")
        if args:
            G.counter = count(obs.obs_data_get_int(args[0], "saved_int"))
        G.n = next(G.counter)
        p = obs.obs_properties_get(props, "button")
        obs.obs_property_set_description(p, f"refresh pressed {G.n} times")
        return True
    
    
    def script_description():
        return "Modify property and save/load from settings "
    
    
    def script_load(settings):
        G.settings = settings
    
    
    def script_save(settings):
        obs.obs_data_set_int(settings, "saved_int", G.n)
        G.settings = settings
    
    
    def script_properties():
        props = obs.obs_properties_create()
        b = obs.obs_properties_add_button(
            props, "button", "refresh pressed m times", refresh_pressed
        )
        obs.obs_property_set_modified_callback(b, refresh_pressed)
        obs.obs_properties_apply_settings(props, G.settings)
        return props

    In order to access settings in callback they must be global.

  3. jdbodyfelt commented on Feb 10, 2021

    @jdbodyfelt
    Author

    Thank you! On button press, I'm looking to auto-iterate integer counter widgets. Been using the global solution, but seems in script_update I may have been assigning in the wrong direction (settings = G.settings). I'll play some more with it, and if I get it working I'll post my solution...

  4. MarioMey commented on Feb 10, 2021

    @MarioMey
    Contributor

    @jdbodyfelt if you have more questions, ask them in Discussion section. There is where I ask my doubts 😉.

  5. Repository owner locked and limited conversation to collaborators on Jul 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions