CallbackProperty

class glue.external.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)

Parameters

default – The initial value for the property

Methods Summary

add_callback(self, instance, func[, …])

Add a callback to a specific instance that manages this property

clear_callbacks(self, instance)

Remove all callbacks on this property.

disable(self, instance)

Disable callbacks for a specific instance

enable(self, instance)

Enable previously-disabled callbacks for a specific instance

enabled(self, instance)

notify(self, instance, old, new)

Call all callback functions with the current value

remove_callback(self, instance, func)

Remove a previously-added callback

setter(self, func)

Method to use as a decorator, to mimic @property.setter

Methods Documentation

add_callback(self, 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 as func(new)

priorityint, optional

This can optionally be used to force a certain order of execution of callbacks (larger values indicate a higher priority).

clear_callbacks(self, instance)[source]

Remove all callbacks on this property.

disable(self, instance)[source]

Disable callbacks for a specific instance

enable(self, instance)[source]

Enable previously-disabled callbacks for a specific instance

enabled(self, instance)[source]
notify(self, 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 calling add_callback()

Parameters
instance

The instance to consider

old

The old value of the property

new

The new value of the property

remove_callback(self, instance, func)[source]

Remove a previously-added callback

Parameters
instance

The instance to detach the callback from

funcfunc

The callback function to remove

setter(self, func)[source]

Method to use as a decorator, to mimic @property.setter