Gtk.ShortcutController

g GObject.GInterface GObject.GInterface Gio.ListModel Gio.ListModel GObject.GInterface->Gio.ListModel Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable GObject.Object GObject.Object Gtk.EventController Gtk.EventController GObject.Object->Gtk.EventController Gtk.ShortcutController Gtk.ShortcutController Gio.ListModel->Gtk.ShortcutController Gtk.Buildable->Gtk.ShortcutController Gtk.EventController->Gtk.ShortcutController

Subclasses:

None

Methods

Inherited:

Gtk.EventController (13), GObject.Object (37), Gio.ListModel (4), Gtk.Buildable (1)

Structs:

GObject.ObjectClass (5)

class

new ()

class

new_for_model (model)

add_shortcut (shortcut)

get_mnemonics_modifiers ()

get_scope ()

remove_shortcut (shortcut)

set_mnemonics_modifiers (modifiers)

set_scope (scope)

Virtual Methods

Inherited:

GObject.Object (7), Gio.ListModel (3), Gtk.Buildable (9)

Properties

Inherited:

Gtk.EventController (4)

Name

Type

Flags

Short Description

item-type

GObject.GType

r

mnemonic-modifiers

Gdk.ModifierType

r/w/en

model

Gio.ListModel

w/co/en

n-items

int

r

scope

Gtk.ShortcutScope

r/w/en

Signals

Inherited:

GObject.Object (1), Gio.ListModel (1)

Fields

Inherited:

GObject.Object (1), Gio.ListModel (1)

Class Details

class Gtk.ShortcutController(**kwargs)
Bases:

Gtk.EventController, Gio.ListModel, Gtk.Buildable

Abstract:

No

Structure:

Gtk.ShortcutControllerClass

GtkShortcutController is an event controller that manages shortcuts.

Most common shortcuts are using this controller implicitly, e.g. by adding a mnemonic underline to a [class`Gtk`.Label], or by installing a key binding using [method`Gtk`.WidgetClass.add_binding], or by adding accelerators to global actions using [method`Gtk`.Application.set_accels_for_action].

But it is possible to create your own shortcut controller, and add shortcuts to it.

GtkShortcutController implements [iface`Gio`.ListModel] for querying the shortcuts that have been added to it.

Gtk.ShortcutController as Gtk.Buildable

``GtkShortcutController``s can be created in [class`Gtk`.Builder] ui files, to set up shortcuts in the same place as the widgets.

An example of a UI definition fragment with GtkShortcutController : ```xml

<child>

managed <child>

<Control>k activate </object> </child> </object> </child> </object> ```

This example creates a [class`Gtk`.ActivateAction] for triggering the `activate` signal of the [class`Gtk`.Button]. See [ctor`Gtk`.ShortcutAction.parse_string] for the syntax for other kinds of [class`Gtk`.ShortcutAction]. See [ctor`Gtk`.ShortcutTrigger.parse_string] to learn more about the syntax for triggers.

classmethod new()[source]
Returns:

a newly created shortcut controller

Return type:

Gtk.EventController

Creates a new shortcut controller.

classmethod new_for_model(model)[source]
Parameters:

model (Gio.ListModel) – a GListModel containing shortcuts

Returns:

a newly created shortcut controller

Return type:

Gtk.EventController

Creates a new shortcut controller that takes its shortcuts from the given list model.

A controller created by this function does not let you add or remove individual shortcuts using the shortcut controller api, but you can change the contents of the model.

add_shortcut(shortcut)[source]
Parameters:

shortcut (Gtk.Shortcut) – a GtkShortcut

Adds shortcut to the list of shortcuts handled by self.

If this controller uses an external shortcut list, this function does nothing.

get_mnemonics_modifiers()[source]
Returns:

the controller’s mnemonics modifiers

Return type:

Gdk.ModifierType

Gets the mnemonics modifiers for when this controller activates its shortcuts.

get_scope()[source]
Returns:

the controller’s scope

Return type:

Gtk.ShortcutScope

Gets the scope for when this controller activates its shortcuts.

See [method`Gtk`.ShortcutController.set_scope] for details.

remove_shortcut(shortcut)[source]
Parameters:

shortcut (Gtk.Shortcut) – a GtkShortcut

Removes shortcut from the list of shortcuts handled by self.

If shortcut had not been added to controller or this controller uses an external shortcut list, this function does nothing.

set_mnemonics_modifiers(modifiers)[source]
Parameters:

modifiers (Gdk.ModifierType) – the new mnemonics_modifiers to use

Sets the controller to use the given modifier for mnemonics.

The mnemonics modifiers determines which modifiers need to be pressed to allow activation of shortcuts with mnemonics triggers.

GTK normally uses the Alt modifier for mnemonics, except in ``GtkPopoverMenu``s, where mnemonics can be triggered without any modifiers. It should be very rarely necessary to change this, and doing so is likely to interfere with other shortcuts.

This value is only relevant for local shortcut controllers. Global and managed shortcut controllers will have their shortcuts activated from other places which have their own modifiers for activating mnemonics.

set_scope(scope)[source]
Parameters:

scope (Gtk.ShortcutScope) – the new scope to use

Sets the controller to have the given scope.

The scope allows shortcuts to be activated outside of the normal event propagation. In particular, it allows installing global keyboard shortcuts that can be activated even when a widget does not have focus.

With Gtk.ShortcutScope.LOCAL, shortcuts will only be activated when the widget has focus.

Property Details

Gtk.ShortcutController.props.item_type
Name:

item-type

Type:

GObject.GType

Default Value:

<GType GObject>

Flags:

READABLE

The type of items. See [method`Gio`.ListModel.get_item_type].

New in version 4.8.

Gtk.ShortcutController.props.mnemonic_modifiers
Name:

mnemonic-modifiers

Type:

Gdk.ModifierType

Default Value:

Gdk.ModifierType.ALT_MASK

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The modifiers that need to be pressed to allow mnemonics activation.

Gtk.ShortcutController.props.model
Name:

model

Type:

Gio.ListModel

Default Value:

None

Flags:

WRITABLE, CONSTRUCT_ONLY, EXPLICIT_NOTIFY

A list model to take shortcuts from.

Gtk.ShortcutController.props.n_items
Name:

n-items

Type:

int

Default Value:

0

Flags:

READABLE

The number of items. See [method`Gio`.ListModel.get_n_items].

New in version 4.8.

Gtk.ShortcutController.props.scope
Name:

scope

Type:

Gtk.ShortcutScope

Default Value:

Gtk.ShortcutScope.LOCAL

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

What scope the shortcuts will be handled in.