diff --git a/source/IAccessibleHandler/types.py b/source/IAccessibleHandler/types.py index 2d9e81a39ba..ec4318d7252 100644 --- a/source/IAccessibleHandler/types.py +++ b/source/IAccessibleHandler/types.py @@ -29,3 +29,4 @@ class RelationType(str, enum.Enum): CONTROLLER_FOR = "controllerFor" ERROR = "error" ERROR_FOR = "errorFor" + LABELLED_BY = "labelledBy" diff --git a/source/NVDAObjects/IAccessible/__init__.py b/source/NVDAObjects/IAccessible/__init__.py index 2ab07700488..3e2cb96094e 100644 --- a/source/NVDAObjects/IAccessible/__init__.py +++ b/source/NVDAObjects/IAccessible/__init__.py @@ -9,7 +9,6 @@ Optional, Tuple, Union, - List, ) from comtypes.automation import IEnumVARIANT, VARIANT @@ -1162,13 +1161,20 @@ def isPointInObject(self, x, y): return False return True - def _get_labeledBy(self): + def _get_labeledBy(self) -> "IAccessible | None": + label = self._getIA2RelationFirstTarget(IAccessibleHandler.RelationType.LABELLED_BY) + if label: + return label + try: - (pacc, accChild) = IAccessibleHandler.accNavigate( + ret = IAccessibleHandler.accNavigate( self.IAccessibleObject, self.IAccessibleChildID, IAccessibleHandler.NAVRELATION_LABELLED_BY, ) + if not ret: + return None + (pacc, accChild) = ret obj = IAccessible(IAccessibleObject=pacc, IAccessibleChildID=accChild) return obj except COMError: @@ -1940,7 +1946,7 @@ def _get_detailsRelations(self) -> Tuple["IAccessible"]: # due to caching of baseObject.AutoPropertyObject, do not attempt to return a generator. return tuple(detailsRelsGen) - def _get_controllerFor(self) -> List[NVDAObject]: + def _get_controllerFor(self) -> list[NVDAObject]: control = self._getIA2RelationFirstTarget(IAccessibleHandler.RelationType.CONTROLLER_FOR) if control: return [control] diff --git a/user_docs/en/changes.md b/user_docs/en/changes.md index 8e10c9ca3dd..36af04e82f0 100644 --- a/user_docs/en/changes.md +++ b/user_docs/en/changes.md @@ -108,7 +108,10 @@ Add-ons will need to be re-tested and have their manifest updated. * Removed the requirement to indent function parameter lists by two tabs from NVDA's Coding Standards, to be compatible with modern automatic linting. (#17126, @XLTechie) * Added the [VS Code workspace configuration for NVDA](https://nvaccess.org/nvaccess/vscode-nvda) as a git submodule. (#17003) * In the `brailleTables` module, a `getDefaultTableForCurrentLang` function has been added (#17222, @nvdaes) -* Retrieving the `labeledBy` property now works for UIA elements supporting the corresponding `LabeledBy` UIA property. (#17442, @michaelweghorn) +* Retrieving the `labeledBy` property now works for: + * objects in applications implementing the `labelled-by` IAccessible2 relation. (#17436, @michaelweghorn) + * UIA elements supporting the corresponding `LabeledBy` UIA property. (#17442, @michaelweghorn) + #### API Breaking Changes