[orca/570658-whereami] Push some code out of where_am_I and into the script



commit cc1706899ccbff93c44e87246cb859ad1e4b3afd
Author: Willie Walker <william walker sun com>
Date:   Thu Jun 4 13:48:39 2009 -0400

    Push some code out of where_am_I and into the script
    
    This is in preparation for handling "where am I" for text
---
 src/orca/braille.py                           |    2 +-
 src/orca/default.py                           |   69 ++++++++++++++-
 src/orca/scripts/apps/evolution/script.py     |   68 +++++++++++++++
 src/orca/scripts/apps/evolution/where_am_i.py |   68 ---------------
 src/orca/where_am_I.py                        |  115 +-----------------------
 5 files changed, 140 insertions(+), 182 deletions(-)

diff --git a/src/orca/braille.py b/src/orca/braille.py
index 193622e..601fd96 100644
--- a/src/orca/braille.py
+++ b/src/orca/braille.py
@@ -618,7 +618,7 @@ class Text(Region):
                 n += 1
 
         if attrIndicator:
-            enabledAttributes = script.attribsToDictionary(
+            enabledAttributes = script.attributeStringToDictionary(
                 settings.enabledBrailledTextAttributes)
 
             offset = self.lineOffset
diff --git a/src/orca/default.py b/src/orca/default.py
index 153c338..4512394 100644
--- a/src/orca/default.py
+++ b/src/orca/default.py
@@ -4452,6 +4452,69 @@ class Script(script.Script):
 
         return True
 
+    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
+        objects on either side to see if they are none zero length and
+        have text selections.
+
+        Arguments:
+        - obj: the text object to start checking for selected text.
+
+        Returns: an indication of whether this object has selected text,
+        or adjacent text objects have selected text.
+        """
+
+        currentSelected = False
+        otherSelected = False
+        text = obj.queryText()
+        nSelections = text.getNSelections()
+        if nSelections:
+            currentSelected = True
+        else:
+            otherSelected = False
+            text = obj.queryText()
+            displayedText = text.getText(0, -1)
+            if len(displayedText) == 0:
+                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:
+                                otherSelected = 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:
+                                otherSelected = True
+                            else:
+                                displayedText = nextObjText.getText(0, -1)
+                                if len(displayedText) == 0:
+                                    current = nextObj
+                                    morePossibleSelections = True
+                            break
+
+        return [currentSelected, otherSelected]
+
     def reportScriptInfo(self, inputEvent=None):
         """Output useful information on the current script via speech
         and braille.  This information will be helpful to script writers.
@@ -7601,7 +7664,7 @@ class Script(script.Script):
 
         texti.setCaretOffset(offset)
 
-    def attribsToDictionary(self, dict_string):
+    def attributeStringToDictionary(self, dict_string):
         """Creates a Python dict from a typical attributes list returned from
         different AT-SPI methods.
 
@@ -7742,11 +7805,11 @@ class Script(script.Script):
             return rv, 0, 0
 
         if get_defaults:
-            rv.update(self.attribsToDictionary(texti.getDefaultAttributes()))
+            rv.update(self.attributeStringToDictionary(texti.getDefaultAttributes()))
 
         attrib_str, start, end = texti.getAttributes(offset)
 
-        rv.update(self.attribsToDictionary(attrib_str))
+        rv.update(self.attributeStringToDictionary(attrib_str))
 
         return rv, start, end
 
diff --git a/src/orca/scripts/apps/evolution/script.py b/src/orca/scripts/apps/evolution/script.py
index df46d4f..05d4685 100644
--- a/src/orca/scripts/apps/evolution/script.py
+++ b/src/orca/scripts/apps/evolution/script.py
@@ -375,6 +375,74 @@ class Script(default.Script):
 
         return hrs + ' ' + mins + ' ' + suffix
 
+    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
+        objects on either side to see if they are none zero length and
+        have text selections.
+
+        Arguments:
+        - obj: the text object to start checking for selected text.
+
+        Returns: an indication of whether this object has selected text,
+        or adjacent text objects have selected text.
+        """
+
+        currentSelected = False
+        otherSelected = False
+        nSelections = obj.queryText().getNSelections()
+        if nSelections:
+            currentSelected = True
+        else:
+            otherSelected = False
+            displayedText = obj.queryText().getText(0, -1)
+            if len(displayedText) == 0:
+                container = obj.parent.parent
+                current = obj.parent.getIndexInParent()
+                morePossibleSelections = True
+                while morePossibleSelections:
+                    morePossibleSelections = False
+                    if (current-1) >= 0:
+                        prevPanel = container[current-1]
+                        prevObj = prevPanel[0]
+                        try:
+                            prevObjText = prevObj.queryText()
+                        except:
+                            prevObjText = None
+
+                        if prevObj and prevObjText:
+                            if prevObjText.getNSelections() > 0:
+                                otherSelected = True
+                            else:
+                                displayedText = prevObjText.getText(0, -1)
+                                if len(displayedText) == 0:
+                                    current -= 1
+                                    morePossibleSelections = True
+
+                current = obj.parent.getIndexInParent()
+                morePossibleSelections = True
+                while morePossibleSelections:
+                    morePossibleSelections = False
+                    if (current+1) < container.childCount:
+                        nextPanel = container[current+1]
+                        nextObj = nextPanel[0]
+                        try:
+                            nextObjText = nextObj.queryText()
+                        except:
+                            nextObjText = None
+
+                        if nextObj and nextObjText:
+                            if nextObjText.getNSelections() > 0:
+                                otherSelected = True
+                            else:
+                                displayedText = nextObjText.getText(0, -1)
+                                if len(displayedText) == 0:
+                                    current += 1
+                                    morePossibleSelections = True
+
+        return [currentSelected, otherSelected]
+
     def textLines(self, obj):
         """Creates a generator that can be used to iterate over each line
         of a text object, starting at the caret offset.
diff --git a/src/orca/scripts/apps/evolution/where_am_i.py b/src/orca/scripts/apps/evolution/where_am_i.py
index 779783c..c70f10b 100644
--- a/src/orca/scripts/apps/evolution/where_am_i.py
+++ b/src/orca/scripts/apps/evolution/where_am_i.py
@@ -80,74 +80,6 @@ class WhereAmI(where_am_I.WhereAmI):
 
         return text
 
-    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
-        objects on either side to see if they are none zero length and
-        have text selections.
-
-        Arguments:
-        - obj: the text object to start checking for selected text.
-
-        Returns: an indication of whether this object has selected text,
-        or adjacent text objects have selected text.
-        """
-
-        currentSelected = False
-        otherSelected = False
-        nSelections = obj.queryText().getNSelections()
-        if nSelections:
-            currentSelected = True
-        else:
-            otherSelected = False
-            displayedText = obj.queryText().getText(0, -1)
-            if len(displayedText) == 0:
-                container = obj.parent.parent
-                current = obj.parent.getIndexInParent()
-                morePossibleSelections = True
-                while morePossibleSelections:
-                    morePossibleSelections = False
-                    if (current-1) >= 0:
-                        prevPanel = container[current-1]
-                        prevObj = prevPanel[0]
-                        try:
-                            prevObjText = prevObj.queryText()
-                        except:
-                            prevObjText = None
-
-                        if prevObj and prevObjText:
-                            if prevObjText.getNSelections() > 0:
-                                otherSelected = True
-                            else:
-                                displayedText = prevObjText.getText(0, -1)
-                                if len(displayedText) == 0:
-                                    current -= 1
-                                    morePossibleSelections = True
-
-                current = obj.parent.getIndexInParent()
-                morePossibleSelections = True
-                while morePossibleSelections:
-                    morePossibleSelections = False
-                    if (current+1) < container.childCount:
-                        nextPanel = container[current+1]
-                        nextObj = nextPanel[0]
-                        try:
-                            nextObjText = nextObj.queryText()
-                        except:
-                            nextObjText = None
-
-                        if nextObj and nextObjText:
-                            if nextObjText.getNSelections() > 0:
-                                otherSelected = True
-                            else:
-                                displayedText = nextObjText.getText(0, -1)
-                                if len(displayedText) == 0:
-                                    current += 1
-                                    morePossibleSelections = True
-
-        return [currentSelected, otherSelected]
-
     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
diff --git a/src/orca/where_am_I.py b/src/orca/where_am_I.py
index 7c700a3..8c0d042 100644
--- a/src/orca/where_am_I.py
+++ b/src/orca/where_am_I.py
@@ -180,32 +180,6 @@ class WhereAmI:
         print "================"
         self._speakText(obj, basicOnly)
 
-    def _getSpeechForAllTextSelection(self, obj):
-        """Check if this object has text associated with it and it's
-        completely selected.
-
-        Arguments:
-        - obj: the object being presented
-        """
-
-        utterance = []
-        try:
-            textObj = obj.queryText()
-        except:
-            pass
-        else:
-            noOfSelections = textObj.getNSelections()
-            if noOfSelections == 1:
-                [string, startOffset, endOffset] = \
-                   textObj.getTextAtOffset(0, pyatspi.TEXT_BOUNDARY_LINE_START)
-                if startOffset == 0 and endOffset == len(string):
-                    # Translators: when the user selects (highlights) text in
-                    # a document, Orca lets them know this.
-                    #
-                    utterance = [C_("text", "selected")]
-
-        return utterance
-
     # pylint: disable-msg=W0142
 
     def getTextSelection(self, obj):
@@ -319,69 +293,6 @@ class WhereAmI:
 
         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
-        objects on either side to see if they are none zero length and
-        have text selections.
-
-        Arguments:
-        - obj: the text object to start checking for selected text.
-
-        Returns: an indication of whether this object has selected text,
-        or adjacent text objects have selected text.
-        """
-
-        currentSelected = False
-        otherSelected = False
-        text = obj.queryText()
-        nSelections = text.getNSelections()
-        if nSelections:
-            currentSelected = True
-        else:
-            otherSelected = False
-            text = obj.queryText()
-            displayedText = text.getText(0, -1)
-            if len(displayedText) == 0:
-                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:
-                                otherSelected = 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:
-                                otherSelected = True
-                            else:
-                                displayedText = nextObjText.getText(0, -1)
-                                if len(displayedText) == 0:
-                                    current = nextObj
-                                    morePossibleSelections = True
-                            break
-
-        return [currentSelected, otherSelected]
-
     def _getTextContents(self, obj, basicOnly):
         """Returns utterences for text.
 
@@ -401,7 +312,7 @@ class WhereAmI:
             "_getTextContents: caretOffset=%d, nSelections=%d" % \
             (caretOffset, nSelections))
 
-        [current, other] = self._hasTextSelections(obj)
+        [current, other] = self._script.hasTextSelections(obj)
         if (not basicOnly and (current or other)) or \
            (basicOnly and current):
             selected = True
@@ -487,11 +398,13 @@ class WhereAmI:
         attribStr = ""
 
         defaultAttributes = text.getDefaultAttributes()
-        attributesDictionary = self._stringToDictionary(defaultAttributes)
+        attributesDictionary = \
+            self._script.attributeStringToDictionary(defaultAttributes)
 
         charAttributes = text.getAttributes(textOffset)
         if charAttributes[0]:
-            charDict = self._stringToDictionary(charAttributes[0])
+            charDict = \
+                self._script.attributeStringToDictionary(charAttributes[0])
             for key in charDict.keys():
                 attributesDictionary[key] = charDict[key]
 
@@ -544,24 +457,6 @@ class WhereAmI:
         else:
             return ""
 
-    def _stringToDictionary(self, tokenString):
-        """Converts a string of text attribute tokens of the form
-        <key>:<value>; into a dictionary of keys and values.
-        Text before the colon is the key and text afterwards is the
-        value. If there is a final semi-colon, then it's ignored.
-        """
-
-        dictionary = {}
-        allTokens = tokenString.split(";")
-        for token in allTokens:
-            item = token.split(":")
-            if len(item) == 2:
-                item[0] = item[0].lstrip()
-                item[1] = item[1].lstrip()
-                dictionary[item[0]] = item[1]
-
-        return dictionary
-
     def getWhereAmI(self, obj, basicOnly):
         """Returns an array of strings (and possibly voice and audio
         specifications) that represent the complete speech for the



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