launch.event_handler module

Module for EventHandler class.

class launch.event_handler.BaseEventHandler[source]

Bases: object

Base class for event handlers, which handle events in the launch system.

Entities yielded by the event handler can access the event being handled via the context’s locals, e.g. context.locals.event As another example, getting the name of the event as a Substitution: launch.substitutions.LocalSubstitution(‘event.name’).

__init__(*, matcher: Callable[[Event], bool], handle_once: bool = False)[source]

Create a BaseEventHandler.

Param:

matcher is a callable that takes an event and returns True if the event should be handled by this event handler, False otherwise.

Param:

handle_once is a flag that, if True, unregisters this EventHandler after being handled once.

describe() Tuple[str, List[LaunchDescriptionEntity | Iterable[LaunchDescriptionEntity]]][source]

Return the description list with 0 as a string, and then LaunchDescriptionEntity’s.

handle(event: Event, context: LaunchContext) LaunchDescriptionEntity | Iterable[LaunchDescriptionEntity] | None[source]

Handle the given event.

This implementation should always be called by child classes in order to properly support common event handler functionality.

property handle_once

Getter for handle_once flag.

property handler_description

Return the string description of the handler.

This should be overridden.

property matcher_description

Return the string description of the matcher.

This should be overridden.

matches(event: Event) bool[source]

Return True if the given event should be handled by this event handler.

class launch.event_handler.EventHandler[source]

Bases: BaseEventHandler

__init__(*, matcher: Callable[[Event], bool], entities: LaunchDescriptionEntity | Iterable[LaunchDescriptionEntity] | None = None, handle_once: bool = False) None[source]

Create an EventHandler.

Param:

matcher is a callable that takes an event and returns True if the event should be handled by this event handler, False otherwise.

Param:

entities is an LaunchDescriptionEntity or list of them, and is returned by handle() unconditionally if matcher returns True.

Param:

handle_once is a flag that, if True, unregisters this EventHandler after being handled once.

describe() Tuple[str, List[LaunchDescriptionEntity | Iterable[LaunchDescriptionEntity]]][source]

Return the description list with 0 as a string, and then LaunchDescriptionEntity’s.

property entities

Getter for entities.

handle(event: Event, context: LaunchContext) LaunchDescriptionEntity | Iterable[LaunchDescriptionEntity] | None[source]

Handle the given event.