Skip to content

Commit

Permalink
Incubates #8045
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelDCurran committed Mar 5, 2018
2 parents df90f0b + 1889803 commit 5664089
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
11 changes: 11 additions & 0 deletions source/NVDAObjects/UIA/__init__.py
Expand Up @@ -31,6 +31,7 @@
from NVDAObjects.behaviors import ProgressBar, EditableTextWithoutAutoSelectDetection, Dialog, Notification, EditableTextWithSuggestions
import braille
import time
import ui

class UIATextInfo(textInfos.TextInfo):

Expand Down Expand Up @@ -1391,6 +1392,16 @@ def event_UIA_systemAlert(self):
# Ideally, we wouldn't use getBrailleTextForProperties directly.
braille.handler.message(braille.getBrailleTextForProperties(name=self.name, role=self.role))

def event_UIA_notification(self, notificationKind=None, notificationProcessing=None, displayString=None, activityId=None):
"""
Introduced in Windows 10 Fall Creators Update (build 16299).
This base implementation announces all notifications from the UIA element.
Unlike other events, the text to be announced is not the name of the object, and parameters control how the incoming notification should be processed.
Subclasses can override this event and can react to notification processing instructions.
"""
if displayString:
ui.message(displayString)

class TreeviewItem(UIA):

def _get_value(self):
Expand Down
24 changes: 19 additions & 5 deletions source/_UIAHandler.py
Expand Up @@ -154,7 +154,7 @@
}

class UIAHandler(COMObject):
_com_interfaces_=[IUIAutomationEventHandler,IUIAutomationFocusChangedEventHandler,IUIAutomationPropertyChangedEventHandler]
_com_interfaces_=[IUIAutomationEventHandler,IUIAutomationFocusChangedEventHandler,IUIAutomationPropertyChangedEventHandler,IUIAutomationNotificationEventHandler]

def __init__(self):
super(UIAHandler,self).__init__()
Expand Down Expand Up @@ -187,10 +187,13 @@ def MTAThreadFunc(self):
except (COMError,WindowsError,NameError):
self.clientObject=CoCreateInstance(CUIAutomation._reg_clsid_,interface=IUIAutomation,clsctx=CLSCTX_INPROC_SERVER)
if isUIA8:
try:
self.clientObject=self.clientObject.QueryInterface(IUIAutomation3)
except COMError:
self.clientObject=self.clientObject.QueryInterface(IUIAutomation2)
# #8009: use appropriate interface based on highest supported interface.
for interface in (IUIAutomation5, IUIAutomation4, IUIAutomation3, IUIAutomation2):
try:
self.clientObject=self.clientObject.QueryInterface(interface)
break
except COMError:
pass
log.info("UIAutomation: %s"%self.clientObject.__class__.__mro__[1].__name__)
self.windowTreeWalker=self.clientObject.createTreeWalker(self.clientObject.CreateNotCondition(self.clientObject.CreatePropertyCondition(UIA_NativeWindowHandlePropertyId,0)))
self.windowCacheRequest=self.clientObject.CreateCacheRequest()
Expand All @@ -211,6 +214,9 @@ def MTAThreadFunc(self):
self.clientObject.AddPropertyChangedEventHandler(self.rootElement,TreeScope_Subtree,self.baseCacheRequest,self,UIAPropertyIdsToNVDAEventNames.keys())
for x in UIAEventIdsToNVDAEventNames.iterkeys():
self.clientObject.addAutomationEventHandler(x,self.rootElement,TreeScope_Subtree,self.baseCacheRequest,self)
# #7984: add support for notification event (IUIAutomation5, part of Windows 10 build 16299 and later).
if isinstance(self.clientObject, IUIAutomation5):
self.clientObject.AddNotificationEventHandler(self.rootElement,TreeScope_Subtree,self.baseCacheRequest,self)
except Exception as e:
self.MTAThreadInitException=e
finally:
Expand Down Expand Up @@ -293,6 +299,14 @@ def IUIAutomationPropertyChangedEventHandler_HandlePropertyChangedEvent(self,sen
obj=focus
eventHandler.queueEvent(NVDAEventName,obj)

def IUIAutomationNotificationEventHandler_HandleNotificationEvent(self,sender,NotificationKind,NotificationProcessing,displayString,activityId):
if not self.MTAThreadInitEvent.isSet():
# UIAHandler hasn't finished initialising yet, so just ignore this event.
return
import NVDAObjects.UIA
obj=NVDAObjects.UIA.UIA(UIAElement=sender)
eventHandler.queueEvent("UIA_notification",obj, notificationKind=NotificationKind, notificationProcessing=NotificationProcessing, displayString=displayString, activityId=activityId)

def _isUIAWindowHelper(self,hwnd):
# UIA in NVDA's process freezes in Windows 7 and below
processID=winUser.getWindowThreadProcessID(hwnd)[0]
Expand Down

0 comments on commit 5664089

Please sign in to comment.