Skip to content

Commit

Permalink
UIAHandler.getNearestWindowHandle: Cache the result and use the cache…
Browse files Browse the repository at this point in the history
… for any future call. This yields a noticeable performance improvement in Windows 10 Task View and File Explorer.

Re #5229.
  • Loading branch information
jcsteh committed Aug 11, 2015
1 parent 228c33d commit 020e3f6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions source/_UIAHandler.py
Expand Up @@ -289,14 +289,20 @@ def isUIAWindow(self,hwnd):
return v[0]

def getNearestWindowHandle(self,UIAElement):
if hasattr(UIAElement,"_nearestWindowHandle"):
# Called previously. Use cached result.
return UIAElement._nearestWindowHandle
try:
UIAElement=self.windowTreeWalker.NormalizeElementBuildCache(UIAElement,self.windowCacheRequest)
new=self.windowTreeWalker.NormalizeElementBuildCache(UIAElement,self.windowCacheRequest)
except COMError:
return None
try:
return UIAElement.cachedNativeWindowHandle
window=new.cachedNativeWindowHandle
except COMError:
return None
window=None
# Cache for future use to improve performance.
UIAElement._nearestWindowHandle=window
return window

def isNativeUIAElement(self,UIAElement):
#Due to issues dealing with UIA elements coming from the same process, we do not class these UIA elements as usable.
Expand Down

0 comments on commit 020e3f6

Please sign in to comment.