[orca/570658] Continue work on embedding ACSS in the speech results.
- From: William Walker <wwalker src gnome org>
- To: svn-commits-list gnome org
- Subject: [orca/570658] Continue work on embedding ACSS in the speech results.
- Date: Wed, 13 May 2009 12:34:29 -0400 (EDT)
commit c0d96cebba099658e37c3ee386f06729c3e3e024
Author: Willie Walker <william walker sun com>
Date: Wed May 13 12:33:45 2009 -0400
Continue work on embedding ACSS in the speech results.
---
src/orca/altspeechgenerator.py | 58 +++++++++++++++++++++++++++------------
src/orca/formatting.py | 18 +++---------
src/orca/speechgenerator.py | 41 +++++++++++++++++++++++++++-
3 files changed, 85 insertions(+), 32 deletions(-)
diff --git a/src/orca/altspeechgenerator.py b/src/orca/altspeechgenerator.py
index c0e3c1a..f639d7d 100755
--- a/src/orca/altspeechgenerator.py
+++ b/src/orca/altspeechgenerator.py
@@ -30,6 +30,7 @@ __license__ = "LGPL"
import sys
import traceback
+import debug
import pyatspi
import rolenames
import settings
@@ -76,6 +77,16 @@ class AltSpeechGenerator:
name = name[0].lower() + name[1:]
self._methodsDict[name] = method
+ # Verify the formatting strings are OK. This is only
+ # for verification and does not effect the function of
+ # Orca at all.
+ #
+ # Populate the entire globals with empty arrays
+ # for the results of all the legal method names.
+ #
+ methods = {}
+ for key in self._methodsDict.keys():
+ methods[key] = []
for roleKey in self._script.formatting["speech"]:
for speechKey in ["focused", "unfocused"]:
try:
@@ -88,10 +99,9 @@ class AltSpeechGenerator:
# It's legal to have an empty string for speech.
#
continue
- generatedResultsDict = {}
while True:
try:
- eval(evalString, generatedResultsDict)
+ eval(evalString, methods)
break
except NameError:
info = _formatExceptionInfo()
@@ -99,12 +109,15 @@ class AltSpeechGenerator:
arg = arg.replace("name '", "")
arg = arg.replace("' is not defined", "")
if not self._methodsDict.has_key(arg):
- print roleKey, speechKey, evalString, \
- " no function for '%s'\n" % arg
- generatedResultsDict[arg] = ""
+ debug.printException(
+ debug.LEVEL_SEVERE,
+ "Unable to find function for '%s'\n" % arg)
except:
- print roleKey, speechKey, evalString, \
- _formatExceptionInfo()
+ debug.printException(debug.LEVEL_SEVERE)
+ debug.println(
+ debug.LEVEL_SEVERE,
+ "While processing '%s' '%s' '%s' '%s'" \
+ % (roleKey, speechKey, evalString, methods))
break
#####################################################################
@@ -742,10 +755,18 @@ class AltSpeechGenerator:
# #
#####################################################################
+ def _getVoice(self, obj, **args):
+ voiceKey = args.get('role', obj.getRole())
+ try:
+ voice = settings.voices[voiceKey]
+ except:
+ voice = settings.voices[settings.DEFAULT_VOICE]
+ return [voice]
+
def getSpeech(self, obj, already_focused=False, **args):
# pylint: disable-msg=W0142
result = []
- generatedResultsDict = {}
+ methods = {}
try:
# We sometimes want to override the role. We'll keep the
# role in the args dictionary as a means to let us do so.
@@ -753,11 +774,11 @@ class AltSpeechGenerator:
args['role'] = args.get('role', obj.getRole())
# We loop through the format string, catching each error
- # as we go. Each error should always be a NameError, where
- # the name is the name of one of our generator functions.
- # When we encounter this, we call the function and get its
- # results, placing them in the generatedResultDict,
- # which serves as the globals for the call to eval.
+ # as we go. Each error should always be a NameError,
+ # where the name is the name of one of our generator
+ # functions. When we encounter this, we call the function
+ # and get its results, placing them in the globals for the
+ # the call to eval.
#
args['already_focused'] = already_focused
format = self._script.formatting.getFormat('speech',
@@ -765,7 +786,7 @@ class AltSpeechGenerator:
assert(format)
while True:
try:
- result = eval(format, generatedResultsDict)
+ result = eval(format, methods)
break
except NameError:
result = []
@@ -774,12 +795,13 @@ class AltSpeechGenerator:
arg = arg.replace("name '", "")
arg = arg.replace("' is not defined", "")
if not self._methodsDict.has_key(arg):
- print("unable to find function for '%s'\n" % arg)
+ debug.printException(
+ debug.LEVEL_SEVERE,
+ "Unable to find function for '%s'\n" % arg)
break
- generatedResultsDict[arg] = \
- self._methodsDict[arg](obj, **args)
+ methods[arg] = self._methodsDict[arg](obj, **args)
except:
- print _formatExceptionInfo()
+ debug.printException(debug.LEVEL_SEVERE)
result = []
return result
diff --git a/src/orca/formatting.py b/src/orca/formatting.py
index ddc76f8..22ca0bf 100755
--- a/src/orca/formatting.py
+++ b/src/orca/formatting.py
@@ -30,10 +30,6 @@ import pyatspi
# pylint: disable-msg=C0301
defaultFormatting = {
- 'voices': {
- 'default': ACSS({}),
- 'name' : ACSS({ACSS.AVERAGE_PITCH : 5.6}),
- },
'speech': {
'default': {
'focused': '',
@@ -89,7 +85,11 @@ defaultFormatting = {
'unfocused': 'labelAndName + percentage'
},
pyatspi.ROLE_PUSH_BUTTON: {
- 'unfocused': 'labelAndName + roleName'
+ # [[[TODO: WDW - this is just an example of embedding a
+ # voice in the format. It should be removed when we've
+ # figured that stuff out.]]]
+ #
+ 'unfocused': 'voice + labelAndName + [voice + roleName]'
},
pyatspi.ROLE_RADIO_BUTTON: {
'focused': 'radioState',
@@ -191,11 +191,3 @@ class Formatting(dict):
else:
format = roleDict['unfocused']
return format
-
- def getVoice(self, **args):
- role = args.get('role',None)
- if self['voices'].has_key(role):
- voice = self['voice'][role]
- else:
- voice = self['voice']['default']
- return voice
diff --git a/src/orca/speechgenerator.py b/src/orca/speechgenerator.py
index 9dcff3a..2816def 100755
--- a/src/orca/speechgenerator.py
+++ b/src/orca/speechgenerator.py
@@ -1859,6 +1859,42 @@ class SpeechGenerator:
return utterances
+ def _dumpAndStripAltSpeech(self, result, indent=""):
+ """Dumps and strips the array-based speech from the
+ alternate speech generator. The full result is
+ dumped to stdout and the return value is a single
+ depth array of only strings."""
+ import acss
+ newResult = []
+ subString = None
+ didACSS = False
+ for element in result:
+ if isinstance(element, basestring):
+ if subString:
+ subString += " " + element
+ else:
+ subString = element
+ newResult.append(element)
+ else:
+ if subString:
+ print indent + subString
+ subString = None
+ if isinstance(element, list):
+ newResult.extend(
+ self._dumpAndStripAltSpeech(element, indent))
+ elif isinstance(element, acss.ACSS):
+ print indent + '<voice acss=\"%s">' % element
+ indent += " "
+ didACSS = True
+ else:
+ print indent + "UNKNOWN element", element
+ if subString:
+ print indent + subString
+ if didACSS:
+ print indent[:-2] + '</voice>'
+
+ return newResult
+
def getSpeech(self, obj, already_focused, **args):
"""Get the speech for an Accessible object. This will look
first to the specific speech generators and then to the
@@ -1878,11 +1914,14 @@ class SpeechGenerator:
else:
generator = self._getDefaultSpeech
print("processing obj of role %s\n" % obj.getRoleName())
- result1 = [" ".join(generator(obj, already_focused))]
+ result1 = [" ".join(generator(obj, already_focused))]
print("r%d='%s'\n" %(len(result1[0]), result1))
result2 = self.alt.getSpeech(obj, \
already_focused=already_focused, **args)
+ print result2
+ result2 = self._dumpAndStripAltSpeech(result2)
+
# making the returned values from alt.getSpeech into a string.
speak = [" ".join(result2)]
print("s%d='%s'\n" %(len(speak[0]), speak))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]