[orca] Fix whereAmI details for Nautilus



commit 2f72181334f3d8ae8cb2ee4dcb7d08cae1e07e5b
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Tue Oct 29 10:25:24 2013 -0400

    Fix whereAmI details for Nautilus

 src/orca/script_utilities.py |   16 ++++++++++++
 src/orca/scripts/default.py  |   19 ++++----------
 src/orca/speech_generator.py |   53 ++++++++++++++++++-----------------------
 3 files changed, 45 insertions(+), 43 deletions(-)
---
diff --git a/src/orca/script_utilities.py b/src/orca/script_utilities.py
index b275c45..85b1ff3 100644
--- a/src/orca/script_utilities.py
+++ b/src/orca/script_utilities.py
@@ -2851,3 +2851,19 @@ class Utilities:
             return 0, 0
 
         return hyperlink.startIndex, hyperlink.endIndex
+
+    def selectedChildren(self, obj):
+        try:
+            selection = obj.querySelection()
+        except:
+            return []
+
+        children = []
+        for x in range(selection.nSelectedChildren):
+            children.append(selection.getSelectedChild(x))
+
+        return children
+
+    def focusedChild(self, obj):
+        isFocused = lambda x: x and x.getState().contains(pyatspi.STATE_FOCUSED)
+        return pyatspi.findDescendant(obj, isFocused)
diff --git a/src/orca/scripts/default.py b/src/orca/scripts/default.py
index a3afac6..b4ac17b 100644
--- a/src/orca/scripts/default.py
+++ b/src/orca/scripts/default.py
@@ -2361,15 +2361,9 @@ class Script(script.Script):
                     newFocus = parent[index]
 
                 else:
-                    # Well...we'll first see if there is a selection.  If there
-                    # is, we'll use it.
-                    #
-                    try:
-                        selection = event.source.querySelection()
-                    except NotImplementedError:
-                        selection = None
-                    if selection and selection.nSelectedChildren > 0:
-                        newFocus = selection.getSelectedChild(0)
+                    selectedChildren = self.utilities.selectedChildren(newFocus)
+                    if selectedChildren:
+                        newFocus = selectedChildren[0]
 
         orca.setLocusOfFocus(event, newFocus)
 
@@ -2495,10 +2489,9 @@ class Script(script.Script):
         elif (event.source != orca_state.locusOfFocus) and \
               event.source.getState().contains(pyatspi.STATE_FOCUSED):
             newFocus = event.source
-            if event.source.childCount:
-                selection = event.source.querySelection()
-                if selection.nSelectedChildren > 0:
-                    newFocus = selection.getSelectedChild(0)
+            selectedChildren = self.utilities.selectedChildren(newFocus)
+            if selectedChildren:
+                newFocus = selectedChildren[0]
 
             orca.setLocusOfFocus(event, newFocus)
 
diff --git a/src/orca/speech_generator.py b/src/orca/speech_generator.py
index f4a161d..b2e0d84 100644
--- a/src/orca/speech_generator.py
+++ b/src/orca/speech_generator.py
@@ -1393,35 +1393,26 @@ class SpeechGenerator(generator.Generator):
         and the position of the current item. This object will be an icon
         panel or a layered pane.
         """
+
         if _settingsManager.getSetting('onlySpeakDisplayedText'):
             return []
 
+        container = obj
+        if not 'Selection' in pyatspi.listInterfaces(container):
+            container = obj.parent
+            if not 'Selection' in pyatspi.listInterfaces(container):
+                return []
+
         result = []
         acss = self.voice(SYSTEM)
-        # TODO - JD: Is there a better way to do this other than
-        # hard-coding it in?
-        #
-        if args.get('role', obj.getRole()) \
-                in [pyatspi.ROLE_ICON, pyatspi.ROLE_CANVAS]:
-            obj = obj.parent
-        childCount = obj.childCount
-        selectedItems = []
-        totalSelectedItems = 0
-        currentItem = 0
-        for child in obj:
-            state = child.getState()
-            if state.contains(pyatspi.STATE_SELECTED):
-                totalSelectedItems += 1
-                selectedItems.append(child)
-            if state.contains(pyatspi.STATE_FOCUSED):
-                currentItem = child.getIndexInParent() + 1
-        countString = messages.selectedItemsCount(totalSelectedItems, childCount)
-        result.append(countString)
+        childCount = container.childCount
+        selectedCount = len(self._script.utilities.selectedChildren(container))
+        result.append(messages.selectedItemsCount(selectedCount, childCount))
         result.extend(acss)
         result.append(self._script.formatting.getString(
                           mode='speech',
                           stringType='iconindex') \
-                      % {"index" : currentItem,
+                      % {"index" : obj.getIndexInParent() + 1,
                          "total" : childCount})
         result.extend(acss)
         return result
@@ -1431,16 +1422,18 @@ class SpeechGenerator(generator.Generator):
         specifications) containing the names of all the selected items.
         This object will be an icon panel or a layered pane.
         """
-        result = []
-        # TODO - JD: Is there a better way to do this other than
-        # hard-coding it in?
-        #
-        if args.get('role', obj.getRole()) == pyatspi.ROLE_ICON:
-            obj = obj.parent
-        for child in obj:
-            if child.getState().contains(pyatspi.STATE_SELECTED):
-                result.extend(self._generateLabelAndName(child))
-        return result
+
+        if _settingsManager.getSetting('onlySpeakDisplayedText'):
+            return []
+
+        container = obj
+        if not 'Selection' in pyatspi.listInterfaces(container):
+            container = obj.parent
+            if not 'Selection' in pyatspi.listInterfaces(container):
+                return []
+
+        selectedItems = self._script.utilities.selectedChildren(container)
+        return list(map(self._generateLabelAndName, selectedItems))
 
     def _generateUnfocusedDialogCount(self, obj,  **args):
         """Returns an array of strings (and possibly voice and audio


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