我正在尝试将accelgroup(键盘快捷键)添加到Gio.Menu项目中。
但我还没有办法做到这一点。就像在这个例子中,我想用<Ctrl>+o
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)
我该怎么做?
答案 0 :(得分: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