colour.utilities.MixinCallback#
- class colour.utilities.MixinCallback[source]#
Bases:
object
A mixin providing support for callbacks.
Attributes
Methods
Examples
>>> class WithCallback(MixinCallback): ... def __init__(self): ... super().__init__() ... self.attribute_a = "a" >>> with_callback = WithCallback() >>> def _on_attribute_a_changed(self, name: str, value: str) -> str: ... return value.upper() >>> with_callback.register_callback( ... "attribute_a", "on_attribute_a_changed", _on_attribute_a_changed ... ) >>> with_callback.attribute_a = "a" >>> with_callback.attribute_a 'A'
- property callbacks: defaultdict[str, List[Callback]]#
Getter property for the callbacks.
- Returns:
Callbacks.
- Return type:
defaultdict
- register_callback(attribute: str, name: str, function: Callable) None [source]#
Register the callback with given name for given attribute.
- Parameters:
- Return type:
None
Examples
>>> class WithCallback(MixinCallback): ... def __init__(self): ... super().__init__() ... self.attribute_a = "a" ... >>> with_callback = WithCallback() >>> with_callback.register_callback( ... "attribute_a", "callback", lambda *args: None ... ) >>> with_callback.callbacks defaultdict(<class 'list'>, {'attribute_a': [Callback(name='callback', function=<function <lambda> at 0x...>)]})
- unregister_callback(attribute: str, name: str) None [source]#
Unregister the callback with given name for given attribute.
- Parameters:
- Return type:
None
Examples
>>> class WithCallback(MixinCallback): ... def __init__(self): ... super().__init__() ... self.attribute_a = "a" ... >>> with_callback = WithCallback() >>> with_callback.register_callback( ... "attribute_a", "callback", lambda s, n, v: v ... ) >>> with_callback.callbacks defaultdict(<class 'list'>, {'attribute_a': [Callback(name='callback', function=<function <lambda> at 0x...>)]}) >>> with_callback.unregister_callback("attribute_a", "callback") >>> with_callback.callbacks defaultdict(<class 'list'>, {})
- __weakref__#
list of weak references to the object