Gtk.AccelLabel

const Gtk = imports.gi.Gtk;

let accel_label = new Gtk.AccelLabel({
    accel_closure: value,
    accel_widget: value,
});
  

The Gtk.AccelLabel widget is a subclass of Gtk.Label that also displays an accelerator key on the right of the label text, e.g. 'Ctl+S'. It is commonly used in menus to show the keyboard short-cuts for commands.

The accelerator key to display is not set explicitly. Instead, the Gtk.AccelLabel displays the accelerators which have been added to a particular widget. This widget is set by calling Gtk.set_accel_widget.

For example, a Gtk.MenuItem widget may have an accelerator added to emit the "activate" signal when the 'Ctl+S' key combination is pressed. A Gtk.AccelLabel is created and added to the Gtk.MenuItem, and Gtk.set_accel_widget is called with the Gtk.MenuItem as the second argument. The Gtk.AccelLabel will now display 'Ctl+S' after its label.

Note that creating a Gtk.MenuItem with Gtk.new_with_label (or one of the similar functions for Gtk.CheckMenuItem and Gtk.RadioMenuItem) automatically adds a Gtk.AccelLabel to the Gtk.MenuItem and calls Gtk.set_accel_widget to set it up for you.

A Gtk.AccelLabel will only display accelerators which have Gtk.AccelFlags.visible set (see Gtk.AccelFlags). A Gtk.AccelLabel can display multiple accelerators and even signal names, though it is almost always used to display just one accelerator key. <example> <title>Creating a simple menu item with an accelerator key.</title> <programlisting> GtkWidget *save_item; GtkAccelGroup *accel_group;

/<!---->* Create a GtkAccelGroup and add it to the window. *<!---->/ accel_group = gtk_accel_group_new (<!-- -->); gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);

/<!---->* Create the menu item using the convenience function. *<!---->/ save_item = gtk_menu_item_new_with_label ("Save"); gtk_widget_show (save_item); gtk_container_add (GTK_CONTAINER (menu), save_item);

/<!---->* Now add the accelerator to the GtkMenuItem. Note that since we called gtk_menu_item_new_with_label(<!-- -->) to create the GtkMenuItem the GtkAccelLabel is automatically set up to display the GtkMenuItem accelerators. We just need to make sure we use GTK_ACCEL_VISIBLE here. *<!---->/ gtk_widget_add_accelerator (save_item, "activate", accel_group, GDK_KEY_s, GDK_CONTROL_MASK, GTK_ACCEL_VISIBLE); </programlisting> </example>

Hierarchy

  • GObject.Object
    • GObject.InitiallyUnowned
      • Gtk.Widget
        • Gtk.Misc
          • Gtk.Label
            • Gtk.AccelLabel