changeset 4a35f57d3356 in tryton:default
details: https://hg.tryton.org/tryton?cmd=changeset&node=4a35f57d3356
description:
        Set underline on the first hardware keycode

        issue10306
        review338161002
diffstat:

 tryton/common/underline.py |  17 ++++++++++++++++-
 1 files changed, 16 insertions(+), 1 deletions(-)

diffs (27 lines):

diff -r f81f804ef4f1 -r 4a35f57d3356 tryton/common/underline.py
--- a/tryton/common/underline.py        Wed May 05 23:09:25 2021 +0200
+++ b/tryton/common/underline.py        Sun May 16 18:00:27 2021 +0200
@@ -1,7 +1,22 @@
 # This file is part of Tryton.  The COPYRIGHT file at the top level of
 # this repository contains the full copyright notices and license terms.
+from gi.repository import Gdk
+
+
+def find_hardware_keycode(string):
+    keymap = Gdk.Keymap.get_for_display(Gdk.Display.get_default())
+    for i, c in enumerate(string):
+        found, keys = keymap.get_entries_for_keyval(
+            Gdk.unicode_to_keyval(ord(c)))
+        if found:
+            return i
+    return -1
 
 
 def set_underline(label):
     "Set underscore for mnemonic accelerator"
-    return '_' + label.replace('_', '__')
+    label = label.replace('_', '__')
+    position = find_hardware_keycode(label)
+    if position >= 0:
+        label = label[:position] + '_' + label[position:]
+    return label

Reply via email to