ShortcutController#
Superclasses: EventController
, Object
Implemented Interfaces: ListModel
, Buildable
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 Label
, or by installing a key
binding using add_binding
, or by adding accelerators
to global actions using set_accels_for_action
.
But it is possible to create your own shortcut controller, and add shortcuts to it.
GtkShortcutController
implements ListModel
for querying the
shortcuts that have been added to it.
GtkShortcutController as GtkBuildable#
GtkShortcutController
’s can be created in Builder
ui files, to set up
shortcuts in the same place as the widgets.
An example of a UI definition fragment with GtkShortcutController
:
<object class='GtkButton'>
<child>
<object class='GtkShortcutController'>
<property name='scope'>managed</property>
<child>
<object class='GtkShortcut'>
<property name='trigger'><Control>k</property>
<property name='action'>activate</property>
</object>
</child>
</object>
</child>
</object>
This example creates a ActivateAction
for triggering the
activate
signal of the Button
. See parse_string
for the syntax for other kinds of ShortcutAction
. See
parse_string
to learn more about the syntax
for triggers.
Constructors#
- class ShortcutController
- classmethod new() EventController #
Creates a new shortcut controller.
- classmethod new_for_model(model: ListModel) 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.
- Parameters:
model – a
GListModel
containing shortcuts
Methods#
- class ShortcutController
- add_shortcut(shortcut: Shortcut) None #
Adds
shortcut
to the list of shortcuts handled byself
.If this controller uses an external shortcut list, this function does nothing.
- Parameters:
shortcut – a
GtkShortcut
- get_mnemonics_modifiers() ModifierType #
Gets the mnemonics modifiers for when this controller activates its shortcuts.
- get_scope() ShortcutScope #
Gets the scope for when this controller activates its shortcuts.
See
set_scope
for details.
- remove_shortcut(shortcut: Shortcut) None #
Removes
shortcut
from the list of shortcuts handled byself
.If
shortcut
had not been added tocontroller
or this controller uses an external shortcut list, this function does nothing.- Parameters:
shortcut – a
GtkShortcut
- set_mnemonics_modifiers(modifiers: ModifierType) None #
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.
- Parameters:
modifiers – the new mnemonics_modifiers to use
- set_scope(scope: ShortcutScope) None #
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
LOCAL
, shortcuts will only be activated when the widget has focus.- Parameters:
scope – the new scope to use
Properties#
- class ShortcutController
-
- props.mnemonic_modifiers: ModifierType#
The type of the None singleton.
- props.scope: ShortcutScope#
The type of the None singleton.