orca r3755 - in trunk: . src/orca src/orca/scripts
- From: eitani svn gnome org
- To: svn-commits-list gnome org
- Subject: orca r3755 - in trunk: . src/orca src/orca/scripts
- Date: Tue, 25 Mar 2008 23:45:26 +0000 (GMT)
Author: eitani
Date: Tue Mar 25 23:45:25 2008
New Revision: 3755
URL: http://svn.gnome.org/viewvc/orca?rev=3755&view=rev
Log:
* src/orca/braille.py:
* src/orca/default.py:
* src/orca/scripts/StarOffice.py:
* src/orca/settings.py:
Fix for bug #523268 - Did a minor refactor for braille support of
text attributes .
Modified:
trunk/ChangeLog
trunk/src/orca/braille.py
trunk/src/orca/default.py
trunk/src/orca/scripts/StarOffice.py
trunk/src/orca/settings.py
Modified: trunk/src/orca/braille.py
==============================================================================
--- trunk/src/orca/braille.py (original)
+++ trunk/src/orca/braille.py Tue Mar 25 23:45:25 2008
@@ -555,83 +555,42 @@
# Start with an empty mask.
#
stringLength = len(self.string) - len(self.eol)
- attrMask = ['\x00']*stringLength
+ lineEndOffset = self.lineOffset + stringLength
+ regionMask = [settings.TEXT_ATTR_BRAILLE_NONE]*stringLength
attrIndicator = settings.textAttributesBrailleIndicator
selIndicator = settings.brailleSelectorIndicator
- indicateAttr = (attrIndicator != settings.TEXT_ATTR_BRAILLE_NONE)
- indicateSel = (selIndicator != settings.BRAILLE_SEL_NONE)
+ script = orca_state.activeScript
- if indicateAttr and settings.enabledBrailledTextAttributes:
- # Identify what attributes the user cares about. Also get the
- # default attributes for the text object because those attributes
- # may not be included as attributes for the character.
- #
- script = orca_state.activeScript
- enabledAttributes = settings.enabledBrailledTextAttributes
- [userAttrList, userAttrDict] = \
- script.textAttrsToDictionary(enabledAttributes)
- defaultAttributes = text.getDefaultAttributes()
- [defaultAttrList, defaultAttrDict] = \
- script.textAttrsToDictionary(defaultAttributes)
-
- # [[[TODO - HACK - JD: The end offset returned by SO/OOo is the
- # offset of the first character that doesn't have the attribute
- # in question; all other apps return the offset of the last
- # character that has that attribute]]]
- #
- adjustment = 0
- appName = orca_state.locusOfFocus.getApplication().name
- if appName.startswith("soffice"):
- adjustment += 1
-
- i = self.lineOffset
- endOffset = self.lineOffset + stringLength
- while i < endOffset - 1:
- for attribute in userAttrList:
- defaultValue = None
- if attribute in defaultAttrList:
- defaultValue = defaultAttrDict[attribute]
- [value, start, end, defined] = \
- text.getAttributeValue(i, attribute)
-
- notOfInterest = userAttrDict[attribute]
- if defined:
- weCare = (value != notOfInterest)
- elif defaultValue and len(notOfInterest):
- weCare = (defaultValue != notOfInterest)
- else:
- weCare = False
-
- if weCare and start >= 0:
- maskStart = start - self.lineOffset
- maskEnd = end - self.lineOffset - adjustment
- maskLength = maskEnd - maskStart
- attrMask[maskStart:maskEnd] = \
- [attrIndicator] * maskLength
- if (end <= i):
- break
-
- i = end
-
- if indicateSel:
- nSelections = text.getNSelections()
- if nSelections:
- for i in range(0, nSelections):
- [start, end] = text.getSelection(i)
- maskStart = max(self.lineOffset, start) - self.lineOffset
- maskEnd = min(end - self.lineOffset, stringLength)
- # Combine the selection indicator with the attribute
- # indicator.
- #
- for j in range(maskStart, maskEnd):
- if attrMask[j] != '\x00' \
- and attrMask[j] != selIndicator:
- attrMask[j] = '\xc0'
- else:
- attrMask[j] = selIndicator
-
- mask = "".join(attrMask)
+ if attrIndicator:
+ enabledAttributes = script.attribsToDictionary(
+ settings.enabledBrailledTextAttributes)
+
+ offset = self.lineOffset
+ while offset < lineEndOffset:
+ attributes, startOffset, endOffset = \
+ script.getTextAttributes(self.accessible,
+ offset, True)
+ mask = settings.TEXT_ATTR_BRAILLE_NONE
+ offset = endOffset
+ for attrib in attributes:
+ if enabledAttributes.get(attrib, '') != '':
+ if enabledAttributes[attrib] != attributes[attrib]:
+ mask = attrIndicator
+ break
+ if mask != settings.TEXT_ATTR_BRAILLE_NONE:
+ maskStart = max(startOffset - self.lineOffset, 0)
+ maskEnd = min(endOffset - self.lineOffset, stringLength)
+ for i in xrange(maskStart, maskEnd):
+ regionMask[i] |= attrIndicator
+
+ if selIndicator:
+ selections = script.getTextSelections(self.accessible)
+ for startOffset, endOffset in selections:
+ maskStart = max(startOffset - self.lineOffset, 0)
+ maskEnd = min(endOffset - self.lineOffset, stringLength)
+ for i in xrange(maskStart, maskEnd):
+ regionMask[i] |= selIndicator
if self.contracted:
contractedMask = [0] * len(self.rawLine)
@@ -640,24 +599,23 @@
# Transform the offsets.
outPos = \
[offset - len(self.label) - 1 for offset in outPos]
- for i, m in enumerate(mask):
+ for i, m in enumerate(regionMask):
try:
- contractedMask[outPos[i]] |= ord(m)
+ contractedMask[outPos[i]] |= m
except IndexError:
continue
- mask = ''.join(map(chr, contractedMask))
+ regionMask = contractedMask
# Add empty mask characters for the EOL character as well as for
# any label that might be present.
#
- for i in range (0, len(self.eol)):
- mask += '\x00'
+ regionMask += [0]*len(self.eol)
+
if self.label:
- for i in range (0, len(self.label) + 1):
- mask = '\x00' + mask
+ regionMask = [0]*len(self.label) + mask
- return mask
+ return ''.join(map(chr, regionMask))
def contractLine(self, line, cursorOffset=0, expandOnCursor=True):
contracted, inPos, outPos, cursorPos = Region.contractLine(
Modified: trunk/src/orca/default.py
==============================================================================
--- trunk/src/orca/default.py (original)
+++ trunk/src/orca/default.py Tue Mar 25 23:45:25 2008
@@ -6739,6 +6739,74 @@
"""
print "\a"
+ def attribsToDictionary(self, dict_string):
+ """Creates a Python dict from a typical attributes list returned from
+ different AT-SPI methods.
+
+ Arguments:
+ - dict_string: A list of colon seperated key/value pairs seperated by
+ semicolons.
+
+ Returns a Python dict of the given attributes.
+ """
+ try:
+ return dict(
+ map(lambda pair: pair.strip().split(':'),
+ dict_string.strip(';').split(';')))
+ except ValueError:
+ return {}
+
+ def getTextSelections(self, acc):
+ """Get a list of text selections in the given accessible object,
+ equivelent to getNSelections()*texti.getSelection()
+
+ Arguments:
+ - acc: An accessible.
+
+ Returns list of start and end offsets for multiple selections, or an
+ empty list if nothing is selected or if the accessible does not support
+ the text interface.
+ """
+ rv = []
+ try:
+ texti = acc.queryText()
+ except:
+ return rv
+
+ for i in xrange(texti.getNSelections()):
+ rv.append(texti.getSelection(i))
+
+ return rv
+
+ def getTextAttributes(self, acc, offset, get_defaults=False):
+ """Get the text attributes run for a given offset in a given accessible
+
+ Arguments:
+ - acc: An accessible.
+ - offset: Offset in the accessible's text for which to retrieve the
+ attributes.
+ - get_defaults: Get the default attributes as well as the unique ones.
+ Default is True
+
+ Returns a dictionary of attributes, a start offset where the attributes
+ begin, and an end offset. Returns ({}, 0, 0) if the accessible does not
+ supprt the text attribute.
+ """
+ rv = {}
+ try:
+ texti = acc.queryText()
+ except:
+ return rv, 0, 0
+
+ if get_defaults:
+ rv.update(self.attribsToDictionary(texti.getDefaultAttributes()))
+
+ attrib_str, start, end = texti.getAttributes(offset)
+
+ rv.update(self.attribsToDictionary(attrib_str))
+
+ return rv, start, end
+
# Dictionary that defines the state changes we care about for various
# objects. The key represents the role and the value represents a list
# of states that we care about.
Modified: trunk/src/orca/scripts/StarOffice.py
==============================================================================
--- trunk/src/orca/scripts/StarOffice.py (original)
+++ trunk/src/orca/scripts/StarOffice.py Tue Mar 25 23:45:25 2008
@@ -2779,3 +2779,21 @@
speech.speak(text)
else:
default.Script.onTextInserted(self, event)
+
+ def getTextAttributes(self, acc, offset, get_defaults=False):
+ """Get the text attributes run for a given offset in a given accessible
+
+ Arguments:
+ - acc: An accessible.
+ - offset: Offset in the accessible's text for which to retrieve the
+ attributes.
+ - get_defaults: Get the default attributes as well as the unique ones.
+ Default is True
+
+ Returns a dictionary of attributes, a start offset where the attributes
+ begin, and an end offset. Returns ({}, 0, 0) if the accessible does not
+ supprt the text attribute.
+ """
+ rv, start, end = \
+ default.Script.getTextAttributes(self, acc, offset, get_defaults)
+ return rv, start, end - 1
Modified: trunk/src/orca/settings.py
==============================================================================
--- trunk/src/orca/settings.py (original)
+++ trunk/src/orca/settings.py Tue Mar 25 23:45:25 2008
@@ -221,10 +221,10 @@
# The values represent the character to be used in the attrOr
# field of brlAPI's writeStruct.
#
-BRAILLE_SEL_NONE = '\x00' # 00000000
-BRAILLE_SEL_7 = '\x40' # 01000000
-BRAILLE_SEL_8 = '\x80' # 10000000
-BRAILLE_SEL_BOTH = '\xc0' # 11000000
+BRAILLE_SEL_NONE = 0x00 # 00000000
+BRAILLE_SEL_7 = 0x40 # 01000000
+BRAILLE_SEL_8 = 0x80 # 10000000
+BRAILLE_SEL_BOTH = 0xc0 # 11000000
brailleSelectorIndicator = BRAILLE_SEL_BOTH
# Speech punctuation levels (see verbalizePunctuationStyle).
@@ -593,10 +593,10 @@
# The values represent the character to be used in the attrOr
# field of brlAPI's writeStruct.
#
-TEXT_ATTR_BRAILLE_NONE = '\x00' # 00000000
-TEXT_ATTR_BRAILLE_7 = '\x40' # 01000000
-TEXT_ATTR_BRAILLE_8 = '\x80' # 10000000
-TEXT_ATTR_BRAILLE_BOTH = '\xc0' # 11000000
+TEXT_ATTR_BRAILLE_NONE = 0x00 # 00000000
+TEXT_ATTR_BRAILLE_7 = 0x40 # 01000000
+TEXT_ATTR_BRAILLE_8 = 0x80 # 10000000
+TEXT_ATTR_BRAILLE_BOTH = 0xc0 # 11000000
textAttributesBrailleIndicator = TEXT_ATTR_BRAILLE_NONE
# The limit to enable a repeat character count to be spoken.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]