[orca] Begin moving KeyboardEvent methods out of orca.py and into the KeyboardEvent class in input_event.py
- From: Joanmarie Diggs <joanied src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [orca] Begin moving KeyboardEvent methods out of orca.py and into the KeyboardEvent class in input_event.py
- Date: Tue, 20 Dec 2011 22:06:03 +0000 (UTC)
commit 88acdf4f4f76a917d6b4217ae4dd9d11af77b26a
Author: Joanmarie Diggs <jdiggs igalia com>
Date: Tue Dec 20 16:59:05 2011 -0500
Begin moving KeyboardEvent methods out of orca.py and into the KeyboardEvent class in input_event.py.
src/orca/input_event.py | 185 +++++++++++++++++-
src/orca/orca.py | 363 ++++-------------------------------
src/orca/speech.py | 18 +-
src/orca/speechdispatcherfactory.py | 12 +-
src/orca/speechserver.py | 19 +-
5 files changed, 233 insertions(+), 364 deletions(-)
---
diff --git a/src/orca/input_event.py b/src/orca/input_event.py
index f08b4fb..9a1d034 100644
--- a/src/orca/input_event.py
+++ b/src/orca/input_event.py
@@ -1,6 +1,7 @@
# Orca
#
# Copyright 2005-2008 Sun Microsystems Inc.
+# Copyright 2011 Igalia, S.L.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
@@ -26,13 +27,17 @@ will be used which should be used to handle all input events."""
__id__ = "$Id$"
__version__ = "$Revision$"
__date__ = "$Date$"
-__copyright__ = "Copyright (c) 2005-2008 Sun Microsystems Inc."
+__copyright__ = "Copyright (c) 2005-2008 Sun Microsystems Inc." \
+ "Copyright (c) 2010-2011 Igalia, S.L."
__license__ = "LGPL"
-import debug
-import settings
+import pyatspi
import time
+import unicodedata
+
+import debug
import orca_state
+import settings
KEYBOARD_EVENT = "keyboard"
BRAILLE_EVENT = "braille"
@@ -47,13 +52,22 @@ class InputEvent:
Arguments:
- eventType: the input event type (one of KEYBOARD_EVENT, BRAILLE_EVENT,
- MOUSE_BUTTON_EVENT, MOUSE_MOTION_EVENT, SPEECH_EVENT).
+ MOUSE_BUTTON_EVENT, MOUSE_MOTION_EVENT, SPEECH_EVENT).
"""
self.type = eventType
class KeyboardEvent(InputEvent):
+ TYPE_UNKNOWN = "unknown"
+ TYPE_PRINTABLE = "printable"
+ TYPE_MODIFIER = "modifier"
+ TYPE_LOCKING = "locking"
+ TYPE_FUNCTION = "function"
+ TYPE_ACTION = "action"
+ TYPE_NAVIGATION = "navigation"
+ TYPE_DIACRITICAL = "diacritical"
+
def __init__(self, event):
"""Creates a new InputEvent of type KEYBOARD_EVENT.
@@ -61,8 +75,6 @@ class KeyboardEvent(InputEvent):
- event: the AT-SPI keyboard event
"""
- # We start just copying the pyatspi event.
- #
InputEvent.__init__(self, KEYBOARD_EVENT)
self.id = event.id
self.type = event.type
@@ -84,7 +96,7 @@ class KeyboardEvent(InputEvent):
# are filled.
#
script = orca_state.activeScript
- if (script):
+ if script:
script.checkKeyboardEventData(self)
# Control characters come through as control characters, so we
@@ -101,6 +113,43 @@ class KeyboardEvent(InputEvent):
if value < 32:
self.event_string = chr(value + 0x40)
+ self.keyType = None
+ if self.isNavigationKey():
+ self.keyType = KeyboardEvent.TYPE_NAVIGATION
+ self.shouldEcho = settings.enableNavigationKeys
+ elif self.isActionKey():
+ self.keyType = KeyboardEvent.TYPE_ACTION
+ self.shouldEcho = settings.enableActionKeys
+ elif self.isModifierKey():
+ self.keyType = KeyboardEvent.TYPE_MODIFIER
+ self.shouldEcho = settings.enableModifierKeys
+ elif self.isFunctionKey():
+ self.keyType = KeyboardEvent.TYPE_FUNCTION
+ self.shouldEcho = settings.enableFunctionKeys
+ elif self.isDiacriticalKey():
+ self.keyType = KeyboardEvent.TYPE_DIACRITICAL
+ self.shouldEcho = settings.enableDiacriticalKeys
+ elif self.isLockingKey():
+ self.keyType = KeyboardEvent.TYPE_LOCKING
+ self.shouldEcho = settings.enableLockingKeys
+ elif self.isPrintableKey():
+ self.keyType = KeyboardEvent.TYPE_PRINTABLE
+ self.shouldEcho = \
+ settings.enablePrintableKeys or settings.enableEchoByCharacter
+ else:
+ self.keyType = KeyboardEvent.TYPE_UNKNOWN
+ self.shouldEcho = False
+
+ # Never echo if the user doesn't want any echo, as defined by
+ # preferences and whether or not we are in a password field.
+ self.shouldEcho = self.shouldEcho and settings.enableKeyEcho
+ if self.shouldEcho:
+ try:
+ role = orca_state.locusOfFocus.getRole()
+ except:
+ pass
+ else:
+ self.shouldEcho = role != pyatspi.ROLE_PASSWORD_TEXT
def toString(self):
return ("KEYBOARDEVENT: type=%d\n" % self.type) \
@@ -111,7 +160,127 @@ class KeyboardEvent(InputEvent):
+ (" keyval_name=(%s)\n" % self.keyval_name) \
+ (" is_text=%s\n" % self.is_text) \
+ (" timestamp=%d\n" % self.timestamp) \
- + (" time=%f" % time.time())
+ + (" time=%f\n" % time.time()) \
+ + (" keyType=%s\n" % self.keyType) \
+ + (" shouldEcho=%s\n" % self.shouldEcho)
+
+ def isNavigationKey(self):
+ """Return True if this is a navigation key."""
+
+ if self.keyType:
+ return self.keyType == KeyboardEvent.TYPE_NAVIGATION
+
+ return self.event_string in \
+ ["Left", "Right", "Up", "Down", "Home", "End"]
+
+ def isActionKey(self):
+ """Return True if this is an action key."""
+
+ if self.keyType:
+ return self.keyType == KeyboardEvent.TYPE_ACTION
+
+ return self.event_string in \
+ ["Return", "Escape", "Tab", "BackSpace", "Delete",
+ "Page_Up", "Page_Down"]
+
+ def isDiacriticalKey(self):
+ """Return True if this is a non-spacing diacritical key."""
+
+ if self.keyType:
+ return self.keyType == KeyboardEvent.TYPE_DIACRITICAL
+
+ return self.event_string.startswith("dead_")
+
+ def isFunctionKey(self):
+ """Return True if this is a function key."""
+
+ if self.keyType:
+ return self.keyType == KeyboardEvent.TYPE_FUNCTION
+
+ return self.event_string in \
+ ["F1", "F2", "F3", "F4", "F5", "F6",
+ "F7","F8", "F9", "F10", "F11", "F12"]
+
+ def isLockingKey(self):
+ """Return True if this is a locking key."""
+
+ if self.keyType:
+ return self.keyType in KeyboardEvent.TYPE_LOCKING
+
+ lockingKeys = ["Caps_Lock", "Num_Lock", "Scroll_Lock"]
+ if not self.event_string in lockingKeys:
+ return False
+
+ if not orca_state.bypassNextCommand:
+ return not self.event_string in settings.orcaModifierKeys
+
+ return True
+
+ def isModifierKey(self):
+ """Return True if this is a modifier key."""
+
+ if self.keyType:
+ return self.keyType == KeyboardEvent.TYPE_MODIFIER
+
+ modifierKeys = ['Alt_L', 'Alt_R', 'Control_L', 'Control_R',
+ 'Shift_L', 'Shift_R', 'Meta_L', 'Meta_R']
+
+ if not orca_state.bypassNextCommand:
+ orcaMods = settings.orcaModifierKeys
+ try:
+ orcaMods = map(lambda x: x.encode('UTF-8'), orcaMods)
+ except (UnicodeDecodeError, UnicodeEncodeError):
+ pass
+ modifierKeys.extend(orcaMods)
+
+ string = self.event_string
+ if isinstance(string, unicode):
+ string = string.encode('UTF-8')
+
+ return string in modifierKeys
+
+ def isPrintableKey(self):
+ """Return True if this is a printable key."""
+
+ if self.keyType:
+ return self.keyType == KeyboardEvent.TYPE_PRINTABLE
+
+ if self.event_string == "space":
+ return True
+
+ unicodeString = self.event_string.decode("UTF-8")
+ if not len(unicodeString) == 1:
+ return False
+
+ if unicodeString.isalnum() or unicodeString.isspace():
+ return True
+
+ return unicodedata.category(unicodeString)[0] in ('P', 'S')
+
+ def isCharacterEchoable(self):
+ """Returns True if the script will echo this event as part of
+ character echo. We do this to not double-echo a given printable
+ character."""
+
+ if not self.isPrintableKey():
+ return False
+
+ script = orca_state.activeScript
+ return script and script.utilities.willEchoCharacter(self)
+
+ def getLockingState(self):
+ """Returns True if the event locked a locking key, False if the
+ event unlocked a locking key, and None if we do not know or this
+ is not a locking key."""
+
+ if self.event_string == "Caps_Lock":
+ mod = pyatspi.MODIFIER_SHIFTLOCK
+ elif self.event_string == "Num_Lock":
+ mod = pyatspi.MODIFIER_NUMLOCK
+ else:
+ return None
+
+ return not self.modifiers & (1 << mod)
class BrailleEvent(InputEvent):
diff --git a/src/orca/orca.py b/src/orca/orca.py
index 50355af..f95e1a2 100644
--- a/src/orca/orca.py
+++ b/src/orca/orca.py
@@ -34,7 +34,6 @@ import re
import signal
import sys
import time
-import unicodedata
import shutil
from gi.repository.Gio import Settings
@@ -792,181 +791,6 @@ _keyBindings = None
#
_orcaModifierPressed = False
-def isPrintableKey(event_string):
- """Return an indication of whether this is an alphanumeric or
- punctuation key.
-
- Arguments:
- - event: the event string
-
- Returns True if this is an alphanumeric or punctuation key.
- """
-
- if event_string == "space":
- reply = True
- else:
- unicodeString = event_string.decode("UTF-8")
- reply = (len(unicodeString) == 1) \
- and (unicodeString.isalnum() or unicodeString.isspace()
- or unicodedata.category(unicodeString)[0] in ('P', 'S'))
- debug.println(debug.LEVEL_FINEST,
- "orca.isPrintableKey: returning: %s" % reply)
- return reply
-
-def isModifierKey(event_string):
- """Return an indication of whether this is a modifier key.
-
- Arguments:
- - event: the event string
-
- Returns True if this is a modifier key
- """
-
- modifierKeys = [ 'Alt_L', 'Alt_R', 'Control_L', 'Control_R', \
- 'Shift_L', 'Shift_R', 'Meta_L', 'Meta_R' ]
-
- if not orca_state.bypassNextCommand:
- orcaModifiers = settings.orcaModifierKeys
- try:
- orcaModifiers = map(lambda x: x.encode('UTF-8'), orcaModifiers)
- except (UnicodeDecodeError, UnicodeEncodeError):
- pass
- modifierKeys.extend(orcaModifiers)
-
- if isinstance(event_string, unicode):
- event_string.encode('UTF-8')
-
- reply = event_string in modifierKeys
- debug.println(debug.LEVEL_FINEST,
- "orca.isModifierKey: returning: %s" % reply)
- return reply
-
-def isLockingKey(event_string):
- """Return an indication of whether this is a locking key.
-
- Arguments:
- - event: the event string
-
- Returns True if this is a locking key.
- """
-
- lockingKeys = [ "Caps_Lock", "Num_Lock", "Scroll_Lock" ]
-
- reply = event_string in lockingKeys
- if not orca_state.bypassNextCommand:
- reply = reply and not event_string in settings.orcaModifierKeys
- debug.println(debug.LEVEL_FINEST,
- "orca.isLockingKey: returning: %s" % reply)
- return reply
-
-def isFunctionKey(event_string):
- """Return an indication of whether this is a function key.
-
- Arguments:
- - event: the event string
-
- Returns True if this is a function key.
- """
-
- # [[[TODO:richb - what should be done about the function keys on the left
- # side of my Sun keyboard and the other keys (like Scroll Lock), which
- # generate "Fn" key events?]]]
-
- functionKeys = [ "F1", "F2", "F3", "F4", "F5", "F6",
- "F7", "F8", "F9", "F10", "F11", "F12" ]
-
- reply = event_string in functionKeys
- debug.println(debug.LEVEL_FINEST,
- "orca.isFunctionKey: returning: %s" % reply)
- return reply
-
-def isActionKey(event_string):
- """Return an indication of whether this is an action key.
-
- Arguments:
- - event: the event string
-
- Returns True if this is an action key.
- """
-
- actionKeys = [ "Return", "Escape", "Tab", "BackSpace", "Delete",
- "Page_Up", "Page_Down", "Home", "End" ]
-
- reply = event_string in actionKeys
- debug.println(debug.LEVEL_FINEST,
- "orca.isActionKey: returning: %s" % reply)
- return reply
-
-def isNavigationKey(event_string):
- """Return an indication of whether this is a navigation (arrow) key
- or if the user has the Orca modifier key held done.
-
- Arguments:
- - event: the event string
- - modifiers: key modifiers state
-
- Returns True if this is a navigation key.
- """
-
- navigationKeys = [ "Left", "Right", "Up", "Down" ]
-
- reply = event_string in navigationKeys
- if not reply and not orca_state.bypassNextCommand:
- reply = _orcaModifierPressed
-
- debug.println(debug.LEVEL_FINEST,
- "orca.isNavigationKey: returning: %s" % reply)
- return reply
-
-def isDiacriticalKey(event_string):
- """Return an indication of whether this is a non-spacing diacritical key
-
- Arguments:
- - event: the event string
- - modifiers: key modifiers state
-
- Returns True if this is a non-spacing diacritical key
- """
-
- reply = event_string.startswith("dead_")
-
- debug.println(debug.LEVEL_FINEST,
- "orca.isDiacriticalKey: returning: %s" % reply)
- return reply
-
-class KeyEventType:
- """Definition of available key event types."""
-
- # An alphanumeric or punctuation key event.
- PRINTABLE = 'PRINTABLE'
-
- # A modifier key event.
- MODIFIER = 'MODIFIER'
-
- # A locking key event.
- LOCKING = 'LOCKING'
-
- # A locking key lock event.
- LOCKING_LOCKED = 'LOCKING_LOCKED'
-
- # A locking key unlock event.
- LOCKING_UNLOCKED = 'LOCKING_UNLOCKED'
-
- # A function key event.
- FUNCTION = 'FUNCTION'
-
- # An action key event.
- ACTION = 'ACTION'
-
- # A navigation key event.
- NAVIGATION = 'NAVIGATION'
-
- # A diacritical key event.
- DIACRITICAL = 'DIACRITICAL'
-
- def __init__(self):
- pass
-
def keyEcho(event):
"""If the keyEcho setting is enabled, check to see what type of key
event it is and echo it via speech, if the user wants that type of
@@ -979,126 +803,42 @@ def keyEcho(event):
- event: an AT-SPI DeviceEvent
"""
- # If this keyboard event was for an object like a password text
- # field, then don't echo it.
- #
- try:
- role = orca_state.locusOfFocus.getRole()
- except (LookupError, RuntimeError):
- debug.println(debug.LEVEL_SEVERE,
- "orca.keyEcho() - locusOfFocus no longer exists")
- setLocusOfFocus(None, None, False)
+ if not event.shouldEcho:
return False
- except:
- pass
- else:
- if role == pyatspi.ROLE_PASSWORD_TEXT:
- return False
event_string = event.event_string
+ modifiers = event.modifiers
+ eventType = event.keyType
debug.println(debug.LEVEL_FINEST,
"orca.keyEcho: string to echo: %s" % event_string)
- # If key echo is enabled, then check to see what type of key event
- # it is and echo it via speech, if the user wants that type of key
- # echoed.
- #
- if settings.enableKeyEcho:
-
- if isModifierKey(event_string):
- if not settings.enableModifierKeys:
- return False
- eventType = KeyEventType.MODIFIER
-
- elif isNavigationKey(event_string):
- if not settings.enableNavigationKeys:
- return False
- eventType = KeyEventType.NAVIGATION
-
- elif isDiacriticalKey(event_string):
- if not settings.enableDiacriticalKeys:
- return False
- eventType = KeyEventType.DIACRITICAL
-
- elif isPrintableKey(event_string):
- if not (settings.enablePrintableKeys \
- or settings.enableEchoByCharacter):
- return False
- eventType = KeyEventType.PRINTABLE
-
- elif isLockingKey(event_string):
- if not settings.enableLockingKeys:
- return False
- eventType = KeyEventType.LOCKING
-
- modifiers = event.modifiers
-
- brailleMessage = None
- if event_string == "Caps_Lock":
- if modifiers & (1 << pyatspi.MODIFIER_SHIFTLOCK):
- eventType = KeyEventType.LOCKING_UNLOCKED
- brailleMessage = keynames.getKeyName(event_string) \
- + " " + _("off")
- else:
- eventType = KeyEventType.LOCKING_LOCKED
- brailleMessage = keynames.getKeyName(event_string) \
- + " " + _("on")
-
- elif event_string == "Num_Lock":
- if modifiers & (1 << pyatspi.MODIFIER_NUMLOCK):
- eventType = KeyEventType.LOCKING_UNLOCKED
- else:
- eventType = KeyEventType.LOCKING_LOCKED
-
- if brailleMessage:
- braille.displayMessage(brailleMessage,
- flashTime=settings.brailleFlashTime)
-
- elif isFunctionKey(event_string):
- if not settings.enableFunctionKeys:
- return False
- eventType = KeyEventType.FUNCTION
-
- elif isActionKey(event_string):
- if not settings.enableActionKeys:
- return False
- eventType = KeyEventType.ACTION
-
+ if event.event_string == "Caps_Lock":
+ if event.getLockingState():
+ brailleMessage = keynames.getKeyName(event_string) + " " + _("off")
else:
- debug.println(debug.LEVEL_FINEST,
- "orca.keyEcho: event string not handled: %s" % event_string)
- return False
+ brailleMessage = keynames.getKeyName(event_string) + " " + _("on")
+ braille.displayMessage(brailleMessage,
+ flashTime=settings.brailleFlashTime)
- # We keep track of the time as means to let others know that
- # we are probably echoing a key and should not be interrupted.
- #
- orca_state.lastKeyEchoTime = time.time()
+ # We keep track of the time as means to let others know that
+ # we are probably echoing a key and should not be interrupted.
+ #
+ orca_state.lastKeyEchoTime = time.time()
- # Before we echo printable keys, let's try to make sure the
- # character echo isn't going to also echo something.
- #
- characterEcho = \
- eventType == KeyEventType.PRINTABLE \
- and not _orcaModifierPressed \
- and orca_state.activeScript \
- and orca_state.activeScript.utilities.willEchoCharacter(event)
-
- # One last check for echoing -- a PRINTABLE key may have squeaked
- # through due to the enableEchoByCharacter check above. We only
- # want to echo PRINTABLE keys if enablePrintableKeys is True.
- #
- if not (characterEcho or
- (eventType == KeyEventType.PRINTABLE \
- and not settings.enablePrintableKeys)):
- debug.println(debug.LEVEL_FINEST,
- "orca.keyEcho: speaking: %s" % event_string)
- speech.speakKeyEvent(event_string, eventType)
- return True
- elif characterEcho:
- debug.println(debug.LEVEL_FINEST,
- "orca.keyEcho: letting character echo handle: %s" \
- % event_string)
- return False
+ # Before we echo printable keys, let's try to make sure the
+ # character echo isn't going to also echo something.
+ #
+ characterEcho = event.isCharacterEchoable() and not _orcaModifierPressed
+ if not characterEcho:
+ debug.println(debug.LEVEL_FINEST,
+ "orca.keyEcho: speaking: %s" % event_string)
+ speech.speakKeyEvent(event)
+ return True
+
+ debug.println(debug.LEVEL_FINEST,
+ "orca.keyEcho: letting character echo handle: %s" \
+ % event_string)
+ return False
def _setClickCount(inputEvent):
"""Sets the count of the number of clicks a user has made to one
@@ -1136,8 +876,7 @@ def _processKeyCaptured(event):
"""
if event.type == 0:
- if isModifierKey(event.event_string) \
- or isLockingKey(event.event_string):
+ if event.isModifierKey() or event.isLockingKey():
return True
else:
# We want the keyname rather than the printable character.
@@ -1214,37 +953,8 @@ def _processKeyboardEvent(event):
if keyboardEvent.type == pyatspi.KEY_PRESSED_EVENT:
braille.killFlash()
- # See if this is one of our special Orca modifier keys.
- #
- # Just looking at the keycode should suffice, but there is a
- # "feature" in the Java Access Bridge where it chooses to emit
- # Java platform-independent keycodes instead of the keycodes
- # for the base platform:
- #
- # http://bugzilla.gnome.org/show_bug.cgi?id=106004
- # http://bugzilla.gnome.org/show_bug.cgi?id=318615
- #
- # So...we need to workaround this problem.
- #
- # If you make the following expression True we will get a positive
- # match for all keysyms associated with a given keysym specified
- # as an Orca modifier key.
- #
- # For example, assume the Orca modifier is set to \ for some
- # reason. The key that has \ on it produces \ without the Shift
- # key and | with the Shift key. If the following expression is
- # True, both the \ and | will be viewed as the Orca modifier. If
- # the following expression is False, only the \ will be viewed as
- # the Orca modifier (i.e., Shift+\ will still function as the |
- # character). In general, I think we want to avoid sucking in all
- # possible keysyms because it can have unexpected results.
- #
- if False:
- allPossibleKeysyms = []
- for keysym in settings.orcaModifierKeys:
- allPossibleKeysyms.extend(keybindings.getAllKeysyms(keysym))
- else:
- allPossibleKeysyms = settings.orcaModifierKeys
+
+ allPossibleKeysyms = settings.orcaModifierKeys
try:
allPossibleKeysyms = \
@@ -1291,7 +1001,7 @@ def _processKeyboardEvent(event):
# store the "click count" for the purpose of supporting keybindings
# with unique behaviors when double- or triple-clicked.
#
- if not isModifierKey(keyboardEvent.event_string):
+ if not keyboardEvent.isModifierKey():
_setClickCount(keyboardEvent)
orca_state.lastNonModifierKeyEvent = keyboardEvent
@@ -1311,16 +1021,15 @@ def _processKeyboardEvent(event):
consumed = notification_messages.listNotificationMessages(
keyboardEvent)
if (not consumed):
- consumed = _keyBindings.consumeKeyboardEvent( \
- None, keyboardEvent)
+ consumed = _keyBindings.consumeKeyboardEvent(
+ None, keyboardEvent)
if (not consumed):
consumed = _eventManager.processKeyboardEvent(keyboardEvent)
if (not consumed) and settings.learnModeEnabled:
if keyboardEvent.type == pyatspi.KEY_PRESSED_EVENT:
clickCount = orca_state.activeScript.getClickCount()
- if isPrintableKey(keyboardEvent.event_string) \
- and clickCount == 2:
- orca_state.activeScript.phoneticSpellCurrentItem(\
+ if keyboardEvent.isPrintableKey() and clickCount == 2:
+ orca_state.activeScript.phoneticSpellCurrentItem(
keyboardEvent.event_string)
else:
# Check to see if there are localized words to be
@@ -1347,7 +1056,7 @@ def _processKeyboardEvent(event):
_restoreOrcaKeys = False
if not consumed \
- and not isModifierKey(keyboardEvent.event_string) \
+ and not keyboardEvent.isModifierKey() \
and keyboardEvent.type == pyatspi.KEY_PRESSED_EVENT:
orca_state.bypassNextCommand = False
except:
diff --git a/src/orca/speech.py b/src/orca/speech.py
index d8ae598..bcad38c 100644
--- a/src/orca/speech.py
+++ b/src/orca/speech.py
@@ -35,7 +35,6 @@ import time
import chnames
import debug
import keynames
-import orca
import orca_state
import settings
import sound
@@ -271,32 +270,29 @@ def speak(content, acss=None, interrupt=True):
string = " ".join(toSpeak)
_speak(string, activeVoice, interrupt)
-def speakKeyEvent(event_string, eventType):
+def speakKeyEvent(event):
"""Speaks a key event immediately.
Arguments:
- - event_string: string representing the key event as defined by
- input_event.KeyboardEvent.
- - eventType: key event type as one of orca.KeyEventType constants.
-
+ - event: input_event.KeyboardEvent to speak.
"""
if settings.silenceSpeech:
return
if _speechserver:
- _speechserver.speakKeyEvent(event_string, eventType)
+ _speechserver.speakKeyEvent(event)
else:
# Check to see if there are localized words to be spoken for
# this key event.
#
- event_string = keynames.getKeyName(event_string)
-
- if eventType == orca.KeyEventType.LOCKING_LOCKED:
+ event_string = keynames.getKeyName(event.event_string)
+ lockingState = event.getLockingState()
+ if lockingState == True:
# Translators: this represents the state of a locking modifier
# key (e.g., Caps Lock)
#
event_string += " " + _("on")
- elif eventType == orca.KeyEventType.LOCKING_UNLOCKED:
+ elif lockingState == False:
# Translators: this represents the state of a locking modifier
# key (e.g., Caps Lock)
#
diff --git a/src/orca/speechdispatcherfactory.py b/src/orca/speechdispatcherfactory.py
index 8f3691f..b58b161 100644
--- a/src/orca/speechdispatcherfactory.py
+++ b/src/orca/speechdispatcherfactory.py
@@ -45,7 +45,6 @@ import chnames
import debug
import speechserver
import settings
-import orca
import orca_state
import punctuation_settings
from acss import ACSS
@@ -463,21 +462,20 @@ class SpeechServer(speechserver.SpeechServer):
utilities.adjustForPronunciation(name)
self.speak(name, acss)
- def speakKeyEvent(self, event_string, eventType):
- if eventType == orca.KeyEventType.PRINTABLE:
+ def speakKeyEvent(self, event):
+ if event.isPrintableKey():
# We currently only handle printable characters by Speech
# Dispatcher's KEY command. For other keys, such as Ctrl, Shift
# etc. we prefer Orca's verbalization.
- if event_string.decode("UTF-8").isupper():
+ if event.event_string.decode("UTF-8").isupper():
acss = settings.voices[settings.UPPERCASE_VOICE]
else:
acss = None
- key = self.KEY_NAMES.get(event_string, event_string)
+ key = self.KEY_NAMES.get(event.event_string, event.event_string)
self._apply_acss(acss)
self._send_command(self._client.key, key)
else:
- return super(SpeechServer, self).speakKeyEvent(event_string,
- eventType)
+ return super(SpeechServer, self).speakKeyEvent(event)
def increaseSpeechRate(self, step=5):
self._change_default_speech_rate()
diff --git a/src/orca/speechserver.py b/src/orca/speechserver.py
index 58f42b1..4e373c1 100644
--- a/src/orca/speechserver.py
+++ b/src/orca/speechserver.py
@@ -33,7 +33,6 @@ __license__ = "LGPL"
import logging
import keynames
import settings
-import orca
import orca_state
log = logging.getLogger("speech")
@@ -184,17 +183,14 @@ class SpeechServer(object):
"""
pass
- def speakKeyEvent(self, event_string, eventType):
+ def speakKeyEvent(self, event):
"""Speaks a key event immediately.
Arguments:
- - event_string: string representing the key event as defined by
- input_event.KeyboardEvent.
- - eventType: key event type as one of orca.KeyEventType constants.
-
+ - event: the input_event.KeyboardEvent.
"""
- if eventType == orca.KeyEventType.PRINTABLE and \
- event_string.decode("UTF-8").isupper():
+ if event.isPrintableKey() \
+ and event.event_string.decode("UTF-8").isupper():
voice = ACSS(settings.voices[settings.UPPERCASE_VOICE])
else:
voice = ACSS(settings.voices[settings.DEFAULT_VOICE])
@@ -202,17 +198,18 @@ class SpeechServer(object):
# Check to see if there are localized words to be spoken for
# this key event.
#
- event_string = keynames.getKeyName(event_string)
+ event_string = keynames.getKeyName(event.event_string)
if orca_state.activeScript and orca_state.usePronunciationDictionary:
event_string = orca_state.activeScript.\
utilities.adjustForPronunciation(event_string)
- if eventType == orca.KeyEventType.LOCKING_LOCKED:
+ lockingState = event.getLockingState()
+ if lockingState == True:
# Translators: this represents the state of a locking modifier
# key (e.g., Caps Lock)
#
event_string += " " + _("on")
- elif eventType == orca.KeyEventType.LOCKING_UNLOCKED:
+ elif lockingState == False:
# Translators: this represents the state of a locking modifier
# key (e.g., Caps Lock)
#
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]