[orca] Fix for bgo#620320 - Speaking of indentation should be handled by the speech generator.



commit 8dd3be6d22df3e03c10e23e62f4f3d106dab2196
Author: Mesar Hameed <mhameed src gnome org>
Date:   Fri Jun 4 10:17:53 2010 +0100

    Fix for bgo#620320 - Speaking of indentation should be handled by the speech generator.

 src/orca/default.py                       |   56 ++-------------------------
 src/orca/generator.py                     |    4 +-
 src/orca/scripts/apps/evolution/script.py |    5 +-
 src/orca/scripts/apps/soffice/script.py   |    8 ++-
 src/orca/speech_generator.py              |   59 +++++++++++++++++++++++++++++
 5 files changed, 74 insertions(+), 58 deletions(-)
---
diff --git a/src/orca/default.py b/src/orca/default.py
index c7e8267..e69053b 100644
--- a/src/orca/default.py
+++ b/src/orca/default.py
@@ -4370,8 +4370,10 @@ class Script(script.Script):
             else:
                 voice = self.voices[settings.DEFAULT_VOICE]
 
-            if settings.enableSpeechIndentation:
-                self.speakTextIndentation(obj, line)
+            result = \
+              self.speechGenerator.generateTextIndentation(obj, line=line)
+            if result:
+                speech.speak(result[0])
             line = self.utilities.adjustForLinks(obj, line, startOffset)
             line = self.utilities.adjustForRepeats(line)
             speech.speak(line, voice)
@@ -4455,56 +4457,6 @@ class Script(script.Script):
         orca_state.lastWord = word
         speech.speak(word, voice)
 
-    def speakTextIndentation(self, obj, line):
-        """Speaks a summary of the number of spaces and/or tabs at the
-        beginning of the given line.
-
-        Arguments:
-        - obj: the text object.
-        - line: the string to check for spaces and tabs.
-        """
-
-        # For the purpose of speaking the text indentation, replace
-        # occurances of UTF-8 '\302\240' (non breaking space) with
-        # spaces.
-        #
-        line = line.replace("\302\240",  " ")
-        line = line.decode("UTF-8")
-
-        spaceCount = 0
-        tabCount = 0
-        utterance = ""
-        offset = 0
-        while True:
-            while (offset < len(line)) and line[offset] == ' ':
-                spaceCount += 1
-                offset += 1
-            if spaceCount:
-                # Translators: this is the number of space characters on a line
-                # of text.
-                #
-                utterance += ngettext("%d space",
-                                      "%d spaces",
-                                      spaceCount) % spaceCount + " "
-
-            while (offset < len(line)) and line[offset] == '\t':
-                tabCount += 1
-                offset += 1
-            if tabCount:
-                # Translators: this is the number of tab characters on a line
-                # of text.
-                #
-                utterance += ngettext("%d tab",
-                                      "%d tabs",
-                                      tabCount) % tabCount + " "
-
-            if not (spaceCount  or tabCount):
-                break
-            spaceCount  = tabCount = 0
-
-        if len(utterance):
-            speech.speak(utterance)
-
     def stopSpeechOnActiveDescendantChanged(self, event):
         """Whether or not speech should be stopped prior to setting the
         locusOfFocus in onActiveDescendantChanged.
diff --git a/src/orca/generator.py b/src/orca/generator.py
index 9dd74e1..a9a0c6b 100644
--- a/src/orca/generator.py
+++ b/src/orca/generator.py
@@ -221,8 +221,9 @@ class Generator:
 
             debug.println(
                 debug.LEVEL_ALL,
-                "generate %s for %s (args=%s) using '%s'" \
+                "\n\n\ngenerate %s for %s %s (args=%s) using '%s'" \
                 % (self._mode,
+                   args['formatType'], 
                    debug.getAccessibleDetails(obj),
                    repr(args),
                    format))
@@ -254,6 +255,7 @@ class Generator:
         debug.println(debug.LEVEL_ALL, "generate %s results:" % self._mode)
         for element in result:
             debug.println(debug.LEVEL_ALL, "  " + str(element))
+        debug.println(debug.LEVEL_ALL, "\n\n\n")
 
         return result
 
diff --git a/src/orca/scripts/apps/evolution/script.py b/src/orca/scripts/apps/evolution/script.py
index 75f394b..51e75c3 100644
--- a/src/orca/scripts/apps/evolution/script.py
+++ b/src/orca/scripts/apps/evolution/script.py
@@ -1128,8 +1128,9 @@ class Script(default.Script):
 
         [string, caretOffset, startOffset] = self.getTextLineAtCaret(obj)
         self.updateBraille(newLocusOfFocus)
-        if settings.enableSpeechIndentation:
-            self.speakTextIndentation(obj, string)
+        result = self.speechGenerator.generateTextIndentation(obj, string)
+        if result:
+            speech.speak(result[0])
         line = self.utilities.adjustForRepeats(string)
 
         if self.utilities.speakBlankLine(obj):
diff --git a/src/orca/scripts/apps/soffice/script.py b/src/orca/scripts/apps/soffice/script.py
index 5b7c366..222ed7a 100644
--- a/src/orca/scripts/apps/soffice/script.py
+++ b/src/orca/scripts/apps/soffice/script.py
@@ -1265,9 +1265,11 @@ class Script(default.Script):
             hypertext = None
 
         if not hypertext or (hypertext.getNLinks() == 0):
-            if settings.enableSpeechIndentation:
-                self.speakTextIndentation(event.source,
-                                          textToSpeak.encode("UTF-8"))
+            result = self.speechGenerator.generateTextIndentation( \
+              event.source, line=textToSpeak.encode("UTF-8"))
+            if result:
+                speech.speak(result[0])
+
             speech.speak(textToSpeak.encode("UTF-8"), None, False)
         else:
             started = False
diff --git a/src/orca/speech_generator.py b/src/orca/speech_generator.py
index 62bc8fc..4181028 100644
--- a/src/orca/speech_generator.py
+++ b/src/orca/speech_generator.py
@@ -886,6 +886,65 @@ class SpeechGenerator(generator.Generator):
                     result = [C_("text", "selected")]
         return result
 
+    def generateTextIndentation(self, obj, **args):
+        return self._generateTextIndentation(obj, **args)
+
+    def _generateTextIndentation(self, obj, **args):
+        """Speaks a summary of the number of spaces and/or tabs at the
+        beginning of the given line.
+
+        Arguments:
+        - obj: the text object.
+        - line: the string to check for spaces and tabs.
+        """
+        if not settings.enableSpeechIndentation:
+            return []
+        line =  args.get('alreadyFocused', "")
+        if not line:
+            [line, caretOffset, startOffset] = \
+              self._script.getTextLineAtCaret(obj)
+        # For the purpose of speaking the text indentation, replace
+        # occurances of UTF-8 '\302\240' (non breaking space) with
+        # spaces.
+        #
+        line = line.replace("\302\240",  " ")
+        line = line.decode("UTF-8")
+
+        spaceCount = 0
+        tabCount = 0
+        utterance = ""
+        offset = 0
+        while True:
+            while (offset < len(line)) and line[offset] == ' ':
+                spaceCount += 1
+                offset += 1
+            if spaceCount:
+                # Translators: this is the number of space characters on a line
+                # of text.
+                #
+                utterance += ngettext("%d space",
+                                      "%d spaces",
+                                      spaceCount) % spaceCount + " "
+
+            while (offset < len(line)) and line[offset] == '\t':
+                tabCount += 1
+                offset += 1
+            if tabCount:
+                # Translators: this is the number of tab characters on a line
+                # of text.
+                #
+                utterance += ngettext("%d tab",
+                                      "%d tabs",
+                                      tabCount) % tabCount + " "
+
+            if not (spaceCount  or tabCount):
+                break
+            spaceCount  = tabCount = 0
+
+        if len(utterance):
+            return [utterance]
+        return []
+
     #####################################################################
     #                                                                   #
     # Tree interface information                                        #



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]