将键盘快捷键添加到 GIo.Menu
add keyboard shortcuts to GIo.Menu
我正在尝试将 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)
我该怎么做?
您不会将键绑定添加到 Gio.Action 本身,而是将它们添加到 Widget 或应用程序,例如:
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
我正在尝试将 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)
我该怎么做?
您不会将键绑定添加到 Gio.Action 本身,而是将它们添加到 Widget 或应用程序,例如:
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