Gtk::AccelGroup
class Gtk::AccelGroup
A Gtk::AccelGroup represents a group of keyboard accelerators, typically attached to a toplevel Gtk::Window (with Gtk::Window#add_accel_group. Usually you won't need to create a Gtk::AccelGroup directly; instead, when using Gtk::ItemFactory, Ruby/GTK2 automatically sets up the accelerators for your menus in the item factory's Gtk::AccelGroup.
Note that accelerators are different from mnemonics. Accelerators are shortcuts for activating a menu item; they appear alongside the menu item they're a shortcut for. For example "Ctrl+Q" might appear alongside the "Quit" menu item. Mnemonics are shortcuts for GUI elements such as text entries or buttons; they appear as underlined characters. See Gtk::Label.new. Menu items can have both accelerators and mnemonics, of course.
Description
Example 1. Hello World with Ctrl + 'A'
require 'gtk2' ag = Gtk::AccelGroup.new ag.connect(Gdk::Keyval::GDK_A, Gdk::Window::CONTROL_MASK, Gtk::ACCEL_VISIBLE) { p "Hello World." } win = Gtk::Window.new.add_accel_group(ag).show_all Gtk.main
Example 2. Hello World with 'B' (Using accel path)
require 'gtk2' AccelMap.add_entry("<TEST Application>/test", Gdk::Keyval::GDK_B, 0) ag = Gtk::AccelGroup.new ag.connect("<TEST Application>/test") { p "Hello World." } win = Gtk::Window.new.add_accel_group(ag).show_all Gtk.main
Class Methods
Gtk::AccelGroup.new
-
Creates a new Gtk::AccelGroup.
- Returns: a new Gtk::AccelGroup
Gtk::AccelGroup.activate(object, accel_key, accel_mods)
-
Finds the first accelerator in any Gtk::AccelGroup attached to object that matches accel_key and accel_mods, and activates that accelerator. If an accelerator was activated and handled this keypress, true is returned.
- object: the GLib::Object, usually a Gtk::Window, on which to activate the accelerator.
- accel_key: accelerator keyval from a key event
- accel_mods: keyboard state mask from a key event (GdkModifierType)
- Returns: true if the accelerator was handled, false otherwise
Gtk::AccelGroup.from_accel_closure(closure)
-
Finds the Gtk::AccelGroup to which closure is connected; see Gtk::AccelGroup#connect.
- closure: a GLib::Closure
- Returns: the Gtk::AccelGroup to which closure is connected, or nil
Gtk::AccelGroup.from_object(object)
-
Gets an array of all accel groups which are attached to object.
- object: a GLib::Object, usually a Gtk::Window
- Returns: an Array of all accel groups which are attached to object
Instance Methods
connect(accel_key, accel_mods, accel_flags, closure)
connect(accel_key, accel_mods, accel_flags) {...}
-
Installs an accelerator in this group. When accel_group is being activated in response to a call to Gtk::AccelGroup.activate, closure or block will be invoked if the accel_key and accel_mods from Gtk::AccelGroup.activate match those of this connection.
Note that, due to implementation details, a single closure can only be connected to one accelerator group.
- accel_key: key value of the accelerator(the constants are in Gdk::Keyval)
- accel_mods: modifier combination of the accelerator(GdkModifierType)
- accel_flags: a flag mask to configure this accelerator(GtkAccelFlags)
- closure: GLib::Closure to be executed upon accelerator activation
- {...}: if closure = nil and a block is given, the block will be invoked if the accel_key and accel_mods from Gtk::AccelGroup.activate match those of this connection.
- Returns: self
connect(accel_path, closure)
connect(accel_path) {...}
-
Installs an accelerator in this group, using an accelerator path to look up the appropriate key and modifiers (see Gtk::AccelMap#add_entry). When accel_group is being activated in response to a call to Gtk::AccelGroup.activate, closure or block will be invoked if the accel_key and accel_mods from Gtk::AccelGroup.activate match the key and modifiers for the path.
- accel_path : path used for determining key and modifiers.
- closure: GLib::Closure to be executed upon accelerator activation
- {...}: if closure = nil and a block is given, the block will be invoked if the accel_key and accel_mods from Gtk::AccelGroup.activate match those of this connection.
- Returns: self
disconnect(closure)
-
Removes an accelerator previously installed through Gtk::AccelGroup#connect.
- closure: the GLib::Closure to remove from this accelerator group
- Returns: true if the closure was found and got disconnected
disconnect_key(accel_key, accel_mods)
-
Removes an accelerator previously installed through Gtk::AccelGroup#connect.
- accel_key: key value of the accelerator (Gdk::Keyval)
- accel_mods: modifier combination of the accelerator (GdkModifierType)
- Returns: true if there was an accelerator which could be removed, false otherwise
query(accel_key, accel_mods)
-
Queries an accelerator group for all entries matching accel_key and accel_mods.
- accel_key: key value of the accelerator (Gdk::Keyval)
- accel_mods: modifier combination of the accelerator (GdkModifierType)
- Returns: an array of location to return the number of entries(Gtk::AccelGroupEntry) found, or nil.
lock
lock {...}
-
Locks the given accelerator group. Locking an acelerator group prevents the accelerators contained within it to be changed during runtime. Refer to Gtk::AccelMap.change_entry about runtime accelerator changes. If called more than once, AccelGroup remains locked until Gtk::AccelGroup#unlock has been called an equivalent number of times.
- {...}: If block is given, it is locked untill the whole of the block.
- Returns: self
unlock
-
Undoes the last call to Gtk::AccelGroup#lock on this accel_group.
- Returns: self
find {...}
-
Finds the first entry in an accelerator group for which block returns true and returns its Gtk::AccelKey. Since 2.2
- {...}: a block to filter the entries of accel_group with
- Returns: the key of the first entry passing find_func. The key is owned by GTK+ and must not be freed.
activate(accel_quark, acceleratable, accel_key, accel_mods)
-
(no document) Since 2.4
- accel_quark: String or Fixnum.
- acceleratable:
- accel_key: key value of the accelerator (Gdk::Keyval)
- accel_mods: modifier combination of the accelerator (GdkModifierType)
locked?
-
Gets the Is the accel group locked.
- Returns: Is the accel group locked
modifier_mask
-
Gets the Modifier Mask.
- Returns: Modifier Mask
Properties
is-locked: true or false (Read)
- Is the accel group locked
modifier-mask: Gdk::ModifierType (Read)
- Modifier Mask
Signals
accel-activate: self, arg1, accel_key, accel_mods
-
- self: Gtk::AccelGroup
- arg1: GLib::Object
- accel_key: Key code constants of Gdk::Keyval
- accel_mods: GdkModifierType
accel-changed: self, accel_key, accel_mods
-
- self: Gtk::AccelGroup
- accel_key: Key code constants of Gdk::Keyval
- accel_mods: GdkModifierType.
Keyword(s):
References:[Gtk::Action] [api-gtk-index] [tut-gtk2-mnstbs-mnub] [Gtk::AccelGroupEntry] [index-ruby-gtk2] [Gtk::AccelLabel] [Gtk::Menu] [tut-gtk2-mnstbs-popup] [Gtk::AccelKey] [Ruby/GTK] [Gtk::AccelMap] [ruby-gtk-object-hierarchy] [Gtk::Window] [Gtk::ItemFactory] [Gtk::UIManager] [Gtk::ImageMenuItem] [Gtk::Widget] [News_20031116_1] [Gtk::AccelGroup]