1
將加速器添加到僅包含Vte.Terminal()的Gtk.EventBox()上出現的菜單中時出現問題。菜單顯示OK,複製和粘貼工作正常,但加速器似乎不起作用。他們被VTE抓到之前,他們到達我的eventBox(奇怪,因爲我的事件箱高於vte小部件),例如,Ctrl + Shift + C作爲Ctrl + C在終端上,只是中斷當前的過程。有關如何去做這件事的任何想法?GTK +:向VTE添加自定義加速器
menuitem-accelerator的相關關聯是評論代碼。
def terminalBox(self, terminal):
"""Given a terminal, creates an EventBox for the Box that has as
a children said terminal"""
eventTerminalBox = Gtk.EventBox()
terminalBox = Gtk.Box()
terminalBox.pack_start(terminal, True, True, 0)
eventTerminalBox.connect("button_press_event", self.right_click)
eventTerminalBox.add(terminalBox)
return eventTerminalBox
def right_click(self, eventbox, event):
"""Defines the menu created when a user rightclicks on the
terminal eventbox"""
menu = Gtk.Menu()
copy = Gtk.MenuItem("Copy")
paste = Gtk.MenuItem("Paste")
menu.append(paste)
menu.append(copy)
# TODO: make accelerators for copy paste work. add accel for paste
#accelgroup = Gtk.AccelGroup()
#self.add_accel_group(accelgroup)
#accellabel = Gtk.AccelLabel("Copy/Paste")
#accellabel.set_hexpand(True)
#copy.add_accelerator("activate",
# accelgroup,
# Gdk.keyval_from_name("c"),
# Gdk.ModifierType.SHIFT_MASK |
# Gdk.ModifierType.CONTROL_MASK,
# Gtk.AccelFlags.VISIBLE)
copy.connect("activate", self.copy_text)
paste.connect("activate", self.paste_text)
copy.show()
paste.show()
menu.popup(None, None, None, None, event.button, event.time)
def copy_text(self, button):
"""What happens when the user copies text"""
content = self.selection_clipboard.wait_for_text()
self.clipboard.set_text(content, -1)
def paste_text(self, button):
"""What happens when the user pastes text"""
currentTerminal = self.getCurrentFocusedTerminal()
currentTerminal.paste_clipboard()