[orca] Move event_string correction code for input events into input_event.py
- From: Joanmarie Diggs <joanied src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [orca] Move event_string correction code for input events into input_event.py
- Date: Mon, 11 Nov 2019 20:23:14 +0000 (UTC)
commit 9d9330925f4c7e45934f5e895e091077bd05687b
Author: Joanmarie Diggs <jdiggs igalia com>
Date: Mon Nov 11 15:22:49 2019 -0500
Move event_string correction code for input events into input_event.py
src/orca/input_event.py | 69 +++++++++++++++++++++-
src/orca/script.py | 18 ------
.../scripts/toolkits/J2SE-access-bridge/script.py | 39 ------------
3 files changed, 68 insertions(+), 58 deletions(-)
---
diff --git a/src/orca/input_event.py b/src/orca/input_event.py
index 47d984672..1a64dca76 100644
--- a/src/orca/input_event.py
+++ b/src/orca/input_event.py
@@ -90,6 +90,64 @@ class KeyboardEvent(InputEvent):
TYPE_PUNCTUATION = "punctuation"
TYPE_SPACE = "space"
+ GDK_PUNCTUATION_KEYS = [Gdk.KEY_acute,
+ Gdk.KEY_ampersand,
+ Gdk.KEY_apostrophe,
+ Gdk.KEY_asciicircum,
+ Gdk.KEY_asciitilde,
+ Gdk.KEY_asterisk,
+ Gdk.KEY_at,
+ Gdk.KEY_backslash,
+ Gdk.KEY_bar,
+ Gdk.KEY_braceleft,
+ Gdk.KEY_braceright,
+ Gdk.KEY_bracketleft,
+ Gdk.KEY_bracketright,
+ Gdk.KEY_brokenbar,
+ Gdk.KEY_cedilla,
+ Gdk.KEY_cent,
+ Gdk.KEY_colon,
+ Gdk.KEY_comma,
+ Gdk.KEY_copyright,
+ Gdk.KEY_currency,
+ Gdk.KEY_degree,
+ Gdk.KEY_diaeresis,
+ Gdk.KEY_dollar,
+ Gdk.KEY_EuroSign,
+ Gdk.KEY_equal,
+ Gdk.KEY_exclam,
+ Gdk.KEY_exclamdown,
+ Gdk.KEY_grave,
+ Gdk.KEY_greater,
+ Gdk.KEY_guillemotleft,
+ Gdk.KEY_guillemotright,
+ Gdk.KEY_hyphen,
+ Gdk.KEY_less,
+ Gdk.KEY_macron,
+ Gdk.KEY_minus,
+ Gdk.KEY_notsign,
+ Gdk.KEY_numbersign,
+ Gdk.KEY_paragraph,
+ Gdk.KEY_parenleft,
+ Gdk.KEY_parenright,
+ Gdk.KEY_percent,
+ Gdk.KEY_period,
+ Gdk.KEY_periodcentered,
+ Gdk.KEY_plus,
+ Gdk.KEY_plusminus,
+ Gdk.KEY_question,
+ Gdk.KEY_questiondown,
+ Gdk.KEY_quotedbl,
+ Gdk.KEY_quoteleft,
+ Gdk.KEY_quoteright,
+ Gdk.KEY_registered,
+ Gdk.KEY_section,
+ Gdk.KEY_semicolon,
+ Gdk.KEY_slash,
+ Gdk.KEY_sterling,
+ Gdk.KEY_underscore,
+ Gdk.KEY_yen]
+
def __init__(self, event):
"""Creates a new InputEvent of type KEYBOARD_EVENT.
@@ -119,8 +177,17 @@ class KeyboardEvent(InputEvent):
self._result_reason = None
self._bypassOrca = None
+ # Some implementors don't populate this field at all. More often than not,
+ # the event_string and the keyval_name coincide for input events.
+ if not self.event_string:
+ self.event_string = self.keyval_name
+
+ # Some implementors do populate the field, but with the keyname rather than
+ # the printable character. This messes us up with punctuation.
+ if len(self.event_string) > 1 and self.id in KeyboardEvent.GDK_PUNCTUATION_KEYS:
+ self.event_string = chr(self.id)
+
if self._script:
- self._script.checkKeyboardEventData(self)
self._app = self._script.app
if not self._window:
self._window = self._script.utilities.activeWindow()
diff --git a/src/orca/script.py b/src/orca/script.py
index ddf1dcaac..d1905f614 100644
--- a/src/orca/script.py
+++ b/src/orca/script.py
@@ -379,24 +379,6 @@ class Script:
return skip
- def checkKeyboardEventData(self, keyboardEvent):
- """Checks the data on the keyboard event.
-
- Some toolkits don't fill all the key event fields, and/or fills
- them out with unexpected data. This method tries to fill in the
- missing fields and validate/standardize the data we've been given.
- While any script can override this method, it is expected that
- this will only be done at the toolkit script level.
-
- Arguments:
- - keyboardEvent: an instance of input_event.KeyboardEvent
- """
-
- if keyboardEvent.event_string == '':
- msg = 'INFO: Setting event_string to: %s' % keyboardEvent.keyval_name
- debug.println(debug.LEVEL_INFO, msg, True)
- keyboardEvent.event_string = keyboardEvent.keyval_name
-
def consumesKeyboardEvent(self, keyboardEvent):
"""Called when a key is pressed on the keyboard.
diff --git a/src/orca/scripts/toolkits/J2SE-access-bridge/script.py
b/src/orca/scripts/toolkits/J2SE-access-bridge/script.py
index b3851f1b2..b9f36a444 100644
--- a/src/orca/scripts/toolkits/J2SE-access-bridge/script.py
+++ b/src/orca/scripts/toolkits/J2SE-access-bridge/script.py
@@ -73,45 +73,6 @@ class Script(default.Script):
"""Returns the utilites for this script."""
return Utilities(self)
- def checkKeyboardEventData(self, keyboardEvent):
- """Checks the data on the keyboard event.
-
- Some toolkits don't fill all the key event fields, and/or fills
- them out with unexpected data. This method tries to fill in the
- missing fields and validate/standardize the data we've been given.
- While any script can override this method, it is expected that
- this will only be done at the toolkit script level.
-
- Arguments:
- - keyboardEvent: an instance of input_event.KeyboardEvent
- """
-
- default.Script.checkKeyboardEventData(self, keyboardEvent)
-
- if not keyboardEvent.keyval_name:
- return
-
- from gi.repository import Gdk
-
- keymap = Gdk.Keymap.get_default()
- keyval = Gdk.keyval_from_name(keyboardEvent.keyval_name)
- success, entries = keymap.get_entries_for_keyval(keyval)
- for entry in entries:
- if entry.group == 0:
- keyboardEvent.hw_code = entry.keycode
- break
-
- # Put the event_string back to what it was prior to the Java
- # Atk Wrapper hack which gives us the keyname and not the
- # expected and needed printable character for punctuation
- # marks.
- #
- if keyboardEvent.event_string == keyboardEvent.keyval_name \
- and len(keyboardEvent.event_string) > 1:
- keyval = Gdk.keyval_from_name(keyboardEvent.keyval_name)
- if 0 < keyval < 256:
- keyboardEvent.event_string = chr(keyval)
-
def onCaretMoved(self, event):
# Java's SpinButtons are the most caret movement happy thing
# I've seen to date. If you Up or Down on the keyboard to
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]