Gtk.ShortcutController¶
- Subclasses:
None
Methods¶
- Inherited:
Gtk.EventController (13), GObject.Object (37), Gio.ListModel (4), Gtk.Buildable (1)
- Structs:
class |
|
class |
|
|
|
|
|
|
|
|
|
|
Virtual Methods¶
- Inherited:
Properties¶
- Inherited:
Name |
Type |
Flags |
Short Description |
---|---|---|---|
r |
|||
r/w/en |
|||
w/co/en |
|||
r |
|||
r/w/en |
Signals¶
- Inherited:
Fields¶
- Inherited:
Class Details¶
- class Gtk.ShortcutController(**kwargs)¶
- Bases:
- Abstract:
No
- Structure:
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.``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:
Creates a new shortcut controller.
- classmethod new_for_model(model)[source]¶
- Parameters:
model (
Gio.ListModel
) – aGListModel
containing shortcuts- Returns:
a newly created shortcut controller
- Return type:
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
) – aGtkShortcut
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:
Gets the mnemonics modifiers for when this controller activates its shortcuts.
- get_scope()[source]¶
- Returns:
the controller’s scope
- Return type:
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
) – aGtkShortcut
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:
- Default Value:
<GType GObject>
- Flags:
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:
- Default Value:
- Flags:
The modifiers that need to be pressed to allow mnemonics activation.
- Gtk.ShortcutController.props.model¶
- Name:
model
- Type:
- Default Value:
- Flags:
A list model to take shortcuts from.
- Gtk.ShortcutController.props.n_items¶
-
The number of items. See [method`Gio`.ListModel.get_n_items].
New in version 4.8.
- Gtk.ShortcutController.props.scope¶
- Name:
scope
- Type:
- Default Value:
- Flags:
What scope the shortcuts will be handled in.