[orca] Improve reliability of unfocusedAlertAndDialogCount()



commit 2843ed1b1302a2876ffe764f24728ce73a4105a5
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Wed Nov 13 11:18:53 2019 -0500

    Improve reliability of unfocusedAlertAndDialogCount()

 src/orca/script_utilities.py | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)
---
diff --git a/src/orca/script_utilities.py b/src/orca/script_utilities.py
index 586edf202..d62f6adac 100644
--- a/src/orca/script_utilities.py
+++ b/src/orca/script_utilities.py
@@ -2447,19 +2447,13 @@ class Utilities:
         Returns the alert and dialog count.
         """
 
-        alertAndDialogCount = 0
-        app = obj.getApplication()
-        window = self.topLevelObject(obj)
-        if window and window.getRole() != pyatspi.ROLE_ALERT and \
-           window.getRole() != pyatspi.ROLE_DIALOG and \
-           not self.isFunctionalDialog(window):
-            for child in app:
-                if child.getRole() == pyatspi.ROLE_ALERT or \
-                   child.getRole() == pyatspi.ROLE_DIALOG or \
-                   self.isFunctionalDialog(child):
-                    alertAndDialogCount += 1
-
-        return alertAndDialogCount
+        roles = [pyatspi.ROLE_ALERT, pyatspi.ROLE_DIALOG]
+        isDialog = lambda x: x and x.getRole() in roles or self.isFunctionalDialog(x)
+        dialogs = [x for x in obj.getApplication() if isDialog(x)]
+        dialogs.extend([x for x in self.topLevelObject(obj) if isDialog(x)])
+        showing = list(filter(self.isShowingAndVisible, dialogs))
+        unfocused = list(filter(lambda x: not self.canBeActiveWindow(x), showing))
+        return len(unfocused)
 
     def uri(self, obj):
         """Return the URI for a given link object.


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