Skip to content

Commit

Permalink
Support UIA LabeledBy property (#17443)
Browse files Browse the repository at this point in the history
Fixes #17442

Summary of the issue:
UIA has a UIA_LabeledByPropertyId property, see https://learn.microsoft.com/en-us/windows/win32/winauto/uiauto-automation-element-propids :

Identifies the LabeledBy property, which is an automation element that contains the text label for this element.
This property can be used to retrieve, for example, the static text label for a combo box.
Variant type: VT_UNKNOWN
Default value: NULL

However, that one was so far not taken into account by NVDA's "labeledBy" property for UIA elements.

Description of user facing changes
None, unless they're using the Python console or addons making use of the property.

Description of development approach
Override NVDAObject._get_labeledBy in UIA to retrieve and return the UIAElement reported by the UIA_LabeledByPropertyId property.
  • Loading branch information
michaelweghorn authored Nov 29, 2024
1 parent 70cd311 commit f0b3626
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions source/NVDAObjects/UIA/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

"""Support for UI Automation (UIA) controls."""

from __future__ import annotations
import typing
from typing import (
Generator,
Expand Down Expand Up @@ -2386,6 +2387,19 @@ def _get_controllerFor(self):
objList.append(obj)
return objList

def _get_labeledBy(self) -> UIA | None:
try:
val = self._getUIACacheablePropertyValue(UIAHandler.UIA_LabeledByPropertyId)
if not val or val == UIAHandler.handler.reservedNotSupportedValue:
return None
element = val.QueryInterface(UIAHandler.IUIAutomationElement).buildUpdatedCache(
UIAHandler.handler.baseCacheRequest,
)
return UIA(UIAElement=element)
except COMError:
pass
return super()._get_labeledBy()

def event_UIA_controllerFor(self) -> None:
return self.event_controllerForChange()

Expand Down
1 change: 1 addition & 0 deletions user_docs/en/changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ 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)

#### API Breaking Changes

Expand Down

0 comments on commit f0b3626

Please sign in to comment.