CallbackProperty¶
- class echo.CallbackProperty(default=None, docstring=None, getter=None, setter=None)[source]¶
Bases:
object
A property that callback functions can be added to.
When a callback property changes value, each callback function is called with information about the state change. Otherwise, callback properties behave just like normal instance variables.
CallbackProperties must be defined at the class level. Use the helper function
add_callback()
to attach a callback to a specific instance of a class with CallbackProperties- Parameters
- default
The initial value for the property
- docstringstr
The docstring for the property
- getter, setterfunc
Custom getter and setter functions (advanced)
Methods
add_callback
(instance, func[, echo_old, ...])Add a callback to a specific instance that manages this property
clear_callbacks
(instance)Remove all callbacks on this property.
disable
(instance)Disable callbacks for a specific instance
enable
(instance)Enable previously-disabled callbacks for a specific instance
notify
(instance, old, new)Call all callback functions with the current value
remove_callback
(instance, func)Remove a previously-added callback
setter
(func)Method to use as a decorator, to mimic @property.setter
enabled
Methods Summary
add_callback
(instance, func[, echo_old, ...])Add a callback to a specific instance that manages this property
clear_callbacks
(instance)Remove all callbacks on this property.
disable
(instance)Disable callbacks for a specific instance
enable
(instance)Enable previously-disabled callbacks for a specific instance
enabled
(instance)notify
(instance, old, new)Call all callback functions with the current value
remove_callback
(instance, func)Remove a previously-added callback
setter
(func)Method to use as a decorator, to mimic @property.setter
Methods Documentation
- add_callback(instance, func, echo_old=False, priority=0)[source]¶
Add a callback to a specific instance that manages this property
- Parameters
- instance
The instance to add the callback to
- funcfunc
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).
- notify(instance, old, new)[source]¶
Call all callback functions with the current value
Each callback will either be called using callback(new) or callback(old, new) depending on whether
echo_old
was set to True when callingadd_callback()
- Parameters
- instance
The instance to consider
- old
The old value of the property
- new
The new value of the property