[virt-manager PATCH 11/16] i18n: show localized accelerators in Send key menu

Pino Toscano ptoscano at redhat.com
Tue Jul 14 07:41:55 UTC 2020


Turn the menu labels into GTK accelerator strings, so we can parse them
to convert them into a proper user representation.

There is a small behaviour change: the menu items do not have mnemonics
anymore by default.

Signed-off-by: Pino Toscano <ptoscano at redhat.com>
---
 virtManager/details/console.py | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/virtManager/details/console.py b/virtManager/details/console.py
index ae9b85ed..062a019c 100644
--- a/virtManager/details/console.py
+++ b/virtManager/details/console.py
@@ -105,21 +105,22 @@ class _TimedRevealer(vmmGObject):
 def build_keycombo_menu(on_send_key_fn):
     menu = Gtk.Menu()
 
-    def make_item(name, combo):
-        item = Gtk.MenuItem.new_with_mnemonic(name)
+    def make_item(accel, combo):
+        name = Gtk.accelerator_get_label(*Gtk.accelerator_parse(accel))
+        item = Gtk.MenuItem(name)
         item.connect("activate", on_send_key_fn, combo)
 
         menu.add(item)
 
-    make_item("Ctrl+Alt+_Backspace", ["Control_L", "Alt_L", "BackSpace"])
-    make_item("Ctrl+Alt+_Delete", ["Control_L", "Alt_L", "Delete"])
+    make_item("<Control><Alt>BackSpace", ["Control_L", "Alt_L", "BackSpace"])
+    make_item("<Control><Alt>Delete", ["Control_L", "Alt_L", "Delete"])
     menu.add(Gtk.SeparatorMenuItem())
 
     for i in range(1, 13):
-        make_item("Ctrl+Alt+F_%d" % i, ["Control_L", "Alt_L", "F%d" % i])
+        make_item("<Control><Alt>F%d" % i, ["Control_L", "Alt_L", "F%d" % i])
     menu.add(Gtk.SeparatorMenuItem())
 
-    make_item("_Printscreen", ["Print"])
+    make_item("Print", ["Print"])
 
     menu.show_all()
     return menu
-- 
2.26.2




More information about the virt-tools-list mailing list