Event#

Initializing the Event Class#

An Event is created by using the following constructor:

Event(callback, arg)

This constructor uses two parameters:

Parameter

Description

callback

Optional. A previously defined function that will be called as a thread when the event is broadcast.

arg

Optional. A tuple that is used to pass arguments to the event callback function.

# Define the function broadcasted_event().
def broadcasted_event():
    brain.screen.print("Event was broadcast")
# Construct an Event "event" with the
# Event class.
event = Event(broadcasted_event)

This event object will be used in all subsequent examples throughout this API documentation when referring to Event class methods.

Class Methods#

set()#

The set(callback, arg) method sets a new callback and arguments for the event.

Parameters

Description

callback

The new callback function to be called when the event is triggered.

arg

Optional. A tuple of arguments to pass to the callback function.

Returns: None.

# Define a function event_occured()
def event_occured():
    brain.screen.print("event occured")

# Set the event to run event_occured() instead of print()
# when the event is broadcast.
event.set(event_occured)

broadcast()#

The broadcast() method broadcasts the event and causes all registered callback functions to run.

Returns: None.

# Broadcast event and run print().
event.broadcast()

broadcast_and_wait()#

The broadcast_and_wait() method broadcasts the event, causes all registered callback functions to run, and waits until all callback functions have been completed.

Returns: None.

# Broadcast event and wait for completion.
event.broadcast_and_wait()