Skip to content

Gtk.Shortcut

class — extends GObject.Object

Describes a keyboard shortcut.

It contains a description of how to trigger the shortcut via a ShortcutTrigger and a way to activate the shortcut on a widget via a ShortcutAction.

The actual work is usually done via ShortcutController, which decides if and when to activate a shortcut. Using that controller directly however is rarely necessary as various higher level convenience APIs exist on GtkWidgets that make it easier to use shortcuts in GTK.

GtkShortcut does provide functionality to make it easy for users to work with shortcuts, either by providing informational strings for display purposes or by allowing shortcuts to be configured.

Constructors

new

@classmethod
def new(cls, trigger: ShortcutTrigger | None = ..., action: ShortcutAction | None = ...) -> Shortcut

Creates a new GtkShortcut that is triggered by trigger and then activates action.

Parameters:

  • trigger — The trigger that will trigger the shortcut
  • action — The action that will be activated upon triggering

Methods

get_action

def get_action(self) -> ShortcutAction | None

Gets the action that is activated by this shortcut.

get_arguments

def get_arguments(self) -> GLib.Variant | None

Gets the arguments that are passed when activating the shortcut.

get_trigger

def get_trigger(self) -> ShortcutTrigger | None

Gets the trigger used to trigger self.

set_action

def set_action(self, action: ShortcutAction | None = ...) -> None

Sets the new action for self to be action.

Parameters:

  • action — The new action. If the action is None, the nothing action will be used.

set_arguments

def set_arguments(self, args: GLib.Variant | None = ...) -> None

Sets the arguments to pass when activating the shortcut.

Parameters:

  • args — arguments to pass when activating self

set_trigger

def set_trigger(self, trigger: ShortcutTrigger | None = ...) -> None

Sets the new trigger for self to be trigger.

Parameters:

  • trigger — The new trigger. If the trigger is None, the never trigger will be used.

Properties

action

action: ShortcutAction  # read/write

The action that gets activated by this shortcut.

arguments

arguments: GLib.Variant  # read/write

Arguments passed to activation.

trigger

trigger: ShortcutTrigger  # read/write

The trigger that triggers this shortcut.