How to run code when user toggles my checkbox? (or other UI element? Callbacks?)

Sorry if this is a FAQ but the answer’s eluding me.

I’ve coded a simple panel with several properties and a couple of check-boxes. It shows up in the Properties box on the right of the 3D view.

I need to change the values of some of the properties if the user toggles one of the check-boxes, but I can’t find how to run code on a parameter / checkbox change. I can only see how to tie code to operators (buttons).

Is there a way to provide a callback function for parameter changes? Say I needed to let the user specify a start and end frame for recording, and needed to make sure the end frame was never before the start frame - I’d need to run code each time the user changed one of the parameters (ideally as they’re dragging the values).

Googled “blender python checkbox callback” with no luck - what should I be looking for?

Thanks!

e.g.

def my_prop_callback(self, context):
    if context.scene.my_prop:
        pass # do something here if user checks checkbox (but not uncheck, just as an example)

bpy.types.Scene.my_prop = bpy.props.BoolProperty(update=my_prop_callback)

Perfect, thanks!

Quick question: your code -

def my_prop_callback(self, context): 
    if context.scene.my_prop:
        pass # do something here

… what’s the “pass” for?

My code seems to work without it. Why is it inside the if block?

pass is a python keyword that you use as a place-holder when building your code structure. You replace it with actual code as you implement your methods.

http://docs.python.org/3.3/tutorial/controlflow.html#pass-statements

yep, i had to place something in that if-block or python would had complained about unexpected indent. You can replace it by your actual code.