[orca] More debugging details



commit 3450f9d3ee40b257d355ec99bf0d539c2cc509be
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Thu Feb 13 17:31:12 2020 +0100

    More debugging details

 src/orca/debug.py                        | 76 ++++++++++++++++++--------------
 src/orca/scripts/web/script_utilities.py | 26 ++++++++---
 2 files changed, 63 insertions(+), 39 deletions(-)
---
diff --git a/src/orca/debug.py b/src/orca/debug.py
index 3d6d08016..279794399 100644
--- a/src/orca/debug.py
+++ b/src/orca/debug.py
@@ -304,6 +304,38 @@ def printDetails(level, indent, accessible, includeApp=True, timestamp=False):
                 getAccessibleDetails(level, accessible, indent, includeApp),
                 timestamp)
 
+def statesToString(acc, indent=""):
+    try:
+        states = acc.getState().getStates()
+    except:
+        return "%sstates=(exception)" % indent
+
+    return "%sstates='%s'" % (indent, " ".join(map(pyatspi.stateToString, states)))
+
+def relationsToString(acc, indent=""):
+    try:
+        relations = [r.getRelationType() for r in acc.getRelationSet()]
+    except:
+        return "%srelations=(exception)" % indent
+
+    return "%srelations='%s'" % (indent, " ".join(map(pyatspi.relationToString, [r for r in relations])))
+
+def interfacesToString(acc, indent=""):
+    try:
+        interfaces = pyatspi.listInterfaces(acc)
+    except:
+        return "%sinterfaces=(exception)" % indent
+
+    return "%sinterfaces='%s'" % (indent, " ".join(interfaces))
+
+def attributesToString(acc, indent=""):
+    try:
+        attributes = acc.getAttributes()
+    except:
+        return "%sattributes=(exception)" % indent
+
+    return "%sattributes='%s'" % (indent, " ".join(attributes))
+
 def getAccessibleDetails(level, acc, indent="", includeApp=True):
     """Returns a string, suitable for printing, that describes the
     given accessible.
@@ -334,51 +366,29 @@ def getAccessibleDetails(level, acc, indent="", includeApp=True):
     else:
         string = indent
 
-    # create the States string
-    try:
-        stateSet = acc.getState()
-    except:
-        string += "(exception getting state set)"
     try:
-        states = stateSet.getStates()
+        name_string = "name='%s'" % acc.name
     except:
-        string += "(exception getting states)"
-        states = []
-    state_strings = []
-    for state in states:
-        state_strings.append(pyatspi.stateToString(state))
-    state_string = ' '.join(state_strings)
-
-    # create the relations string
-    try:
-        relations = acc.getRelationSet()
-    except:
-        string += "(exception getting relation set)"
-        relations = None
-    if relations:
-        relation_strings = []
-        for relation in relations:
-            relation_strings.append( \
-                          pyatspi.relationToString(relation.getRelationType()))
-        rel_string = ' '.join(relation_strings)
-    else:
-        rel_string = ''
+        name_string = "name=(exception)"
 
     try:
-        iface_string = " ".join(pyatspi.utils.listInterfaces(acc))
+        role_string = "role='%s'" % acc.getRoleName()
     except:
-        iface_string = "(exception calling listInterfaces)"
+        role_string = "role=(exception)"
+
+    state_string = statesToString(acc, indent)
+    rel_string = relationsToString(acc, indent)
+    iface_string = interfacesToString(acc, indent)
+    attr_string = attributesToString(acc, indent)
 
     try:
-        string += "name='%s' role='%s' state='%s' \n%srelations='%s' interfaces='%s'" \
-                  % (acc.name or 'None', acc.getRoleName(),
-                     state_string, indent, rel_string, iface_string)
+        string += "%s %s \n%s \n%s \n%s \n%s" \
+                  % (name_string, role_string, state_string, rel_string, iface_string, attr_string)
     except:
         string += "(exception fetching data)"
 
     return string
 
-
 # The following code originated from the following URL:
 # 
 # http://www.dalkescientific.com/writings/diary/archive/ \
diff --git a/src/orca/scripts/web/script_utilities.py b/src/orca/scripts/web/script_utilities.py
index a19758503..87ce01799 100644
--- a/src/orca/scripts/web/script_utilities.py
+++ b/src/orca/scripts/web/script_utilities.py
@@ -1490,6 +1490,22 @@ class Utilities(script_utilities.Utilities):
 
         return False
 
+    def _debugContentsInfo(self, obj, offset, contents, contentsMsg=""):
+        if debug.LEVEL_INFO < debug.debugLevel:
+            return
+
+        msg = "WEB: %s for %s at offset %i:" % (contentsMsg, obj, offset)
+        debug.println(debug.LEVEL_INFO, msg, True)
+
+        for i, (acc, start, end, string) in enumerate(contents):
+            indent = " " * 8
+            extents = self.getExtents(acc, start, end)
+            states = debug.statesToString(acc, indent)
+            attrs = debug.attributesToString(acc, indent)
+            msg = "     %i. %s (chars: %i-%i) '%s' extents=%s\n%s\n%s" % \
+                (i, acc, start, end, string, extents, states, attrs)
+            debug.println(debug.LEVEL_INFO, msg, True)
+
     def getLineContentsAtOffset(self, obj, offset, layoutMode=None, useCache=True):
         if not obj:
             return []
@@ -1499,6 +1515,7 @@ class Utilities(script_utilities.Utilities):
 
         if useCache:
             if self.findObjectInContents(obj, offset, self._currentLineContents, usingCache=True) != -1:
+                self._debugContentsInfo(obj, offset, self._currentLineContents, "Line (cached)")
                 return self._currentLineContents
 
         if layoutMode is None:
@@ -1537,6 +1554,8 @@ class Utilities(script_utilities.Utilities):
         if not layoutMode:
             if useCache:
                 self._currentLineContents = objects
+
+            self._debugContentsInfo(obj, offset, objects, "Line (not layout mode)")
             return objects
 
         firstObj, firstStart, firstEnd, firstString = objects[0]
@@ -1599,6 +1618,7 @@ class Utilities(script_utilities.Utilities):
         if useCache:
             self._currentLineContents = objects
 
+        self._debugContentsInfo(obj, offset, objects, "Line (layout mode)")
         return objects
 
     def getPreviousLineContents(self, obj=None, offset=-1, layoutMode=None, useCache=True):
@@ -1619,9 +1639,6 @@ class Utilities(script_utilities.Utilities):
             debug.println(debug.LEVEL_INFO, msg, True)
 
         line = self.getLineContentsAtOffset(obj, offset, layoutMode, useCache)
-        msg = "WEB: Line contents for %s, %i: %s" % (obj, offset, line)
-        debug.println(debug.LEVEL_INFO, msg, True)
-
         if not (line and line[0]):
             return []
 
@@ -1665,9 +1682,6 @@ class Utilities(script_utilities.Utilities):
             debug.println(debug.LEVEL_INFO, msg, True)
 
         line = self.getLineContentsAtOffset(obj, offset, layoutMode, useCache)
-        msg = "WEB: Line contents for %s, %i: %s" % (obj, offset, line)
-        debug.println(debug.LEVEL_INFO, msg, True)
-
         if not (line and line[0]):
             return []
 


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