add_callback¶
- echo.add_callback(instance, prop, callback, echo_old=False, priority=0, validator=False)[source]¶
Attach a callback function to a property in an instance
- Parameters:
- instance
The instance to add the callback to
- propstr
Name of callback property in instance
- callbackfunc
The callback function to add
- echo_oldbool, optional
If True, the callback function will be invoked with both the old and new values of the property, as
func(old, new). If False (the default), will be invoked asfunc(new)- priorityint, optional
This can optionally be used to force a certain order of execution of callbacks (larger values indicate a higher priority).
- validatorbool, optional
Whether the callback is a validator, which is a special kind of callback that gets called before the property is set. The validator can return a modified value (for example it can be used to change the types of values or change properties in-place) or it can also raise an exception.
Examples
class Foo: bar = CallbackProperty(0) def callback(value): pass f = Foo() add_callback(f, 'bar', callback)