Skip to content

Commit

Permalink
Allow UIA to work again on Win7 after pr #12210 (#12233)
Browse files Browse the repository at this point in the history
With the merging of pr #12210 it became impossible to interact with UI Automation controls on Windows 7.

* Fetching the annotationTypes UIA property raises a COMError if not implemented by the control. On newer Operating Systems UIA core returns a default.
 * Fetching the SelectionPattern2 interface also causes a COMError on older Operating Systems if not implemented by the control.

Therefore: 
* Catch COMError when fetching UIA annotationTypes.
* Catch COMError when fetching the UIA SelectionPattern2 interface.

Fixes #12227
  • Loading branch information
michaelDCurran authored Mar 26, 2021
1 parent 9a1cca5 commit 656ecb5
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions source/NVDAObjects/UIA/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1193,10 +1193,14 @@ def _get_UIASelectionPattern(self):
return self.UIASelectionPattern

def _get_UIASelectionPattern2(self):
self.UIASelectionPattern2 = self._getUIAPattern(
UIAHandler.UIA_SelectionPattern2Id,
UIAHandler.IUIAutomationSelectionPattern2
)
try:
self.UIASelectionPattern2 = self._getUIAPattern(
UIAHandler.UIA_SelectionPattern2Id,
UIAHandler.IUIAutomationSelectionPattern2
)
except COMError:
# SelectionPattern2 is not available on older Operating Systems such as Windows 7
self.UIASelectionPattern2 = None
return self.UIASelectionPattern2

def getSelectedItemsCount(self, maxItems=None):
Expand Down Expand Up @@ -1462,7 +1466,11 @@ def _get_states(self):
states.add(controlTypes.STATE_CHECKABLE)
if s==UIAHandler.ToggleState_On:
states.add(controlTypes.STATE_CHECKED)
annotationTypes = self._getUIACacheablePropertyValue(UIAHandler.UIA_AnnotationTypesPropertyId)
try:
annotationTypes = self._getUIACacheablePropertyValue(UIAHandler.UIA_AnnotationTypesPropertyId)
except COMError:
# annotationTypes cannot be fetched on older Operating Systems such as Windows 7.
annotationTypes = None
if annotationTypes:
if UIAHandler.AnnotationType_Comment in annotationTypes:
states.add(controlTypes.STATE_HASCOMMENT)
Expand Down

0 comments on commit 656ecb5

Please sign in to comment.