Skip to content

pygase.event

Handle events in PyGaSe clients, servers and state machines.

Contains the basic components of the PyGaSe event framework.

Contents

  • Event: class for serializable event objects with event type and data
  • UniversalEventHandler: class for components that can handle various event types

Event

Event(self, event_type:str, *args, **kwargs)

Send PyGaSe events and attached data via UDP packages.

Arguments

  • event_type (str): string that identifies the event and links it to a handler

Arguments

Additional positional and keyword arguments represent event data and will be passed to the handler function on the other side of the connection.

Attributes

  • type (str):
  • handler_args (list):
  • handler_kwargs (dict):

UniversalEventHandler

UniversalEventHandler(self)

Handle PyGaSe events with callback functions.

register_event_handler

UniversalEventHandler.register_event_handler(self, event_type:str, event_handler_function) -> None

Register an event handler for a specific event type.

Arguments

  • event_type (str): string that identifies the events to be handled by this function
  • event_handler_function (callable, coroutine): callback function or coroutine that will be invoked with the handler args and kwargs with which the incoming event has been dispatched

Raises

  • TypeError: if event_handler_function is not callable

handle

UniversalEventHandler.handle(self, event:pygase.event.Event, **kwargs)

Asynchronously invoke the appropriate handler function.

This method is a coroutine and must be awaited.

Arguments

  • event (Event): the event to be handled

keyword arguments to be passed to the handler function (in addition to those already attached to the event)

has_event_type

UniversalEventHandler.has_event_type(self, event_type:str) -> bool

Check if a handler was registered for event_type.