Skip to content

hololinked.core.meta.EventSource

Base class to add event functionality to an object, it is not meant to be subclassed directly by the end-user.

UML Diagram

Source code in repo/hololinked/hololinked/core/meta.py
class EventSource:
    """
    Base class to add event functionality to an object, it is not meant to be subclassed directly by the end-user.

    [UML Diagram](https://docs.hololinked.dev/UML/PDF/Thing.pdf)
    """

    id: str
    eventloop: "EventLoop | None"

    def __init__(self) -> None:
        self.create_events_registry()

    # creating name without underscore causes clash with the metaclass method
    # with same name
    def create_events_registry(self) -> None:
        """Creates a registry for available `Events` based on `EventsRegistry`."""
        self._events_registry = EventsRegistry(self.__class__, self)  # ty: ignore[invalid-argument-type]

    @property
    def events(self) -> EventsRegistry:
        """Container for the event descriptors of the object."""
        return self._events_registry

    @property
    def event_bus(self) -> "EventBus | None":
        """
        The `EventBus` this object's events are published through.

        Valid only after starting the event loop object.
        """
        try:
            return self.eventloop.event_bus if self.eventloop else None
        except AttributeError:
            return None

Attributes

events property

events: EventsRegistry

Container for the event descriptors of the object.

event_bus property

event_bus: EventBus | None

The EventBus this object's events are published through.

Valid only after starting the event loop object.

Functions

create_events_registry

create_events_registry() -> None

Creates a registry for available Events based on EventsRegistry.

Source code in repo/hololinked/hololinked/core/meta.py
def create_events_registry(self) -> None:
    """Creates a registry for available `Events` based on `EventsRegistry`."""
    self._events_registry = EventsRegistry(self.__class__, self)  # ty: ignore[invalid-argument-type]