Re: [Java-gnome-developer] Global keybindings (unimplemented?)
Brought to you by:
afcowie
From: Adam J. <ajo...@re...> - 2006-05-04 15:08:45
|
Khiraly wrote: > Hi! > > I have this python code: > > # key accelerators > self.accel_group = gtk.AccelGroup() > self.accel_group.connect_group(ord('q'), > gtk.gdk.CONTROL_MASK, > gtk.ACCEL_LOCKED, > self.delete) > self.accel_group.connect_group(ord('w'), > gtk.gdk.CONTROL_MASK, > gtk.ACCEL_LOCKED, > self.remove_current_book) > self.accel_group.connect_group(ord('t'), > gtk.gdk.CONTROL_MASK, > gtk.ACCEL_LOCKED, > self.add_new_book) > > This python code is implementing global keybindings: > Ctrl-Q - quit the application > Ctrl-W - close the active notebook page > Ctrl-T - add a new notebook page > > Can somebody help me to port this to java? > Im not finding any connect_group/connectGroup method anywhere. > In order to use keyboard accelerators, you should create an Action object and then assign the keyboard shortcut to that. Here's an example: // Close action AccelGroup ag this.close = new Action("close", "Close", "Close Window", GtkStockItem.CLOSE.getString()); this.close.setAccelGroup(ag); this.close.setAccelPath("<myWin>/File/Close"); this.close.addListener(new ActionListener() { public void actionEvent(ActionEvent action) { myWindow.this.destroy(); } }); AccelMap.changeEntry("<myWin>/File/Close", KeyValue.x, ModifierType.CONTROL_MASK, true); this.close.connectAccelerator(); You will also have to set the accelerator group for the window you want the keyboard shortcut to be active in by using org.gnu.gtk.Window.addAccelGroup(). You can find more information about Actions in the online javadocs at http://java-gnome.sourceforge.net/docs/javadoc/index.html Hope this helps, Adam Jocksch |