|
36 | 36 | _UIA_GRIDITEM_PATTERN_ID = 10007 |
37 | 37 | _UIA_TRANSFORM_PATTERN_ID = 10016 |
38 | 38 | _UIA_WINDOW_PATTERN_ID = 10009 |
| 39 | +_UIA_LEGACYIACCESSIBLE_PATTERN_ID = 10018 |
39 | 40 | _UIA_AUTOMATIONID_PROPERTY = 30011 |
40 | 41 | _EXPAND_STATES = {0: "collapsed", 1: "expanded", 2: "partial", 3: "leaf"} |
41 | 42 | _WINDOW_VISUAL_STATES = {"normal": 0, "maximized": 1, "minimized": 2} |
@@ -351,6 +352,24 @@ def window_interaction_state(self, name=None, role=None, app_name=None, |
351 | 352 | except (OSError, AttributeError, ValueError, TypeError): |
352 | 353 | return None |
353 | 354 |
|
| 355 | + def legacy_info(self, name=None, role=None, app_name=None, |
| 356 | + automation_id=None) -> Optional[Dict[str, Any]]: |
| 357 | + raw = self._find_raw(name, role, app_name, automation_id) |
| 358 | + pattern = self._pattern(raw, _UIA_LEGACYIACCESSIBLE_PATTERN_ID, |
| 359 | + "IUIAutomationLegacyIAccessiblePattern" |
| 360 | + ) if raw else None |
| 361 | + if pattern is None: |
| 362 | + return None |
| 363 | + return _read_legacy(pattern) |
| 364 | + |
| 365 | + def legacy_default_action(self, name=None, role=None, app_name=None, |
| 366 | + automation_id=None): |
| 367 | + return self._invoke_pattern_method( |
| 368 | + name, role, app_name, automation_id, |
| 369 | + _UIA_LEGACYIACCESSIBLE_PATTERN_ID, |
| 370 | + "IUIAutomationLegacyIAccessiblePattern", |
| 371 | + lambda pattern: pattern.DoDefaultAction()) |
| 372 | + |
354 | 373 | def get_table_headers(self, name=None, role=None, app_name=None, |
355 | 374 | automation_id=None) -> Optional[Dict[str, Any]]: |
356 | 375 | raw = self._find_raw(name, role, app_name, automation_id) |
@@ -493,6 +512,28 @@ def _as_text(value) -> str: |
493 | 512 | return str(value or "") |
494 | 513 |
|
495 | 514 |
|
| 515 | +# (key, LegacyIAccessiblePattern attribute, cast) for the MSAA bridge read. |
| 516 | +_LEGACY_READS = ( |
| 517 | + ("name", "CurrentName", _as_text), |
| 518 | + ("value", "CurrentValue", _as_text), |
| 519 | + ("description", "CurrentDescription", _as_text), |
| 520 | + ("default_action", "CurrentDefaultAction", _as_text), |
| 521 | + ("role", "CurrentRole", int), |
| 522 | + ("state", "CurrentState", int), |
| 523 | +) |
| 524 | + |
| 525 | + |
| 526 | +def _read_legacy(pattern) -> Dict[str, Any]: |
| 527 | + """Read a LegacyIAccessiblePattern's MSAA fields into a plain dict.""" |
| 528 | + info: Dict[str, Any] = {} |
| 529 | + for key, attribute, cast in _LEGACY_READS: |
| 530 | + try: |
| 531 | + info[key] = cast(getattr(pattern, attribute)) |
| 532 | + except (OSError, AttributeError, ValueError, TypeError): |
| 533 | + info[key] = None |
| 534 | + return info |
| 535 | + |
| 536 | + |
496 | 537 | # (key, UIA element attribute, cast) for the rich properties the flat list omits. |
497 | 538 | _PROPERTY_READS = ( |
498 | 539 | ("enabled", "CurrentIsEnabled", bool), |
|
0 commit comments