2016-07-27 152 views
1

我想將accelgroup(鍵盤快捷鍵)添加到Gio.Menu項目中。 但我還沒有找到辦法做到這一點。就像,在這個例子中,我要打開文件,<Ctrl>+o將鍵盤快捷鍵添加到GIo.Menu

filemenu = Gio.Menu() 
filemenu.append("Open","win.open") 

accelgroup=Gtk.AccelGroup() 
self.add_accel_group(accelgroup) 

# Open menu 
open_action = Gio.SimpleAction(name="open") 
# this line is problematic 
open_action.add_accelerator("activate". Gdk._keyval_from_name("O")) 
open_action.connect("activate", self.MenuElem.file_open_clicked) 
self.add_action(open_action) 

我怎樣才能做到這一點?

回答

2

你不綁定鍵添加到Gio.Action本身將它們添加到窗口小部件或應用程序,例如:

app = # My Gtk.Application instance 
window = # My Gtk.ApplicationWindow instance 
action = Gio.SimpleAction.new('open', None) 

window.add_action(action) 
app.add_accelerator('<Primary>o', 'win.open', None) 
# The 'win.' prefix is because it was added to a Gtk.ApplicationWindow