windows-mcp 0.5.7__py3-none-any.whl → 0.5.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2106 @@
1
+ '''
2
+ uiautomation for Python 3.
3
+ Author: yinkaisheng
4
+ Source: https://github.com/yinkaisheng/Python-UIAutomation-for-Windows
5
+
6
+ This module is for UIAutomation on Windows(Windows XP with SP3, Windows Vista and Windows 7/8/8.1/10).
7
+ It supports UIAutomation for the applications which implmented IUIAutomation, such as MFC, Windows Form, WPF, Modern UI(Metro UI), Qt, Firefox and Chrome.
8
+ Run 'automation.py -h' for help.
9
+
10
+ uiautomation is shared under the Apache Licene 2.0.
11
+ This means that the code can be freely copied and distributed, and costs nothing to use.
12
+ '''
13
+
14
+ import os
15
+ import sys
16
+ import time
17
+ import datetime
18
+ import re
19
+ import shlex
20
+ import struct
21
+ import atexit
22
+ import threading
23
+ import ctypes
24
+ import ctypes.wintypes
25
+ import comtypes
26
+ from io import TextIOWrapper
27
+ from typing import (Any, Callable, Dict, Generator, List, Tuple, Optional, Union, Sequence, TYPE_CHECKING)
28
+ from .enums import *
29
+ from .core import *
30
+ from .core import _AutomationClient
31
+ if TYPE_CHECKING:
32
+ from .controls import Control
33
+
34
+
35
+ METRO_WINDOW_CLASS_NAME = 'Windows.UI.Core.CoreWindow' # for Windows 8 and 8.1
36
+ SEARCH_INTERVAL = 0.5 # search control interval seconds
37
+ MAX_MOVE_SECOND = 1 # simulate mouse move or drag max seconds
38
+ TIME_OUT_SECOND = 10
39
+ OPERATION_WAIT_TIME = 0.5
40
+ MAX_PATH = 260
41
+ DEBUG_SEARCH_TIME = False
42
+ DEBUG_EXIST_DISAPPEAR = False
43
+ S_OK = 0
44
+
45
+ IsPy38OrHigher = sys.version_info[:2] >= (3, 8)
46
+ IsNT6orHigher = os.sys.getwindowsversion().major >= 6
47
+ CurrentProcessIs64Bit = sys.maxsize > 0xFFFFFFFF
48
+ ProcessTime = time.perf_counter # this returns nearly 0 when first call it if python version <= 3.6
49
+ ProcessTime() # need to call it once if python version <= 3.6
50
+ TreeNode = Any
51
+
52
+
53
+ _PatternIdInterfaces = None
54
+
55
+
56
+ def GetPatternIdInterface(patternId: int):
57
+ """
58
+ Get pattern COM interface by pattern id.
59
+ patternId: int, a value in class `PatternId`.
60
+ Return comtypes._cominterface_meta.
61
+ """
62
+ global _PatternIdInterfaces
63
+ if not _PatternIdInterfaces:
64
+ _PatternIdInterfaces = {
65
+ # PatternId.AnnotationPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationAnnotationPattern,
66
+ # PatternId.CustomNavigationPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationCustomNavigationPattern,
67
+ PatternId.DockPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationDockPattern,
68
+ # PatternId.DragPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationDragPattern,
69
+ # PatternId.DropTargetPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationDropTargetPattern,
70
+ PatternId.ExpandCollapsePattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationExpandCollapsePattern,
71
+ PatternId.GridItemPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationGridItemPattern,
72
+ PatternId.GridPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationGridPattern,
73
+ PatternId.InvokePattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationInvokePattern,
74
+ PatternId.ItemContainerPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationItemContainerPattern,
75
+ PatternId.LegacyIAccessiblePattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationLegacyIAccessiblePattern,
76
+ PatternId.MultipleViewPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationMultipleViewPattern,
77
+ # PatternId.ObjectModelPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationObjectModelPattern,
78
+ PatternId.RangeValuePattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationRangeValuePattern,
79
+ PatternId.ScrollItemPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationScrollItemPattern,
80
+ PatternId.ScrollPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationScrollPattern,
81
+ PatternId.SelectionItemPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationSelectionItemPattern,
82
+ PatternId.SelectionPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationSelectionPattern,
83
+ # PatternId.SpreadsheetItemPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationSpreadsheetItemPattern,
84
+ # PatternId.SpreadsheetPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationSpreadsheetPattern,
85
+ # PatternId.StylesPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationStylesPattern,
86
+ PatternId.SynchronizedInputPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationSynchronizedInputPattern,
87
+ PatternId.TableItemPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationTableItemPattern,
88
+ PatternId.TablePattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationTablePattern,
89
+ # PatternId.TextChildPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationTextChildPattern,
90
+ # PatternId.TextEditPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationTextEditPattern,
91
+ PatternId.TextPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationTextPattern,
92
+ # PatternId.TextPattern2: _AutomationClient.instance().UIAutomationCore.IUIAutomationTextPattern2,
93
+ PatternId.TogglePattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationTogglePattern,
94
+ PatternId.TransformPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationTransformPattern,
95
+ # PatternId.TransformPattern2: _AutomationClient.instance().UIAutomationCore.IUIAutomationTransformPattern2,
96
+ PatternId.ValuePattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationValuePattern,
97
+ PatternId.VirtualizedItemPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationVirtualizedItemPattern,
98
+ PatternId.WindowPattern: _AutomationClient.instance().UIAutomationCore.IUIAutomationWindowPattern,
99
+ }
100
+ debug = False
101
+ # the following patterns doesn't exist on Windows 7 or lower
102
+ try:
103
+ _PatternIdInterfaces[PatternId.AnnotationPattern] = _AutomationClient.instance().UIAutomationCore.IUIAutomationAnnotationPattern
104
+ except:
105
+ if debug:
106
+ Logger.WriteLine('UIAutomationCore does not have AnnotationPattern.', ConsoleColor.Yellow)
107
+ try:
108
+ _PatternIdInterfaces[PatternId.CustomNavigationPattern] = _AutomationClient.instance().UIAutomationCore.IUIAutomationCustomNavigationPattern
109
+ except:
110
+ if debug:
111
+ Logger.WriteLine('UIAutomationCore does not have CustomNavigationPattern.', ConsoleColor.Yellow)
112
+ try:
113
+ _PatternIdInterfaces[PatternId.DragPattern] = _AutomationClient.instance().UIAutomationCore.IUIAutomationDragPattern
114
+ except:
115
+ if debug:
116
+ Logger.WriteLine('UIAutomationCore does not have DragPattern.', ConsoleColor.Yellow)
117
+ try:
118
+ _PatternIdInterfaces[PatternId.DropTargetPattern] = _AutomationClient.instance().UIAutomationCore.IUIAutomationDropTargetPattern
119
+ except:
120
+ if debug:
121
+ Logger.WriteLine('UIAutomationCore does not have DropTargetPattern.', ConsoleColor.Yellow)
122
+ try:
123
+ _PatternIdInterfaces[PatternId.ObjectModelPattern] = _AutomationClient.instance().UIAutomationCore.IUIAutomationObjectModelPattern
124
+ except:
125
+ if debug:
126
+ Logger.WriteLine('UIAutomationCore does not have ObjectModelPattern.', ConsoleColor.Yellow)
127
+ try:
128
+ _PatternIdInterfaces[PatternId.SpreadsheetItemPattern] = _AutomationClient.instance().UIAutomationCore.IUIAutomationSpreadsheetItemPattern
129
+ except:
130
+ if debug:
131
+ Logger.WriteLine('UIAutomationCore does not have SpreadsheetItemPattern.', ConsoleColor.Yellow)
132
+ try:
133
+ _PatternIdInterfaces[PatternId.SpreadsheetPattern] = _AutomationClient.instance().UIAutomationCore.IUIAutomationSpreadsheetPattern
134
+ except:
135
+ if debug:
136
+ Logger.WriteLine('UIAutomationCore does not have SpreadsheetPattern.', ConsoleColor.Yellow)
137
+ try:
138
+ _PatternIdInterfaces[PatternId.StylesPattern] = _AutomationClient.instance().UIAutomationCore.IUIAutomationStylesPattern
139
+ except:
140
+ if debug:
141
+ Logger.WriteLine('UIAutomationCore does not have StylesPattern.', ConsoleColor.Yellow)
142
+ try:
143
+ _PatternIdInterfaces[PatternId.SelectionPattern2] = _AutomationClient.instance().UIAutomationCore.IUIAutomationSelectionPattern2
144
+ except:
145
+ if debug:
146
+ Logger.WriteLine('UIAutomationCore does not have SelectionPattern2.', ConsoleColor.Yellow)
147
+ try:
148
+ _PatternIdInterfaces[PatternId.TextChildPattern] = _AutomationClient.instance().UIAutomationCore.IUIAutomationTextChildPattern
149
+ except:
150
+ if debug:
151
+ Logger.WriteLine('UIAutomationCore does not have TextChildPattern.', ConsoleColor.Yellow)
152
+ try:
153
+ _PatternIdInterfaces[PatternId.TextEditPattern] = _AutomationClient.instance().UIAutomationCore.IUIAutomationTextEditPattern
154
+ except:
155
+ if debug:
156
+ Logger.WriteLine('UIAutomationCore does not have TextEditPattern.', ConsoleColor.Yellow)
157
+ try:
158
+ _PatternIdInterfaces[PatternId.TextPattern2] = _AutomationClient.instance().UIAutomationCore.IUIAutomationTextPattern2
159
+ except:
160
+ if debug:
161
+ Logger.WriteLine('UIAutomationCore does not have TextPattern2.', ConsoleColor.Yellow)
162
+ try:
163
+ _PatternIdInterfaces[PatternId.TransformPattern2] = _AutomationClient.instance().UIAutomationCore.IUIAutomationTransformPattern2
164
+ except:
165
+ if debug:
166
+ Logger.WriteLine('UIAutomationCore does not have TransformPattern2.', ConsoleColor.Yellow)
167
+ return _PatternIdInterfaces[patternId]
168
+
169
+
170
+ """
171
+ Control Pattern Mapping for UI Automation Clients.
172
+ Refer https://docs.microsoft.com/en-us/previous-versions//dd319586(v=vs.85)
173
+ """
174
+
175
+
176
+ class AnnotationPattern():
177
+ def __init__(self, pattern=None):
178
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationannotationpattern"""
179
+ self.pattern = pattern
180
+
181
+ @property
182
+ def AnnotationTypeId(self) -> int:
183
+ """
184
+ Property AnnotationTypeId.
185
+ Call IUIAutomationAnnotationPattern::get_CurrentAnnotationTypeId.
186
+ Return int, a value in class `AnnotationType`.
187
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationannotationpattern-get_currentannotationtypeid
188
+ """
189
+ return self.pattern.CurrentAnnotationTypeId
190
+
191
+ @property
192
+ def AnnotationTypeName(self) -> str:
193
+ """
194
+ Property AnnotationTypeName.
195
+ Call IUIAutomationAnnotationPattern::get_CurrentAnnotationTypeName.
196
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationannotationpattern-get_currentannotationtypename
197
+ """
198
+ return self.pattern.CurrentAnnotationTypeName
199
+
200
+ @property
201
+ def Author(self) -> str:
202
+ """
203
+ Property Author.
204
+ Call IUIAutomationAnnotationPattern::get_CurrentAuthor.
205
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationannotationpattern-get_currentauthor
206
+ """
207
+ return self.pattern.CurrentAuthor
208
+
209
+ @property
210
+ def DateTime(self) -> str:
211
+ """
212
+ Property DateTime.
213
+ Call IUIAutomationAnnotationPattern::get_CurrentDateTime.
214
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationannotationpattern-get_currentdatetime
215
+ """
216
+ return self.pattern.CurrentDateTime
217
+
218
+ @property
219
+ def Target(self) -> 'Control':
220
+ """
221
+ Property Target.
222
+ Call IUIAutomationAnnotationPattern::get_CurrentTarget.
223
+ Return `Control` subclass, the element that is being annotated.
224
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationannotationpattern-get_currenttarget
225
+ """
226
+ ele = self.pattern.CurrentTarget
227
+ return Control.CreateControlFromElement(ele)
228
+
229
+
230
+ class CustomNavigationPattern():
231
+ def __init__(self, pattern=None):
232
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationcustomnavigationpattern"""
233
+ self.pattern = pattern
234
+
235
+ def Navigate(self, direction: int) -> 'Control':
236
+ """
237
+ Call IUIAutomationCustomNavigationPattern::Navigate.
238
+ Get the next control in the specified direction within the logical UI tree.
239
+ direction: int, a value in class `NavigateDirection`.
240
+ Return `Control` subclass or None.
241
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationcustomnavigationpattern-navigate
242
+ """
243
+ ele = self.pattern.Navigate(direction)
244
+ return Control.CreateControlFromElement(ele)
245
+
246
+
247
+ class DockPattern():
248
+ def __init__(self, pattern=None):
249
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationdockpattern"""
250
+ self.pattern = pattern
251
+
252
+ @property
253
+ def DockPosition(self) -> int:
254
+ """
255
+ Property DockPosition.
256
+ Call IUIAutomationDockPattern::get_CurrentDockPosition.
257
+ Return int, a value in class `DockPosition`.
258
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationdockpattern-get_currentdockposition
259
+ """
260
+ return self.pattern.CurrentDockPosition
261
+
262
+ def SetDockPosition(self, dockPosition: int, waitTime: float = OPERATION_WAIT_TIME) -> int:
263
+ """
264
+ Call IUIAutomationDockPattern::SetDockPosition.
265
+ dockPosition: int, a value in class `DockPosition`.
266
+ waitTime: float.
267
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationdockpattern-setdockposition
268
+ """
269
+ ret = self.pattern.SetDockPosition(dockPosition)
270
+ time.sleep(waitTime)
271
+ return ret
272
+
273
+
274
+ class DragPattern():
275
+ def __init__(self, pattern=None):
276
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationdragpattern"""
277
+ self.pattern = pattern
278
+
279
+ @property
280
+ def DropEffect(self) -> str:
281
+ """
282
+ Property DropEffect.
283
+ Call IUIAutomationDragPattern::get_CurrentDropEffect.
284
+ Return str, a localized string that indicates what happens
285
+ when the user drops this element as part of a drag-drop operation.
286
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationdragpattern-get_currentdropeffect
287
+ """
288
+ return self.pattern.CurrentDropEffect
289
+
290
+ @property
291
+ def DropEffects(self) -> List[str]:
292
+ """
293
+ Property DropEffects.
294
+ Call IUIAutomationDragPattern::get_CurrentDropEffects, todo SAFEARRAY.
295
+ Return List[str], a list of localized strings that enumerate the full set of effects
296
+ that can happen when this element as part of a drag-and-drop operation.
297
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationdragpattern-get_currentdropeffects
298
+ """
299
+ return self.pattern.CurrentDropEffects
300
+
301
+ @property
302
+ def IsGrabbed(self) -> bool:
303
+ """
304
+ Property IsGrabbed.
305
+ Call IUIAutomationDragPattern::get_CurrentIsGrabbed.
306
+ Return bool, indicates whether the user has grabbed this element as part of a drag-and-drop operation.
307
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationdragpattern-get_currentisgrabbed
308
+ """
309
+ return bool(self.pattern.CurrentIsGrabbed)
310
+
311
+ def GetGrabbedItems(self) -> List['Control']:
312
+ """
313
+ Call IUIAutomationDragPattern::GetCurrentGrabbedItems.
314
+ Return List[Control], a list of `Control` subclasses that represent the full set of items
315
+ that the user is dragging as part of a drag operation.
316
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationdragpattern-getcurrentgrabbeditems
317
+ """
318
+ eleArray = self.pattern.GetCurrentGrabbedItems()
319
+ if eleArray:
320
+ controls = []
321
+ for i in range(eleArray.Length):
322
+ ele = eleArray.GetElement(i)
323
+ con = Control.CreateControlFromElement(element=ele)
324
+ if con:
325
+ controls.append(con)
326
+ return controls
327
+ return []
328
+
329
+
330
+ class DropTargetPattern():
331
+ def __init__(self, pattern=None):
332
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationdroptargetpattern"""
333
+ self.pattern = pattern
334
+
335
+ @property
336
+ def DropTargetEffect(self) -> str:
337
+ """
338
+ Property DropTargetEffect.
339
+ Call IUIAutomationDropTargetPattern::get_CurrentDropTargetEffect.
340
+ Return str, a localized string that describes what happens
341
+ when the user drops the grabbed element on this drop target.
342
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationdragpattern-get_currentdroptargeteffect
343
+ """
344
+ return self.pattern.CurrentDropTargetEffect
345
+
346
+ @property
347
+ def DropTargetEffects(self) -> List[str]:
348
+ """
349
+ Property DropTargetEffects.
350
+ Call IUIAutomationDropTargetPattern::get_CurrentDropTargetEffects, todo SAFEARRAY.
351
+ Return List[str], a list of localized strings that enumerate the full set of effects
352
+ that can happen when the user drops a grabbed element on this drop target
353
+ as part of a drag-and-drop operation.
354
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationdragpattern-get_currentdroptargeteffects
355
+ """
356
+ return self.pattern.CurrentDropTargetEffects
357
+
358
+
359
+ class ExpandCollapsePattern():
360
+ def __init__(self, pattern=None):
361
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationexpandcollapsepattern"""
362
+ self.pattern = pattern
363
+
364
+ @property
365
+ def ExpandCollapseState(self) -> int:
366
+ """
367
+ Property ExpandCollapseState.
368
+ Call IUIAutomationExpandCollapsePattern::get_CurrentExpandCollapseState.
369
+ Return int, a value in class ExpandCollapseState.
370
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationexpandcollapsepattern-get_currentexpandcollapsestate
371
+ """
372
+ return self.pattern.CurrentExpandCollapseState
373
+
374
+ def Collapse(self, waitTime: float = OPERATION_WAIT_TIME) -> bool:
375
+ """
376
+ Call IUIAutomationExpandCollapsePattern::Collapse.
377
+ waitTime: float.
378
+ Return bool, True if succeed otherwise False.
379
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationexpandcollapsepattern-collapse
380
+ """
381
+ try:
382
+ ret = self.pattern.Collapse() == S_OK
383
+ time.sleep(waitTime)
384
+ return ret
385
+ except:
386
+ pass
387
+ return False
388
+
389
+ def Expand(self, waitTime: float = OPERATION_WAIT_TIME) -> bool:
390
+ """
391
+ Call IUIAutomationExpandCollapsePattern::Expand.
392
+ waitTime: float.
393
+ Return bool, True if succeed otherwise False.
394
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationexpandcollapsepattern-expand
395
+ """
396
+ try:
397
+ ret = self.pattern.Expand() == S_OK
398
+ time.sleep(waitTime)
399
+ return ret
400
+ except:
401
+ pass
402
+ return False
403
+
404
+
405
+ class GridItemPattern():
406
+ def __init__(self, pattern=None):
407
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationgriditempattern"""
408
+ self.pattern = pattern
409
+
410
+ @property
411
+ def Column(self) -> int:
412
+ """
413
+ Property Column.
414
+ Call IUIAutomationGridItemPattern::get_CurrentColumn.
415
+ Return int, the zero-based index of the column that contains the item.
416
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationgriditempattern-get_currentcolumn
417
+ """
418
+ return self.pattern.CurrentColumn
419
+
420
+ @property
421
+ def ColumnSpan(self) -> int:
422
+ """
423
+ Property ColumnSpan.
424
+ Call IUIAutomationGridItemPattern::get_CurrentColumnSpan.
425
+ Return int, the number of columns spanned by the grid item.
426
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationgriditempattern-get_currentcolumnspan
427
+ """
428
+ return self.pattern.CurrentColumnSpan
429
+
430
+ @property
431
+ def ContainingGrid(self) -> 'Control':
432
+ """
433
+ Property ContainingGrid.
434
+ Call IUIAutomationGridItemPattern::get_CurrentContainingGrid.
435
+ Return `Control` subclass, the element that contains the grid item.
436
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationgriditempattern-get_currentcontaininggrid
437
+ """
438
+ return Control.CreateControlFromElement(self.pattern.CurrentContainingGrid)
439
+
440
+ @property
441
+ def Row(self) -> int:
442
+ """
443
+ Property Row.
444
+ Call IUIAutomationGridItemPattern::get_CurrentRow.
445
+ Return int, the zero-based index of the row that contains the grid item.
446
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationgriditempattern-get_currentrow
447
+ """
448
+ return self.pattern.CurrentRow
449
+
450
+ @property
451
+ def RowSpan(self) -> int:
452
+ """
453
+ Property RowSpan.
454
+ Call IUIAutomationGridItemPattern::get_CurrentRowSpan.
455
+ Return int, the number of rows spanned by the grid item.
456
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationgriditempattern-get_currentrowspan
457
+ """
458
+ return self.pattern.CurrentRowSpan
459
+
460
+
461
+ class GridPattern():
462
+ def __init__(self, pattern=None):
463
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationgridpattern"""
464
+ self.pattern = pattern
465
+
466
+ @property
467
+ def ColumnCount(self) -> int:
468
+ """
469
+ Property ColumnCount.
470
+ Call IUIAutomationGridPattern::get_CurrentColumnCount.
471
+ Return int, the number of columns in the grid.
472
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationgridpattern-get_currentcolumncount
473
+ """
474
+ return self.pattern.CurrentColumnCount
475
+
476
+ @property
477
+ def RowCount(self) -> int:
478
+ """
479
+ Property RowCount.
480
+ Call IUIAutomationGridPattern::get_CurrentRowCount.
481
+ Return int, the number of rows in the grid.
482
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationgridpattern-get_currentrowcount
483
+ """
484
+ return self.pattern.CurrentRowCount
485
+
486
+ def GetItem(self, row: int, column: int) -> 'Control':
487
+ """
488
+ Call IUIAutomationGridPattern::GetItem.
489
+ Return `Control` subclass, a control representing an item in the grid.
490
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationgridpattern-getitem
491
+ """
492
+ return Control.CreateControlFromElement(self.pattern.GetItem(row, column))
493
+
494
+
495
+ class InvokePattern():
496
+ def __init__(self, pattern=None):
497
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationinvokepattern"""
498
+ self.pattern = pattern
499
+
500
+ def Invoke(self, waitTime: float = OPERATION_WAIT_TIME) -> bool:
501
+ """
502
+ Call IUIAutomationInvokePattern::Invoke.
503
+ Invoke the action of a control, such as a button click.
504
+ waitTime: float.
505
+ Return bool, True if succeed otherwise False.
506
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationinvokepattern-invoke
507
+ """
508
+ ret = self.pattern.Invoke() == S_OK
509
+ time.sleep(waitTime)
510
+ return ret
511
+
512
+
513
+ class ItemContainerPattern():
514
+ def __init__(self, pattern=None):
515
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationitemcontainerpattern"""
516
+ self.pattern = pattern
517
+
518
+ def FindItemByProperty(self, control: 'Control', propertyId: int, propertyValue) -> 'Control':
519
+ """
520
+ Call IUIAutomationItemContainerPattern::FindItemByProperty.
521
+ control: `Control` or its subclass.
522
+ propertyValue: COM VARIANT according to propertyId? todo.
523
+ propertyId: int, a value in class `PropertyId`.
524
+ Return `Control` subclass, a control within a containing element, based on a specified property value.
525
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationitemcontainerpattern-finditembyproperty
526
+ """
527
+ ele = self.pattern.FindItemByProperty(control.Element, propertyId, propertyValue)
528
+ return Control.CreateControlFromElement(ele)
529
+
530
+
531
+ class LegacyIAccessiblePattern():
532
+ def __init__(self, pattern=None):
533
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationlegacyiaccessiblepattern"""
534
+ self.pattern = pattern
535
+
536
+ @property
537
+ def ChildId(self) -> int:
538
+ """
539
+ Property ChildId.
540
+ Call IUIAutomationLegacyIAccessiblePattern::get_CurrentChildId.
541
+ Return int, the Microsoft Active Accessibility child identifier for the element.
542
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationlegacyiaccessiblepattern-get_currentchildid
543
+ """
544
+ return self.pattern.CurrentChildId
545
+
546
+ @property
547
+ def DefaultAction(self) -> str:
548
+ """
549
+ Property DefaultAction.
550
+ Call IUIAutomationLegacyIAccessiblePattern::get_CurrentDefaultAction.
551
+ Return str, the Microsoft Active Accessibility current default action for the element.
552
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationlegacyiaccessiblepattern-get_currentdefaultaction
553
+ """
554
+ return self.pattern.CurrentDefaultAction
555
+
556
+ @property
557
+ def Description(self) -> str:
558
+ """
559
+ Property Description.
560
+ Call IUIAutomationLegacyIAccessiblePattern::get_CurrentDescription.
561
+ Return str, the Microsoft Active Accessibility description of the element.
562
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationlegacyiaccessiblepattern-get_currentdescription
563
+ """
564
+ return self.pattern.CurrentDescription
565
+
566
+ @property
567
+ def Help(self) -> str:
568
+ """
569
+ Property Help.
570
+ Call IUIAutomationLegacyIAccessiblePattern::get_CurrentHelp.
571
+ Return str, the Microsoft Active Accessibility help string for the element.
572
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationlegacyiaccessiblepattern-get_currenthelp
573
+ """
574
+ return self.pattern.CurrentHelp
575
+
576
+ @property
577
+ def KeyboardShortcut(self) -> str:
578
+ """
579
+ Property KeyboardShortcut.
580
+ Call IUIAutomationLegacyIAccessiblePattern::get_CurrentKeyboardShortcut.
581
+ Return str, the Microsoft Active Accessibility keyboard shortcut property for the element.
582
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationlegacyiaccessiblepattern-get_currentkeyboardshortcut
583
+ """
584
+ return self.pattern.CurrentKeyboardShortcut
585
+
586
+ @property
587
+ def Name(self) -> str:
588
+ """
589
+ Property Name.
590
+ Call IUIAutomationLegacyIAccessiblePattern::get_CurrentName.
591
+ Return str, the Microsoft Active Accessibility name property of the element.
592
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationlegacyiaccessiblepattern-get_currentname
593
+ """
594
+ return self.pattern.CurrentName or '' # CurrentName may be None
595
+
596
+ @property
597
+ def Role(self) -> int:
598
+ """
599
+ Property Role.
600
+ Call IUIAutomationLegacyIAccessiblePattern::get_CurrentRole.
601
+ Return int, a value in calss `AccessibleRole`, the Microsoft Active Accessibility role identifier.
602
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationlegacyiaccessiblepattern-get_currentrole
603
+ """
604
+ return self.pattern.CurrentRole
605
+
606
+ @property
607
+ def State(self) -> int:
608
+ """
609
+ Property State.
610
+ Call IUIAutomationLegacyIAccessiblePattern::get_CurrentState.
611
+ Return int, a value in calss `AccessibleState`, the Microsoft Active Accessibility state identifier.
612
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationlegacyiaccessiblepattern-get_currentstate
613
+ """
614
+ return self.pattern.CurrentState
615
+
616
+ @property
617
+ def Value(self) -> str:
618
+ """
619
+ Property Value.
620
+ Call IUIAutomationLegacyIAccessiblePattern::get_CurrentValue.
621
+ Return str, the Microsoft Active Accessibility value property.
622
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationlegacyiaccessiblepattern-get_currentvalue
623
+ """
624
+ return self.pattern.CurrentValue
625
+
626
+ def DoDefaultAction(self, waitTime: float = OPERATION_WAIT_TIME) -> bool:
627
+ """
628
+ Call IUIAutomationLegacyIAccessiblePattern::DoDefaultAction.
629
+ Perform the Microsoft Active Accessibility default action for the element.
630
+ waitTime: float.
631
+ Return bool, True if succeed otherwise False.
632
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationlegacyiaccessiblepattern-dodefaultaction
633
+ """
634
+ ret = self.pattern.DoDefaultAction() == S_OK
635
+ time.sleep(waitTime)
636
+ return ret
637
+
638
+ def GetSelection(self) -> List['Control']:
639
+ """
640
+ Call IUIAutomationLegacyIAccessiblePattern::GetCurrentSelection.
641
+ Return List[Control], a list of `Control` subclasses,
642
+ the Microsoft Active Accessibility property that identifies the selected children of this element.
643
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationlegacyiaccessiblepattern-getcurrentselection
644
+ """
645
+ eleArray = self.pattern.GetCurrentSelection()
646
+ if eleArray:
647
+ controls = []
648
+ for i in range(eleArray.Length):
649
+ ele = eleArray.GetElement(i)
650
+ con = Control.CreateControlFromElement(element=ele)
651
+ if con:
652
+ controls.append(con)
653
+ return controls
654
+ return []
655
+
656
+ def GetIAccessible(self):
657
+ """
658
+ Call IUIAutomationLegacyIAccessiblePattern::GetIAccessible, todo.
659
+ Return an IAccessible object that corresponds to the Microsoft UI Automation element.
660
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationlegacyiaccessiblepattern-getiaccessible
661
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/oleacc/nn-oleacc-iaccessible
662
+ """
663
+ return self.pattern.GetIAccessible()
664
+
665
+ def Select(self, flagsSelect: int, waitTime: float = OPERATION_WAIT_TIME) -> bool:
666
+ """
667
+ Call IUIAutomationLegacyIAccessiblePattern::Select.
668
+ Perform a Microsoft Active Accessibility selection.
669
+ flagsSelect: int, a value in `AccessibleSelection`.
670
+ waitTime: float.
671
+ Return bool, True if succeed otherwise False.
672
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationlegacyiaccessiblepattern-select
673
+ """
674
+ ret = self.pattern.Select(flagsSelect) == S_OK
675
+ time.sleep(waitTime)
676
+ return ret
677
+
678
+ def SetValue(self, value: str, waitTime: float = OPERATION_WAIT_TIME) -> bool:
679
+ """
680
+ Call IUIAutomationLegacyIAccessiblePattern::SetValue.
681
+ Set the Microsoft Active Accessibility value property for the element.
682
+ value: str.
683
+ waitTime: float.
684
+ Return bool, True if succeed otherwise False.
685
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationlegacyiaccessiblepattern-setvalue
686
+ """
687
+ ret = self.pattern.SetValue(value) == S_OK
688
+ time.sleep(waitTime)
689
+ return ret
690
+
691
+
692
+ class MultipleViewPattern():
693
+ def __init__(self, pattern=None):
694
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationmultipleviewpattern"""
695
+ self.pattern = pattern
696
+
697
+ @property
698
+ def CurrentView(self) -> int:
699
+ """
700
+ Property CurrentView.
701
+ Call IUIAutomationMultipleViewPattern::get_CurrentCurrentView.
702
+ Return int, the control-specific identifier of the current view of the control.
703
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationmultipleviewpattern-get_currentcurrentview
704
+ """
705
+ return self.pattern.CurrentCurrentView
706
+
707
+ def GetSupportedViews(self) -> List[int]:
708
+ """
709
+ Call IUIAutomationMultipleViewPattern::GetCurrentSupportedViews, todo.
710
+ Return List[int], a list of int, control-specific view identifiers.
711
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationmultipleviewpattern-getcurrentsupportedviews
712
+ """
713
+ return self.pattern.GetCurrentSupportedViews()
714
+
715
+ def GetViewName(self, view: int) -> str:
716
+ """
717
+ Call IUIAutomationMultipleViewPattern::GetViewName.
718
+ view: int, the control-specific view identifier.
719
+ Return str, the name of a control-specific view.
720
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationmultipleviewpattern-getviewname
721
+ """
722
+ return self.pattern.GetViewName(view)
723
+
724
+ def SetView(self, view: int) -> bool:
725
+ """
726
+ Call IUIAutomationMultipleViewPattern::SetCurrentView.
727
+ Set the view of the control.
728
+ view: int, the control-specific view identifier.
729
+ Return bool, True if succeed otherwise False.
730
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationmultipleviewpattern-setcurrentview
731
+ """
732
+ return self.pattern.SetCurrentView(view) == S_OK
733
+
734
+
735
+ class ObjectModelPattern():
736
+ def __init__(self, pattern=None):
737
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationobjectmodelpattern"""
738
+ self.pattern = pattern
739
+
740
+ # def GetUnderlyingObjectModel(self) -> ctypes.POINTER(comtypes.automation.IUnknown):
741
+ # """
742
+ # Call IUIAutomationObjectModelPattern::GetUnderlyingObjectModel, todo.
743
+ # Return `ctypes.POINTER(comtypes.IUnknown)`, an interface used to access the underlying object model of the provider.
744
+ # Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationobjectmodelpattern-getunderlyingobjectmodel
745
+ # """
746
+ # return self.pattern.GetUnderlyingObjectModel()
747
+
748
+
749
+ class RangeValuePattern():
750
+ def __init__(self, pattern=None):
751
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationrangevaluepattern"""
752
+ self.pattern = pattern
753
+
754
+ @property
755
+ def IsReadOnly(self) -> bool:
756
+ """
757
+ Property IsReadOnly.
758
+ Call IUIAutomationRangeValuePattern::get_CurrentIsReadOnly.
759
+ Return bool, indicates whether the value of the element can be changed.
760
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationrangevaluepattern-get_currentisreadonly
761
+ """
762
+ return bool(self.pattern.CurrentIsReadOnly)
763
+
764
+ @property
765
+ def LargeChange(self) -> float:
766
+ """
767
+ Property LargeChange.
768
+ Call IUIAutomationRangeValuePattern::get_CurrentLargeChange.
769
+ Return float, the value that is added to or subtracted from the value of the control
770
+ when a large change is made, such as when the PAGE DOWN key is pressed.
771
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationrangevaluepattern-get_currentlargechange
772
+ """
773
+ return self.pattern.CurrentLargeChange
774
+
775
+ @property
776
+ def Maximum(self) -> float:
777
+ """
778
+ Property Maximum.
779
+ Call IUIAutomationRangeValuePattern::get_CurrentMaximum.
780
+ Return float, the maximum value of the control.
781
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationrangevaluepattern-get_currentmaximum
782
+ """
783
+ return self.pattern.CurrentMaximum
784
+
785
+ @property
786
+ def Minimum(self) -> float:
787
+ """
788
+ Property Minimum.
789
+ Call IUIAutomationRangeValuePattern::get_CurrentMinimum.
790
+ Return float, the minimum value of the control.
791
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationrangevaluepattern-get_currentminimum
792
+ """
793
+ return self.pattern.CurrentMinimum
794
+
795
+ @property
796
+ def SmallChange(self) -> float:
797
+ """
798
+ Property SmallChange.
799
+ Call IUIAutomationRangeValuePattern::get_CurrentSmallChange.
800
+ Return float, the value that is added to or subtracted from the value of the control
801
+ when a small change is made, such as when an arrow key is pressed.
802
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationrangevaluepattern-get_currentsmallchange
803
+ """
804
+ return self.pattern.CurrentSmallChange
805
+
806
+ @property
807
+ def Value(self) -> float:
808
+ """
809
+ Property Value.
810
+ Call IUIAutomationRangeValuePattern::get_CurrentValue.
811
+ Return float, the value of the control.
812
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationrangevaluepattern-get_currentvalue
813
+ """
814
+ return self.pattern.CurrentValue
815
+
816
+ def SetValue(self, value: float, waitTime: float = OPERATION_WAIT_TIME) -> bool:
817
+ """
818
+ Call IUIAutomationRangeValuePattern::SetValue.
819
+ Set the value of the control.
820
+ value: int.
821
+ waitTime: float.
822
+ Return bool, True if succeed otherwise False.
823
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationrangevaluepattern-setvalue
824
+ """
825
+ ret = self.pattern.SetValue(value) == S_OK
826
+ time.sleep(waitTime)
827
+ return ret
828
+
829
+
830
+ class ScrollItemPattern():
831
+ def __init__(self, pattern=None):
832
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationscrollitempattern"""
833
+ self.pattern = pattern
834
+
835
+ def ScrollIntoView(self, waitTime: float = OPERATION_WAIT_TIME) -> bool:
836
+ """
837
+ Call IUIAutomationScrollItemPattern::ScrollIntoView.
838
+ waitTime: float.
839
+ Return bool, True if succeed otherwise False.
840
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationscrollitempattern-scrollintoview
841
+ """
842
+ ret = self.pattern.ScrollIntoView() == S_OK
843
+ time.sleep(waitTime)
844
+ return ret
845
+
846
+
847
+ class ScrollPattern():
848
+ NoScrollValue = -1
849
+
850
+ def __init__(self, pattern=None):
851
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationscrollpattern"""
852
+ self.pattern = pattern
853
+
854
+ @property
855
+ def HorizontallyScrollable(self) -> bool:
856
+ """
857
+ Property HorizontallyScrollable.
858
+ Call IUIAutomationScrollPattern::get_CurrentHorizontallyScrollable.
859
+ Return bool, indicates whether the element can scroll horizontally.
860
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationscrollpattern-get_currenthorizontallyscrollable
861
+ """
862
+ return bool(self.pattern.CurrentHorizontallyScrollable)
863
+
864
+ @property
865
+ def HorizontalScrollPercent(self) -> float:
866
+ """
867
+ Property HorizontalScrollPercent.
868
+ Call IUIAutomationScrollPattern::get_CurrentHorizontalScrollPercent.
869
+ Return float, the horizontal scroll position.
870
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationscrollpattern-get_currenthorizontalscrollpercent
871
+ """
872
+ return self.pattern.CurrentHorizontalScrollPercent
873
+
874
+ @property
875
+ def HorizontalViewSize(self) -> float:
876
+ """
877
+ Property HorizontalViewSize.
878
+ Call IUIAutomationScrollPattern::get_CurrentHorizontalViewSize.
879
+ Return float, the horizontal size of the viewable region of a scrollable element.
880
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationscrollpattern-get_currenthorizontalviewsize
881
+ """
882
+ return self.pattern.CurrentHorizontalViewSize
883
+
884
+ @property
885
+ def VerticallyScrollable(self) -> bool:
886
+ """
887
+ Property VerticallyScrollable.
888
+ Call IUIAutomationScrollPattern::get_CurrentVerticallyScrollable.
889
+ Return bool, indicates whether the element can scroll vertically.
890
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationscrollpattern-get_currentverticallyscrollable
891
+ """
892
+ return bool(self.pattern.CurrentVerticallyScrollable)
893
+
894
+ @property
895
+ def VerticalScrollPercent(self) -> float:
896
+ """
897
+ Property VerticalScrollPercent.
898
+ Call IUIAutomationScrollPattern::get_CurrentVerticalScrollPercent.
899
+ Return float, the vertical scroll position.
900
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationscrollpattern-get_currentverticalscrollpercent
901
+ """
902
+ return self.pattern.CurrentVerticalScrollPercent
903
+
904
+ @property
905
+ def VerticalViewSize(self) -> float:
906
+ """
907
+ Property VerticalViewSize.
908
+ Call IUIAutomationScrollPattern::get_CurrentVerticalViewSize.
909
+ Return float, the vertical size of the viewable region of a scrollable element.
910
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationscrollpattern-get_currentverticalviewsize
911
+ """
912
+ return self.pattern.CurrentVerticalViewSize
913
+
914
+ def Scroll(self, horizontalAmount: int, verticalAmount: int, waitTime: float = OPERATION_WAIT_TIME) -> bool:
915
+ """
916
+ Call IUIAutomationScrollPattern::Scroll.
917
+ Scroll the visible region of the content area horizontally and vertically.
918
+ horizontalAmount: int, a value in ScrollAmount.
919
+ verticalAmount: int, a value in ScrollAmount.
920
+ waitTime: float.
921
+ Return bool, True if succeed otherwise False.
922
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationscrollpattern-scroll
923
+ """
924
+ ret = self.pattern.Scroll(horizontalAmount, verticalAmount) == S_OK
925
+ time.sleep(waitTime)
926
+ return ret
927
+
928
+ def SetScrollPercent(self, horizontalPercent: float, verticalPercent: float, waitTime: float = OPERATION_WAIT_TIME) -> bool:
929
+ """
930
+ Call IUIAutomationScrollPattern::SetScrollPercent.
931
+ Set the horizontal and vertical scroll positions as a percentage of the total content area within the UI Automation element.
932
+ horizontalPercent: float or int, a value in [0, 100] or ScrollPattern.NoScrollValue(-1) if no scroll.
933
+ verticalPercent: float or int, a value in [0, 100] or ScrollPattern.NoScrollValue(-1) if no scroll.
934
+ waitTime: float.
935
+ Return bool, True if succeed otherwise False.
936
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationscrollpattern-setscrollpercent
937
+ """
938
+ ret = self.pattern.SetScrollPercent(horizontalPercent, verticalPercent) == S_OK
939
+ time.sleep(waitTime)
940
+ return ret
941
+
942
+
943
+ class SelectionItemPattern():
944
+ def __init__(self, pattern=None):
945
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationselectionitempattern"""
946
+ self.pattern = pattern
947
+
948
+ def AddToSelection(self, waitTime: float = OPERATION_WAIT_TIME) -> bool:
949
+ """
950
+ Call IUIAutomationSelectionItemPattern::AddToSelection.
951
+ Add the current element to the collection of selected items.
952
+ waitTime: float.
953
+ Return bool, True if succeed otherwise False.
954
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationselectionitempattern-addtoselection
955
+ """
956
+ ret = self.pattern.AddToSelection() == S_OK
957
+ time.sleep(waitTime)
958
+ return ret
959
+
960
+ @property
961
+ def IsSelected(self) -> bool:
962
+ """
963
+ Property IsSelected.
964
+ Call IUIAutomationScrollPattern::get_CurrentIsSelected.
965
+ Return bool, indicates whether this item is selected.
966
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationscrollpattern-get_currentisselected
967
+ """
968
+ return bool(self.pattern.CurrentIsSelected)
969
+
970
+ @property
971
+ def SelectionContainer(self) -> 'Control':
972
+ """
973
+ Property SelectionContainer.
974
+ Call IUIAutomationScrollPattern::get_CurrentSelectionContainer.
975
+ Return `Control` subclass, the element that supports IUIAutomationSelectionPattern and acts as the container for this item.
976
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationscrollpattern-get_currentselectioncontainer
977
+ """
978
+ ele = self.pattern.CurrentSelectionContainer
979
+ return Control.CreateControlFromElement(ele)
980
+
981
+ def RemoveFromSelection(self, waitTime: float = OPERATION_WAIT_TIME) -> bool:
982
+ """
983
+ Call IUIAutomationSelectionItemPattern::RemoveFromSelection.
984
+ Remove this element from the selection.
985
+ waitTime: float.
986
+ Return bool, True if succeed otherwise False.
987
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationselectionitempattern-removefromselection
988
+ """
989
+ ret = self.pattern.RemoveFromSelection() == S_OK
990
+ time.sleep(waitTime)
991
+ return ret
992
+
993
+ def Select(self, waitTime: float = OPERATION_WAIT_TIME) -> bool:
994
+ """
995
+ Call IUIAutomationSelectionItemPattern::Select.
996
+ Clear any selected items and then select the current element.
997
+ waitTime: float.
998
+ Return bool, True if succeed otherwise False.
999
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationselectionitempattern-select
1000
+ """
1001
+ ret = self.pattern.Select() == S_OK
1002
+ time.sleep(waitTime)
1003
+ return ret
1004
+
1005
+
1006
+ class SelectionPattern():
1007
+ def __init__(self, pattern=None):
1008
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationselectionpattern"""
1009
+ self.pattern = pattern
1010
+
1011
+ @property
1012
+ def CanSelectMultiple(self) -> bool:
1013
+ """
1014
+ Property CanSelectMultiple.
1015
+ Call IUIAutomationSelectionPattern::get_CurrentCanSelectMultiple.
1016
+ Return bool, indicates whether more than one item in the container can be selected at one time.
1017
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationselectionpattern-get_currentcanselectmultiple
1018
+ """
1019
+ return bool(self.pattern.CurrentCanSelectMultiple)
1020
+
1021
+ @property
1022
+ def IsSelectionRequired(self) -> bool:
1023
+ """
1024
+ Property IsSelectionRequired.
1025
+ Call IUIAutomationSelectionPattern::get_CurrentIsSelectionRequired.
1026
+ Return bool, indicates whether at least one item must be selected at all times.
1027
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationselectionpattern-get_currentisselectionrequired
1028
+ """
1029
+ return bool(self.pattern.CurrentIsSelectionRequired)
1030
+
1031
+ def GetSelection(self) -> List['Control']:
1032
+ """
1033
+ Call IUIAutomationSelectionPattern::GetCurrentSelection.
1034
+ Return List[Control], a list of `Control` subclasses, the selected elements in the container..
1035
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationselectionpattern-getcurrentselection
1036
+ """
1037
+ eleArray = self.pattern.GetCurrentSelection()
1038
+ if eleArray:
1039
+ controls = []
1040
+ for i in range(eleArray.Length):
1041
+ ele = eleArray.GetElement(i)
1042
+ con = Control.CreateControlFromElement(element=ele)
1043
+ if con:
1044
+ controls.append(con)
1045
+ return controls
1046
+ return []
1047
+
1048
+
1049
+ class SelectionPattern2(SelectionPattern):
1050
+ """
1051
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationselectionpattern2
1052
+ """
1053
+ def __init__(self, pattern=None):
1054
+ super().__init__(pattern)
1055
+
1056
+ @property
1057
+ def CurrentSelectedItem(self):
1058
+ """
1059
+ Property CurrentSelectedItem.
1060
+ Call IUIAutomationSelectionPattern2::get_CurrentCurrentSelectedItem.
1061
+ Return Control subclass, the currently selected element.
1062
+ """
1063
+ ele = self.pattern.CurrentCurrentSelectedItem
1064
+ return Control.CreateControlFromElement(element=ele) if ele else None
1065
+
1066
+ @property
1067
+ def FirstSelectedItem(self):
1068
+ """
1069
+ Property FirstSelectedItem.
1070
+ Call IUIAutomationSelectionPattern2::get_CurrentFirstSelectedItem.
1071
+ Return Control subclass, the currently selected element.
1072
+ """
1073
+ ele = self.pattern.CurrentFirstSelectedItem
1074
+ return Control.CreateControlFromElement(element=ele) if ele else None
1075
+
1076
+ @property
1077
+ def LastSelectedItem(self):
1078
+ """
1079
+ Property LastSelectedItem.
1080
+ Call IUIAutomationSelectionPattern2::get_CurrentLastSelectedItem.
1081
+ Return Control subclass, the currently selected element.
1082
+ """
1083
+ ele = self.pattern.CurrentLastSelectedItem
1084
+ return Control.CreateControlFromElement(element=ele) if ele else None
1085
+
1086
+ @property
1087
+ def ItemCount(self) -> int:
1088
+ """
1089
+ Property ItemCount.
1090
+ Call IUIAutomationSelectionPattern2::get_CurrentItemCount.
1091
+ """
1092
+ return self.pattern.CurrentItemCount
1093
+
1094
+
1095
+ class SpreadsheetItemPattern():
1096
+ def __init__(self, pattern=None):
1097
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationspreadsheetitempattern"""
1098
+ self.pattern = pattern
1099
+
1100
+ @property
1101
+ def Formula(self) -> str:
1102
+ """
1103
+ Property Formula.
1104
+ Call IUIAutomationSpreadsheetItemPattern::get_CurrentFormula.
1105
+ Return str, the formula for this cell.
1106
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationspreadsheetitempattern-get_currentformula
1107
+ """
1108
+ return self.pattern.CurrentFormula
1109
+
1110
+ def GetAnnotationObjects(self) -> List['Control']:
1111
+ """
1112
+ Call IUIAutomationSelectionPattern::GetCurrentAnnotationObjects.
1113
+ Return List[Control], a list of `Control` subclasses representing the annotations associated with this spreadsheet cell.
1114
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationspreadsheetitempattern-getcurrentannotationobjects
1115
+ """
1116
+ eleArray = self.pattern.GetCurrentAnnotationObjects()
1117
+ if eleArray:
1118
+ controls = []
1119
+ for i in range(eleArray.Length):
1120
+ ele = eleArray.GetElement(i)
1121
+ con = Control.CreateControlFromElement(element=ele)
1122
+ if con:
1123
+ controls.append(con)
1124
+ return controls
1125
+ return []
1126
+
1127
+ def GetAnnotationTypes(self) -> List[int]:
1128
+ """
1129
+ Call IUIAutomationSelectionPattern::GetCurrentAnnotationTypes.
1130
+ Return List[int], a list of int values in class `AnnotationType`,
1131
+ indicating the types of annotations that are associated with this spreadsheet cell.
1132
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationselectionpattern-getcurrentannotationtypes
1133
+ """
1134
+ return self.pattern.GetCurrentAnnotationTypes()
1135
+
1136
+
1137
+ class SpreadsheetPattern():
1138
+ def __init__(self, pattern=None):
1139
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationspreadsheetpattern"""
1140
+ self.pattern = pattern
1141
+
1142
+ def GetItemByName(self, name: str) -> 'Control':
1143
+ """
1144
+ Call IUIAutomationSpreadsheetPattern::GetItemByName.
1145
+ name: str.
1146
+ Return `Control` subclass or None, represents the spreadsheet cell that has the specified name..
1147
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationspreadsheetpattern-getitembyname
1148
+ """
1149
+ ele = self.pattern.GetItemByName(name)
1150
+ return Control.CreateControlFromElement(element=ele)
1151
+
1152
+
1153
+ class StylesPattern():
1154
+ def __init__(self, pattern=None):
1155
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationstylespattern"""
1156
+ self.pattern = pattern
1157
+
1158
+ @property
1159
+ def ExtendedProperties(self) -> str:
1160
+ """
1161
+ Property ExtendedProperties.
1162
+ Call IUIAutomationStylesPattern::get_CurrentExtendedProperties.
1163
+ Return str, a localized string that contains the list of extended properties for an element in a document.
1164
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationstylespattern-get_currentextendedproperties
1165
+ """
1166
+ return self.pattern.CurrentExtendedProperties
1167
+
1168
+ @property
1169
+ def FillColor(self) -> int:
1170
+ """
1171
+ Property FillColor.
1172
+ Call IUIAutomationStylesPattern::get_CurrentFillColor.
1173
+ Return int, the fill color of an element in a document.
1174
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationstylespattern-get_currentfillcolor
1175
+ """
1176
+ return self.pattern.CurrentFillColor
1177
+
1178
+ @property
1179
+ def FillPatternColor(self) -> int:
1180
+ """
1181
+ Property FillPatternColor.
1182
+ Call IUIAutomationStylesPattern::get_CurrentFillPatternColor.
1183
+ Return int, the color of the pattern used to fill an element in a document.
1184
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationstylespattern-get_currentfillpatterncolor
1185
+ """
1186
+ return self.pattern.CurrentFillPatternColor
1187
+
1188
+ @property
1189
+ def Shape(self) -> str:
1190
+ """
1191
+ Property Shape.
1192
+ Call IUIAutomationStylesPattern::get_CurrentShape.
1193
+ Return str, the shape of an element in a document.
1194
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationstylespattern-get_currentshape
1195
+ """
1196
+ return self.pattern.CurrentShape
1197
+
1198
+ @property
1199
+ def StyleId(self) -> int:
1200
+ """
1201
+ Property StyleId.
1202
+ Call IUIAutomationStylesPattern::get_CurrentStyleId.
1203
+ Return int, a value in class `StyleId`, the visual style associated with an element in a document.
1204
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationstylespattern-get_currentstyleid
1205
+ """
1206
+ return self.pattern.CurrentStyleId
1207
+
1208
+ @property
1209
+ def StyleName(self) -> str:
1210
+ """
1211
+ Property StyleName.
1212
+ Call IUIAutomationStylesPattern::get_CurrentStyleName.
1213
+ Return str, the name of the visual style associated with an element in a document.
1214
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationstylespattern-get_currentstylename
1215
+ """
1216
+ return self.pattern.CurrentStyleName
1217
+
1218
+
1219
+ class SynchronizedInputPattern():
1220
+ def __init__(self, pattern=None):
1221
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationsynchronizedinputpattern"""
1222
+ self.pattern = pattern
1223
+
1224
+ def Cancel(self) -> bool:
1225
+ """
1226
+ Call IUIAutomationSynchronizedInputPattern::Cancel.
1227
+ Cause the Microsoft UI Automation provider to stop listening for mouse or keyboard input.
1228
+ Return bool, True if succeed otherwise False.
1229
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationsynchronizedinputpattern-cancel
1230
+ """
1231
+ return self.pattern.Cancel() == S_OK
1232
+
1233
+ def StartListening(self) -> bool:
1234
+ """
1235
+ Call IUIAutomationSynchronizedInputPattern::StartListening.
1236
+ Cause the Microsoft UI Automation provider to start listening for mouse or keyboard input.
1237
+ Return bool, True if succeed otherwise False.
1238
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationsynchronizedinputpattern-startlistening
1239
+ """
1240
+ return self.pattern.StartListening() == S_OK
1241
+
1242
+
1243
+ class TableItemPattern():
1244
+ def __init__(self, pattern=None):
1245
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationtableitempattern"""
1246
+ self.pattern = pattern
1247
+
1248
+ def GetColumnHeaderItems(self) -> List['Control']:
1249
+ """
1250
+ Call IUIAutomationTableItemPattern::GetCurrentColumnHeaderItems.
1251
+ Return List[Control], a list of `Control` subclasses, the column headers associated with a table item or cell.
1252
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtableitempattern-getcurrentcolumnheaderitems
1253
+ """
1254
+ eleArray = self.pattern.GetCurrentColumnHeaderItems()
1255
+ if eleArray:
1256
+ controls = []
1257
+ for i in range(eleArray.Length):
1258
+ ele = eleArray.GetElement(i)
1259
+ con = Control.CreateControlFromElement(element=ele)
1260
+ if con:
1261
+ controls.append(con)
1262
+ return controls
1263
+ return []
1264
+
1265
+ def GetRowHeaderItems(self) -> List['Control']:
1266
+ """
1267
+ Call IUIAutomationTableItemPattern::GetCurrentRowHeaderItems.
1268
+ Return List[Control], a list of `Control` subclasses, the row headers associated with a table item or cell.
1269
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtableitempattern-getcurrentrowheaderitems
1270
+ """
1271
+ eleArray = self.pattern.GetCurrentRowHeaderItems()
1272
+ if eleArray:
1273
+ controls = []
1274
+ for i in range(eleArray.Length):
1275
+ ele = eleArray.GetElement(i)
1276
+ con = Control.CreateControlFromElement(element=ele)
1277
+ if con:
1278
+ controls.append(con)
1279
+ return controls
1280
+ return []
1281
+
1282
+
1283
+ class TablePattern():
1284
+ def __init__(self, pattern=None):
1285
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationtablepattern"""
1286
+ self.pattern = pattern
1287
+
1288
+ @property
1289
+ def RowOrColumnMajor(self) -> int:
1290
+ """
1291
+ Property RowOrColumnMajor.
1292
+ Call IUIAutomationTablePattern::get_CurrentRowOrColumnMajor.
1293
+ Return int, a value in class `RowOrColumnMajor`, the primary direction of traversal for the table.
1294
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtablepattern-get_currentroworcolumnmajor
1295
+ """
1296
+ return self.pattern.CurrentRowOrColumnMajor
1297
+
1298
+ def GetColumnHeaders(self) -> List['Control']:
1299
+ """
1300
+ Call IUIAutomationTablePattern::GetCurrentColumnHeaders.
1301
+ Return List[Control], a list of `Control` subclasses, representing all the column headers in a table..
1302
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtablepattern-getcurrentcolumnheaders
1303
+ """
1304
+ eleArray = self.pattern.GetCurrentColumnHeaders()
1305
+ if eleArray:
1306
+ controls = []
1307
+ for i in range(eleArray.Length):
1308
+ ele = eleArray.GetElement(i)
1309
+ con = Control.CreateControlFromElement(element=ele)
1310
+ if con:
1311
+ controls.append(con)
1312
+ return controls
1313
+ return []
1314
+
1315
+ def GetRowHeaders(self) -> List['Control']:
1316
+ """
1317
+ Call IUIAutomationTablePattern::GetCurrentRowHeaders.
1318
+ Return List[Control], a list of `Control` subclasses, representing all the row headers in a table.
1319
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtablepattern-getcurrentrowheaders
1320
+ """
1321
+ eleArray = self.pattern.GetCurrentRowHeaders()
1322
+ if eleArray:
1323
+ controls = []
1324
+ for i in range(eleArray.Length):
1325
+ ele = eleArray.GetElement(i)
1326
+ con = Control.CreateControlFromElement(element=ele)
1327
+ if con:
1328
+ controls.append(con)
1329
+ return controls
1330
+ return []
1331
+
1332
+
1333
+ class TextRange():
1334
+ def __init__(self, textRange=None):
1335
+ """
1336
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationtextrange
1337
+ """
1338
+ self.textRange = textRange
1339
+
1340
+ def AddToSelection(self, waitTime: float = OPERATION_WAIT_TIME) -> bool:
1341
+ """
1342
+ Call IUIAutomationTextRange::AddToSelection.
1343
+ Add the text range to the collection of selected text ranges in a control that supports multiple, disjoint spans of selected text.
1344
+ waitTime: float.
1345
+ Return bool, True if succeed otherwise False.
1346
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-addtoselection
1347
+ """
1348
+ ret = self.textRange.AddToSelection() == S_OK
1349
+ time.sleep(waitTime)
1350
+ return ret
1351
+
1352
+ def Clone(self) -> 'TextRange':
1353
+ """
1354
+ Call IUIAutomationTextRange::Clone.
1355
+ return `TextRange`, identical to the original and inheriting all properties of the original.
1356
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-clone
1357
+ """
1358
+ return TextRange(textRange=self.textRange.Clone())
1359
+
1360
+ def Compare(self, textRange: 'TextRange') -> bool:
1361
+ """
1362
+ Call IUIAutomationTextRange::Compare.
1363
+ textRange: `TextRange`.
1364
+ Return bool, specifies whether this text range has the same endpoints as another text range.
1365
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-compare
1366
+ """
1367
+ return bool(self.textRange.Compare(textRange.textRange))
1368
+
1369
+ def CompareEndpoints(self, srcEndPoint: int, textRange: 'TextRange', targetEndPoint: int) -> int:
1370
+ """
1371
+ Call IUIAutomationTextRange::CompareEndpoints.
1372
+ srcEndPoint: int, a value in class `TextPatternRangeEndpoint`.
1373
+ textRange: `TextRange`.
1374
+ targetEndPoint: int, a value in class `TextPatternRangeEndpoint`.
1375
+ Return int, a negative value if the caller's endpoint occurs earlier in the text than the target endpoint;
1376
+ 0 if the caller's endpoint is at the same location as the target endpoint;
1377
+ or a positive value if the caller's endpoint occurs later in the text than the target endpoint.
1378
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-compareendpoints
1379
+ """
1380
+ return self.textRange.CompareEndpoints(srcEndPoint, textRange, targetEndPoint)
1381
+
1382
+ def ExpandToEnclosingUnit(self, unit: int, waitTime: float = OPERATION_WAIT_TIME) -> bool:
1383
+ """
1384
+ Call IUIAutomationTextRange::ExpandToEnclosingUnit.
1385
+ Normalize the text range by the specified text unit.
1386
+ The range is expanded if it is smaller than the specified unit,
1387
+ or shortened if it is longer than the specified unit.
1388
+ unit: int, a value in class `TextUnit`.
1389
+ waitTime: float.
1390
+ Return bool, True if succeed otherwise False.
1391
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-expandtoenclosingunit
1392
+ """
1393
+ ret = self.textRange.ExpandToEnclosingUnit(unit) == S_OK
1394
+ time.sleep(waitTime)
1395
+ return ret
1396
+
1397
+ def FindAttribute(self, textAttributeId: int, val, backward: bool) -> Optional['TextRange']:
1398
+ """
1399
+ Call IUIAutomationTextRange::FindAttribute.
1400
+ textAttributeID: int, a value in class `TextAttributeId`.
1401
+ val: COM VARIANT according to textAttributeId? todo.
1402
+ backward: bool, True if the last occurring text range should be returned instead of the first; otherwise False.
1403
+ return `TextRange` or None, a text range subset that has the specified text attribute value.
1404
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-findattribute
1405
+ """
1406
+ textRange = self.textRange.FindAttribute(textAttributeId, val, int(backward))
1407
+ if textRange:
1408
+ return TextRange(textRange=textRange)
1409
+ return None
1410
+
1411
+ def FindText(self, text: str, backward: bool, ignoreCase: bool) -> Optional['TextRange']:
1412
+ """
1413
+ Call IUIAutomationTextRange::FindText.
1414
+ text: str,
1415
+ backward: bool, True if the last occurring text range should be returned instead of the first; otherwise False.
1416
+ ignoreCase: bool, True if case should be ignored; otherwise False.
1417
+ return `TextRange` or None, a text range subset that contains the specified text.
1418
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-findtext
1419
+ """
1420
+ textRange = self.textRange.FindText(text, int(backward), int(ignoreCase))
1421
+ if textRange:
1422
+ return TextRange(textRange=textRange)
1423
+ return None
1424
+
1425
+ def GetAttributeValue(self, textAttributeId: int) -> ctypes.POINTER(comtypes.IUnknown):
1426
+ """
1427
+ Call IUIAutomationTextRange::GetAttributeValue.
1428
+ textAttributeId: int, a value in class `TextAttributeId`.
1429
+ Return `ctypes.POINTER(comtypes.IUnknown)` or None, the value of the specified text attribute across the entire text range, todo.
1430
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-getattributevalue
1431
+ """
1432
+ return self.textRange.GetAttributeValue(textAttributeId)
1433
+
1434
+ def GetBoundingRectangles(self) -> List[Rect]:
1435
+ """
1436
+ Call IUIAutomationTextRange::GetBoundingRectangles.
1437
+ textAttributeId: int, a value in class `TextAttributeId`.
1438
+ Return List[Rect], a list of `Rect`.
1439
+ bounding rectangles for each fully or partially visible line of text in a text range..
1440
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-getboundingrectangles
1441
+
1442
+ for rect in textRange.GetBoundingRectangles():
1443
+ print(rect.left, rect.top, rect.right, rect.bottom, rect.width(), rect.height(), rect.xcenter(), rect.ycenter())
1444
+ """
1445
+ floats = self.textRange.GetBoundingRectangles()
1446
+ rects = []
1447
+ for i in range(len(floats) // 4):
1448
+ rect = Rect(int(floats[i * 4]), int(floats[i * 4 + 1]),
1449
+ int(floats[i * 4]) + int(floats[i * 4 + 2]), int(floats[i * 4 + 1]) + int(floats[i * 4 + 3]))
1450
+ rects.append(rect)
1451
+ return rects
1452
+
1453
+ def GetChildren(self) -> List['Control']:
1454
+ """
1455
+ Call IUIAutomationTextRange::GetChildren.
1456
+ textAttributeId: int, a value in class `TextAttributeId`.
1457
+ Return List[Control], a list of `Control` subclasses, embedded objects that fall within the text range..
1458
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-getchildren
1459
+ """
1460
+ eleArray = self.textRange.GetChildren()
1461
+ if eleArray:
1462
+ controls = []
1463
+ for i in range(eleArray.Length):
1464
+ ele = eleArray.GetElement(i)
1465
+ con = Control.CreateControlFromElement(element=ele)
1466
+ if con:
1467
+ controls.append(con)
1468
+ return controls
1469
+ return []
1470
+
1471
+ def GetEnclosingControl(self) -> 'Control':
1472
+ """
1473
+ Call IUIAutomationTextRange::GetEnclosingElement.
1474
+ Return `Control` subclass, the innermost UI Automation element that encloses the text range.
1475
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-getenclosingelement
1476
+ """
1477
+ return Control.CreateControlFromElement(self.textRange.GetEnclosingElement())
1478
+
1479
+ def GetText(self, maxLength: int = -1) -> str:
1480
+ """
1481
+ Call IUIAutomationTextRange::GetText.
1482
+ maxLength: int, the maximum length of the string to return, or -1 if no limit is required.
1483
+ Return str, the plain text of the text range.
1484
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-gettext
1485
+ """
1486
+ return self.textRange.GetText(maxLength)
1487
+
1488
+ def Move(self, unit: int, count: int, waitTime: float = OPERATION_WAIT_TIME) -> int:
1489
+ """
1490
+ Call IUIAutomationTextRange::Move.
1491
+ Move the text range forward or backward by the specified number of text units.
1492
+ unit: int, a value in class `TextUnit`.
1493
+ count: int, the number of text units to move.
1494
+ A positive value moves the text range forward.
1495
+ A negative value moves the text range backward. Zero has no effect.
1496
+ waitTime: float.
1497
+ Return: int, the number of text units actually moved.
1498
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-move
1499
+ """
1500
+ ret = self.textRange.Move(unit, count)
1501
+ time.sleep(waitTime)
1502
+ return ret
1503
+
1504
+ def MoveEndpointByRange(self, srcEndPoint: int, textRange: 'TextRange', targetEndPoint: int, waitTime: float = OPERATION_WAIT_TIME) -> bool:
1505
+ """
1506
+ Call IUIAutomationTextRange::MoveEndpointByRange.
1507
+ Move one endpoint of the current text range to the specified endpoint of a second text range.
1508
+ srcEndPoint: int, a value in class `TextPatternRangeEndpoint`.
1509
+ textRange: `TextRange`.
1510
+ targetEndPoint: int, a value in class `TextPatternRangeEndpoint`.
1511
+ waitTime: float.
1512
+ Return bool, True if succeed otherwise False.
1513
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-moveendpointbyrange
1514
+ """
1515
+ ret = self.textRange.MoveEndpointByRange(srcEndPoint, textRange.textRange, targetEndPoint) == S_OK
1516
+ time.sleep(waitTime)
1517
+ return ret
1518
+
1519
+ def MoveEndpointByUnit(self, endPoint: int, unit: int, count: int, waitTime: float = OPERATION_WAIT_TIME) -> int:
1520
+ """
1521
+ Call IUIAutomationTextRange::MoveEndpointByUnit.
1522
+ Move one endpoint of the text range the specified number of text units within the document range.
1523
+ endPoint: int, a value in class `TextPatternRangeEndpoint`.
1524
+ unit: int, a value in class `TextUnit`.
1525
+ count: int, the number of units to move.
1526
+ A positive count moves the endpoint forward.
1527
+ A negative count moves backward.
1528
+ A count of 0 has no effect.
1529
+ waitTime: float.
1530
+ Return int, the count of units actually moved.
1531
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-moveendpointbyunit
1532
+ """
1533
+ ret = self.textRange.MoveEndpointByUnit(endPoint, unit, count)
1534
+ time.sleep(waitTime)
1535
+ return ret
1536
+
1537
+ def RemoveFromSelection(self, waitTime: float = OPERATION_WAIT_TIME) -> bool:
1538
+ """
1539
+ Call IUIAutomationTextRange::RemoveFromSelection.
1540
+ Remove the text range from an existing collection of selected text in a text container that supports multiple, disjoint selections.
1541
+ waitTime: float.
1542
+ Return bool, True if succeed otherwise False.
1543
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-removefromselection
1544
+ """
1545
+ ret = self.textRange.RemoveFromSelection() == S_OK
1546
+ time.sleep(waitTime)
1547
+ return ret
1548
+
1549
+ def ScrollIntoView(self, alignTop: bool = True, waitTime: float = OPERATION_WAIT_TIME) -> bool:
1550
+ """
1551
+ Call IUIAutomationTextRange::ScrollIntoView.
1552
+ Cause the text control to scroll until the text range is visible in the viewport.
1553
+ alignTop: bool, True if the text control should be scrolled so that the text range is flush with the top of the viewport;
1554
+ False if it should be flush with the bottom of the viewport.
1555
+ waitTime: float.
1556
+ Return bool, True if succeed otherwise False.
1557
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-scrollintoview
1558
+ """
1559
+ ret = self.textRange.ScrollIntoView(int(alignTop)) == S_OK
1560
+ time.sleep(waitTime)
1561
+ return ret
1562
+
1563
+ def Select(self, waitTime: float = OPERATION_WAIT_TIME) -> bool:
1564
+ """
1565
+ Call IUIAutomationTextRange::Select.
1566
+ Select the span of text that corresponds to this text range, and remove any previous selection.
1567
+ waitTime: float.
1568
+ Return bool, True if succeed otherwise False.
1569
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextrange-select
1570
+ """
1571
+ ret = self.textRange.Select() == S_OK
1572
+ time.sleep(waitTime)
1573
+ return ret
1574
+
1575
+
1576
+ class TextChildPattern():
1577
+ def __init__(self, pattern=None):
1578
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationtextchildpattern"""
1579
+ self.pattern = pattern
1580
+
1581
+ @property
1582
+ def TextContainer(self) -> 'Control':
1583
+ """
1584
+ Property TextContainer.
1585
+ Call IUIAutomationSelectionContainer::get_TextContainer.
1586
+ Return `Control` subclass, the nearest ancestor element that supports the Text control pattern.
1587
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextchildpattern-get_textcontainer
1588
+ """
1589
+ return Control.CreateControlFromElement(self.pattern.TextContainer)
1590
+
1591
+ @property
1592
+ def TextRange(self) -> TextRange:
1593
+ """
1594
+ Property TextRange.
1595
+ Call IUIAutomationSelectionContainer::get_TextRange.
1596
+ Return `TextRange`, a text range that encloses this child element.
1597
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextchildpattern-get_textrange
1598
+ """
1599
+ return TextRange(self.pattern.TextRange)
1600
+
1601
+
1602
+ class TextEditPattern():
1603
+ def __init__(self, pattern=None):
1604
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationtexteditpattern"""
1605
+ self.pattern = pattern
1606
+
1607
+ def GetActiveComposition(self) -> Optional[TextRange]:
1608
+ """
1609
+ Call IUIAutomationTextEditPattern::GetActiveComposition.
1610
+ Return `TextRange` or None, the active composition.
1611
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtexteditpattern-getactivecomposition
1612
+ """
1613
+ textRange = self.pattern.GetActiveComposition()
1614
+ if textRange:
1615
+ return TextRange(textRange=textRange)
1616
+ return None
1617
+
1618
+ def GetConversionTarget(self) -> Optional[TextRange]:
1619
+ """
1620
+ Call IUIAutomationTextEditPattern::GetConversionTarget.
1621
+ Return `TextRange` or None, the current conversion target range..
1622
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtexteditpattern-getconversiontarget
1623
+ """
1624
+ textRange = self.pattern.GetConversionTarget()
1625
+ if textRange:
1626
+ return TextRange(textRange=textRange)
1627
+ return None
1628
+
1629
+
1630
+ class TextPattern():
1631
+ def __init__(self, pattern=None):
1632
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationtextpattern"""
1633
+ self.pattern = pattern
1634
+
1635
+ @property
1636
+ def DocumentRange(self) -> TextRange:
1637
+ """
1638
+ Property DocumentRange.
1639
+ Call IUIAutomationTextPattern::get_DocumentRange.
1640
+ Return `TextRange`, a text range that encloses the main text of a document.
1641
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextpattern-get_documentrange
1642
+ """
1643
+ return TextRange(self.pattern.DocumentRange)
1644
+
1645
+ @property
1646
+ def SupportedTextSelection(self) -> bool:
1647
+ """
1648
+ Property SupportedTextSelection.
1649
+ Call IUIAutomationTextPattern::get_SupportedTextSelection.
1650
+ Return bool, specifies the type of text selection that is supported by the control.
1651
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextpattern-get_supportedtextselection
1652
+ """
1653
+ return bool(self.pattern.SupportedTextSelection)
1654
+
1655
+ def GetSelection(self) -> List[TextRange]:
1656
+ """
1657
+ Call IUIAutomationTextPattern::GetSelection.
1658
+ Return List[TextRange], a list of `TextRange`, represents the currently selected text in a text-based control.
1659
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextpattern-getselection
1660
+ """
1661
+ eleArray = self.pattern.GetSelection()
1662
+ if eleArray:
1663
+ textRanges = []
1664
+ for i in range(eleArray.Length):
1665
+ ele = eleArray.GetElement(i)
1666
+ textRanges.append(TextRange(textRange=ele))
1667
+ return textRanges
1668
+ return []
1669
+
1670
+ def GetVisibleRanges(self) -> List[TextRange]:
1671
+ """
1672
+ Call IUIAutomationTextPattern::GetVisibleRanges.
1673
+ Return List[TextRange], a list of `TextRange`, disjoint text ranges from a text-based control
1674
+ where each text range represents a contiguous span of visible text.
1675
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextpattern-getvisibleranges
1676
+ """
1677
+ eleArray = self.pattern.GetVisibleRanges()
1678
+ if eleArray:
1679
+ textRanges = []
1680
+ for i in range(eleArray.Length):
1681
+ ele = eleArray.GetElement(i)
1682
+ textRanges.append(TextRange(textRange=ele))
1683
+ return textRanges
1684
+ return []
1685
+
1686
+ def RangeFromChild(self, child) -> Optional[TextRange]:
1687
+ """
1688
+ Call IUIAutomationTextPattern::RangeFromChild.
1689
+ child: `Control` or its subclass.
1690
+ Return `TextRange` or None, a text range enclosing a child element such as an image,
1691
+ hyperlink, Microsoft Excel spreadsheet, or other embedded object.
1692
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextpattern-rangefromchild
1693
+ """
1694
+ textRange = self.pattern.RangeFromChild(Control.Element)
1695
+ if textRange:
1696
+ return TextRange(textRange=textRange)
1697
+ return None
1698
+
1699
+ def RangeFromPoint(self, x: int, y: int) -> Optional[TextRange]:
1700
+ """
1701
+ Call IUIAutomationTextPattern::RangeFromPoint.
1702
+ child: `Control` or its subclass.
1703
+ Return `TextRange` or None, the degenerate (empty) text range nearest to the specified screen coordinates.
1704
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextpattern-rangefrompoint
1705
+ """
1706
+ textRange = self.pattern.RangeFromPoint(ctypes.wintypes.POINT(x, y))
1707
+ if textRange:
1708
+ return TextRange(textRange=textRange)
1709
+ return None
1710
+
1711
+
1712
+ class TextPattern2():
1713
+ def __init__(self, pattern=None):
1714
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationtextpattern2"""
1715
+ self.pattern = pattern
1716
+
1717
+
1718
+ class TogglePattern():
1719
+ def __init__(self, pattern=None):
1720
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationtogglepattern"""
1721
+ self.pattern = pattern
1722
+
1723
+ @property
1724
+ def ToggleState(self) -> int:
1725
+ """
1726
+ Property ToggleState.
1727
+ Call IUIAutomationTogglePattern::get_CurrentToggleState.
1728
+ Return int, a value in class `ToggleState`, the state of the control.
1729
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtogglepattern-get_currenttogglestate
1730
+ """
1731
+ return self.pattern.CurrentToggleState
1732
+
1733
+ def Toggle(self, waitTime: float = OPERATION_WAIT_TIME) -> bool:
1734
+ """
1735
+ Call IUIAutomationTogglePattern::Toggle.
1736
+ Cycle through the toggle states of the control.
1737
+ waitTime: float.
1738
+ Return bool, True if succeed otherwise False.
1739
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtogglepattern-toggle
1740
+ """
1741
+ ret = self.pattern.Toggle() == S_OK
1742
+ time.sleep(waitTime)
1743
+ return ret
1744
+
1745
+ def SetToggleState(self, toggleState: int, waitTime: float = OPERATION_WAIT_TIME) -> bool:
1746
+ for i in range(6):
1747
+ if self.ToggleState == toggleState:
1748
+ return True
1749
+ self.Toggle(waitTime)
1750
+ return False
1751
+
1752
+
1753
+ class TransformPattern():
1754
+ def __init__(self, pattern=None):
1755
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationtransformpattern"""
1756
+ self.pattern = pattern
1757
+
1758
+ @property
1759
+ def CanMove(self) -> bool:
1760
+ """
1761
+ Property CanMove.
1762
+ Call IUIAutomationTransformPattern::get_CurrentCanMove.
1763
+ Return bool, indicates whether the element can be moved.
1764
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtransformpattern-get_currentcanmove
1765
+ """
1766
+ return bool(self.pattern.CurrentCanMove)
1767
+
1768
+ @property
1769
+ def CanResize(self) -> bool:
1770
+ """
1771
+ Property CanResize.
1772
+ Call IUIAutomationTransformPattern::get_CurrentCanResize.
1773
+ Return bool, indicates whether the element can be resized.
1774
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtransformpattern-get_currentcanresize
1775
+ """
1776
+ return bool(self.pattern.CurrentCanResize)
1777
+
1778
+ @property
1779
+ def CanRotate(self) -> bool:
1780
+ """
1781
+ Property CanRotate.
1782
+ Call IUIAutomationTransformPattern::get_CurrentCanRotate.
1783
+ Return bool, indicates whether the element can be rotated.
1784
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtransformpattern-get_currentcanrotate
1785
+ """
1786
+ return bool(self.pattern.CurrentCanRotate)
1787
+
1788
+ def Move(self, x: int, y: int, waitTime: float = OPERATION_WAIT_TIME) -> bool:
1789
+ """
1790
+ Call IUIAutomationTransformPattern::Move.
1791
+ Move the UI Automation element.
1792
+ x: int.
1793
+ y: int.
1794
+ waitTime: float.
1795
+ Return bool, True if succeed otherwise False.
1796
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtransformpattern-move
1797
+ """
1798
+ ret = self.pattern.Move(x, y) == S_OK
1799
+ time.sleep(waitTime)
1800
+ return ret
1801
+
1802
+ def Resize(self, width: int, height: int, waitTime: float = OPERATION_WAIT_TIME) -> bool:
1803
+ """
1804
+ Call IUIAutomationTransformPattern::Resize.
1805
+ Resize the UI Automation element.
1806
+ width: int.
1807
+ height: int.
1808
+ waitTime: float.
1809
+ Return bool, True if succeed otherwise False.
1810
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtransformpattern-resize
1811
+ """
1812
+ ret = self.pattern.Resize(width, height) == S_OK
1813
+ time.sleep(waitTime)
1814
+ return ret
1815
+
1816
+ def Rotate(self, degrees: int, waitTime: float = OPERATION_WAIT_TIME) -> bool:
1817
+ """
1818
+ Call IUIAutomationTransformPattern::Rotate.
1819
+ Rotates the UI Automation element.
1820
+ degrees: int.
1821
+ waitTime: float.
1822
+ Return bool, True if succeed otherwise False.
1823
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtransformpattern-rotate
1824
+ """
1825
+ ret = self.pattern.Rotate(degrees) == S_OK
1826
+ time.sleep(waitTime)
1827
+ return ret
1828
+
1829
+
1830
+ class TransformPattern2():
1831
+ def __init__(self, pattern=None):
1832
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationtransformpattern2"""
1833
+ self.pattern = pattern
1834
+
1835
+ @property
1836
+ def CanZoom(self) -> bool:
1837
+ """
1838
+ Property CanZoom.
1839
+ Call IUIAutomationTransformPattern2::get_CurrentCanZoom.
1840
+ Return bool, indicates whether the control supports zooming of its viewport.
1841
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtransformpattern2-get_CurrentCanZoom
1842
+ """
1843
+ return bool(self.pattern.CurrentCanZoom)
1844
+
1845
+ @property
1846
+ def ZoomLevel(self) -> float:
1847
+ """
1848
+ Property ZoomLevel.
1849
+ Call IUIAutomationTransformPattern2::get_CurrentZoomLevel.
1850
+ Return float, the zoom level of the control's viewport.
1851
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtransformpattern2-get_currentzoomlevel
1852
+ """
1853
+ return self.pattern.CurrentZoomLevel
1854
+
1855
+ @property
1856
+ def ZoomMaximum(self) -> float:
1857
+ """
1858
+ Property ZoomMaximum.
1859
+ Call IUIAutomationTransformPattern2::get_CurrentZoomMaximum.
1860
+ Return float, the maximum zoom level of the control's viewport.
1861
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtransformpattern2-get_currentzoommaximum
1862
+ """
1863
+ return self.pattern.CurrentZoomMaximum
1864
+
1865
+ @property
1866
+ def ZoomMinimum(self) -> float:
1867
+ """
1868
+ Property ZoomMinimum.
1869
+ Call IUIAutomationTransformPattern2::get_CurrentZoomMinimum.
1870
+ Return float, the minimum zoom level of the control's viewport.
1871
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtransformpattern2-get_currentzoomminimum
1872
+ """
1873
+ return self.pattern.CurrentZoomMinimum
1874
+
1875
+ def Zoom(self, zoomLevel: float, waitTime: float = OPERATION_WAIT_TIME) -> bool:
1876
+ """
1877
+ Call IUIAutomationTransformPattern2::Zoom.
1878
+ Zoom the viewport of the control.
1879
+ zoomLevel: float for int.
1880
+ waitTime: float.
1881
+ Return bool, True if succeed otherwise False.
1882
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtransformpattern2-zoom
1883
+ """
1884
+ ret = self.pattern.Zoom(zoomLevel) == S_OK
1885
+ time.sleep(waitTime)
1886
+ return ret
1887
+
1888
+ def ZoomByUnit(self, zoomUnit: int, waitTime: float = OPERATION_WAIT_TIME) -> bool:
1889
+ """
1890
+ Call IUIAutomationTransformPattern2::ZoomByUnit.
1891
+ Zoom the viewport of the control by the specified unit.
1892
+ zoomUnit: int, a value in class `ZoomUnit`.
1893
+ waitTime: float.
1894
+ Return bool, True if succeed otherwise False.
1895
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtransformpattern2-zoombyunit
1896
+ """
1897
+ ret = self.pattern.ZoomByUnit(zoomUnit) == S_OK
1898
+ time.sleep(waitTime)
1899
+ return ret
1900
+
1901
+
1902
+ class ValuePattern():
1903
+ def __init__(self, pattern=None):
1904
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationvaluepattern"""
1905
+ self.pattern = pattern
1906
+
1907
+ @property
1908
+ def IsReadOnly(self) -> bool:
1909
+ """
1910
+ Property IsReadOnly.
1911
+ Call IUIAutomationTransformPattern2::IUIAutomationValuePattern::get_CurrentIsReadOnly.
1912
+ Return bool, indicates whether the value of the element is read-only.
1913
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationvaluepattern-get_currentisreadonly
1914
+ """
1915
+ return bool(self.pattern.CurrentIsReadOnly)
1916
+
1917
+ @property
1918
+ def Value(self) -> str:
1919
+ """
1920
+ Property Value.
1921
+ Call IUIAutomationTransformPattern2::IUIAutomationValuePattern::get_CurrentValue.
1922
+ Return str, the value of the element.
1923
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationvaluepattern-get_currentvalue
1924
+ """
1925
+ return self.pattern.CurrentValue
1926
+
1927
+ def SetValue(self, value: str, waitTime: float = OPERATION_WAIT_TIME) -> bool:
1928
+ """
1929
+ Call IUIAutomationTransformPattern2::IUIAutomationValuePattern::SetValue.
1930
+ Set the value of the element.
1931
+ value: str.
1932
+ waitTime: float.
1933
+ Return bool, True if succeed otherwise False.
1934
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationvaluepattern-setvalue
1935
+ """
1936
+ ret = self.pattern.SetValue(value) == S_OK
1937
+ time.sleep(waitTime)
1938
+ return ret
1939
+
1940
+
1941
+ class VirtualizedItemPattern():
1942
+ def __init__(self, pattern=None):
1943
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationvirtualizeditempattern"""
1944
+ self.pattern = pattern
1945
+
1946
+ def Realize(self, waitTime: float = OPERATION_WAIT_TIME) -> bool:
1947
+ """
1948
+ Call IUIAutomationVirtualizedItemPattern::Realize.
1949
+ Create a full UI Automation element for a virtualized item.
1950
+ waitTime: float.
1951
+ Return bool, True if succeed otherwise False.
1952
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationvirtualizeditempattern-realize
1953
+ """
1954
+ ret = self.pattern.Realize() == S_OK
1955
+ time.sleep(waitTime)
1956
+ return ret
1957
+
1958
+
1959
+ class WindowPattern():
1960
+ def __init__(self, pattern=None):
1961
+ """Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationwindowpattern"""
1962
+ self.pattern = pattern
1963
+
1964
+ def Close(self, waitTime: float = OPERATION_WAIT_TIME) -> bool:
1965
+ """
1966
+ Call IUIAutomationWindowPattern::Close.
1967
+ Close the window.
1968
+ waitTime: float.
1969
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationwindowpattern-close
1970
+ """
1971
+ ret = self.pattern.Close() == S_OK
1972
+ time.sleep(waitTime)
1973
+ return ret
1974
+
1975
+ @property
1976
+ def CanMaximize(self) -> bool:
1977
+ """
1978
+ Property CanMaximize.
1979
+ Call IUIAutomationWindowPattern::get_CurrentCanMaximize.
1980
+ Return bool, indicates whether the window can be maximized.
1981
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationwindowpattern-get_currentcanmaximize
1982
+ """
1983
+ return bool(self.pattern.CurrentCanMaximize)
1984
+
1985
+ @property
1986
+ def CanMinimize(self) -> bool:
1987
+ """
1988
+ Property CanMinimize.
1989
+ Call IUIAutomationWindowPattern::get_CurrentCanMinimize.
1990
+ Return bool, indicates whether the window can be minimized.
1991
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationwindowpattern-get_currentcanminimize
1992
+ """
1993
+ return bool(self.pattern.CurrentCanMinimize)
1994
+
1995
+ @property
1996
+ def IsModal(self) -> bool:
1997
+ """
1998
+ Property IsModal.
1999
+ Call IUIAutomationWindowPattern::get_CurrentIsModal.
2000
+ Return bool, indicates whether the window is modal.
2001
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationwindowpattern-get_currentismodal
2002
+ """
2003
+ return bool(self.pattern.CurrentIsModal)
2004
+
2005
+ @property
2006
+ def IsTopmost(self) -> bool:
2007
+ """
2008
+ Property IsTopmost.
2009
+ Call IUIAutomationWindowPattern::get_CurrentIsTopmost.
2010
+ Return bool, indicates whether the window is the topmost element in the z-order.
2011
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationwindowpattern-get_currentistopmost
2012
+ """
2013
+ return bool(self.pattern.CurrentIsTopmost)
2014
+
2015
+ @property
2016
+ def WindowInteractionState(self) -> int:
2017
+ """
2018
+ Property WindowInteractionState.
2019
+ Call IUIAutomationWindowPattern::get_CurrentWindowInteractionState.
2020
+ Return int, a value in class `WindowInteractionState`,
2021
+ the current state of the window for the purposes of user interaction.
2022
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationwindowpattern-get_currentwindowinteractionstate
2023
+ """
2024
+ return self.pattern.CurrentWindowInteractionState
2025
+
2026
+ @property
2027
+ def WindowVisualState(self) -> int:
2028
+ """
2029
+ Property WindowVisualState.
2030
+ Call IUIAutomationWindowPattern::get_CurrentWindowVisualState.
2031
+ Return int, a value in class `WindowVisualState`,
2032
+ the visual state of the window; that is, whether it is in the normal, maximized, or minimized state.
2033
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationwindowpattern-get_currentwindowvisualstate
2034
+ """
2035
+ return self.pattern.CurrentWindowVisualState
2036
+
2037
+ def SetWindowVisualState(self, state: int, waitTime: float = OPERATION_WAIT_TIME) -> bool:
2038
+ """
2039
+ Call IUIAutomationWindowPattern::SetWindowVisualState.
2040
+ Minimize, maximize, or restore the window.
2041
+ state: int, a value in class `WindowVisualState`.
2042
+ waitTime: float.
2043
+ Return bool, True if succeed otherwise False.
2044
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationwindowpattern-setwindowvisualstate
2045
+ """
2046
+ ret = self.pattern.SetWindowVisualState(state) == S_OK
2047
+ time.sleep(waitTime)
2048
+ return ret
2049
+
2050
+ def WaitForInputIdle(self, milliseconds: int) -> bool:
2051
+ '''
2052
+ Call IUIAutomationWindowPattern::WaitForInputIdle.
2053
+ Cause the calling code to block for the specified time or
2054
+ until the associated process enters an idle state, whichever completes first.
2055
+ milliseconds: int.
2056
+ Return bool, True if succeed otherwise False.
2057
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationwindowpattern-waitforinputidle
2058
+ '''
2059
+ return self.pattern.WaitForInputIdle(milliseconds) == S_OK
2060
+
2061
+
2062
+ PatternConstructors = {
2063
+ PatternId.AnnotationPattern: AnnotationPattern,
2064
+ PatternId.CustomNavigationPattern: CustomNavigationPattern,
2065
+ PatternId.DockPattern: DockPattern,
2066
+ PatternId.DragPattern: DragPattern,
2067
+ PatternId.DropTargetPattern: DropTargetPattern,
2068
+ PatternId.ExpandCollapsePattern: ExpandCollapsePattern,
2069
+ PatternId.GridItemPattern: GridItemPattern,
2070
+ PatternId.GridPattern: GridPattern,
2071
+ PatternId.InvokePattern: InvokePattern,
2072
+ PatternId.ItemContainerPattern: ItemContainerPattern,
2073
+ PatternId.LegacyIAccessiblePattern: LegacyIAccessiblePattern,
2074
+ PatternId.MultipleViewPattern: MultipleViewPattern,
2075
+ PatternId.ObjectModelPattern: ObjectModelPattern,
2076
+ PatternId.RangeValuePattern: RangeValuePattern,
2077
+ PatternId.ScrollItemPattern: ScrollItemPattern,
2078
+ PatternId.ScrollPattern: ScrollPattern,
2079
+ PatternId.SelectionItemPattern: SelectionItemPattern,
2080
+ PatternId.SelectionPattern: SelectionPattern,
2081
+ PatternId.SpreadsheetItemPattern: SpreadsheetItemPattern,
2082
+ PatternId.SpreadsheetPattern: SpreadsheetPattern,
2083
+ PatternId.StylesPattern: StylesPattern,
2084
+ PatternId.SynchronizedInputPattern: SynchronizedInputPattern,
2085
+ PatternId.TableItemPattern: TableItemPattern,
2086
+ PatternId.TablePattern: TablePattern,
2087
+ PatternId.TextChildPattern: TextChildPattern,
2088
+ PatternId.TextEditPattern: TextEditPattern,
2089
+ PatternId.TextPattern: TextPattern,
2090
+ PatternId.TextPattern2: TextPattern2,
2091
+ PatternId.TogglePattern: TogglePattern,
2092
+ PatternId.TransformPattern: TransformPattern,
2093
+ PatternId.TransformPattern2: TransformPattern2,
2094
+ PatternId.ValuePattern: ValuePattern,
2095
+ PatternId.VirtualizedItemPattern: VirtualizedItemPattern,
2096
+ PatternId.WindowPattern: WindowPattern,
2097
+ }
2098
+
2099
+
2100
+ def CreatePattern(patternId: int, pattern: ctypes.POINTER(comtypes.IUnknown)):
2101
+ """Create a concreate pattern by pattern id and pattern(POINTER(IUnknown))."""
2102
+ subPattern = pattern.QueryInterface(GetPatternIdInterface(patternId))
2103
+ if subPattern:
2104
+ return PatternConstructors[patternId](pattern=subPattern)
2105
+
2106
+