Skip to content

Gtk.EventControllerFocus

class — extends EventController

Tracks keyboard focus.

The event controller offers EventControllerFocus.enter and EventControllerFocus.leave signals, as well as EventControllerFocus.is-focus and EventControllerFocus.contains-focus properties which are updated to reflect focus changes inside the widget hierarchy that is rooted at the controllers widget.

Constructors

new

@classmethod
def new(cls) -> EventController

Creates a new event controller that will handle focus events.

Methods

contains_focus

def contains_focus(self) -> bool

Returns True if focus is within self or one of its children.

is_focus

def is_focus(self) -> bool

Returns True if focus is within self, but not one of its children.

Properties

contains_focus

contains_focus: bool  # read-only

True if focus is contained in the controllers widget.

See EventControllerFocus.is-focus for whether the focus is in the widget itself or inside a descendent.

When handling focus events, this property is updated before EventControllerFocus.enter or EventControllerFocus.leave are emitted.

is_focus

is_focus: bool  # read-only

True if focus is in the controllers widget itself, as opposed to in a descendent widget.

See also EventControllerFocus.contains-focus.

When handling focus events, this property is updated before EventControllerFocus.enter or EventControllerFocus.leave are emitted.

Signals

enter

def on_enter(self) -> None: ...

Emitted whenever the focus enters into the widget or one of its descendents.

Note that this means you may not get an ::enter signal even though the widget becomes the focus location, in certain cases (such as when the focus moves from a descendent of the widget to the widget itself). If you are interested in these cases, you can monitor the EventControllerFocus.is-focus property for changes.

leave

def on_leave(self) -> None: ...

Emitted whenever the focus leaves the widget hierarchy that is rooted at the widget that the controller is attached to.

Note that this means you may not get a ::leave signal even though the focus moves away from the widget, in certain cases (such as when the focus moves from the widget to a descendent). If you are interested in these cases, you can monitor the EventControllerFocus.is-focus property for changes.