Adw.ShortcutLabel

g Adw.ShortcutLabel Adw.ShortcutLabel GObject.GInterface GObject.GInterface Gtk.Accessible Gtk.Accessible GObject.GInterface->Gtk.Accessible Gtk.Buildable Gtk.Buildable GObject.GInterface->Gtk.Buildable Gtk.ConstraintTarget Gtk.ConstraintTarget GObject.GInterface->Gtk.ConstraintTarget GObject.InitiallyUnowned GObject.InitiallyUnowned Gtk.Widget Gtk.Widget GObject.InitiallyUnowned->Gtk.Widget GObject.Object GObject.Object GObject.Object->GObject.InitiallyUnowned Gtk.Accessible->Gtk.Widget Gtk.Buildable->Gtk.Widget Gtk.ConstraintTarget->Gtk.Widget Gtk.Widget->Adw.ShortcutLabel

Subclasses:

None

Methods

Inherited:

Gtk.Widget (183), GObject.Object (37), Gtk.Accessible (17), Gtk.Buildable (1)

Structs:

Gtk.WidgetClass (18), GObject.ObjectClass (5)

class

new (accelerator)

get_accelerator ()

get_disabled_text ()

set_accelerator (accelerator)

set_disabled_text (disabled_text)

Virtual Methods

Inherited:

Gtk.Widget (25), GObject.Object (7), Gtk.Accessible (6), Gtk.Buildable (9)

Properties

Inherited:

Gtk.Widget (35), Gtk.Accessible (1)

Name

Type

Flags

Short Description

accelerator

str

r/w/en

disabled-text

str

r/w/en

Signals

Inherited:

Gtk.Widget (13), GObject.Object (1)

Fields

Inherited:

Gtk.Widget (13), GObject.Object (1)

Class Details

class Adw.ShortcutLabel(**kwargs)
Bases:

Gtk.Widget

Abstract:

No

Structure:

Adw.ShortcutLabelClass

A widget that displays a keyboard shortcut.

<picture> <source srcset=”shortcut-label-dark.png” media=”(prefers-color-scheme: dark)”> <img src=”shortcut-label.png” alt=”shortcut-label”> </picture>

The shown shortcut can be set using the [property`ShortcutLabel`:py:data::accelerator<Adw.ShortcutLabel.props.accelerator>] property.

Optionally, if no shortcut is set, AdwShortcutLabel will display a placeholder set with the [property`ShortcutLabel`:py:data::disabled-text<Adw.ShortcutLabel.props.disabled_text>] property.

The following types of shortcuts can be displayed:

  • A single shortcut in [func`Gtk`.accelerator_parse] format, e.g. <Control>C:

    <picture> <source srcset=”shortcut-label-single-dark.png” media=”(prefers-color-scheme: dark)”> <img src=”shortcut-label-single.png” alt=”shortcut-label-single”> </picture>

  • Multiple alternative shortcuts, separated with spaces, e.g. <Shift>A Home:

    <picture> <source srcset=”shortcut-label-alternative-dark.png” media=”(prefers-color-scheme: dark)”> <img src=”shortcut-label-alternative.png” alt=”shortcut-label-alternative”> </picture>

  • A range of shortcuts, separated with ..., e.g. <Alt>1...9:

    <picture> <source srcset=”shortcut-label-range-dark.png” media=”(prefers-color-scheme: dark)”> <img src=”shortcut-label-range.png” alt=”shortcut-label-range”> </picture>

  • Multiple keys pressed at once, separated with &, e.g. Control_L&Control_R:

    <picture> <source srcset=”shortcut-label-multiple-dark.png” media=”(prefers-color-scheme: dark)”> <img src=”shortcut-label-multiple.png” alt=”shortcut-label-multiple”> </picture>

  • Multiple shortcuts or keys, pressed sequentially, separated with +, e.g. <Control>C+<Control>X:

    <picture> <source srcset=”shortcut-label-sequence-dark.png” media=”(prefers-color-scheme: dark)”> <img src=”shortcut-label-sequence.png” alt=”shortcut-label-sequence”> </picture>

::: note <, > and & need to be escaped as &lt;, &gt; and &amp; when used in UI files.

CSS nodes

AdwShortcutLabel has a single CSS node with name shortcut-label. The individual keycap labels each have the .keycap style class, while the labels separating them have the .dimmed style class.

Accessibility

AdwShortcutLabel uses the GTK_ACCESSIBLE_ROLE_LABEL role.

See also: [class`ShortcutsDialog`].

New in version 1.8.

classmethod new(accelerator)
Parameters:

accelerator (str) – the accelerator to show

Returns:

the newly created AdwShortcutLabel

Return type:

Gtk.Widget

Creates a new AdwShortcutLabel showing accelerator.

New in version 1.8.

get_accelerator()
Returns:

the displayed accelerator

Return type:

str

Gets the accelerator displayed by self.

New in version 1.8.

get_disabled_text()
Returns:

the text displayed when no accelerator is set

Return type:

str

Gets the text displayed by self when no accelerator is set.

New in version 1.8.

set_accelerator(accelerator)
Parameters:

accelerator (str) – the accelerator to be displayed

Sets the accelerator to be displayed by self.

New in version 1.8.

set_disabled_text(disabled_text)
Parameters:

disabled_text (str) – the text displayed when no accelerator is set

Sets the text to be displayed by self when no accelerator is set.

New in version 1.8.

Property Details

Adw.ShortcutLabel.props.accelerator
Name:

accelerator

Type:

str

Default Value:

''

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The displayed accelerator.

New in version 1.8.

Adw.ShortcutLabel.props.disabled_text
Name:

disabled-text

Type:

str

Default Value:

''

Flags:

READABLE, WRITABLE, EXPLICIT_NOTIFY

The text displayed when no accelerator is set.

New in version 1.8.