[orca] More debugging output and handle another instance of defunct objects



commit 9358dc708d1ea7831cc4fb1e7127acc1c6e0ecba
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Sun May 5 13:51:53 2019 -0400

    More debugging output and handle another instance of defunct objects

 src/orca/generator.py                              | 12 +++++++---
 src/orca/label_inference.py                        | 28 +++++++++++++---------
 src/orca/scripts/toolkits/Chromium/script.py       | 10 ++++++++
 .../scripts/toolkits/Chromium/script_utilities.py  | 12 ++++++++--
 src/orca/scripts/toolkits/Gecko/script.py          | 10 ++++++++
 src/orca/scripts/web/script.py                     | 15 ++++++++++++
 6 files changed, 71 insertions(+), 16 deletions(-)
---
diff --git a/src/orca/generator.py b/src/orca/generator.py
index 955236e60..ac05d7455 100644
--- a/src/orca/generator.py
+++ b/src/orca/generator.py
@@ -306,9 +306,15 @@ class Generator:
         name = self._script.utilities.displayedText(obj)
         if obj.getRole() == pyatspi.ROLE_COMBO_BOX:
             children = self._script.utilities.selectedChildren(obj)
-            if not children and obj.childCount:
-                children = self._script.utilities.selectedChildren(obj[0])
-            children = children or [child for child in obj]
+            if not children:
+                try:
+                    children = self._script.utilities.selectedChildren(obj[0])
+                except:
+                    pass
+            try:
+                children = children or [child for child in obj]
+            except:
+                pass
             names = map(self._script.utilities.displayedText, children)
             names = list(filter(lambda x: x, names))
             if len(names) == 1:
diff --git a/src/orca/label_inference.py b/src/orca/label_inference.py
index b5573f3f2..2f7a93c3c 100644
--- a/src/orca/label_inference.py
+++ b/src/orca/label_inference.py
@@ -55,30 +55,30 @@ class LabelInference:
         Returns the text which we think is the label, or None.
         """
 
-        debug.println(debug.LEVEL_FINE, "INFER label for: %s" % obj)
+        debug.println(debug.LEVEL_INFO, "INFER label for: %s" % obj, True)
         if not obj:
             return None, []
 
         if focusedOnly and not obj.getState().contains(pyatspi.STATE_FOCUSED):
-            debug.println(debug.LEVEL_FINE, "INFER - object not focused")
+            debug.println(debug.LEVEL_INFO, "INFER - object not focused", True)
             return None, []
 
         result, objects = None, []
         if not result:
             result, objects = self.inferFromTextLeft(obj)
-            debug.println(debug.LEVEL_FINE, "INFER - Text Left: %s" % result)
+            debug.println(debug.LEVEL_INFO, "INFER - Text Left: %s" % result, True)
         if not result or self._preferRight(obj):
             result, objects = self.inferFromTextRight(obj) or result
-            debug.println(debug.LEVEL_FINE, "INFER - Text Right: %s" % result)
+            debug.println(debug.LEVEL_INFO, "INFER - Text Right: %s" % result, True)
         if not result:
             result, objects = self.inferFromTable(obj)
-            debug.println(debug.LEVEL_FINE, "INFER - Table: %s" % result)
+            debug.println(debug.LEVEL_INFO, "INFER - Table: %s" % result, True)
         if not result:
             result, objects = self.inferFromTextAbove(obj)
-            debug.println(debug.LEVEL_FINE, "INFER - Text Above: %s" % result)
+            debug.println(debug.LEVEL_INFO, "INFER - Text Above: %s" % result, True)
         if not result:
             result, objects = self.inferFromTextBelow(obj)
-            debug.println(debug.LEVEL_FINE, "INFER - Text Below: %s" % result)
+            debug.println(debug.LEVEL_INFO, "INFER - Text Below: %s" % result, True)
 
         # TODO - We probably do not wish to "infer" from these. Instead, we
         # should ensure that this content gets presented as part of the widget.
@@ -86,7 +86,7 @@ class LabelInference:
         # are each something other than a label.)
         if not result:
             result, objects = obj.name, []
-            debug.println(debug.LEVEL_FINE, "INFER - Name: %s" % result)
+            debug.println(debug.LEVEL_INFO, "INFER - Name: %s" % result, True)
         if result:
             result = result.strip()
             result = result.replace("\n", " ")
@@ -94,7 +94,7 @@ class LabelInference:
         # Desperate times call for desperate measures....
         if not result:
             result, objects = self.inferFromTextLeft(obj, proximity=200)
-            debug.println(debug.LEVEL_FINE, "INFER - Text Left with proximity of 200: %s" % result)
+            debug.println(debug.LEVEL_INFO, "INFER - Text Left with proximity of 200: %s" % result, True)
 
         self.clearCache()
         return result, objects
@@ -152,7 +152,7 @@ class LabelInference:
         try:
             children = [child for child in obj]
         except (LookupError, RuntimeError):
-            debug.println(debug.LEVEL_FINE, 'Dead Accessible in %s' % obj)
+            debug.println(debug.LEVEL_INFO, 'Dead Accessible in %s' % obj, True)
             return False
 
         children = [x for x in children if x.getRole() != pyatspi.ROLE_LINK]
@@ -229,7 +229,13 @@ class LabelInference:
             skipTextExtents = [pyatspi.ROLE_ENTRY, pyatspi.ROLE_PASSWORD_TEXT]
             if not obj.getRole() in skipTextExtents:
                 if endOffset == -1:
-                    endOffset = text.characterCount
+                    try:
+                        endOffset = text.characterCount
+                    except:
+                        msg = "ERROR: Exception getting character count for %s" % obj
+                        debug.println(debug.LEVEL_INFO, msg, True)
+                        return extents
+
                 extents = text.getRangeExtents(startOffset, endOffset, 0)
 
         if not (extents[2] and extents[3]):
diff --git a/src/orca/scripts/toolkits/Chromium/script.py b/src/orca/scripts/toolkits/Chromium/script.py
index d94d44343..63cd5eb1f 100644
--- a/src/orca/scripts/toolkits/Chromium/script.py
+++ b/src/orca/scripts/toolkits/Chromium/script.py
@@ -245,6 +245,16 @@ class Script(web.Script):
         debug.println(debug.LEVEL_INFO, msg, True)
         default.Script.onDocumentReload(self, event)
 
+    def onExpandedChanged(self, event):
+        """Callback for object:state-changed:expanded accessibility events."""
+
+        if super().onExpandedChanged(event):
+            return
+
+        msg = "CHROMIUM: Passing along event to default script"
+        debug.println(debug.LEVEL_INFO, msg, True)
+        default.Script.onExpandedChanged(self, event)
+
     def onFocus(self, event):
         """Callback for focus: accessibility events."""
 
diff --git a/src/orca/scripts/toolkits/Chromium/script_utilities.py 
b/src/orca/scripts/toolkits/Chromium/script_utilities.py
index a8895e357..e6198d6e6 100644
--- a/src/orca/scripts/toolkits/Chromium/script_utilities.py
+++ b/src/orca/scripts/toolkits/Chromium/script_utilities.py
@@ -86,11 +86,19 @@ class Utilities(web.Utilities):
         if result or "Selection" in pyatspi.listInterfaces(obj):
             return result
 
+        try:
+            childCount = obj.childCount
+        except:
+            msg = "CHROMIUM: Exception getting child count of %s" % obj
+            debug.println(debug.LEVEL_INFO, msg, True)
+            return result
+
         # HACK: Ideally, we'd use the selection interface to get the selected
         # children. But that interface is not implemented yet. This hackaround
         # is extremely non-performant.
-        for child in obj:
-            if child.getState().contains(pyatspi.STATE_SELECTED):
+        for i in range(childCount):
+            child = obj[i]
+            if child and child.getState().contains(pyatspi.STATE_SELECTED):
                 result.append(child)
 
         return result
diff --git a/src/orca/scripts/toolkits/Gecko/script.py b/src/orca/scripts/toolkits/Gecko/script.py
index 70700df69..fe32de89c 100644
--- a/src/orca/scripts/toolkits/Gecko/script.py
+++ b/src/orca/scripts/toolkits/Gecko/script.py
@@ -172,6 +172,16 @@ class Script(web.Script):
         debug.println(debug.LEVEL_INFO, msg, True)
         default.Script.onDocumentReload(self, event)
 
+    def onExpandedChanged(self, event):
+        """Callback for object:state-changed:expanded accessibility events."""
+
+        if super().onExpandedChanged(event):
+            return
+
+        msg = "GECKO: Passing along event to default script"
+        debug.println(debug.LEVEL_INFO, msg, True)
+        default.Script.onExpandedChanged(self, event)
+
     def onFocus(self, event):
         """Callback for focus: accessibility events."""
 
diff --git a/src/orca/scripts/web/script.py b/src/orca/scripts/web/script.py
index 72de5a677..61688ccb4 100644
--- a/src/orca/scripts/web/script.py
+++ b/src/orca/scripts/web/script.py
@@ -1692,6 +1692,21 @@ class Script(default.Script):
         self._loadingDocumentContent = True
         return True
 
+    def onExpandedChanged(self, event):
+        """Callback for object:state-changed:expanded accessibility events."""
+
+        if self.utilities.isZombie(event.source):
+            msg = "WEB: Event source is Zombie"
+            debug.println(debug.LEVEL_INFO, msg, True)
+            return True
+
+        if not self.utilities.inDocumentContent(event.source):
+            msg = "WEB: Event source is not in document content"
+            debug.println(debug.LEVEL_INFO, msg, True)
+            return False
+
+        return False
+
     def onFocusedChanged(self, event):
         """Callback for object:state-changed:focused accessibility events."""
 


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