[orca] Don't keep asking the registry for the desktop



commit f6128f684a842729d96ee7c537d06208f680a222
Author: Joanmarie Diggs <jdiggs igalia com>
Date:   Sun Feb 28 15:08:12 2016 -0500

    Don't keep asking the registry for the desktop
    
    Calling getDesktop() when children are being removed can fail if the
    registry is being flooded by event spam. Especially if the spam event
    type happens to be object:children-changed:remove.

 src/orca/event_manager.py    |    5 +++--
 src/orca/script_manager.py   |    9 ++++-----
 src/orca/script_utilities.py |    4 +++-
 3 files changed, 10 insertions(+), 8 deletions(-)
---
diff --git a/src/orca/event_manager.py b/src/orca/event_manager.py
index de9a0a7..c2175a2 100644
--- a/src/orca/event_manager.py
+++ b/src/orca/event_manager.py
@@ -49,6 +49,7 @@ class EventManager:
         self._asyncMode = asyncMode
         self._scriptListenerCounts = {}
         self.registry = pyatspi.Registry
+        self._desktop = pyatspi.Registry.getDesktop(0)
         self._active = False
         self._enqueueCount = 0
         self._dequeueCount = 0
@@ -131,7 +132,7 @@ class EventManager:
         # This should ultimately be changed as there are valid reasons
         # to handle these events at the application level.
         if event.type.startswith('object:children-changed:remove') \
-           and event.source != self.registry.getDesktop(0):
+           and event.source != self._desktop:
             msg = 'EVENT MANAGER: Ignoring because event type is ignored'
             debug.println(debug.LEVEL_INFO, msg, True)
             return True
@@ -603,7 +604,7 @@ class EventManager:
 
         if eType.startswith("object:children-changed:remove"):
             try:
-                if event.source == self.registry.getDesktop(0):
+                if event.source == self._desktop:
                     _scriptManager.reclaimScripts()
                     return
             except (LookupError, RuntimeError):
diff --git a/src/orca/script_manager.py b/src/orca/script_manager.py
index 4fa5e71..9b5fb8c 100644
--- a/src/orca/script_manager.py
+++ b/src/orca/script_manager.py
@@ -25,6 +25,7 @@ __copyright__ = "Copyright (c) 2011. Orca Team."
 __license__   = "LGPL"
 
 import importlib
+import pyatspi
 
 from . import debug
 from . import orca_state
@@ -65,6 +66,7 @@ class ScriptManager:
              'gnome-terminal-server': 'gnome-terminal'}
 
         self.setActiveScript(None, "__init__")
+        self._desktop = pyatspi.Registry.getDesktop(0)
         debug.println(debug.LEVEL_INFO, 'SCRIPT MANAGER: Initialized', True)
 
     def activate(self):
@@ -278,16 +280,13 @@ class ScriptManager:
         deleting any scripts as necessary.
         """
 
-        from pyatspi import Registry
-
+        appList = list(self.appScripts.keys())
         try:
-            desktop = Registry.getDesktop(0)
+            appList = [a for a in appList if a != None and a not in self._desktop]
         except:
             debug.printException(debug.LEVEL_FINEST)
             return
 
-        appList = list(self.appScripts.keys())
-        appList = [a for a in appList if a != None and a not in desktop]
         for app in appList:
             appScript = self.appScripts.pop(app)
             del appScript
diff --git a/src/orca/script_utilities.py b/src/orca/script_utilities.py
index b459e6a..f199461 100644
--- a/src/orca/script_utilities.py
+++ b/src/orca/script_utilities.py
@@ -64,6 +64,8 @@ _settingsManager = settings_manager.getManager()
 
 class Utilities:
 
+    _desktop = pyatspi.Registry.getDesktop(0)
+
     EMBEDDED_OBJECT_CHARACTER = '\ufffc'
     SUPERSCRIPT_DIGITS = \
         ['\u2070', '\u00b9', '\u00b2', '\u00b3', '\u2074',
@@ -1320,7 +1322,7 @@ class Utilities:
         as a list of Accessible objects.
         """
 
-        return [x for x in pyatspi.Registry.getDesktop(0) if x is not None]
+        return [x for x in Utilities._desktop if x is not None]
 
     def labelsForObject(self, obj):
         """Return a list of the objects that are labelling this object.


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