Skip to content

Add ax_events: reactive UIA focus-change wait#424

Merged
JE-Chen merged 1 commit into
devfrom
feat/ax-events-batch
Jun 24, 2026
Merged

Add ax_events: reactive UIA focus-change wait#424
JE-Chen merged 1 commit into
devfrom
feat/ax-events-batch

Conversation

@JE-Chen

@JE-Chen JE-Chen commented Jun 24, 2026

Copy link
Copy Markdown
Member

Why

The accessibility recorder polls the focused element every ~250 ms, so it can miss a fast focus transition and reacts a quarter-second late. UIA exposes real events: wait_for_focus_change blocks on the native AddFocusChangedEventHandler and returns the moment focus moves — the zero-latency, miss-free "wait until focus lands on the dialog" primitive, the accessibility-tree analogue of wait_for_window / wait_for_image.

Eighth and final feature of the ROUND-15 native-UIA depth lane (which is now complete: virtualized, ax_props, table_pattern, transform_window, legacy_accessible, advanced TextPattern, selection_view, ax_events).

Design

  • Extends the accessibility backend ABC (base.py _unsupported default) + a real subscription in windows_backend.py: a comtypes.COMObject focus handler pushes events onto a queue.Queue, wait_for_focus_change blocks on events.get(timeout=...) and registers / unregisters the handler under a threading.Lock (per the concurrency rules), returning the newly-focused element or None on timeout. Falls back to None if the handler interface is unavailable.
  • 5 layers wired: core → facade __all__AC_wait_for_focus_change → read-only ac_wait_for_focus_change MCP tool → Script Builder (Native UI). Qt-free verified.

Tests

test/unit_test/headless/test_ax_events_batch.py — fake backend covers element-returned, timeout → None, the unsupported-backend error, the executor {changed, element} wrapper, and 5-layer wiring. 13 passed with the selection_view sibling. The real COM event path is not run in CI (no Windows backend), matching the rest of the accessibility lane.

The accessibility recorder polls focus every ~250ms, missing fast
transitions and reacting late. wait_for_focus_change blocks on the
native AddFocusChangedEventHandler and returns the moment focus moves -
zero-latency, miss-free, the accessibility-tree analogue of
wait_for_window. The real event handler is registered/unregistered
under a lock on the calling thread (COMObject + queue). Extends the
backend ABC + Windows UIA backend via the fake-backend seam.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 23 complexity · 0 duplication

Metric Results
Complexity 23
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@JE-Chen JE-Chen merged commit 0736593 into dev Jun 24, 2026
16 checks passed
@JE-Chen JE-Chen deleted the feat/ax-events-batch branch June 24, 2026 22:44
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant