ruby-****@sourc*****
ruby-****@sourc*****
2012年 10月 25日 (木) 09:28:04 JST
------------------------- REMOTE_ADDR = 184.145.49.94 REMOTE_HOST = URL = http://ruby-gnome2.sourceforge.jp/hiki.cgi?tut-gtk2-mnstbs-popup ------------------------- @@ -288,12 +288,16 @@ {{image_right("accelerator-keys-2.png")}} -All accelerators, regardless of whether they are associated with menus or not use global Gtk::AccelMap object which defines a list entries in this table in the form of mappings between a unique accelerator name (in the Gtk::AccelMap known as the ((*'accel_path')*))and the actual key combinations. These accelerators (keys) and/or 'accel_paths' eventually have to be mapped to actions either with the help of 'Gtk::AccelGroup#connect(accel_key, accel_mods, accel_flags, closure)', 'Gtk::AccelGroup#connect(accel_key, accel_mods, accel_flags) {...}', or 'Gtk::AccelGroup#connect(accel_path, closure)', or 'Gtk::AccelGroup#connect(accel_path) {...}'. +All accelerators, regardless of whether they are associated with menus or not, use global Gtk::AccelMap object which defines a list entries in this table in the form of mappings between a unique accelerator name (in the Gtk::AccelMap known as the ((*'accel_path')*))and the actual key combinations. These accelerators (keys) and/or 'accel_paths' eventually have to be mapped to actions either. There however, is a difference how actions are associated with menu item accelerators in windows with menus and in windows without menus, i.e. for windows themselves. First you will notice that in either case we use Gtk::Window#add_accel_group(group). Note, that this statement is mandatory only in the programs without menus, but should be included in programs with menus only when in addition to triggering actions through menu items you also wish to provide the access to this functionality via accelerator keys. The other more pronounced difference is how actions are associated either with menu items, or merely with the accelerator abstractions, as is the case in programs without the menus. While for menu items their respective actions are triggered by a specified signal (remember the((*"accel_signal='activate'"*)) parameter to the Gtk::Widget#add_accelerator method above), in programs without menus accelerator key actions are associated directly to the corresponding accelerator key abstractions (e.g.: 'accel_key,...' and 'accel_path'). This is accomplished with the help of 'Gtk::AccelGroup#connect(accel_key, accel_mods, accel_flags, closure)', 'Gtk::AccelGroup#connect(accel_key, accel_mods, accel_flags) {...}', or 'Gtk::AccelGroup#connect(accel_path, closure)', or 'Gtk::AccelGroup#connect(accel_path) {...}'. -Following program example will make things more clear: + +{{image_right("accelerator-keys-2.png")}} + +Following program example will make these things more clear. In this program's main window we defined only a label reminding the user what key combinations are available to elicit a different action for each of them. For instance, as suggested by the text on the label, pressing merely a single key 'A' or 'B', or a combination '<Ctrl+Shift>+C' will print a particular message on the console (control terminal from which you executed 'ruby custom-accelerators.rb'). Note also, that we are not at all concerned with any kind of signal here. + +((*custom-accelerators.rb*)) -((*custom-accelerators*)) #!/usr/bin/env ruby