OSDN Git Service

UIAHandler.getNearestWindowHandle: Cache the result and use the cache for any future...
authorJames Teh <jamie@nvaccess.org>
Tue, 11 Aug 2015 06:11:27 +0000 (16:11 +1000)
committerJames Teh <jamie@nvaccess.org>
Tue, 11 Aug 2015 06:11:27 +0000 (16:11 +1000)
Re #5229.

source/_UIAHandler.py

index 635942d..fdae520 100644 (file)
@@ -289,14 +289,20 @@ class UIAHandler(COMObject):
                return v[0]\r
 \r
        def getNearestWindowHandle(self,UIAElement):\r
+               if hasattr(UIAElement,"_nearestWindowHandle"):\r
+                       # Called previously. Use cached result.\r
+                       return UIAElement._nearestWindowHandle\r
                try:\r
-                       UIAElement=self.windowTreeWalker.NormalizeElementBuildCache(UIAElement,self.windowCacheRequest)\r
+                       new=self.windowTreeWalker.NormalizeElementBuildCache(UIAElement,self.windowCacheRequest)\r
                except COMError:\r
                        return None\r
                try:\r
-                       return UIAElement.cachedNativeWindowHandle\r
+                       window=new.cachedNativeWindowHandle\r
                except COMError:\r
-                       return None\r
+                       window=None\r
+               # Cache for future use to improve performance.\r
+               UIAElement._nearestWindowHandle=window\r
+               return window\r
 \r
        def isNativeUIAElement(self,UIAElement):\r
                #Due to issues dealing with UIA elements coming from the same process, we do not class these UIA elements as usable.\r