[orca] Move the code which sanity checks the active window into a separate method



commit 1e0c463fddecf462587297e9b445a877560454d1
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Wed Feb 22 13:05:20 2017 -0500

    Move the code which sanity checks the active window into a separate method
    
    Apparently the destruction and (re)creation of accessible windows in
    Gecko apps is happening in between our calls to documentFrame(), so we
    need to be able to do just the sanity check elsewhere.

 src/orca/scripts/web/script_utilities.py |   63 +++++++++++++++--------------
 1 files changed, 33 insertions(+), 30 deletions(-)
---
diff --git a/src/orca/scripts/web/script_utilities.py b/src/orca/scripts/web/script_utilities.py
index be400b0..ef68b0e 100644
--- a/src/orca/scripts/web/script_utilities.py
+++ b/src/orca/scripts/web/script_utilities.py
@@ -217,7 +217,7 @@ class Utilities(script_utilities.Utilities):
 
         return list(filter(self.isDocument, targets))
 
-    def documentFrame(self, obj=None):
+    def sanityCheckActiveWindow(self):
         app = self._script.app
         try:
             windowInApp = orca_state.activeWindow in app
@@ -227,40 +227,43 @@ class Utilities(script_utilities.Utilities):
             windowInApp = False
 
         if windowInApp:
-            window = orca_state.activeWindow
+            return True
+
+        msg = "WARNING: %s is not in %s" % (orca_state.activeWindow, app)
+        debug.println(debug.LEVEL_INFO, msg, True)
+
+        try:
+            script = _scriptManager.getScript(app, orca_state.activeWindow)
+            msg = "WEB: Script for active Window is %s" % script
+            debug.println(debug.LEVEL_INFO, msg, True)
+        except:
+            msg = "ERROR: Exception getting script for active window"
+            debug.println(debug.LEVEL_INFO, msg, True)
         else:
-            msg = "WARNING: %s is not in %s" % (orca_state.activeWindow, app)
+            if type(script) == type(self._script):
+                attrs = script.getTransferableAttributes()
+                for attr, value in attrs.items():
+                    msg = "WEB: Setting %s to %s" % (attr, value)
+                    debug.println(debug.LEVEL_INFO, msg, True)
+                    setattr(self._script, attr, value)
+
+        window = self.activeWindow(app)
+        try:
+            self._script.app = window.getApplication()
+            msg = "WEB: updating script's app to %s" % self._script.app
+            debug.println(debug.LEVEL_INFO, msg, True)
+        except:
+            msg = "ERROR: Exception getting app for %s" % window
             debug.println(debug.LEVEL_INFO, msg, True)
+            return False
 
-            try:
-                script = _scriptManager.getScript(app, orca_state.activeWindow)
-                msg = "WEB: Script for active Window is %s" % script
-                debug.println(debug.LEVEL_INFO, msg, True)
-            except:
-                msg = "ERROR: Exception getting script for active window"
-                debug.println(debug.LEVEL_INFO, msg, True)
-            else:
-                if type(script) == type(self._script):
-                    attrs = script.getTransferableAttributes()
-                    for attr, value in attrs.items():
-                        msg = "WEB: Setting %s to %s" % (attr, value)
-                        debug.println(debug.LEVEL_INFO, msg, True)
-                        setattr(self._script, attr, value)
-
-            window = self.activeWindow(app)
-            try:
-                self._script.app = window.getApplication()
-                msg = "WEB: updating script's app to %s" % self._script.app
-                debug.println(debug.LEVEL_INFO, msg, True)
-            except:
-                msg = "ERROR: Exception getting app for %s" % window
-                debug.println(debug.LEVEL_INFO, msg, True)
-            else:
-                orca_state.activeWindow = window
+        orca_state.activeWindow = window
+        return True
 
-        if window:
+    def documentFrame(self, obj=None):
+        if self.sanityCheckActiveWindow():
             isShowing = lambda x: x and x.getState().contains(pyatspi.STATE_SHOWING)
-            documents = self._getDocumentsEmbeddedBy(window)
+            documents = self._getDocumentsEmbeddedBy(orca_state.activeWindow)
             documents = list(filter(isShowing, documents))
             if len(documents) == 1:
                 return documents[0]


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