bundles / astropy 7.0.1 / astropy / io / fits / util / NotifierMixin
class
astropy.io.fits.util:NotifierMixin
source: /astropy/io/fits/util.py :33
Signature
class NotifierMixin ( ) Members
Summary
Mixin class that provides services by which objects can register listeners to changes on that object.
Extended Summary
All methods provided by this class are underscored, since this is intended for internal use to communicate between classes in a generic way, and is not machinery that should be exposed to users of the classes involved.
Use the _add_listener method to register a listener on an instance of the notifier. This registers the listener with a weak reference, so if no other references to the listener exist it is automatically dropped from the list and does not need to be manually removed.
Call the _notify method on the notifier to update all listeners upon changes. _notify('change_type', *args, **kwargs) results in calling listener._update_change_type(*args, **kwargs) on all listeners subscribed to that notifier.
If a particular listener does not have the appropriate update method it is ignored.
Examples
class Widget(NotifierMixin): state = 1 def __init__(self, name): self.name = name def update_state(self): self.state += 1 self._notify('widget_state_changed', self) class WidgetListener: def _update_widget_state_changed(self, widget): print('Widget {0} changed state to {1}'.format( widget.name, widget.state)) widget = Widget('fred') listener = WidgetListener() widget._add_listener(listener) widget.update_state()✓
Widget fred changed state to 2
Aliases
-
astropy.io.fits.column.NotifierMixin