[orca] Detection code for bgo#607847. This attempts to find problems with missing keysyms in the X keymap



commit b31b1c4a6f5992247b8c7d8981e6867d907be504
Author: Willie Walker <william walker sun com>
Date:   Sun Jan 24 14:18:30 2010 -0500

    Detection code for bgo#607847.  This attempts to find problems with
    missing keysyms in the X keymap as well as keybindings that map to
    the same physical key.  It is turned off by default.  To enable it,
    set settings.validateKeyBindings=True.

 src/orca/keybindings.py |   51 +++++++++++++++++++++++++++++++++++++++++++++++
 src/orca/script.py      |    4 +++
 src/orca/settings.py    |    5 ++++
 3 files changed, 60 insertions(+), 0 deletions(-)
---
diff --git a/src/orca/keybindings.py b/src/orca/keybindings.py
index 5e4d80f..a647c4f 100644
--- a/src/orca/keybindings.py
+++ b/src/orca/keybindings.py
@@ -383,3 +383,54 @@ class KeyBindings:
                     debug.printException(debug.LEVEL_SEVERE)
 
         return consumed
+
+    def validate(self):
+        """Tries to find keybindings where the keysym is not set for the
+        keyboard layout or where multiple keybindings map to the same
+        physical key."""
+
+        errorString = ""
+
+        # Find keybindings where the keysym is not found in the
+        # system's keymap.
+        #
+        for keyBinding in self.keyBindings:
+            keysymstring = keyBinding.keysymstring
+            if keysymstring:
+                if not getKeycode(keysymstring):
+                    errorString += "No physical key defines %s\n" \
+                                   % keysymstring
+                    if keyBinding.handler:
+                        errorString += "needed for %s\n" \
+                                       % keyBinding.handler.description
+
+        # Now, find duplicate bindings that are unintended duplicates.
+        #
+        for i in range(0, len(self.keyBindings)):
+            iKeyBinding = self.keyBindings[i]
+            if not iKeyBinding.keycode:
+                iKeyBinding.keycode = getKeycode(iKeyBinding.keysymstring)
+            if iKeyBinding.keycode:
+                for j in range(i + 1, len(self.keyBindings)):
+                    jKeyBinding = self.keyBindings[j]
+                    if not jKeyBinding.keycode:
+                        jKeyBinding.keycode = \
+                            getKeycode(jKeyBinding.keysymstring)
+                    if (iKeyBinding.keycode == jKeyBinding.keycode) \
+                       and (iKeyBinding.click_count \
+                            == jKeyBinding.click_count) \
+                       and (iKeyBinding.handler != jKeyBinding.handler) \
+                       and ((iKeyBinding.modifiers
+                             & iKeyBinding.modifier_mask) \
+                            == (jKeyBinding.modifiers
+                                & jKeyBinding.modifier_mask)):
+                        errorString += "%s maps to the same key as %s\n" \
+                                       % (iKeyBinding.keysymstring,
+                                          jKeyBinding.keysymstring)
+                        if iKeyBinding.handler:
+                            errorString += "used by %s\n" \
+                                           % iKeyBinding.handler.description
+                        if jKeyBinding.handler:
+                            errorString += "used by %s\n" \
+                                           % jKeyBinding.handler.description
+        return errorString
diff --git a/src/orca/script.py b/src/orca/script.py
index 5aae7d0..e337968 100644
--- a/src/orca/script.py
+++ b/src/orca/script.py
@@ -86,6 +86,10 @@ class Script:
         self.pointOfReference = {}
         self.setupInputEventHandlers()
         self.keyBindings = self.getKeyBindings()
+        if settings.validateKeyBindings:
+            validation = self.keyBindings.validate()
+            if len(validation):
+                debug.println(debug.LEVEL_SEVERE, validation)
         self.brailleBindings = self.getBrailleBindings()
         self.app_pronunciation_dict = self.getPronunciations()
 
diff --git a/src/orca/settings.py b/src/orca/settings.py
index 9f9bc24..22a4bcc 100644
--- a/src/orca/settings.py
+++ b/src/orca/settings.py
@@ -228,6 +228,11 @@ DESKTOP_MODIFIER_KEYS = ["Insert", "KP_Insert"]
 LAPTOP_MODIFIER_KEYS  = ["Caps_Lock"]
 orcaModifierKeys      = DESKTOP_MODIFIER_KEYS
 
+# If True, some validation of the keybindings will be done to check for
+# missing keysyms and duplicate keys used for different operations.
+#
+validateKeyBindings = False
+
 # A new modifier to use (set by the press of any key in the
 # orcaModifierKeys list) to represent the Orca modifier.
 #



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]