Gtk.ShortcutController¶
class — extends EventController, Gio.ListModel, Buildable
Manages keyboard shortcuts and their activation.
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 WidgetClass.add_binding, or by adding accelerators
to global actions using Application.set_accels_for_action.
But it is possible to create your own shortcut controller, and add shortcuts to it.
GtkShortcutController implements Gio.ListModel for querying the
shortcuts that have been added to it.
GtkShortcutController as GtkBuildable¶
GtkShortcutControllers 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 ShortcutAction.parse_string
for the syntax for other kinds of ShortcutAction. See
ShortcutTrigger.parse_string to learn more about the syntax
for triggers.
Constructors¶
new¶
Creates a new shortcut controller.
new_for_model¶
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— aGListModelcontaining shortcuts
Methods¶
add_shortcut¶
Adds shortcut to the list of shortcuts handled by self.
If this controller uses an external shortcut list, this function does nothing.
Parameters:
shortcut— aGtkShortcut
get_mnemonics_modifiers¶
Gets the mnemonics modifiers for when this controller activates its shortcuts.
get_scope¶
Gets the scope for when this controller activates its shortcuts.
See ShortcutController.set_scope for details.
remove_shortcut¶
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.
Parameters:
shortcut— aGtkShortcut
set_mnemonics_modifiers¶
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 GtkPopoverMenus,
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¶
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 ShortcutScope.LOCAL, shortcuts will only be activated
when the widget has focus.
Parameters:
scope— the new scope to use
Properties¶
item_type¶
The type of items. See Gio.ListModel.get_item_type.
mnemonic_modifiers¶
The modifiers that need to be pressed to allow mnemonics activation.
model¶
A list model to take shortcuts from.
n_items¶
The number of items. See Gio.ListModel.get_n_items.
scope¶
What scope the shortcuts will be handled in.