GtkShortcutController

gtk.shortcut_controller.ShortcutController is an event controller that manages shortcuts.

Most common shortcuts are using this controller implicitly, e.g. by adding a mnemonic underline to a gtk.label.Label, or by installing a key binding using gtk.widget_class.WidgetClass.addBinding, or by adding accelerators to global actions using gtk.application.Application.setAccelsForAction.

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

gtk.shortcut_controller.ShortcutController implements gio.list_model.ListModel for querying the shortcuts that have been added to it.

GtkShortcutController as GtkBuildable

gtk.shortcut_controller.ShortcutControllers can be created in gtk.builder.Builder ui files, to set up shortcuts in the same place as the widgets.

An example of a UI definition fragment with gtk.shortcut_controller.ShortcutController:

<object class='GtkButton'>
  <child>
    <object class='GtkShortcutController'>
      <property name='scope'>managed</property>
      <child>
        <object class='GtkShortcut'>
          <property name='trigger'>&lt;Control&gt;k</property>
          <property name='action'>activate</property>
        </object>
      </child>
    </object>
  </child>
</object>

This example creates a gtk.activate_action.ActivateAction for triggering the activate signal of the gtk.button.Button. See gtk.shortcut_action.ShortcutAction.parseString for the syntax for other kinds of gtk.shortcut_action.ShortcutAction. See gtk.shortcut_trigger.ShortcutTrigger.parseString to learn more about the syntax for triggers.

struct GtkShortcutController