[orca/570658-whereami] Migrate more where am I stuff to the script



commit b7b8481c839ef66c1c810d5d730584dc090bffc1
Author: Willie Walker <william walker sun com>
Date:   Thu Jun 4 15:51:08 2009 -0400

    Migrate more where am I stuff to the script
    
    This also includes the fix for bgo#582307 - Text selection announcement
    via Where Am I behaves oddly. These two spaces were overlapping a lot,
    so I rolled it in.
---
 src/orca/braille.py                             |    2 +-
 src/orca/default.py                             |  112 ++++++++++++++++++++--
 src/orca/scripts/apps/evolution/script.py       |   83 +++++++++++++++-
 src/orca/scripts/apps/evolution/where_am_i.py   |   77 ---------------
 src/orca/where_am_I.py                          |  118 +----------------------
 test/keystrokes/gtk-demo/role_text_multiline.py |    6 +-
 6 files changed, 191 insertions(+), 207 deletions(-)

diff --git a/src/orca/braille.py b/src/orca/braille.py
index 601fd96..c09187b 100644
--- a/src/orca/braille.py
+++ b/src/orca/braille.py
@@ -642,7 +642,7 @@ class Text(Region):
                         regionMask[i] |= attrIndicator
 
         if selIndicator:
-            selections = script.getTextSelections(self.accessible)
+            selections = script.getAllTextSelections(self.accessible)
             for startOffset, endOffset in selections:
                 maskStart = max(startOffset - self.lineOffset, 0)
                 maskEnd = min(endOffset - self.lineOffset, stringLength)
diff --git a/src/orca/default.py b/src/orca/default.py
index 4512394..17262d8 100644
--- a/src/orca/default.py
+++ b/src/orca/default.py
@@ -25,7 +25,7 @@ for GTK."""
 __id__        = "$Id$"
 __version__   = "$Revision$"
 __date__      = "$Date$"
-__copyright__ = "Copyright (c) 2005-2009 Sun Microsystems Inc."
+__copyright__ = "Copyright (c) 2004-2009 Sun Microsystems Inc."
 __license__   = "LGPL"
 
 import locale
@@ -2523,7 +2523,7 @@ class Script(script.Script):
             # speech and braille generator classes can subclass.  For
             # now, I've kind of hacked at the speech result.  The idea
             # is that the speech result might return an audio cue and
-            # voice specification.  Of course, if it does that, then 
+            # voice specification.  Of course, if it does that, then
             # the speechResult[0] assumption will fail. :-(]]]
             #
             speechResult = self.whereAmI.getWhereAmI(obj, True)
@@ -3286,7 +3286,7 @@ class Script(script.Script):
 
                 if objText.getNSelections() > 0:
                     [textContents, startOffset, endOffset] = \
-                        self.whereAmI.getTextSelection(obj)
+                        self.getSelectedText(obj)
 
                     # Now that we have the full selection, adjust based
                     # on the relation type. (see above comment)
@@ -4178,7 +4178,7 @@ class Script(script.Script):
                 pass
             else:
                 [textContents, startOffset, endOffset] = \
-                    self.whereAmI.getTextSelections(obj, True)
+                    self.getAllSelectedText(obj)
                 if textContents:
                     utterances = []
                     utterances.append(textContents)
@@ -4454,7 +4454,7 @@ class Script(script.Script):
 
     def hasTextSelections(self, obj):
         """Return an indication of whether this object has selected text.
-        Note that it's possible that this object has no text, but is part
+        Note that it's possible that this object has no selection, but is part
         of a selected text area. Because of this, we need to check the
         objects on either side to see if they are none zero length and
         have text selections.
@@ -4476,7 +4476,7 @@ class Script(script.Script):
             otherSelected = False
             text = obj.queryText()
             displayedText = text.getText(0, -1)
-            if len(displayedText) == 0:
+            if (text.caretOffset == 0) or len(displayedText) == 0:
                 current = obj
                 morePossibleSelections = True
                 while morePossibleSelections:
@@ -7751,7 +7751,105 @@ class Script(script.Script):
         else:
             return inner_container
 
-    def getTextSelections(self, acc):
+    # pylint: disable-msg=W0142
+
+    def getSelectedText(self, obj):
+        """Get the text selection for the given object.
+
+        Arguments:
+        - obj: the text object to extract the selected text from.
+
+        Returns: the selected text contents plus the start and end
+        offsets within the text.
+        """
+
+        textContents = ""
+        textObj = obj.queryText()
+        nSelections = textObj.getNSelections()
+        for i in range(0, nSelections):
+            [startOffset, endOffset] = textObj.getSelection(i)
+
+            debug.println(debug.LEVEL_FINEST,
+                "getSelectedText: selection start=%d, end=%d" % \
+                (startOffset, endOffset))
+
+            selectedText = textObj.getText(startOffset, endOffset)
+            debug.println(debug.LEVEL_FINEST,
+                "getSelectedText: selected text=<%s>" % selectedText)
+
+            if i > 0:
+                textContents += " "
+            textContents += selectedText
+
+        return [textContents, startOffset, endOffset]
+
+    def getAllSelectedText(self, obj):
+        """Get all the text applicable text selections for the given object.
+        including any previous or next text objects that also have
+        selected text and add in their text contents.
+
+        Arguments:
+        - obj: the text object to start extracting the selected text from.
+
+        Returns: all the selected text contents plus the start and end
+        offsets within the text for the given object.
+        """
+
+        textContents = ""
+        startOffset = 0
+        endOffset = 0
+        text = obj.queryText()
+        if text.getNSelections() > 0:
+            [textContents, startOffset, endOffset] = \
+                self.getSelectedText(obj)
+
+        current = obj
+        morePossibleSelections = True
+        while morePossibleSelections:
+            morePossibleSelections = False
+            for relation in current.getRelationSet():
+                if relation.getRelationType() \
+                   == pyatspi.RELATION_FLOWS_FROM:
+                    prevObj = relation.getTarget(0)
+                    prevObjText = prevObj.queryText()
+                    if prevObjText.getNSelections() > 0:
+                        [newTextContents, start, end] = \
+                            self.getSelectedText(prevObj)
+                        textContents = newTextContents + " " + textContents
+                        current = prevObj
+                        morePossibleSelections = True
+                    else:
+                        displayedText = prevObjText.getText(0, -1)
+                        if len(displayedText) == 0:
+                            current = prevObj
+                            morePossibleSelections = True
+                    break
+
+        current = obj
+        morePossibleSelections = True
+        while morePossibleSelections:
+            morePossibleSelections = False
+            for relation in current.getRelationSet():
+                if relation.getRelationType() \
+                   == pyatspi.RELATION_FLOWS_TO:
+                    nextObj = relation.getTarget(0)
+                    nextObjText = nextObj.queryText()
+                    if nextObjText.getNSelections() > 0:
+                        [newTextContents, start, end] = \
+                            self.getSelectedText(nextObj)
+                        textContents += " " + newTextContents
+                        current = nextObj
+                        morePossibleSelections = True
+                    else:
+                        displayedText = nextObjText.getText(0, -1)
+                        if len(displayedText) == 0:
+                            current = nextObj
+                            morePossibleSelections = True
+                    break
+
+        return [textContents, startOffset, endOffset]
+
+    def getAllTextSelections(self, acc):
         """Get a list of text selections in the given accessible object,
         equivelent to getNSelections()*texti.getSelection()
 
diff --git a/src/orca/scripts/apps/evolution/script.py b/src/orca/scripts/apps/evolution/script.py
index 05d4685..ed26499 100644
--- a/src/orca/scripts/apps/evolution/script.py
+++ b/src/orca/scripts/apps/evolution/script.py
@@ -375,7 +375,82 @@ class Script(default.Script):
 
         return hrs + ' ' + mins + ' ' + suffix
 
-    def hasTextSelections(self, obj):
+     def getAllSelectedText(self, obj):
+        """Get all the text applicable text selections for the given object.
+        If there is selected text, look to see if there are any previous
+        or next text objects that also have selected text and add in their
+        text contents.
+
+        Arguments:
+        - obj: the text object to start extracting the selected text from.
+
+        Returns: all the selected text contents plus the start and end
+        offsets within the text for the given object.
+        """
+
+        textContents = ""
+        startOffset = 0
+        endOffset = 0
+        if obj.queryText().getNSelections() > 0:
+            [textContents, startOffset, endOffset] = \
+                                            self.getSelectedText(obj)
+
+        # Unfortunately, Evolution doesn't use the FLOWS_FROM and
+        # FLOWS_TO relationships to easily allow us to get to previous
+        # and next text objects. Instead we have to move up the
+        # component hierarchy until we get to the object containing all
+        # the panels (with each line containing a single text item).
+        # We can then check in both directions to see if there is other
+        # contiguous text that is selected. We also have to jump over
+        # zero length (empty) text lines and continue checking on the
+        # other side.
+        #
+        container = obj.parent.parent
+        current = obj.parent.getIndexInParent()
+        morePossibleSelections = True
+        while morePossibleSelections:
+            morePossibleSelections = False
+            if (current-1) >= 0:
+                prevPanel = container[current-1]
+                try:
+                    prevObj = prevPanel[0]
+                    displayedText = prevObj.queryText().getText(0, -1)
+                    if len(displayedText) == 0:
+                        current -= 1
+                        morePossibleSelections = True
+                    elif prevObj.queryText().getNSelections() > 0:
+                        [newTextContents, start, end] = \
+                                     self.getSelectedText(prevObj)
+                        textContents = newTextContents + " " + textContents
+                        current -= 1
+                        morePossibleSelections = True
+                except:
+                    pass
+
+        current = obj.parent.getIndexInParent()
+        morePossibleSelections = True
+        while morePossibleSelections:
+            morePossibleSelections = False
+            if (current+1) < container.childCount:
+                nextPanel = container[current+1]
+                try:
+                    nextObj = nextPanel[0]
+                    displayedText = nextObj.queryText().getText(0, -1)
+                    if len(displayedText) == 0:
+                        current += 1
+                        morePossibleSelections = True
+                    elif nextObj.queryText().getNSelections() > 0:
+                        [newTextContents, start, end] = \
+                                     self.getSelectedText(nextObj)
+                        textContents += " " + newTextContents
+                        current += 1
+                        morePossibleSelections = True
+                except:
+                    pass
+
+        return [textContents, startOffset, endOffset]
+
+   def hasTextSelections(self, obj):
         """Return an indication of whether this object has selected text.
         Note that it's possible that this object has no text, but is part
         of a selected text area. Because of this, we need to check the
@@ -632,7 +707,7 @@ class Script(default.Script):
         return False
 
     def getMisspelledWordAndBody(self, suggestionsList, messagePanel):
-        """Gets the misspelled word from the spelling dialog and the 
+        """Gets the misspelled word from the spelling dialog and the
         list of words from the message body.
 
         Arguments:
@@ -1368,7 +1443,7 @@ class Script(default.Script):
                                            "Home", "End", "Return", "Tab"]:
                         return
 
-                    # If the last keyboard event was a "same line" 
+                    # If the last keyboard event was a "same line"
                     # navigation key, then pass this event onto the
                     # onCaretMoved() method in the parent class for
                     # speaking. See bug #516565 for more details.
@@ -1402,7 +1477,7 @@ class Script(default.Script):
 
             if not self.pointOfReference.get('activeDescendantInfo'):
                 [badWord, allTokens] = \
-                    self.getMisspelledWordAndBody(event.source, 
+                    self.getMisspelledWordAndBody(event.source,
                                                   self.message_panel)
                 self.speakMisspeltWord(allTokens, badWord)
 
diff --git a/src/orca/scripts/apps/evolution/where_am_i.py b/src/orca/scripts/apps/evolution/where_am_i.py
index c70f10b..85a67f3 100644
--- a/src/orca/scripts/apps/evolution/where_am_i.py
+++ b/src/orca/scripts/apps/evolution/where_am_i.py
@@ -79,80 +79,3 @@ class WhereAmI(where_am_I.WhereAmI):
         debug.println(self._debugLevel, "cell=<%s>" % text)
 
         return text
-
-    def getTextSelections(self, obj, doubleClick):
-        """Get all the text applicable text selections for the given object.
-        If the user doubleclicked, look to see if there are any previous
-        or next text objects that also have selected text and add in their
-        text contents.
-
-        Arguments:
-        - obj: the text object to start extracting the selected text from.
-        - doubleClick: True if the user double-clicked the "where am I" key.
-
-        Returns: all the selected text contents plus the start and end
-        offsets within the text for the given object.
-        """
-
-        textContents = ""
-        startOffset = 0
-        endOffset = 0
-        if obj.queryText().getNSelections() > 0:
-            [textContents, startOffset, endOffset] = \
-                                            self.getTextSelection(obj)
-
-        if doubleClick:
-            # Unfortunately, Evolution doesn't use the FLOWS_FROM and
-            # FLOWS_TO relationships to easily allow us to get to previous
-            # and next text objects. Instead we have to move up the
-            # component hierarchy until we get to the object containing all
-            # the panels (with each line containing a single text item).
-            # We can then check in both directions to see if there is other
-            # contiguous text that is selected. We also have to jump over
-            # zero length (empty) text lines and continue checking on the
-            # other side.
-            #
-            container = obj.parent.parent
-            current = obj.parent.getIndexInParent()
-            morePossibleSelections = True
-            while morePossibleSelections:
-                morePossibleSelections = False
-                if (current-1) >= 0:
-                    prevPanel = container[current-1]
-                    try:
-                        prevObj = prevPanel[0]
-                        displayedText = prevObj.queryText().getText(0, -1)
-                        if len(displayedText) == 0:
-                            current -= 1
-                            morePossibleSelections = True
-                        elif prevObj.queryText().getNSelections() > 0:
-                            [newTextContents, start, end] = \
-                                         self.getTextSelection(prevObj)
-                            textContents = newTextContents + " " + textContents
-                            current -= 1
-                            morePossibleSelections = True
-                    except:
-                        pass
-
-            current = obj.parent.getIndexInParent()
-            morePossibleSelections = True
-            while morePossibleSelections:
-                morePossibleSelections = False
-                if (current+1) < container.childCount:
-                    nextPanel = container[current+1]
-                    try:
-                        nextObj = nextPanel[0]
-                        displayedText = nextObj.queryText().getText(0, -1)
-                        if len(displayedText) == 0:
-                            current += 1
-                            morePossibleSelections = True
-                        elif nextObj.queryText().getNSelections() > 0:
-                            [newTextContents, start, end] = \
-                                         self.getTextSelection(nextObj)
-                            textContents += " " + newTextContents
-                            current += 1
-                            morePossibleSelections = True
-                    except:
-                        pass
-
-        return [textContents, startOffset, endOffset]
diff --git a/src/orca/where_am_I.py b/src/orca/where_am_I.py
index 8c0d042..4c20d2e 100644
--- a/src/orca/where_am_I.py
+++ b/src/orca/where_am_I.py
@@ -180,119 +180,6 @@ class WhereAmI:
         print "================"
         self._speakText(obj, basicOnly)
 
-    # pylint: disable-msg=W0142
-
-    def getTextSelection(self, obj):
-        """Get the text selection for the given object.
-
-        Arguments:
-        - obj: the text object to extract the selected text from.
-
-        Returns: the selected text contents plus the start and end
-        offsets within the text.
-        """
-
-        textContents = ""
-        textObj = obj.queryText()
-        nSelections = textObj.getNSelections()
-        for i in range(0, nSelections):
-            [startOffset, endOffset] = textObj.getSelection(i)
-
-            debug.println(self._debugLevel,
-                "getTextSelection: selection start=%d, end=%d" % \
-                (startOffset, endOffset))
-
-            selectedText = textObj.getText(startOffset, endOffset)
-            debug.println(self._debugLevel,
-                "getTextSelection: selected text=<%s>" % selectedText)
-
-            if i > 0:
-                textContents += " "
-            textContents += selectedText
-
-        return [textContents, startOffset, endOffset]
-
-    def getTextSelections(self, obj, basicOnly):
-        """Get all the text applicable text selections for the given object.
-        If the user is doing a detailed whereAmI, look to see if there are
-        any previous or next text objects that also have selected text and
-        add in their text contents.
-
-        Arguments:
-        - obj: the text object to start extracting the selected text from.
-        - basicOnly: True if the user is performing a standard/basic whereAmI.
-
-        Returns: all the selected text contents plus the start and end
-        offsets within the text for the given object.
-        """
-
-        textContents = ""
-        startOffset = 0
-        endOffset = 0
-        text = obj.queryText()
-        if text.getNSelections() > 0:
-            [textContents, startOffset, endOffset] = \
-                                            self.getTextSelection(obj)
-
-        if not basicOnly:
-            current = obj
-            morePossibleSelections = True
-            while morePossibleSelections:
-                morePossibleSelections = False
-                for relation in current.getRelationSet():
-                    if relation.getRelationType() == \
-                           pyatspi.RELATION_FLOWS_FROM:
-                        prevObj = relation.getTarget(0)
-                        prevObjText = prevObj.queryText()
-                        if prevObjText.getNSelections() > 0:
-                            [newTextContents, start, end] = \
-                                         self.getTextSelection(prevObj)
-                            textContents = newTextContents + " " + textContents
-                            current = prevObj
-                            morePossibleSelections = True
-                        else:
-                            displayedText = prevObjText.getText(0, -1)
-                            if len(displayedText) == 0:
-                                current = prevObj
-                                morePossibleSelections = True
-                        break
-
-            current = obj
-            morePossibleSelections = True
-            while morePossibleSelections:
-                morePossibleSelections = False
-                for relation in current.getRelationSet():
-                    if relation.getRelationType() == \
-                           pyatspi.RELATION_FLOWS_TO:
-                        nextObj = relation.getTarget(0)
-                        nextObjText = nextObj.queryText()
-                        if nextObjText.getNSelections() > 0:
-                            [newTextContents, start, end] = \
-                                         self.getTextSelection(nextObj)
-                            textContents += " " + newTextContents
-                            current = nextObj
-                            morePossibleSelections = True
-                        else:
-                            displayedText = nextObjText.getText(0, -1)
-                            if len(displayedText) == 0:
-                                current = nextObj
-                                morePossibleSelections = True
-                        break
-
-        else:
-            # We're only interested in the text selected on this line.
-            #
-            [line, lineStart, lineEnd] = \
-                   text.getTextAtOffset(text.caretOffset,
-                                        pyatspi.TEXT_BOUNDARY_LINE_START)
-            if lineStart != endOffset:
-                startOffset = max(startOffset, lineStart)
-                endOffset = min(endOffset, lineEnd)
-                textContents = line[startOffset - lineStart:
-                                    endOffset - lineStart]
-
-        return [textContents, startOffset, endOffset]
-
     def _getTextContents(self, obj, basicOnly):
         """Returns utterences for text.
 
@@ -313,11 +200,10 @@ class WhereAmI:
             (caretOffset, nSelections))
 
         [current, other] = self._script.hasTextSelections(obj)
-        if (not basicOnly and (current or other)) or \
-           (basicOnly and current):
+        if current or other:
             selected = True
             [textContents, startOffset, endOffset] = \
-                                  self.getTextSelections(obj, basicOnly)
+                self._script.getAllSelectedText(obj)
         else:
             # Get the line containing the caret
             #
diff --git a/test/keystrokes/gtk-demo/role_text_multiline.py b/test/keystrokes/gtk-demo/role_text_multiline.py
index 0bda89a..285d084 100644
--- a/test/keystrokes/gtk-demo/role_text_multiline.py
+++ b/test/keystrokes/gtk-demo/role_text_multiline.py
@@ -307,7 +307,8 @@ sequence.append(utils.AssertPresentationAction(
     "Basic Where Am I multiline selection",
     ["BRAILLE LINE:  'The keyboard sure can get sticky. $l'",
      "     VISIBLE:  'The keyboard sure can get sticky', cursor=13",
-     "SPEECH OUTPUT: 'text The keyboard'",
+     "SPEECH OUTPUT: 'text I'm just typing away like a mad little monkey with nothing better to do in my life than eat fruit and type.",
+     "The keyboard'",
      "SPEECH OUTPUT: 'selected'"]))
 
 ########################################################################
@@ -323,7 +324,8 @@ sequence.append(utils.AssertPresentationAction(
      "     VISIBLE:  'The keyboard sure can get sticky', cursor=13",
      "BRAILLE LINE:  'The keyboard sure can get sticky. $l'",
      "     VISIBLE:  'The keyboard sure can get sticky', cursor=13",
-     "SPEECH OUTPUT: 'text The keyboard'",
+     "SPEECH OUTPUT: 'text I'm just typing away like a mad little monkey with nothing better to do in my life than eat fruit and type.",
+     "The keyboard'",
      "SPEECH OUTPUT: 'selected'",
      "SPEECH OUTPUT: 'text I'm just typing away like a mad little monkey with nothing better to do in my life than eat fruit and type.",
      "The keyboard'",



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