Skip to content

An AI Agent that interacts with Windows OS at GUI level.

Python

Convert UIA ids to enums

jeomona4d2f309028b
diff --git a/docs/pattern_methods_map.md b/docs/pattern_methods_map.md
new file mode 100644
index 0000000..516d851
--- /dev/null
+++ b/docs/pattern_methods_map.md
@@ -0,0 +1,335 @@
+# UIA Pattern Methods Map
+
+This document maps each pattern wrapper in `windows_use/uia/patterns.py` to the public properties and methods exposed by that wrapper.
+
+Notes:
+- Properties are listed under `Properties`.
+- Callable actions are listed under `Methods`.
+- `ObjectModelPattern` is present as a wrapper class, but it currently has no public members.
+- UIA pattern IDs that exist in `windows_use/uia/enums.py` but do not have a wrapper class here are not listed.
+
+## AnnotationPattern
+
+Properties:
+- `AnnotationTypeId`
+- `AnnotationTypeName`
+- `Author`
+- `DateTime`
+- `Target`
+
+Methods:
+- None
+
+## CustomNavigationPattern
+
+Properties:
+- None
+
+Methods:
+- `Navigate`
+
+## DockPattern
+
+Properties:
+- `DockPosition`
+
+Methods:
+- `SetDockPosition`
+
+## DragPattern
+
+Properties:
+- `DropEffect`
+- `DropEffects`
+- `IsGrabbed`
+
+Methods:
+- `GetGrabbedItems`
+
+## DropTargetPattern
+
+Properties:
+- `DropTargetEffect`
+- `DropTargetEffects`
+
+Methods:
+- None
+
+## ExpandCollapsePattern
+
+Properties:
+- `ExpandCollapseState`
+
+Methods:
+- `Collapse`
+- `Expand`
+
+## GridItemPattern
+
+Properties:
+- `Column`
+- `ColumnSpan`
+- `ContainingGrid`
+- `Row`
+- `RowSpan`
+
+Methods:
+- None
+
+## GridPattern
+
+Properties:
+- `ColumnCount`
+- `RowCount`
+
+Methods:
+- `GetItem`
+
+## InvokePattern
+
+Properties:
+- None
+
+Methods:
+- `Invoke`
+
+## ItemContainerPattern
+
+Properties:
+- None
+
+Methods:
+- `FindItemByProperty`
+
+## LegacyIAccessiblePattern
+
+Properties:
+- `ChildId`
+- `DefaultAction`
+- `Description`
+- `Help`
+- `KeyboardShortcut`
+- `Name`
+- `Role`
+- `State`
+- `Value`
+
+Methods:
+- `DoDefaultAction`
+- `GetSelection`
+- `GetIAccessible`
+- `Select`
+- `SetValue`
+
+## MultipleViewPattern
+
+Properties:
+- `CurrentView`
+
+Methods:
+- `GetSupportedViews`
+- `GetViewName`
+- `SetView`
+
+## ObjectModelPattern
+
+Properties:
+- None
+
+Methods:
+- None
+
+## RangeValuePattern
+
+Properties:
+- `IsReadOnly`
+- `LargeChange`
+- `Maximum`
+- `Minimum`
+- `SmallChange`
+- `Value`
+
+Methods:
+- `SetValue`
+
+## ScrollItemPattern
+
+Properties:
+- None
+
+Methods:
+- `ScrollIntoView`
+
+## ScrollPattern
+
+Properties:
+- `HorizontallyScrollable`
+- `HorizontalScrollPercent`
+- `HorizontalViewSize`
+- `VerticallyScrollable`
+- `VerticalScrollPercent`
+- `VerticalViewSize`
+
+Methods:
+- `Scroll`
+- `SetScrollPercent`
+
+## SelectionItemPattern
+
+Properties:
+- `IsSelected`
+- `SelectionContainer`
+
+Methods:
+- `AddToSelection`
+- `RemoveFromSelection`
+- `Select`
+
+## SelectionPattern
+
+Properties:
+- `CanSelectMultiple`
+- `IsSelectionRequired`
+
+Methods:
+- `GetSelection`
+
+## SpreadsheetItemPattern
+
+Properties:
+- `Formula`
+
+Methods:
+- `GetAnnotationObjects`
+- `GetAnnotationTypes`
+
+## SpreadsheetPattern
+
+Properties:
+- None
+
+Methods:
+- `GetItemByName`
+
+## StylesPattern
+
+Properties:
+- `ExtendedProperties`
+- `FillColor`
+- `FillPatternColor`
+- `Shape`
+- `StyleId`
+- `StyleName`
+
+Methods:
+- None
+
+## SynchronizedInputPattern
+
+Properties:
+- None
+
+Methods:
+- `Cancel`
+- `StartListening`
+
+## TableItemPattern
+
+Properties:
+- None
+
+Methods:
+- `GetColumnHeaderItems`
+- `GetRowHeaderItems`
+
+## TablePattern
+
+Properties:
+- `RowOrColumnMajor`
+
+Methods:
+- `GetColumnHeaders`
+- `GetRowHeaders`
+
+## TextChildPattern
+
+Properties:
+- `TextContainer`
+- `TextRange`
+
+Methods:
+- None
+
+## TextEditPattern
+
+Properties:
+- None
+
+Methods:
+- `GetActiveComposition`
+- `GetConversionTarget`
+
+## TextPattern
+
+Properties:
+- `DocumentRange`
+- `SupportedTextSelection`
+
+Methods:
+- `GetSelection`
+- `GetVisibleRanges`
+- `RangeFromChild`
+- `RangeFromPoint`
+
+## TogglePattern
+
+Properties:
+- `ToggleState`
+
+Methods:
+- `Toggle`
+- `SetToggleState`
+
+## TransformPattern
+
+Properties:
+- `CanMove`
+- `CanResize`
+- `CanRotate`
+
+Methods:
+- `Move`
+- `Resize`
+- `Rotate`
+
+## ValuePattern
+
+Properties:
+- `IsReadOnly`
+- `Value`
+
+Methods:
+- `SetValue`
+
+## VirtualizedItemPattern
+
+Properties:
+- None
+
+Methods:
+- `Realize`
+
+## WindowPattern
+
+Properties:
+- `CanMaximize`
+- `CanMinimize`
+- `IsModal`
+- `IsTopmost`
+- `WindowInteractionState`
+- `WindowVisualState`
+
+Methods:
+- `Close`
+- `SetWindowVisualState`
+- `WaitForInputIdle`
diff --git a/windows_use/agent/tree/views.py b/windows_use/agent/tree/views.py
index 5c46e9d..affd480 100644
--- a/windows_use/agent/tree/views.py
+++ b/windows_use/agent/tree/views.py
@@ -177,15 +177,11 @@ class SelectorMap(dict):
return node
def control_of(self, index: int) -> Optional['Control']:
- node = self.get(index)
+ node = self.node_of(index)
return node.control if node else None
- def center_of(self, index: int) -> Optional[Center]:
- node = self.get(index)
- return node.center if node else None
-
def hwnd_of(self, index: int) -> int | None:
- node = self.get(index)
+ node = self.node_of(index)
return node.hwnd if node else None
def __repr__(self) -> str:
diff --git a/windows_use/uia/controls.py b/windows_use/uia/controls.py
index 974db42..7238095 100644
--- a/windows_use/uia/controls.py
+++ b/windows_use/uia/controls.py
@@ -1000,6 +1000,28 @@ class Control():
self._supportedPatterns[patternId] = pattern
return pattern
+ @property
+ def AvailablePatternIds(self) -> List[PatternId]:
+ """
+ Return the UI Automation pattern ids currently supported by this control.
+ These ids can be passed directly into `GetPattern()`.
+ """
+ supported_pattern_ids: List[PatternId] = []
+ for pattern_id in PatternConstructors.keys():
+ try:
+ if self.GetPattern(pattern_id):
+ supported_pattern_ids.append(pattern_id)
+ except comtypes.COMError:
+ continue
+ return supported_pattern_ids
+
+ @property
+ def AvailablePatternNames(self) -> List[str]:
+ """
+ Return the UI Automation pattern names currently supported by this control.
+ """
+ return [PatternIdNames.get(pattern_id, str(pattern_id)) for pattern_id in self.AvailablePatternIds]
+
def GetLegacyIAccessiblePattern(self) -> LegacyIAccessiblePattern:
"""
Return `LegacyIAccessiblePattern` if it supports the pattern else None.
@@ -4517,4 +4539,3 @@ def WaitHotKeyReleased(hotkey: Tuple[int, int]) -> None:
break
else:
break
-
diff --git a/windows_use/uia/enums.py b/windows_use/uia/enums.py
index c649d44..5f87d21 100644
--- a/windows_use/uia/enums.py
+++ b/windows_use/uia/enums.py
@@ -37,7 +37,7 @@ ProcessTime = time.perf_counter # this returns nearly 0 when first call it if p
ProcessTime() # need to call it once if python version <= 3.6
TreeNode = Any
-class ControlType:
+class ControlType(IntEnum):
"""
ControlType from IUIAutomation.
Refer https://docs.microsoft.com/en-us/windows/win32/winauto/uiauto-controltype-ids
@@ -130,7 +130,7 @@ ControlTypeNames = {
}
-class PatternId:
+class PatternId(IntEnum):
"""
PatternId from IUIAutomation.
Refer https://docs.microsoft.com/en-us/windows/win32/winauto/uiauto-controlpattern-ids
@@ -211,7 +211,7 @@ PatternIdNames = {
}
-class PropertyId:
+class PropertyId(IntEnum):
"""
PropertyId from IUIAutomation.
Refer https://docs.microsoft.com/en-us/windows/win32/winauto/uiauto-automation-element-propids