Skip to content

hololinked.core.meta.EventsRegistry

Bases: DescriptorRegistry

A DescriptorRegistry for events of a Thing class or Thing instance.

UML Diagram

Source code in hololinked\core\meta.py
class EventsRegistry(DescriptorRegistry):
    """
    A `DescriptorRegistry` for events of a `Thing` class or `Thing` instance.

    [UML Diagram](http://localhost:8000/UML/PDF/DescriptorRegistry.pdf)
    """

    @property
    def descriptor_object(self):
        return Event

    descriptors = property(DescriptorRegistry.get_descriptors) # type: typing.Dict[str, Event]

    values = property(DescriptorRegistry.get_values, 
                    doc=DescriptorRegistry.get_values.__doc__) # type: typing.Dict[str, EventDispatcher]

    def __getitem__(self, key: str) -> Event | EventDispatcher:
        if self.owner_inst is not None:
            return self.descriptors[key].__get__(self.owner_inst, self.owner_cls)
        return self.descriptors[key]

    def __contains__(self, event: Event) -> bool:
        return event in self.descriptors.values() or event in self.descriptors

    def clear(self):
        super().clear()
        for attr in ['_change_events', '_observables']:
            try: 
                delattr(self, f'_{self._qualified_prefix}_{self.__class__.__name__.lower()}{attr}')
            except AttributeError:
                pass

    @property
    def change_events(self) -> typing.Dict[str, Event]:
        """dictionary of change events of observable properties"""
        try:
            return getattr(self, f'_{self._qualified_prefix}_{self.__class__.__name__.lower()}_change_events')
        except AttributeError:
            change_events = dict()
            for name, evt in self.descriptors.items():
                if not evt._observable:
                    continue
                change_events[name] = evt
            setattr(
                self, 
                f'_{self._qualified_prefix}_{self.__class__.__name__.lower()}_change_events', 
                change_events
            )
            return change_events

    @property   
    def observables(self) -> typing.Dict[str, Property]:
        """dictionary of all properties that are observable, i.e. that which push change events"""
        try:
            return getattr(self, f'_{self._qualified__prefix}_{self.__class__.__name__.lower()}_observables')
        except AttributeError:
            props = dict()
            for name, prop in self.owner_cls.properties.descriptors.items():
                if not isinstance(prop, Property) or not prop._observable:
                    continue
                props[name] = prop
            setattr(
                self, 
                f'_{self._qualified_prefix}_{self.__class__.__name__.lower()}_observables', 
                props
            )
            return props

Attributes

change_events property

change_events: Dict[str, Event]

dictionary of change events of observable properties

observables property

observables: Dict[str, Property]

dictionary of all properties that are observable, i.e. that which push change events