[orca] Remove some script calls from speech.py and vice versa
- From: Joanmarie Diggs <joanied src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [orca] Remove some script calls from speech.py and vice versa
- Date: Mon, 9 Jun 2014 19:34:05 +0000 (UTC)
commit 26046bc82becc9752d19209b7c9bdaffffa0f874
Author: Joanmarie Diggs <jdiggs igalia com>
Date: Mon Jun 9 10:31:49 2014 -0400
Remove some script calls from speech.py and vice versa
src/orca/script_utilities.py | 10 +++++
src/orca/scripts/default.py | 45 ++++++++++++++-----------
src/orca/scripts/toolkits/Gecko/script.py | 3 +-
src/orca/scripts/toolkits/WebKitGtk/script.py | 2 +-
src/orca/speech.py | 31 +----------------
5 files changed, 39 insertions(+), 52 deletions(-)
---
diff --git a/src/orca/script_utilities.py b/src/orca/script_utilities.py
index 79fd890..69a8c30 100644
--- a/src/orca/script_utilities.py
+++ b/src/orca/script_utilities.py
@@ -2260,6 +2260,10 @@ class Utilities:
return "".join(adjustedLine)
+ @staticmethod
+ def _processMultiCaseString(string):
+ return re.sub(r'(?<=[a-z])(?=[A-Z])', ' ', string)
+
def adjustForPronunciation(self, line):
"""Adjust the line to replace words in the pronunciation dictionary,
with what those words actually sound like.
@@ -2271,6 +2275,9 @@ class Utilities:
dictionary.
"""
+ if settings.speakMultiCaseStringsAsWords:
+ line = self._processMultiCaseString(line)
+
if not settings.usePronunciationDictionary:
return line
@@ -2278,6 +2285,9 @@ class Utilities:
words = self.WORDS_RE.split(line)
newLine = ''.join(map(pronunciation_dict.getPronunciation, words))
+ if settings.speakMultiCaseStringsAsWords:
+ newLine = self._processMultiCaseString(newLine)
+
return newLine
def adjustForRepeats(self, line):
diff --git a/src/orca/scripts/default.py b/src/orca/scripts/default.py
index b47146a..2b5b107 100644
--- a/src/orca/scripts/default.py
+++ b/src/orca/scripts/default.py
@@ -37,6 +37,7 @@ from gi.repository import Gtk, Gdk
import pyatspi
import orca.braille as braille
+import orca.chnames as chnames
import orca.colornames as colornames
import orca.cmdnames as cmdnames
import orca.debug as debug
@@ -1372,12 +1373,8 @@ class Script(script.Script):
- itemString: the string to spell.
"""
- for (charIndex, character) in enumerate(itemString):
- if character.isupper():
- speech.speakCharacter(character,
- self.voices[settings.UPPERCASE_VOICE])
- else:
- speech.speakCharacter(character)
+ for character in itemString:
+ self.speakCharacter(character)
def _reviewCurrentItem(self, inputEvent, targetCursorCell=0,
speechType=1):
@@ -1527,11 +1524,8 @@ class Script(script.Script):
self.speakUnicodeCharacter(charString)
elif speechType == 2:
self.phoneticSpellCurrentItem(charString)
- elif charString.isupper():
- speech.speakCharacter(charString,
- self.voices[settings.UPPERCASE_VOICE])
else:
- speech.speakCharacter(charString)
+ self.speakCharacter(charString)
self.updateBrailleReview()
self.currentReviewContents = charString
@@ -2582,6 +2576,10 @@ class Script(script.Script):
else:
return
+ if len(character) == 1:
+ self.speakCharacter(character)
+ return
+
if self.utilities.linkIndex(event.source, text.caretOffset) >= 0:
voice = self.voices[settings.HYPERLINK_VOICE]
elif character.isupper():
@@ -2593,10 +2591,7 @@ class Script(script.Script):
# right now because it is typically something else
# related to this event.
#
- if len(character) == 1:
- speech.speakCharacter(character, voice)
- else:
- speech.speak(character, voice, False)
+ speech.speak(character, voice, False)
def onTextInserted(self, event):
"""Called whenever text is inserted into an object.
@@ -2693,7 +2688,7 @@ class Script(script.Script):
if string.isupper():
speech.speak(string, self.voices[settings.UPPERCASE_VOICE])
elif not string.isalnum():
- speech.speakCharacter(string)
+ self.speakCharacter(string)
else:
speech.speak(string)
@@ -3446,7 +3441,7 @@ class Script(script.Script):
return
else:
self.speakMisspelledIndicator(obj, offset)
- speech.speakCharacter(character, voice)
+ self.speakCharacter(character)
def sayLine(self, obj):
"""Speaks the line of an AccessibleText object that contains the
@@ -3541,14 +3536,12 @@ class Script(script.Script):
if lastKey == "Right" and len(lastWord) > 0:
lastChar = lastWord[len(lastWord) - 1]
if lastChar == "\n" and lastWord != word:
- voice = self.voices[settings.DEFAULT_VOICE]
- speech.speakCharacter("\n", voice)
+ self.speakCharacter("\n")
if lastKey == "Left" and len(word) > 0:
lastChar = word[len(word) - 1]
if lastChar == "\n" and lastWord != word:
- voice = self.voices[settings.DEFAULT_VOICE]
- speech.speakCharacter("\n", voice)
+ self.speakCharacter("\n")
if self.utilities.linkIndex(obj, offset) >= 0:
voice = self.voices[settings.HYPERLINK_VOICE]
@@ -4593,6 +4586,18 @@ class Script(script.Script):
# #
########################################################################
+ def speakCharacter(self, character):
+ """Method to speak a single character. Scripts should use this
+ method rather than calling speech.speakCharacter directly."""
+
+ if character.isupper():
+ voice = self.voices[settings.UPPERCASE_VOICE]
+ else:
+ voice = self.voices[settings.DEFAULT_VOICE]
+
+ spokenCharacter = chnames.getCharacterName(character)
+ speech.speakCharacter(spokenCharacter, voice)
+
def speakMessage(self, string, voice=None, interrupt=True):
"""Method to speak a single string. Scripts should use this
method rather than calling speech.speak directly.
diff --git a/src/orca/scripts/toolkits/Gecko/script.py b/src/orca/scripts/toolkits/Gecko/script.py
index b28ce20..24fb08b 100644
--- a/src/orca/scripts/toolkits/Gecko/script.py
+++ b/src/orca/scripts/toolkits/Gecko/script.py
@@ -3630,8 +3630,7 @@ class Script(default.Script):
self.speakMisspelledIndicator(obj, characterOffset)
if obj:
if character and character != self.EMBEDDED_OBJECT_CHARACTER:
- speech.speakCharacter(character,
- self.getACSS(obj, character))
+ self.speakCharacter(character)
elif not self.utilities.isEntry(obj):
# We won't have a character if we move to the end of an
# entry (in which case we're not on a character and therefore
diff --git a/src/orca/scripts/toolkits/WebKitGtk/script.py b/src/orca/scripts/toolkits/WebKitGtk/script.py
index 17dae82..8e0b4a7 100644
--- a/src/orca/scripts/toolkits/WebKitGtk/script.py
+++ b/src/orca/scripts/toolkits/WebKitGtk/script.py
@@ -309,7 +309,7 @@ class Script(default.Script):
objects = self.utilities.getObjectsFromEOCs(obj, boundary=boundary)
for (obj, start, end, string) in objects:
if string:
- speech.speakCharacter(string)
+ self.speakCharacter(string)
else:
speech.speak(self.speechGenerator.generateSpeech(obj))
diff --git a/src/orca/speech.py b/src/orca/speech.py
index 2a52b3c..f8ad088 100644
--- a/src/orca/speech.py
+++ b/src/orca/speech.py
@@ -27,11 +27,8 @@ __copyright__ = "Copyright (c) 2005-2009 Sun Microsystems Inc."
__license__ = "LGPL"
import importlib
-
-import re
import time
-from . import chnames
from . import debug
from . import logger
from . import orca_state
@@ -48,12 +45,6 @@ log = _logger.newLog("speech")
#
_speechserver = None
-# regular expressions for multiCaseStrings
-#
-multiCaseReg1 = re.compile("([a-z]+)([A-Z])")
-multiCaseReg2 = re.compile("([A-Z][A-Z]+)([A-Z][a-z]+)")
-multiCaseReg3 = re.compile("([A-Z])([A-Z][a-z]+)")
-
def getSpeechServerFactories():
"""Imports all known SpeechServer factory modules. Returns a list
of modules that implement the getSpeechServers method, which
@@ -153,13 +144,6 @@ def sayAll(utteranceIterator, progressCallback):
def _speak(text, acss, interrupt):
"""Speaks the individual string using the given ACSS."""
- if settings.speakMultiCaseStringsAsWords:
- text = _processMultiCaseString(text)
- if orca_state.activeScript:
- text = orca_state.activeScript.utilities.adjustForPronunciation(text)
- if settings.speakMultiCaseStringsAsWords:
- text = _processMultiCaseString(text)
-
logLine = "SPEECH OUTPUT: '" + text + "'"
extraDebug = ""
if acss in list(settings.voices.values()):
@@ -280,9 +264,8 @@ def speakCharacter(character, acss=None):
if settings.silenceSpeech:
return
- spokenCharacter = chnames.getCharacterName(character)
- debug.println(debug.LEVEL_INFO, "SPEECH OUTPUT: '" + spokenCharacter + "'")
- log.info("SPEECH OUTPUT: '%s'" % spokenCharacter)
+ debug.println(debug.LEVEL_INFO, "SPEECH OUTPUT: '" + character + "'")
+ log.info("SPEECH OUTPUT: '%s'" % character)
if _speechserver:
_speechserver.speakCharacter(character, acss=acss)
@@ -385,13 +368,3 @@ def test():
server.shutdown()
except:
debug.printException(debug.LEVEL_OFF)
-
-def _processMultiCaseString(string):
- """Helper function, applies the regexes to split multiCaseStrings
- to multiple words.
- """
-
- string = multiCaseReg1.sub('\\1 \\2', string)
- string = multiCaseReg2.sub('\\1 \\2', string)
- string = multiCaseReg3.sub('\\1 \\2', string)
- return string
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]