napari.utils.events.Event#

class napari.utils.events.Event(type_name: str, native: Any = None, **kwargs: Any)[source]#

Bases: object

Class describing events that occur and can be reacted to with callbacks. Each event instance contains information about a single event that has occurred such as a key press, mouse motion, timer activation, etc.

Subclasses: KeyEvent, MouseEvent, TouchEvent, StylusEvent

The creation of events and passing of events to the appropriate callback functions is the responsibility of EventEmitter instances.

Note that each event object has an attribute for each of the input arguments listed below.

Parameters:
  • type (str) – String indicating the event type (e.g. mouse_press, key_release)

  • native (object (optional)) – The native GUI event object

  • **kwargs (keyword arguments) – All extra keyword arguments become attributes of the event object.

Methods

Attributes

blocked

This boolean property indicates whether the event will be delivered to event callbacks.

handled

This boolean property indicates whether the event has already been acted on by an event handler.

native

source

The object that the event applies to (i.e. the source of the event).

sources

List of objects that the event applies to (i.e. are or have been a source of the event).

type

Details

property blocked: bool#

This boolean property indicates whether the event will be delivered to event callbacks. If it is set to True, then no further callbacks will receive the event. When possible, it is recommended to use Event.handled rather than Event.blocked.

property handled: bool#

This boolean property indicates whether the event has already been acted on by an event handler. Since many handlers may have access to the same events, it is recommended that each check whether the event has already been handled as well as set handled=True if it decides to act on the event.

property source: Any#

The object that the event applies to (i.e. the source of the event).

property sources: List[Any]#

List of objects that the event applies to (i.e. are or have been a source of the event). Can contain multiple objects in case the event traverses a hierarchy of objects.