[orca] Fix for bgo#581372 - Move cursor routing and six dot key handling from braille.py to script
- From: William Walker <wwalker src gnome org>
- To: svn-commits-list gnome org
- Subject: [orca] Fix for bgo#581372 - Move cursor routing and six dot key handling from braille.py to script
- Date: Tue, 5 May 2009 14:19:47 -0400 (EDT)
commit 423e67d56b9bb954b5df15c58e1fb666fbb675bf
Author: Willie Walker <william walker sun com>
Date: Tue May 5 14:13:37 2009 -0400
Fix for bgo#581372 - Move cursor routing and six dot key handling from braille.py to script
With the cleanup from bgo#581532 to remove the custom brl module and
move directly to the brlapi module provided by BrlTTY/BrlAPI, we are
now able to handle BrlAPI commands much better. This patch 'uncovers'
the handling the cursor routing keys and the six dot keys; they are
no longer swallowed/handled by the braille.py module alone. Instead,
they go to the script like any other event. By default, the script
just turns around and calls braille.py methods, but it can also feel
free to override them. For example, it might look at keyboard
modifiers along with a cursor routing key to see if it wants to
select text or not.
As a note, the BrlAPI events come to us as a dictionary containing a
bunch of information about the event. For example, the cursor routing
command contains information about which routing key was pressed. The
six dots command, which is used to turn contracted braille on or off,
contains information about whether the user wants to turn contracted
braille on (dots 2-3-5 on my Baum display) or off (dots 2-3-6 on my
Baum display). Right now, expressing interest in braille events is
still done by the command (e.g., brlapi.KEY_CMD_HOME,
brlapi.KEY_CMD_ROUTE, brlapi.KEY_CMD_SIXDOTS) and it is up to the
event handler to determine how to handle the arguments.
---
src/orca/braille.py | 96 ++++++++++++++-------------------
src/orca/default.py | 37 +++++++++++++
src/orca/focus_tracking_presenter.py | 15 +++---
src/orca/orca.py | 6 +-
src/orca/script.py | 4 +-
5 files changed, 91 insertions(+), 67 deletions(-)
diff --git a/src/orca/braille.py b/src/orca/braille.py
index ae9e475..5109ac8 100644
--- a/src/orca/braille.py
+++ b/src/orca/braille.py
@@ -78,9 +78,6 @@ _initialized = False
#
monitor = None
-BRL_FLG_REPEAT_INITIAL = 0x800000
-BRL_FLG_REPEAT_DELAY = 0x400000
-
# Common names for most used BrlTTY commands, to be shown in the GUI:
# ATM, the ones used in default.py are:
#
@@ -137,6 +134,21 @@ command_name[brlapi.KEY_CMD_BOT_LEFT] = _("Bottom Right")
#
command_name[brlapi.KEY_CMD_HOME] = _("Cursor Position")
+# Translators: this is a command for a button on a refreshable braille
+# display (an external hardware device used by people who are blind).
+# When pressing the button, the display toggles between contracted and
+# contracted braille.
+#
+command_name[brlapi.KEY_CMD_SIXDOTS] = _("Six Dots")
+
+# Translators: this is a command for a button on a refreshable braille
+# display (an external hardware device used by people who are blind).
+# This command represents a whole set of buttons known as cursor
+# routings keys and are a way for a user to tell the machine they are
+# interested in a particular character on the display.
+#
+command_name[brlapi.KEY_CMD_ROUTE] = _("Cursor Routing")
+
# The size of the physical display (width, height). The coordinate system of
# the display is set such that the upper left is (0,0), x values increase from
# left to right, and y values increase from top to bottom.
@@ -190,7 +202,7 @@ def _printBrailleEvent(level, command):
debug.printInputEvent(
level,
- "BRAILLE EVENT: %x" % command)
+ "BRAILLE EVENT: %s" % repr(command))
class Region:
"""A Braille region to be displayed on the display. The width of
@@ -309,9 +321,6 @@ class Region:
return offset
def setContractedBraille(self, contracted):
- if self.contracted == contracted:
- return
- self.contracted = contracted
if contracted:
self.contractionTable = settings.brailleContractionTable or \
_defaultContractionTable
@@ -320,10 +329,13 @@ class Region:
self.expandRegion()
def contractRegion(self):
+ if self.contracted:
+ return
self.string, self.inPos, self.outPos, self.cursorOffset = \
self.contractLine(self.rawLine,
self.cursorOffset,
self.expandOnCursor)
+ self.contracted = True
def expandRegion(self):
if not self.contracted:
@@ -333,6 +345,7 @@ class Region:
self.cursorOffset = self.inPos[self.cursorOffset]
except IndexError:
self.cursorOffset = len(self.string)
+ self.contracted = False
class Component(Region):
"""A subclass of Region backed by an accessible. This Region will react
@@ -1125,29 +1138,30 @@ def returnToRegionWithFocus(inputEvent=None):
return True
-def _processBrailleEvent(command):
+def setContractedBraille(event):
+ settings.enableContractedBraille = \
+ (event.event["flags"] & brlapi.KEY_FLG_TOGGLE_ON) != 0
+ for line in _lines:
+ line.setContractedBraille(settings.enableContractedBraille)
+ refresh()
+
+def processRoutingKey(event):
+ cell = event.event["argument"]
+ if len(_lines) > 0:
+ cursor = cell + viewport[0]
+ lineNum = viewport[1]
+ _lines[lineNum].processRoutingKey(cursor)
+ return True
+
+def _processBrailleEvent(event):
"""Handles BrlTTY command events. This passes commands on to Orca for
- processing. If Orca does not handle them (as indicated by a return value
- of false from the callback passed to init, it will attempt to handle the
- command itself - either by panning the viewport or passing cursor routing
- keys to the Regions for handling.
+ processing.
Arguments:
- - command: the BrlAPI command for the key that was pressed.
+ - event: the BrlAPI input event (expanded)
"""
- _printBrailleEvent(debug.LEVEL_FINE, command)
-
- # [[[TODO: WDW - DaveM suspects the Alva driver is sending us a
- # repeat flag. So...let's kill a couple birds here until BrlTTY
- # 3.8 fixes the problem: we'll disable autorepeat and we'll also
- # strip out the autorepeat flag if this is the first press of a
- # button.]]]
- #
- if command & BRL_FLG_REPEAT_INITIAL:
- command &= ~(BRL_FLG_REPEAT_INITIAL | BRL_FLG_REPEAT_DELAY)
- elif command & BRL_FLG_REPEAT_DELAY:
- return True
+ _printBrailleEvent(debug.LEVEL_FINE, event)
consumed = False
@@ -1160,24 +1174,11 @@ def _processBrailleEvent(command):
# Like key event handlers, a return value of True means
# the command was consumed.
#
- consumed = _callback(command)
+ consumed = _callback(event)
except:
debug.printException(debug.LEVEL_WARNING)
consumed = False
- if (command >= 0x100) and (command < (0x100 + _displaySize[0])):
- if len(_lines) > 0:
- cursor = (command - 0x100) + viewport[0]
- lineNum = viewport[1]
- _lines[lineNum].processRoutingKey(cursor)
- consumed = True
-
- if command in (0x2141, 65): # Toggle six dot braille
- settings.enableContractedBraille = not settings.enableContractedBraille
- for line in _lines:
- line.setContractedBraille(settings.enableContractedBraille)
- refresh()
-
if settings.timeoutCallback and (settings.timeoutTime > 0):
signal.alarm(0)
@@ -1189,21 +1190,7 @@ def _brlAPIKeyReader(source, condition):
"""
key = _brlAPI.readKey(False)
if key:
- #flags = key >> 32
- lower = key & 0xFFFFFFFF
- #keyType = lower >> 29
- keyCode = lower & 0x1FFFFFFF
-
- # [[TODO: WDW - HACK If we have a cursor routing key, map
- # it back to the code we used to get with earlier versions
- # of BrlAPI (i.e., bit 0x100 was the indicator of a cursor
- # routing key instead of 0x1000). This may change before
- # the offical BrlAPI Python bindings are released.]]]
- #
- if keyCode & 0x10000:
- keyCode = 0x100 | (keyCode & 0xFF)
- if keyCode:
- _processBrailleEvent(keyCode)
+ _processBrailleEvent(_brlAPI.expandKeyCode(key))
return _brlAPIRunning
def setupKeyRanges(keys):
@@ -1230,7 +1217,6 @@ def setupKeyRanges(keys):
keySet.append(brlapi.KEY_TYPE_CMD | key)
_brlAPI.acceptKeys(brlapi.rangeType_command, keySet)
- _brlAPI.acceptKeys(brlapi.rangeType_key, [65])
def init(callback=None, tty=7):
"""Initializes the braille module, connecting to the BrlTTY driver.
diff --git a/src/orca/default.py b/src/orca/default.py
index 1ffe2e0..bf597af 100644
--- a/src/orca/default.py
+++ b/src/orca/default.py
@@ -671,6 +671,28 @@ class Script(script.Script):
#
_("Returns to object with keyboard focus."))
+ self.inputEventHandlers["contractedBrailleHandler"] = \
+ input_event.InputEventHandler(
+ Script.setContractedBraille,
+ # Translators: braille can be displayed in many ways.
+ # Contracted braille provides a more efficient means
+ # to represent text, especially long documents. The
+ # feature used here is an option to toggle between
+ # contracted and uncontracted.
+ #
+ _("Turns contracted braille on and off."))
+
+ self.inputEventHandlers["processRoutingKeyHandler"] = \
+ input_event.InputEventHandler(
+ Script.processRoutingKey,
+ # Translators: hardware braille displays often have
+ # buttons near each braille cell. These are called
+ # cursor routing keys and are a way for a user to
+ # tell the machine they are interested in a particular
+ # character on the display.
+ #
+ _("Processes a cursor routing key."))
+
self.inputEventHandlers["enterLearnModeHandler"] = \
input_event.InputEventHandler(
Script.enterLearnMode,
@@ -1935,6 +1957,10 @@ class Script(script.Script):
self.inputEventHandlers["reviewBottomLeftHandler"]
brailleBindings[braille.brlapi.KEY_CMD_HOME] = \
self.inputEventHandlers["goBrailleHomeHandler"]
+ brailleBindings[braille.brlapi.KEY_CMD_SIXDOTS] = \
+ self.inputEventHandlers["contractedBrailleHandler"]
+ brailleBindings[braille.brlapi.KEY_CMD_ROUTE] = \
+ self.inputEventHandlers["processRoutingKeyHandler"]
return brailleBindings
@@ -4940,6 +4966,17 @@ class Script(script.Script):
else:
return braille.returnToRegionWithFocus(inputEvent)
+ def setContractedBraille(self, inputEvent=None):
+ """Toggles contracted braille."""
+ braille.setContractedBraille(inputEvent)
+ return True
+
+ def processRoutingKey(self, inputEvent=None):
+ """Processes a cursor routing key."""
+
+ braille.processRoutingKey(inputEvent)
+ return True
+
def leftClickReviewItem(self, inputEvent=None):
"""Performs a left mouse button click on the current item."""
diff --git a/src/orca/focus_tracking_presenter.py b/src/orca/focus_tracking_presenter.py
index cdf0e42..708ba7a 100644
--- a/src/orca/focus_tracking_presenter.py
+++ b/src/orca/focus_tracking_presenter.py
@@ -751,7 +751,8 @@ class FocusTrackingPresenter(presentation_manager.PresentationManager):
event = e
elif isinstance(e, input_event.BrailleEvent):
debug.println(debug.LEVEL_ALL,
- "----------> QUEUEING BRAILLE COMMAND %d" % e.event)
+ "----------> QUEUEING BRAILLE COMMAND %s" \
+ % repr(e.event))
event = e
else:
if e.type in settings.ignoredEventsList:
@@ -894,15 +895,15 @@ class FocusTrackingPresenter(presentation_manager.PresentationManager):
% (pressRelease, event.event_string))
elif isinstance(event, input_event.BrailleEvent):
debug.println(debug.LEVEL_ALL,
- "DEQUEUED BRAILLE COMMAND %d <----------" \
- % event.event)
+ "DEQUEUED BRAILLE COMMAND %s <----------" \
+ % repr(event.event))
debug.println(debug.eventDebugLevel,
- "\nvvvvv PROCESS BRAILLE EVENT %d vvvvv"\
- % event.event)
+ "\nvvvvv PROCESS BRAILLE EVENT %s vvvvv"\
+ % repr(event.event))
self._processBrailleEvent(event)
debug.println(debug.eventDebugLevel,
- "\n^^^^^ PROCESS BRAILLE EVENT %d ^^^^^"\
- % event.event)
+ "\n^^^^^ PROCESS BRAILLE EVENT %s ^^^^^"\
+ % repr(event.event))
else:
if (not debug.eventDebugFilter) \
or (debug.eventDebugFilter \
diff --git a/src/orca/orca.py b/src/orca/orca.py
index 5663ca1..8d8cd93 100644
--- a/src/orca/orca.py
+++ b/src/orca/orca.py
@@ -820,11 +820,11 @@ def _processKeyboardEvent(event):
# #
########################################################################
-def _processBrailleEvent(command):
+def _processBrailleEvent(event):
"""Called whenever a key is pressed on the Braille display.
Arguments:
- - command: the BrlAPI command for the key that was pressed.
+ - command: the BrlAPI event for the key that was pressed.
Returns True if the event was consumed; otherwise False
"""
@@ -835,7 +835,7 @@ def _processBrailleEvent(command):
#
speech.stop()
- event = BrailleEvent(command)
+ event = BrailleEvent(event)
orca_state.lastInputEvent = event
try:
diff --git a/src/orca/script.py b/src/orca/script.py
index a31cb98..563e09d 100644
--- a/src/orca/script.py
+++ b/src/orca/script.py
@@ -442,7 +442,7 @@ class Script:
elif "default" in user_bindings_map:
user_bindings = user_bindings_map["default"]
- command = brailleEvent.event
+ command = brailleEvent.event["command"]
consumes = False
if user_bindings:
consumes = command in user_bindings
@@ -481,7 +481,7 @@ class Script:
#
consumed = False
user_bindings = None
- command = brailleEvent.event
+ command = brailleEvent.event["command"]
user_bindings_map = settings.brailleBindingsMap
if self.name in user_bindings_map:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]