windows-mcp 0.5.7__py3-none-any.whl → 0.5.9__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,4790 @@
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)
28
+ from .enums import *
29
+ from .core import *
30
+ from .core import _AutomationClient
31
+ from .patterns import *
32
+
33
+
34
+ METRO_WINDOW_CLASS_NAME = 'Windows.UI.Core.CoreWindow' # for Windows 8 and 8.1
35
+ SEARCH_INTERVAL = 0.5 # search control interval seconds
36
+ MAX_MOVE_SECOND = 1 # simulate mouse move or drag max seconds
37
+ TIME_OUT_SECOND = 10
38
+ OPERATION_WAIT_TIME = 0.5
39
+ MAX_PATH = 260
40
+ DEBUG_SEARCH_TIME = False
41
+ DEBUG_EXIST_DISAPPEAR = False
42
+ S_OK = 0
43
+
44
+ IsPy38OrHigher = sys.version_info[:2] >= (3, 8)
45
+ IsNT6orHigher = os.sys.getwindowsversion().major >= 6
46
+ CurrentProcessIs64Bit = sys.maxsize > 0xFFFFFFFF
47
+ ProcessTime = time.perf_counter # this returns nearly 0 when first call it if python version <= 3.6
48
+ ProcessTime() # need to call it once if python version <= 3.6
49
+ TreeNode = Any
50
+
51
+ class Control():
52
+ ValidKeys = set(['ControlType', 'ClassName', 'AutomationId', 'Name', 'SubName', 'RegexName', 'Depth', 'Compare'])
53
+
54
+ def __init__(self, searchFromControl: Optional['Control'] = None, searchDepth: int = 0xFFFFFFFF,
55
+ searchInterval: float = SEARCH_INTERVAL, foundIndex: int = 1, element=None,
56
+ ControlType: Optional[int] = None,
57
+ Name: Optional[str] = None,
58
+ SubName: Optional[str] = None,
59
+ RegexName: Optional[str] = None,
60
+ ClassName: Optional[str] = None,
61
+ AutomationId: Optional[str] = None,
62
+ Depth: Optional[int] = None,
63
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
64
+ **searchProperties):
65
+ """
66
+ searchFromControl: `Control` or its subclass, if it is None, search from root control(Desktop).
67
+ searchDepth: int, max search depth from searchFromControl.
68
+ foundIndex: int, starts with 1, >= 1.
69
+ searchInterval: float, wait searchInterval after every search in self.Refind and self.Exists, the global timeout is TIME_OUT_SECOND.
70
+ element: `ctypes.POINTER(IUIAutomationElement)`, internal use only.
71
+
72
+ ControlType: int, a value in class `ControlType`.
73
+ Name: str.
74
+ SubName: str, a part str in Name.
75
+ RegexName: str, supports regex using re.match.
76
+ You can only use one of Name, SubName, RegexName.
77
+ ClassName: str.
78
+ AutomationId: str.
79
+ Depth: int, only search controls in relative depth from searchFromControl, ignore controls in depth(0~Depth-1),
80
+ if set, searchDepth will be set to Depth too.
81
+ Compare: Callable[[Control, int], bool], custom compare function(control: Control, depth: int) -> bool.
82
+
83
+ searchProperties, other properties specified for the control, only for debug log.
84
+
85
+ `Control` wraps IUIAutomationElement.
86
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nn-uiautomationclient-iuiautomationelement
87
+ """
88
+ self._element = element
89
+ self._elementDirectAssign = True if element else False
90
+ self.searchFromControl = searchFromControl
91
+ self.searchDepth = Depth or searchDepth
92
+ self.searchInterval = searchInterval
93
+ self.foundIndex = foundIndex
94
+ self.searchProperties = searchProperties
95
+ if Name is not None:
96
+ searchProperties['Name'] = Name
97
+ if SubName is not None:
98
+ searchProperties['SubName'] = SubName
99
+ if RegexName is not None:
100
+ searchProperties['RegexName'] = RegexName
101
+ self.regexName = re.compile(RegexName)
102
+ else:
103
+ self.regexName = None
104
+ if ClassName is not None:
105
+ searchProperties['ClassName'] = ClassName
106
+ if AutomationId is not None:
107
+ searchProperties['AutomationId'] = AutomationId
108
+ if ControlType is not None:
109
+ searchProperties['ControlType'] = ControlType
110
+ if Depth is not None:
111
+ searchProperties['Depth'] = Depth
112
+ if Compare is not None:
113
+ searchProperties['Compare'] = Compare
114
+ self._supportedPatterns = {}
115
+
116
+ def __str__(self) -> str:
117
+ return 'ControlType: {0} ClassName: {1} AutomationId: {2} Rect: {3} Name: {4} Handle: 0x{5:X}({5})'.format(
118
+ self.ControlTypeName, self.ClassName, self.AutomationId, self.BoundingRectangle, self.Name, self.NativeWindowHandle)
119
+
120
+ def __repr__(self) -> str:
121
+ return '<{0} ClassName={1!r} AutomationId={2} Rect={3} Name={4!r} Handle=0x{5:X}({5})>'.format(
122
+ self.__class__.__name__, self.ClassName, self.AutomationId, self.BoundingRectangle, self.Name, self.NativeWindowHandle)
123
+
124
+ def __getitem__(self, pos: int) -> Optional['Control']:
125
+ if pos == 1:
126
+ return self.GetFirstChildControl()
127
+ elif pos == -1:
128
+ return self.GetLastChildControl()
129
+ elif pos > 1:
130
+ child = self.GetFirstChildControl()
131
+ for _ in range(pos - 1):
132
+ if child is None:
133
+ return None
134
+ child = child.GetNextSiblingControl()
135
+ return child
136
+ elif pos < -1:
137
+ child = self.GetLastChildControl()
138
+ for _ in range(-pos - 1):
139
+ if child is None:
140
+ return None
141
+ child = child.GetPreviousSiblingControl()
142
+ return child
143
+ else:
144
+ raise ValueError
145
+
146
+ @staticmethod
147
+ def CreateControlFromElement(element:'ctypes.POINTER(IUIAutomationElement)') -> Optional['Control']:
148
+ """
149
+ Create a concreate `Control` from a com type `IUIAutomationElement`.
150
+ element: `ctypes.POINTER(IUIAutomationElement)`.
151
+ Return a subclass of `Control`, an instance of the control's real type.
152
+ """
153
+ if element:
154
+ controlType = element.CurrentControlType
155
+ if controlType in ControlConstructors:
156
+ return ControlConstructors[controlType](element=element)
157
+ else:
158
+ Logger.WriteLine("element.CurrentControlType returns {}, invalid ControlType!".format(controlType), ConsoleColor.Red) # rarely happens
159
+ return None
160
+
161
+ @staticmethod
162
+ def CreateControlFromControl(control: 'Control') -> Optional['Control']:
163
+ """
164
+ Create a concreate `Control` from a control instance, copy it.
165
+ control: `Control` or its subclass.
166
+ Return a subclass of `Control`, an instance of the control's real type.
167
+ For example: if control's ControlType is EditControl, return an EditControl.
168
+ """
169
+ newControl = Control.CreateControlFromElement(control.Element)
170
+ return newControl
171
+
172
+ def SetSearchFromControl(self, searchFromControl: 'Control') -> None:
173
+ """searchFromControl: `Control` or its subclass"""
174
+ self.searchFromControl = searchFromControl
175
+
176
+ def SetSearchDepth(self, searchDepth: int) -> None:
177
+ self.searchDepth = searchDepth
178
+
179
+ def AddSearchProperties(self, **searchProperties) -> None:
180
+ """
181
+ Add search properties using `dict.update`.
182
+ searchProperties: dict, same as searchProperties in `Control.__init__`.
183
+ """
184
+ self.searchProperties.update(searchProperties)
185
+ if 'Depth' in searchProperties:
186
+ self.searchDepth = searchProperties['Depth']
187
+ if 'RegexName' in searchProperties:
188
+ regName = searchProperties['RegexName']
189
+ self.regexName = re.compile(regName) if regName else None
190
+
191
+ def RemoveSearchProperties(self, **searchProperties) -> None:
192
+ """
193
+ searchProperties: dict, same as searchProperties in `Control.__init__`.
194
+ """
195
+ for key in searchProperties:
196
+ del self.searchProperties[key]
197
+ if key == 'RegexName':
198
+ self.regexName = None
199
+
200
+ def GetSearchPropertiesStr(self) -> str:
201
+ strs = ['{}: {}'.format(k, ControlTypeNames[v] if k == 'ControlType' else repr(v)) for k, v in self.searchProperties.items()]
202
+ return '{' + ', '.join(strs) + '}'
203
+
204
+ def GetColorfulSearchPropertiesStr(self, keyColor='DarkGreen', valueColor='DarkCyan') -> str:
205
+ """keyColor, valueColor: str, color name in class ConsoleColor"""
206
+ strs = ['<Color={}>{}</Color>: <Color={}>{}</Color>'.format(keyColor if k in Control.ValidKeys else 'DarkYellow', k, valueColor,
207
+ ControlTypeNames[v] if k == 'ControlType' else repr(v)) for k, v in self.searchProperties.items()]
208
+ return '{' + ', '.join(strs) + '}'
209
+
210
+ def BuildUpdatedCache(self, cacheRequest: 'CacheRequest') -> 'Control':
211
+ """
212
+ Retrieves a new UI Automation element with an updated cache.
213
+ cacheRequest: CacheRequest.
214
+ Return a subclass of `Control`, an instance of the control's real type.
215
+ """
216
+ updatedElement = self.Element.BuildUpdatedCache(cacheRequest.check_request)
217
+ return Control.CreateControlFromElement(updatedElement)
218
+
219
+ @property
220
+ def CachedAcceleratorKey(self) -> str:
221
+ """Get the cached accelerator key."""
222
+ return self.Element.CachedAcceleratorKey
223
+
224
+ @property
225
+ def CachedAccessKey(self) -> str:
226
+ """Get the cached access key."""
227
+ return self.Element.CachedAccessKey
228
+
229
+ @property
230
+ def CachedAriaProperties(self) -> str:
231
+ """Get the cached aria properties."""
232
+ return self.Element.CachedAriaProperties
233
+
234
+ @property
235
+ def CachedAriaRole(self) -> str:
236
+ """Get the cached aria role."""
237
+ return self.Element.CachedAriaRole
238
+
239
+ @property
240
+ def CachedAutomationId(self) -> str:
241
+ """Get the cached automation id."""
242
+ return self.Element.CachedAutomationId
243
+
244
+ @property
245
+ def CachedBoundingRectangle(self) -> Rect:
246
+ """Get the cached bounding rectangle."""
247
+ rect = self.Element.CachedBoundingRectangle
248
+ return Rect(rect.left, rect.top, rect.right, rect.bottom)
249
+
250
+ @property
251
+ def CachedClassName(self) -> str:
252
+ """Get the cached class name."""
253
+ return self.Element.CachedClassName
254
+
255
+ @property
256
+ def CachedControlType(self) -> int:
257
+ """Get the cached control type."""
258
+ return self.Element.CachedControlType
259
+
260
+ @property
261
+ def CachedControlTypeName(self) -> str:
262
+ """Get the cached control type name."""
263
+ try:
264
+ return ControlTypeNames.get(self.CachedControlType, "Unknown")
265
+ except:
266
+ return "Unknown"
267
+
268
+ @property
269
+ def CachedControllerFor(self) -> Any:
270
+ """Get the cached controller for."""
271
+ return self.Element.CachedControllerFor
272
+
273
+ @property
274
+ def CachedCulture(self) -> int:
275
+ """Get the cached culture."""
276
+ return self.Element.CachedCulture
277
+
278
+ @property
279
+ def CachedDescribedBy(self) -> Any:
280
+ """Get the cached described by."""
281
+ return self.Element.CachedDescribedBy
282
+
283
+ @property
284
+ def CachedFlowsTo(self) -> Any:
285
+ """Get the cached flows to."""
286
+ return self.Element.CachedFlowsTo
287
+
288
+ @property
289
+ def CachedFrameworkId(self) -> str:
290
+ """Get the cached framework id."""
291
+ return self.Element.CachedFrameworkId
292
+
293
+ @property
294
+ def CachedHasKeyboardFocus(self) -> bool:
295
+ """Get the cached has keyboard focus."""
296
+ return self.Element.CachedHasKeyboardFocus
297
+
298
+ @property
299
+ def CachedHelpText(self) -> str:
300
+ """Get the cached help text."""
301
+ return self.Element.CachedHelpText
302
+
303
+ @property
304
+ def CachedIsContentElement(self) -> bool:
305
+ """Get the cached is content element."""
306
+ return self.Element.CachedIsContentElement
307
+
308
+ @property
309
+ def CachedIsControlElement(self) -> bool:
310
+ """Get the cached is control element."""
311
+ return self.Element.CachedIsControlElement
312
+
313
+ @property
314
+ def CachedIsDataValidForForm(self) -> bool:
315
+ """Get the cached is data valid for form."""
316
+ return self.Element.CachedIsDataValidForForm
317
+
318
+ @property
319
+ def CachedIsEnabled(self) -> bool:
320
+ """Get the cached is enabled."""
321
+ return self.Element.CachedIsEnabled
322
+
323
+ @property
324
+ def CachedIsKeyboardFocusable(self) -> bool:
325
+ """Get the cached is keyboard focusable."""
326
+ return self.Element.CachedIsKeyboardFocusable
327
+
328
+ @property
329
+ def CachedIsOffscreen(self) -> bool:
330
+ """Get the cached is offscreen."""
331
+ return self.Element.CachedIsOffscreen
332
+
333
+ @property
334
+ def CachedIsPassword(self) -> bool:
335
+ """Get the cached is password."""
336
+ return self.Element.CachedIsPassword
337
+
338
+ @property
339
+ def CachedIsRequiredForForm(self) -> bool:
340
+ """Get the cached is required for form."""
341
+ return self.Element.CachedIsRequiredForForm
342
+
343
+ @property
344
+ def CachedItemStatus(self) -> str:
345
+ """Get the cached item status."""
346
+ return self.Element.CachedItemStatus
347
+
348
+ @property
349
+ def CachedItemType(self) -> str:
350
+ """Get the cached item type."""
351
+ return self.Element.CachedItemType
352
+
353
+ @property
354
+ def CachedLabeledBy(self) -> Any:
355
+ """Get the cached labeled by."""
356
+ return self.Element.CachedLabeledBy
357
+
358
+ @property
359
+ def CachedLocalizedControlType(self) -> str:
360
+ """Get the cached localized control type."""
361
+ return self.Element.CachedLocalizedControlType
362
+
363
+ @property
364
+ def CachedName(self) -> str:
365
+ """Get the cached name."""
366
+ return self.Element.CachedName
367
+
368
+ @property
369
+ def CachedNativeWindowHandle(self) -> int:
370
+ """Get the cached native window handle."""
371
+ return self.Element.CachedNativeWindowHandle
372
+
373
+ @property
374
+ def CachedOrientation(self) -> int:
375
+ """Get the cached orientation."""
376
+ return self.Element.CachedOrientation
377
+
378
+ @property
379
+ def CachedProcessId(self) -> int:
380
+ """Get the cached process id."""
381
+ return self.Element.CachedProcessId
382
+
383
+ @property
384
+ def CachedProviderDescription(self) -> str:
385
+ """Get the cached provider description."""
386
+ return self.Element.CachedProviderDescription
387
+
388
+ @property
389
+ def AcceleratorKey(self) -> str:
390
+ """
391
+ Property AcceleratorKey.
392
+ Call IUIAutomationElement::get_CurrentAcceleratorKey.
393
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentacceleratorkey
394
+ """
395
+ return self.Element.CurrentAcceleratorKey
396
+
397
+ @property
398
+ def AccessKey(self) -> str:
399
+ """
400
+ Property AccessKey.
401
+ Call IUIAutomationElement::get_CurrentAccessKey.
402
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentaccesskey
403
+ """
404
+ return self.Element.CurrentAccessKey
405
+
406
+ @property
407
+ def AriaProperties(self) -> str:
408
+ """
409
+ Property AriaProperties.
410
+ Call IUIAutomationElement::get_CurrentAriaProperties.
411
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentariaproperties
412
+ """
413
+ return self.Element.CurrentAriaProperties
414
+
415
+ @property
416
+ def AriaRole(self) -> str:
417
+ """
418
+ Property AriaRole.
419
+ Call IUIAutomationElement::get_CurrentAriaRole.
420
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentariarole
421
+ """
422
+ return self.Element.CurrentAriaRole
423
+
424
+ @property
425
+ def AutomationId(self) -> str:
426
+ """
427
+ Property AutomationId.
428
+ Call IUIAutomationElement::get_CurrentAutomationId.
429
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentautomationid
430
+ """
431
+ return self.Element.CurrentAutomationId
432
+
433
+ @property
434
+ def BoundingRectangle(self) -> Rect:
435
+ """
436
+ Property BoundingRectangle.
437
+ Call IUIAutomationElement::get_CurrentBoundingRectangle.
438
+ Return `Rect`.
439
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentboundingrectangle
440
+
441
+ rect = control.BoundingRectangle
442
+ print(rect.left, rect.top, rect.right, rect.bottom, rect.width(), rect.height(), rect.xcenter(), rect.ycenter())
443
+ """
444
+ rect = self.Element.CurrentBoundingRectangle
445
+ return Rect(rect.left, rect.top, rect.right, rect.bottom)
446
+
447
+ @property
448
+ def ClassName(self) -> str:
449
+ """
450
+ Property ClassName.
451
+ Call IUIAutomationElement::get_CurrentClassName.
452
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentclassname
453
+ """
454
+ return self.Element.CurrentClassName
455
+
456
+ @property
457
+ def ControlType(self) -> int:
458
+ """
459
+ Property ControlType.
460
+ Return int, a value in class `ControlType`.
461
+ Call IUIAutomationElement::get_CurrentControlType.
462
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentcontroltype
463
+ """
464
+ return self.Element.CurrentControlType
465
+
466
+ # @property
467
+ # def ControllerFor(self):
468
+ # return self.Element.CurrentControllerFor
469
+
470
+ @property
471
+ def Culture(self) -> int:
472
+ """
473
+ Property Culture.
474
+ Call IUIAutomationElement::get_CurrentCulture.
475
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentculture
476
+ """
477
+ return self.Element.CurrentCulture
478
+
479
+ # @property
480
+ # def DescribedBy(self):
481
+ # return self.Element.CurrentDescribedBy
482
+
483
+ # @property
484
+ # def FlowsTo(self):
485
+ # return self.Element.CurrentFlowsTo
486
+
487
+ @property
488
+ def FrameworkId(self) -> str:
489
+ """
490
+ Property FrameworkId.
491
+ Call IUIAutomationElement::get_CurrentFrameworkId.
492
+ Return str, such as Win32, WPF...
493
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentframeworkid
494
+ """
495
+ return self.Element.CurrentFrameworkId
496
+
497
+ @property
498
+ def HasKeyboardFocus(self) -> bool:
499
+ """
500
+ Property HasKeyboardFocus.
501
+ Call IUIAutomationElement::get_CurrentHasKeyboardFocus.
502
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currenthaskeyboardfocus
503
+ """
504
+ return bool(self.Element.CurrentHasKeyboardFocus)
505
+
506
+ @property
507
+ def HelpText(self) -> str:
508
+ """
509
+ Property HelpText.
510
+ Call IUIAutomationElement::get_CurrentHelpText.
511
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currenthelptext
512
+ """
513
+ return self.Element.CurrentHelpText
514
+
515
+ @property
516
+ def IsContentElement(self) -> bool:
517
+ """
518
+ Property IsContentElement.
519
+ Call IUIAutomationElement::get_CurrentIsContentElement.
520
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentiscontentelement
521
+ """
522
+ return bool(self.Element.CurrentIsContentElement)
523
+
524
+ @property
525
+ def IsControlElement(self) -> bool:
526
+ """
527
+ Property IsControlElement.
528
+ Call IUIAutomationElement::get_CurrentIsControlElement.
529
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentiscontrolelement
530
+ """
531
+ return bool(self.Element.CurrentIsControlElement)
532
+
533
+ @property
534
+ def IsDataValidForForm(self) -> bool:
535
+ """
536
+ Property IsDataValidForForm.
537
+ Call IUIAutomationElement::get_CurrentIsDataValidForForm.
538
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentisdatavalidforform
539
+ """
540
+ return bool(self.Element.CurrentIsDataValidForForm)
541
+
542
+ @property
543
+ def IsEnabled(self) -> bool:
544
+ """
545
+ Property IsEnabled.
546
+ Call IUIAutomationElement::get_CurrentIsEnabled.
547
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentisenabled
548
+ """
549
+ return bool(self.Element.CurrentIsEnabled)
550
+
551
+ @property
552
+ def IsKeyboardFocusable(self) -> bool:
553
+ """
554
+ Property IsKeyboardFocusable.
555
+ Call IUIAutomationElement::get_CurrentIsKeyboardFocusable.
556
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentiskeyboardfocusable
557
+ """
558
+ return bool(self.Element.CurrentIsKeyboardFocusable)
559
+
560
+ @property
561
+ def IsOffscreen(self) -> bool:
562
+ """
563
+ Property IsOffscreen.
564
+ Call IUIAutomationElement::get_CurrentIsOffscreen.
565
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentisoffscreen
566
+ """
567
+ return bool(self.Element.CurrentIsOffscreen)
568
+
569
+ @property
570
+ def IsPassword(self) -> bool:
571
+ """
572
+ Property IsPassword.
573
+ Call IUIAutomationElement::get_CurrentIsPassword.
574
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentispassword
575
+ """
576
+ return bool(self.Element.CurrentIsPassword)
577
+
578
+ @property
579
+ def IsRequiredForForm(self) -> bool:
580
+ """
581
+ Property IsRequiredForForm.
582
+ Call IUIAutomationElement::get_CurrentIsRequiredForForm.
583
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentisrequiredforform
584
+ """
585
+ return bool(self.Element.CurrentIsRequiredForForm)
586
+
587
+ @property
588
+ def ItemStatus(self) -> str:
589
+ """
590
+ Property ItemStatus.
591
+ Call IUIAutomationElement::get_CurrentItemStatus.
592
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentitemstatus
593
+ """
594
+ return self.Element.CurrentItemStatus
595
+
596
+ @property
597
+ def ItemType(self) -> str:
598
+ """
599
+ Property ItemType.
600
+ Call IUIAutomationElement::get_CurrentItemType.
601
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentitemtype
602
+ """
603
+ return self.Element.CurrentItemType
604
+
605
+ # @property
606
+ # def LabeledBy(self):
607
+ # return self.Element.CurrentLabeledBy
608
+
609
+ @property
610
+ def LocalizedControlType(self) -> str:
611
+ """
612
+ Property LocalizedControlType.
613
+ Call IUIAutomationElement::get_CurrentLocalizedControlType.
614
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentlocalizedcontroltype
615
+ """
616
+ return self.Element.CurrentLocalizedControlType
617
+
618
+ @property
619
+ def Name(self) -> str:
620
+ """
621
+ Property Name.
622
+ Call IUIAutomationElement::get_CurrentName.
623
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentname
624
+ """
625
+ return self.Element.CurrentName or '' # CurrentName may be None
626
+
627
+ @property
628
+ def NativeWindowHandle(self) -> int:
629
+ """
630
+ Property NativeWindowHandle.
631
+ Call IUIAutomationElement::get_CurrentNativeWindowHandle.
632
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentnativewindowhandle
633
+ """
634
+ try:
635
+ handle = self.Element.CurrentNativeWindowHandle
636
+ except comtypes.COMError as ex:
637
+ return 0
638
+ return 0 if handle is None else handle
639
+
640
+ @property
641
+ def Orientation(self) -> int:
642
+ """
643
+ Property Orientation.
644
+ Return int, a value in class `OrientationType`.
645
+ Call IUIAutomationElement::get_CurrentOrientation.
646
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentorientation
647
+ """
648
+ return self.Element.CurrentOrientation
649
+
650
+ @property
651
+ def ProcessId(self) -> int:
652
+ """
653
+ Property ProcessId.
654
+ Call IUIAutomationElement::get_CurrentProcessId.
655
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentprocessid
656
+ """
657
+ return self.Element.CurrentProcessId
658
+
659
+ @property
660
+ def ProviderDescription(self) -> str:
661
+ """
662
+ Property ProviderDescription.
663
+ Call IUIAutomationElement::get_CurrentProviderDescription.
664
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-get_currentproviderdescription
665
+ """
666
+ return self.Element.CurrentProviderDescription
667
+
668
+ def FindAll(self, scope: int, condition) -> List['Control']:
669
+ """
670
+ Find all UI Automation elements that satisfy the specified condition.
671
+ Call IUIAutomationElement::FindAll.
672
+
673
+ scope: int, a value in class `TreeScope`, specifying the scope of the search.
674
+ condition: a condition object from IUIAutomation.CreateTrueCondition() or similar.
675
+ Return List[Control], a list of `Control` subclasses that match the condition.
676
+
677
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-findall
678
+ """
679
+ elementArray = self.Element.FindAll(scope, condition)
680
+ if not elementArray:
681
+ return []
682
+
683
+ controls = []
684
+ length = elementArray.Length
685
+ for i in range(length):
686
+ element = elementArray.GetElement(i)
687
+ control = Control.CreateControlFromElement(element)
688
+ if control:
689
+ controls.append(control)
690
+ return controls
691
+
692
+ def FindAllBuildCache(self, scope: int, condition, cacheRequest: 'CacheRequest') -> List['Control']:
693
+ """
694
+ Find all UI Automation elements that satisfy the specified condition, and cache properties and patterns.
695
+ Call IUIAutomationElement::FindAllBuildCache.
696
+
697
+ scope: int, a value in class `TreeScope`, specifying the scope of the search.
698
+ condition: a condition object from IUIAutomation.CreateTrueCondition() or similar.
699
+ cacheRequest: CacheRequest, specifies the properties and patterns to cache.
700
+ Return List[Control], a list of `Control` subclasses that match the condition with cached data.
701
+
702
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-findallbuildcache
703
+ """
704
+ elementArray = self.Element.FindAllBuildCache(scope, condition, cacheRequest.check_request)
705
+ if not elementArray:
706
+ return []
707
+
708
+ controls = []
709
+ length = elementArray.Length
710
+ for i in range(length):
711
+ element = elementArray.GetElement(i)
712
+ control = Control.CreateControlFromElement(element)
713
+ if control:
714
+ controls.append(control)
715
+ return controls
716
+
717
+ def FindFirst(self, scope: int, condition) -> Optional['Control']:
718
+ """
719
+ Find the first UI Automation element that satisfies the specified condition.
720
+ Call IUIAutomationElement::FindFirst.
721
+
722
+ scope: int, a value in class `TreeScope`, specifying the scope of the search.
723
+ condition: a condition object from IUIAutomation.CreateTrueCondition() or similar.
724
+ Return `Control` subclass or None.
725
+
726
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-findfirst
727
+ """
728
+ element = self.Element.FindFirst(scope, condition)
729
+ return Control.CreateControlFromElement(element)
730
+
731
+ def FindFirstBuildCache(self, scope: int, condition, cacheRequest: 'CacheRequest') -> Optional['Control']:
732
+ """
733
+ Find the first UI Automation element that satisfies the specified condition, and cache properties and patterns.
734
+ Call IUIAutomationElement::FindFirstBuildCache.
735
+
736
+ scope: int, a value in class `TreeScope`, specifying the scope of the search.
737
+ condition: a condition object from IUIAutomation.CreateTrueCondition() or similar.
738
+ cacheRequest: CacheRequest, specifies the properties and patterns to cache.
739
+ Return `Control` subclass or None with cached data.
740
+
741
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-findfirstbuildcache
742
+ """
743
+ element = self.Element.FindFirstBuildCache(scope, condition, cacheRequest.check_request)
744
+ return Control.CreateControlFromElement(element)
745
+
746
+ def GetCachedChildren(self) -> List['Control']:
747
+ """
748
+ Retrieve the cached child elements of this UI Automation element.
749
+ Call IUIAutomationElement::GetCachedChildren.
750
+
751
+ Return List[Control], a list of cached child `Control` subclasses.
752
+ Note: Children are cached only if the scope of the cache request included TreeScope_Subtree,
753
+ TreeScope_Children, or TreeScope_Descendants.
754
+
755
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-getcachedchildren
756
+ """
757
+ try:
758
+ elementArray = self.Element.GetCachedChildren()
759
+ if not elementArray:
760
+ return []
761
+
762
+ controls = []
763
+ length = elementArray.Length
764
+ for i in range(length):
765
+ element = elementArray.GetElement(i)
766
+ control = Control.CreateControlFromElement(element)
767
+ if control:
768
+ controls.append(control)
769
+ return controls
770
+ except comtypes.COMError as ex:
771
+ return []
772
+
773
+ def GetCachedParent(self) -> Optional['Control']:
774
+ """
775
+ Retrieve the cached parent of this UI Automation element.
776
+ Call IUIAutomationElement::GetCachedParent.
777
+
778
+ Return `Control` subclass or None.
779
+
780
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-getcachedparent
781
+ """
782
+ try:
783
+ element = self.Element.GetCachedParent()
784
+ return Control.CreateControlFromElement(element)
785
+ except comtypes.COMError as ex:
786
+ return None
787
+
788
+ def GetCachedPattern(self, patternId: int):
789
+ """
790
+ Retrieve a cached pattern interface from this UI Automation element.
791
+ Call IUIAutomationElement::GetCachedPattern.
792
+
793
+ patternId: int, a value in class `PatternId`.
794
+ Return a pattern object if the pattern was cached, else None.
795
+
796
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-getcachedpattern
797
+ """
798
+ try:
799
+ pattern = self.Element.GetCachedPattern(patternId)
800
+ if pattern:
801
+ return CreatePattern(patternId, pattern)
802
+ except comtypes.COMError as ex:
803
+ return None
804
+
805
+ def GetCachedPatternAs(self, patternId: int, riid):
806
+ """
807
+ Retrieve a cached pattern interface from this UI Automation element, with a specific interface ID.
808
+ Call IUIAutomationElement::GetCachedPatternAs.
809
+
810
+ patternId: int, a value in class `PatternId`.
811
+ riid: GUID, the interface identifier.
812
+ Return a pattern object if the pattern was cached, else None.
813
+
814
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-getcachedpatternas
815
+ """
816
+ try:
817
+ return self.Element.GetCachedPatternAs(patternId, riid)
818
+ except comtypes.COMError as ex:
819
+ return None
820
+
821
+ def GetCachedPropertyValue(self, propertyId: int) -> Any:
822
+ """
823
+ Retrieve a cached property value from this UI Automation element.
824
+ Call IUIAutomationElement::GetCachedPropertyValue.
825
+
826
+ propertyId: int, a value in class `PropertyId`.
827
+ Return Any, the cached property value corresponding to propertyId.
828
+
829
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-getcachedpropertyvalue
830
+ """
831
+ try:
832
+ return self.Element.GetCachedPropertyValue(propertyId)
833
+ except comtypes.COMError as ex:
834
+ return None
835
+
836
+ def GetCachedPropertyValueEx(self, propertyId: int, ignoreDefaultValue: int) -> Any:
837
+ """
838
+ Retrieve a cached property value from this UI Automation element, optionally ignoring the default value.
839
+ Call IUIAutomationElement::GetCachedPropertyValueEx.
840
+
841
+ propertyId: int, a value in class `PropertyId`.
842
+ ignoreDefaultValue: int, 0 or 1. If 1, a default value is not returned.
843
+ Return Any, the cached property value corresponding to propertyId.
844
+
845
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-getcachedpropertyvalueex
846
+ """
847
+ try:
848
+ return self.Element.GetCachedPropertyValueEx(propertyId, ignoreDefaultValue)
849
+ except comtypes.COMError as ex:
850
+ return None
851
+
852
+ def GetClickablePoint(self) -> Tuple[int, int, bool]:
853
+ """
854
+ Call IUIAutomationElement::GetClickablePoint.
855
+ Return Tuple[int, int, bool], three items tuple (x, y, gotClickable), such as (20, 10, True)
856
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-getclickablepoint
857
+ """
858
+ point, gotClickable = self.Element.GetClickablePoint()
859
+ return (point.x, point.y, bool(gotClickable))
860
+
861
+ def GetPattern(self, patternId: int):
862
+ """
863
+ Call IUIAutomationElement::GetCurrentPattern.
864
+ Get a new pattern by pattern id if it supports the pattern.
865
+ patternId: int, a value in class `PatternId`.
866
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-getcurrentpattern
867
+ """
868
+ try:
869
+ pattern = self.Element.GetCurrentPattern(patternId)
870
+ if pattern:
871
+ subPattern = CreatePattern(patternId, pattern)
872
+ self._supportedPatterns[patternId] = subPattern
873
+ return subPattern
874
+ except comtypes.COMError as ex:
875
+ pass
876
+
877
+ def GetPatternAs(self, patternId: int, riid):
878
+ """
879
+ Call IUIAutomationElement::GetCurrentPatternAs.
880
+ Get a new pattern by pattern id if it supports the pattern, todo.
881
+ patternId: int, a value in class `PatternId`.
882
+ riid: GUID.
883
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-getcurrentpatternas
884
+ """
885
+ return self.Element.GetCurrentPatternAs(patternId, riid)
886
+
887
+ def GetPropertyValue(self, propertyId: int) -> Any:
888
+ """
889
+ Call IUIAutomationElement::GetCurrentPropertyValue.
890
+ propertyId: int, a value in class `PropertyId`.
891
+ Return Any, corresponding type according to propertyId.
892
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-getcurrentpropertyvalue
893
+ """
894
+ return self.Element.GetCurrentPropertyValue(propertyId)
895
+
896
+ def GetPropertyValueEx(self, propertyId: int, ignoreDefaultValue: int) -> Any:
897
+ """
898
+ Call IUIAutomationElement::GetCurrentPropertyValueEx.
899
+ propertyId: int, a value in class `PropertyId`.
900
+ ignoreDefaultValue: int, 0 or 1.
901
+ Return Any, corresponding type according to propertyId.
902
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-getcurrentpropertyvalueex
903
+ """
904
+ return self.Element.GetCurrentPropertyValueEx(propertyId, ignoreDefaultValue)
905
+
906
+ def GetRuntimeId(self) -> List[int]:
907
+ """
908
+ Call IUIAutomationElement::GetRuntimeId.
909
+ Return List[int], a list of int.
910
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-getruntimeid
911
+ """
912
+ return self.Element.GetRuntimeId()
913
+
914
+ # QueryInterface
915
+ # Release
916
+
917
+ def SetFocus(self) -> bool:
918
+ """
919
+ Call IUIAutomationElement::SetFocus.
920
+ Refer https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationelement-setfocus
921
+ """
922
+ try:
923
+ return self.Element.SetFocus() == S_OK
924
+ except comtypes.COMError as ex:
925
+ return False
926
+
927
+ @property
928
+ def Element(self):
929
+ """
930
+ Property Element.
931
+ Return `ctypes.POINTER(IUIAutomationElement)`.
932
+ """
933
+ if not self._element:
934
+ self.Refind(maxSearchSeconds=TIME_OUT_SECOND, searchIntervalSeconds=self.searchInterval)
935
+ return self._element
936
+
937
+ @property
938
+ def ControlTypeName(self) -> str:
939
+ """
940
+ Property ControlTypeName.
941
+ """
942
+ return ControlTypeNames[self.ControlType]
943
+
944
+ def GetCachedPattern(self, patternId: int, cache: bool):
945
+ """
946
+ Get a pattern by patternId.
947
+ patternId: int, a value in class `PatternId`.
948
+ Return a pattern if it supports the pattern else None.
949
+ cache: bool, if True, store the pattern for later use, if False, get a new pattern by `self.GetPattern`.
950
+ """
951
+ if cache:
952
+ pattern = self._supportedPatterns.get(patternId, None)
953
+ if pattern:
954
+ return pattern
955
+ else:
956
+ pattern = self.GetPattern(patternId)
957
+ if pattern:
958
+ self._supportedPatterns[patternId] = pattern
959
+ return pattern
960
+ else:
961
+ pattern = self.GetPattern(patternId)
962
+ if pattern:
963
+ self._supportedPatterns[patternId] = pattern
964
+ return pattern
965
+
966
+ def GetLegacyIAccessiblePattern(self) -> LegacyIAccessiblePattern:
967
+ """
968
+ Return `LegacyIAccessiblePattern` if it supports the pattern else None.
969
+ """
970
+ return self.GetPattern(PatternId.LegacyIAccessiblePattern)
971
+
972
+ def GetAncestorControl(self, condition: Callable[['Control', int], bool]) -> Optional['Control']:
973
+ """
974
+ Get an ancestor control that matches the condition.
975
+ condition: Callable[[Control, int], bool], function(control: Control, depth: int) -> bool,
976
+ depth starts with -1 and decreses when search goes up.
977
+ Return `Control` subclass or None.
978
+ """
979
+ ancestor = self
980
+ depth = 0
981
+ while ancestor is not None:
982
+ ancestor = ancestor.GetParentControl()
983
+ depth -= 1
984
+ if ancestor:
985
+ if condition(ancestor, depth):
986
+ return ancestor
987
+ return None
988
+
989
+ def GetParentControl(self) -> Optional['Control']:
990
+ """
991
+ Return `Control` subclass or None.
992
+ """
993
+ ele = _AutomationClient.instance().ViewWalker.GetParentElement(self.Element)
994
+ return Control.CreateControlFromElement(ele)
995
+
996
+ def GetFirstChildControl(self) -> Optional['Control']:
997
+ """
998
+ Return `Control` subclass or None.
999
+ """
1000
+ ele = _AutomationClient.instance().ViewWalker.GetFirstChildElement(self.Element)
1001
+ return Control.CreateControlFromElement(ele)
1002
+
1003
+ def GetLastChildControl(self) -> Optional['Control']:
1004
+ """
1005
+ Return `Control` subclass or None.
1006
+ """
1007
+ ele = _AutomationClient.instance().ViewWalker.GetLastChildElement(self.Element)
1008
+ return Control.CreateControlFromElement(ele)
1009
+
1010
+ def GetNextSiblingControl(self) -> Optional['Control']:
1011
+ """
1012
+ Return `Control` subclass or None.
1013
+ """
1014
+ ele = _AutomationClient.instance().ViewWalker.GetNextSiblingElement(self.Element)
1015
+ return Control.CreateControlFromElement(ele)
1016
+
1017
+ def GetPreviousSiblingControl(self) -> Optional['Control']:
1018
+ """
1019
+ Return `Control` subclass or None.
1020
+ """
1021
+ ele = _AutomationClient.instance().ViewWalker.GetPreviousSiblingElement(self.Element)
1022
+ return Control.CreateControlFromElement(ele)
1023
+
1024
+ def GetSiblingControl(self, condition: Callable[['Control'], bool], forward: bool = True) -> Optional['Control']:
1025
+ """
1026
+ Get a sibling control that matches the condition.
1027
+ forward: bool, if True, only search next siblings, if False, search pervious siblings first, then search next siblings.
1028
+ condition: Callable[[Control], bool], function(control: Control) -> bool.
1029
+ Return `Control` subclass or None.
1030
+ """
1031
+ if not forward:
1032
+ prev = self
1033
+ while True:
1034
+ prev = prev.GetPreviousSiblingControl()
1035
+ if prev:
1036
+ if condition(prev):
1037
+ return prev
1038
+ else:
1039
+ break
1040
+ next_ = self
1041
+ while True:
1042
+ next_ = next_.GetNextSiblingControl()
1043
+ if next_:
1044
+ if condition(next_):
1045
+ return next_
1046
+ else:
1047
+ break
1048
+
1049
+ def GetChildren(self) -> List['Control']:
1050
+ """
1051
+ Return List[Control], a list of `Control` subclasses.
1052
+ """
1053
+ children = []
1054
+ child = self.GetFirstChildControl()
1055
+ while child:
1056
+ children.append(child)
1057
+ child = child.GetNextSiblingControl()
1058
+ return children
1059
+
1060
+ def _CompareFunction(self, control: 'Control', depth: int) -> bool:
1061
+ """
1062
+ Define how to search.
1063
+ control: `Control` or its subclass.
1064
+ depth: int, tree depth from searchFromControl.
1065
+ Return bool.
1066
+ """
1067
+ compareFunc = None
1068
+ for key, value in self.searchProperties.items():
1069
+ if 'ControlType' == key:
1070
+ if value != control.ControlType:
1071
+ return False
1072
+ elif 'ClassName' == key:
1073
+ if value != control.ClassName:
1074
+ return False
1075
+ elif 'AutomationId' == key:
1076
+ if value != control.AutomationId:
1077
+ return False
1078
+ elif 'Depth' == key:
1079
+ if value != depth:
1080
+ return False
1081
+ elif 'Name' == key:
1082
+ if value != control.Name:
1083
+ return False
1084
+ elif 'SubName' == key:
1085
+ if value not in control.Name:
1086
+ return False
1087
+ elif 'RegexName' == key:
1088
+ if not self.regexName.match(control.Name):
1089
+ return False
1090
+ elif 'Compare' == key:
1091
+ compareFunc = value
1092
+ # use Compare at last
1093
+ if compareFunc and not compareFunc(control, depth):
1094
+ return False
1095
+ return True
1096
+
1097
+ def Exists(self, maxSearchSeconds: float = 5, searchIntervalSeconds: float = SEARCH_INTERVAL, printIfNotExist: bool = False) -> bool:
1098
+ """
1099
+ maxSearchSeconds: float
1100
+ searchIntervalSeconds: float
1101
+ Find control every searchIntervalSeconds seconds in maxSearchSeconds seconds.
1102
+ Return bool, True if find
1103
+ """
1104
+ if self._element and self._elementDirectAssign:
1105
+ # if element is directly assigned, not by searching, just check whether self._element is valid
1106
+ # but I can't find an API in UIAutomation that can directly check
1107
+ rootElement = _AutomationClient.instance().IUIAutomation.GetRootElement()
1108
+ if _AutomationClient.instance().IUIAutomation.CompareElements(self._element, rootElement):
1109
+ return True
1110
+ else:
1111
+ parentElement = _AutomationClient.instance().ViewWalker.GetParentElement(self._element)
1112
+ if parentElement:
1113
+ return True
1114
+ else:
1115
+ return False
1116
+ # find the element
1117
+ if not self.searchProperties:
1118
+ raise LookupError("control's searchProperties must not be empty!")
1119
+ self._element = None
1120
+ startTime = ProcessTime()
1121
+ # Use same timeout(s) parameters for resolve all parents
1122
+ prev = self.searchFromControl
1123
+ if prev and not prev._element and not prev.Exists(maxSearchSeconds, searchIntervalSeconds):
1124
+ if printIfNotExist or DEBUG_EXIST_DISAPPEAR:
1125
+ Logger.ColorfullyLog(self.GetColorfulSearchPropertiesStr() + '<Color=Red> does not exist.</Color>')
1126
+ return False
1127
+ startTime2 = ProcessTime()
1128
+ if DEBUG_SEARCH_TIME:
1129
+ startDateTime = datetime.datetime.now()
1130
+ while True:
1131
+ control = FindControl(self.searchFromControl, self._CompareFunction, self.searchDepth, False, self.foundIndex)
1132
+ if control:
1133
+ self._element = control.Element
1134
+ control._element = 0 # control will be destroyed, but the element needs to be stored in self._element
1135
+ if DEBUG_SEARCH_TIME:
1136
+ Logger.ColorfullyLog('{} TraverseControls: <Color=Cyan>{}</Color>, SearchTime: <Color=Cyan>{:.3f}</Color>s[{} - {}]'.format(
1137
+ self.GetColorfulSearchPropertiesStr(), control.traverseCount, ProcessTime() - startTime2,
1138
+ startDateTime.time(), datetime.datetime.now().time()))
1139
+ return True
1140
+ else:
1141
+ remain = startTime + maxSearchSeconds - ProcessTime()
1142
+ if remain > 0:
1143
+ time.sleep(min(remain, searchIntervalSeconds))
1144
+ else:
1145
+ if printIfNotExist or DEBUG_EXIST_DISAPPEAR:
1146
+ Logger.ColorfullyLog(self.GetColorfulSearchPropertiesStr() + '<Color=Red> does not exist.</Color>')
1147
+ return False
1148
+
1149
+ def Disappears(self, maxSearchSeconds: float = 5, searchIntervalSeconds: float = SEARCH_INTERVAL, printIfNotDisappear: bool = False) -> bool:
1150
+ """
1151
+ maxSearchSeconds: float
1152
+ searchIntervalSeconds: float
1153
+ Check if control disappears every searchIntervalSeconds seconds in maxSearchSeconds seconds.
1154
+ Return bool, True if control disappears.
1155
+ """
1156
+ global DEBUG_EXIST_DISAPPEAR
1157
+ start = ProcessTime()
1158
+ while True:
1159
+ temp = DEBUG_EXIST_DISAPPEAR
1160
+ DEBUG_EXIST_DISAPPEAR = False # do not print for Exists
1161
+ if not self.Exists(0, 0, False):
1162
+ DEBUG_EXIST_DISAPPEAR = temp
1163
+ return True
1164
+ DEBUG_EXIST_DISAPPEAR = temp
1165
+ remain = start + maxSearchSeconds - ProcessTime()
1166
+ if remain > 0:
1167
+ time.sleep(min(remain, searchIntervalSeconds))
1168
+ else:
1169
+ if printIfNotDisappear or DEBUG_EXIST_DISAPPEAR:
1170
+ Logger.ColorfullyLog(self.GetColorfulSearchPropertiesStr() + '<Color=Red> does not disappear.</Color>')
1171
+ return False
1172
+
1173
+ def Refind(self, maxSearchSeconds: float = TIME_OUT_SECOND, searchIntervalSeconds: float = SEARCH_INTERVAL, raiseException: bool = True) -> bool:
1174
+ """
1175
+ Refind the control every searchIntervalSeconds seconds in maxSearchSeconds seconds.
1176
+ maxSearchSeconds: float.
1177
+ searchIntervalSeconds: float.
1178
+ raiseException: bool, if True, raise a LookupError if timeout.
1179
+ Return bool, True if find.
1180
+ """
1181
+ if not self.Exists(maxSearchSeconds, searchIntervalSeconds, False if raiseException else DEBUG_EXIST_DISAPPEAR):
1182
+ if raiseException:
1183
+ Logger.ColorfullyLog('<Color=Red>Find Control Timeout({}s): </Color>{}'.format(maxSearchSeconds, self.GetColorfulSearchPropertiesStr()))
1184
+ raise LookupError('Find Control Timeout({}s): {}'.format(maxSearchSeconds, self.GetSearchPropertiesStr()))
1185
+ else:
1186
+ return False
1187
+ return True
1188
+
1189
+ def GetPosition(self, ratioX: float = 0.5, ratioY: float = 0.5) -> Optional[Tuple[int, int]]:
1190
+ """
1191
+ Gets the position of the center of the control.
1192
+ ratioX: float.
1193
+ ratioY: float.
1194
+ Return Tuple[int, int], two ints tuple (x, y), the cursor positon relative to screen(0, 0)
1195
+ """
1196
+ rect = self.BoundingRectangle
1197
+ if rect.width() == 0 or rect.height() == 0:
1198
+ Logger.ColorfullyLog('<Color=Yellow>Can not move cursor</Color>. {}\'s BoundingRectangle is {}. SearchProperties: {}'.format(
1199
+ self.ControlTypeName, rect, self.GetColorfulSearchPropertiesStr()))
1200
+ return None
1201
+ x = rect.left + int(rect.width() * ratioX)
1202
+ y = rect.top + int(rect.height() * ratioY)
1203
+ return x, y
1204
+
1205
+ def MoveCursorToInnerPos(self, x: Optional[int] = None, y: Optional[int] = None, ratioX: float = 0.5, ratioY: float = 0.5, simulateMove: bool = True) -> Optional[Tuple[int, int]]:
1206
+ """
1207
+ Move cursor to control's internal position, default to center.
1208
+ x: int, if < 0, move to self.BoundingRectangle.right + x, if not None, ignore ratioX.
1209
+ y: int, if < 0, move to self.BoundingRectangle.bottom + y, if not None, ignore ratioY.
1210
+ ratioX: float.
1211
+ ratioY: float.
1212
+ simulateMove: bool.
1213
+ Return Tuple[int, int], two ints tuple (x, y), the cursor positon relative to screen(0, 0)
1214
+ after moving or None if control's width or height is 0.
1215
+ """
1216
+ rect = self.BoundingRectangle
1217
+ if rect.width() == 0 or rect.height() == 0:
1218
+ Logger.ColorfullyLog('<Color=Yellow>Can not move cursor</Color>. {}\'s BoundingRectangle is {}. SearchProperties: {}'.format(
1219
+ self.ControlTypeName, rect, self.GetColorfulSearchPropertiesStr()))
1220
+ return None
1221
+ if x is None:
1222
+ x = rect.left + int(rect.width() * ratioX)
1223
+ else:
1224
+ x = (rect.left if x >= 0 else rect.right) + x
1225
+ if y is None:
1226
+ y = rect.top + int(rect.height() * ratioY)
1227
+ else:
1228
+ y = (rect.top if y >= 0 else rect.bottom) + y
1229
+ if simulateMove and MAX_MOVE_SECOND > 0:
1230
+ MoveTo(x, y, waitTime=0)
1231
+ else:
1232
+ SetCursorPos(x, y)
1233
+ return x, y
1234
+
1235
+ def MoveCursorToMyCenter(self, simulateMove: bool = True) -> Optional[Tuple[int, int]]:
1236
+ """
1237
+ Move cursor to control's center.
1238
+ Return Tuple[int, int], two ints tuple (x, y), the cursor positon relative to screen(0, 0) after moving.
1239
+ """
1240
+ return self.MoveCursorToInnerPos(simulateMove=simulateMove)
1241
+
1242
+ def Click(self, x: Optional[int] = None, y: Optional[int] = None, ratioX: float = 0.5, ratioY: float = 0.5, simulateMove: bool = True, waitTime: float = OPERATION_WAIT_TIME) -> None:
1243
+ """
1244
+ x: int, if < 0, click self.BoundingRectangle.right + x, if not None, ignore ratioX.
1245
+ y: int, if < 0, click self.BoundingRectangle.bottom + y, if not None, ignore ratioY.
1246
+ ratioX: float.
1247
+ ratioY: float.
1248
+ simulateMove: bool, if True, first move cursor to control smoothly.
1249
+ waitTime: float.
1250
+
1251
+ Click(), Click(ratioX=0.5, ratioY=0.5): click center.
1252
+ Click(10, 10): click left+10, top+10.
1253
+ Click(-10, -10): click right-10, bottom-10.
1254
+ """
1255
+ point = self.MoveCursorToInnerPos(x, y, ratioX, ratioY, simulateMove)
1256
+ if point:
1257
+ Click(point[0], point[1], waitTime)
1258
+
1259
+ def MiddleClick(self, x: Optional[int] = None, y: Optional[int] = None, ratioX: float = 0.5, ratioY: float = 0.5, simulateMove: bool = True, waitTime: float = OPERATION_WAIT_TIME) -> None:
1260
+ """
1261
+ x: int, if < 0, middle click self.BoundingRectangle.right + x, if not None, ignore ratioX.
1262
+ y: int, if < 0, middle click self.BoundingRectangle.bottom + y, if not None, ignore ratioY.
1263
+ ratioX: float.
1264
+ ratioY: float.
1265
+ simulateMove: bool, if True, first move cursor to control smoothly.
1266
+ waitTime: float.
1267
+
1268
+ MiddleClick(), MiddleClick(ratioX=0.5, ratioY=0.5): middle click center.
1269
+ MiddleClick(10, 10): middle click left+10, top+10.
1270
+ MiddleClick(-10, -10): middle click right-10, bottom-10.
1271
+ """
1272
+ point = self.MoveCursorToInnerPos(x, y, ratioX, ratioY, simulateMove)
1273
+ if point:
1274
+ MiddleClick(point[0], point[1], waitTime)
1275
+
1276
+ def RightClick(self, x: Optional[int] = None, y: Optional[int] = None, ratioX: float = 0.5, ratioY: float = 0.5, simulateMove: bool = True, waitTime: float = OPERATION_WAIT_TIME) -> None:
1277
+ """
1278
+ x: int, if < 0, right click self.BoundingRectangle.right + x, if not None, ignore ratioX.
1279
+ y: int, if < 0, right click self.BoundingRectangle.bottom + y, if not None, ignore ratioY.
1280
+ ratioX: float.
1281
+ ratioY: float.
1282
+ simulateMove: bool, if True, first move cursor to control smoothly.
1283
+ waitTime: float.
1284
+
1285
+ RightClick(), RightClick(ratioX=0.5, ratioY=0.5): right click center.
1286
+ RightClick(10, 10): right click left+10, top+10.
1287
+ RightClick(-10, -10): right click right-10, bottom-10.
1288
+ """
1289
+ point = self.MoveCursorToInnerPos(x, y, ratioX, ratioY, simulateMove)
1290
+ if point:
1291
+ RightClick(point[0], point[1], waitTime)
1292
+
1293
+ def DoubleClick(self, x: Optional[int] = None, y: Optional[int] = None, ratioX: float = 0.5, ratioY: float = 0.5, simulateMove: bool = True, waitTime: float = OPERATION_WAIT_TIME) -> None:
1294
+ """
1295
+ x: int, if < 0, right click self.BoundingRectangle.right + x, if not None, ignore ratioX.
1296
+ y: int, if < 0, right click self.BoundingRectangle.bottom + y, if not None, ignore ratioY.
1297
+ ratioX: float.
1298
+ ratioY: float.
1299
+ simulateMove: bool, if True, first move cursor to control smoothly.
1300
+ waitTime: float.
1301
+
1302
+ DoubleClick(), DoubleClick(ratioX=0.5, ratioY=0.5): double click center.
1303
+ DoubleClick(10, 10): double click left+10, top+10.
1304
+ DoubleClick(-10, -10): double click right-10, bottom-10.
1305
+ """
1306
+ x, y = self.MoveCursorToInnerPos(x, y, ratioX, ratioY, simulateMove)
1307
+ Click(x, y, GetDoubleClickTime() * 1.0 / 2000)
1308
+ Click(x, y, waitTime)
1309
+
1310
+ def DragDrop(self, x1: int, y1: int, x2: int, y2: int, moveSpeed: float = 1, waitTime: float = OPERATION_WAIT_TIME) -> None:
1311
+ rect = self.BoundingRectangle
1312
+ if rect.width() == 0 or rect.height() == 0:
1313
+ Logger.ColorfullyLog('<Color=Yellow>Can not move cursor</Color>. {}\'s BoundingRectangle is {}. SearchProperties: {}'.format(
1314
+ self.ControlTypeName, rect, self.GetColorfulSearchPropertiesStr()))
1315
+ return
1316
+ x1 = (rect.left if x1 >= 0 else rect.right) + x1
1317
+ y1 = (rect.top if y1 >= 0 else rect.bottom) + y1
1318
+ x2 = (rect.left if x2 >= 0 else rect.right) + x2
1319
+ y2 = (rect.top if y2 >= 0 else rect.bottom) + y2
1320
+ DragDrop(x1, y1, x2, y2, moveSpeed, waitTime)
1321
+
1322
+ def RightDragDrop(self, x1: int, y1: int, x2: int, y2: int, moveSpeed: float = 1, waitTime: float = OPERATION_WAIT_TIME) -> None:
1323
+ rect = self.BoundingRectangle
1324
+ if rect.width() == 0 or rect.height() == 0:
1325
+ Logger.ColorfullyLog('<Color=Yellow>Can not move cursor</Color>. {}\'s BoundingRectangle is {}. SearchProperties: {}'.format(
1326
+ self.ControlTypeName, rect, self.GetColorfulSearchPropertiesStr()))
1327
+ return
1328
+ x1 = (rect.left if x1 >= 0 else rect.right) + x1
1329
+ y1 = (rect.top if y1 >= 0 else rect.bottom) + y1
1330
+ x2 = (rect.left if x2 >= 0 else rect.right) + x2
1331
+ y2 = (rect.top if y2 >= 0 else rect.bottom) + y2
1332
+ RightDragDrop(x1, y1, x2, y2, moveSpeed, waitTime)
1333
+
1334
+ def WheelDown(self, x: Optional[int] = None, y: Optional[int] = None, ratioX: float = 0.5, ratioY: float = 0.5, wheelTimes: int = 1, interval: float = 0.05, waitTime: float = OPERATION_WAIT_TIME) -> None:
1335
+ """
1336
+ Make control have focus first, move cursor to the specified position and mouse wheel down.
1337
+ x: int, if < 0, move x cursor to self.BoundingRectangle.right + x, if not None, ignore ratioX.
1338
+ y: int, if < 0, move y cursor to self.BoundingRectangle.bottom + y, if not None, ignore ratioY.
1339
+ ratioX: float.
1340
+ ratioY: float.
1341
+ wheelTimes: int.
1342
+ interval: float.
1343
+ waitTime: float.
1344
+ """
1345
+ cursorX, cursorY = GetCursorPos()
1346
+ self.SetFocus()
1347
+ self.MoveCursorToInnerPos(x, y, ratioX, ratioY, simulateMove=False)
1348
+ WheelDown(wheelTimes, interval, waitTime)
1349
+ SetCursorPos(cursorX, cursorY)
1350
+
1351
+ def WheelUp(self, x: Optional[int] = None, y: Optional[int] = None, ratioX: float = 0.5, ratioY: float = 0.5, wheelTimes: int = 1, interval: float = 0.05, waitTime: float = OPERATION_WAIT_TIME) -> None:
1352
+ """
1353
+ Make control have focus first, move cursor to the specified position and mouse wheel up.
1354
+ x: int, if < 0, move x cursor to self.BoundingRectangle.right + x, if not None, ignore ratioX.
1355
+ y: int, if < 0, move y cursor to self.BoundingRectangle.bottom + y, if not None, ignore ratioY.
1356
+ ratioX: float.
1357
+ ratioY: float.
1358
+ wheelTimes: int.
1359
+ interval: float.
1360
+ waitTime: float.
1361
+ """
1362
+ cursorX, cursorY = GetCursorPos()
1363
+ self.SetFocus()
1364
+ self.MoveCursorToInnerPos(x, y, ratioX, ratioY, simulateMove=False)
1365
+ WheelUp(wheelTimes, interval, waitTime)
1366
+ SetCursorPos(cursorX, cursorY)
1367
+
1368
+ def ShowWindow(self, cmdShow: int, waitTime: float = OPERATION_WAIT_TIME) -> Optional[bool]:
1369
+ """
1370
+ Get a native handle from self or ancestors until valid and call native `ShowWindow` with cmdShow.
1371
+ cmdShow: int, a value in in class `SW`.
1372
+ waitTime: float.
1373
+ Return bool, True if succeed otherwise False and None if the handle could not be gotten.
1374
+ """
1375
+ handle = self.NativeWindowHandle
1376
+ if not handle:
1377
+ control = self
1378
+ while not handle and control:
1379
+ control = control.GetParentControl()
1380
+ if control:
1381
+ handle = control.NativeWindowHandle
1382
+ else:
1383
+ handle = 0
1384
+ break
1385
+ if handle:
1386
+ ret = ShowWindow(handle, cmdShow)
1387
+ time.sleep(waitTime)
1388
+ return ret
1389
+ return None
1390
+
1391
+ def Show(self, waitTime: float = OPERATION_WAIT_TIME) -> Optional[bool]:
1392
+ """
1393
+ Call native `ShowWindow(SW.Show)`.
1394
+ Return bool, True if succeed otherwise False and None if the handle could not be gotten.
1395
+ """
1396
+ return self.ShowWindow(SW.Show, waitTime)
1397
+
1398
+ def Hide(self, waitTime: float = OPERATION_WAIT_TIME) -> Optional[bool]:
1399
+ """
1400
+ Call native `ShowWindow(SW.Hide)`.
1401
+ waitTime: float
1402
+ Return bool, True if succeed otherwise False and None if the handle could not be gotten.
1403
+ """
1404
+ return self.ShowWindow(SW.Hide, waitTime)
1405
+
1406
+ def MoveWindow(self, x: int, y: int, width: int, height: int, repaint: bool = True) -> bool:
1407
+ """
1408
+ Call native MoveWindow if control has a valid native handle.
1409
+ x: int.
1410
+ y: int.
1411
+ width: int.
1412
+ height: int.
1413
+ repaint: bool.
1414
+ Return bool, True if succeed otherwise False.
1415
+ """
1416
+ handle = self.NativeWindowHandle
1417
+ if handle:
1418
+ return MoveWindow(handle, x, y, width, height, int(repaint))
1419
+ return False
1420
+
1421
+ def GetWindowText(self) -> Optional[str]:
1422
+ """
1423
+ Call native GetWindowText if control has a valid native handle.
1424
+ """
1425
+ handle = self.NativeWindowHandle
1426
+ if handle:
1427
+ return GetWindowText(handle)
1428
+ return None
1429
+
1430
+ def SetWindowText(self, text: str) -> bool:
1431
+ """
1432
+ Call native SetWindowText if control has a valid native handle.
1433
+ """
1434
+ handle = self.NativeWindowHandle
1435
+ if handle:
1436
+ return SetWindowText(handle, text)
1437
+ return False
1438
+
1439
+ def SendKey(self, key: int, waitTime: float = OPERATION_WAIT_TIME) -> None:
1440
+ """
1441
+ Make control have focus first and type a key.
1442
+ `self.SetFocus` may not work for some controls, you may need to click it to make it have focus.
1443
+ key: int, a key code value in class Keys.
1444
+ waitTime: float.
1445
+ """
1446
+ self.SetFocus()
1447
+ SendKey(key, waitTime)
1448
+
1449
+ def SendKeys(self, text: str, interval: float = 0.01, waitTime: float = OPERATION_WAIT_TIME, charMode: bool = True) -> None:
1450
+ """
1451
+ Make control have focus first and type keys.
1452
+ `self.SetFocus` may not work for some controls, you may need to click it to make it have focus.
1453
+ text: str, keys to type, see the docstring of `SendKeys`.
1454
+ interval: float, seconds between keys.
1455
+ waitTime: float.
1456
+ charMode: bool, if False, the text typied is depend on the input method if a input method is on.
1457
+ """
1458
+ self.SetFocus()
1459
+ SendKeys(text, interval, waitTime, charMode)
1460
+
1461
+ def GetPixelColor(self, x: int, y: int) -> Optional[int]:
1462
+ """
1463
+ Call native `GetPixelColor` if control has a valid native handle.
1464
+ Use `self.ToBitmap` if control doesn't have a valid native handle or you get many pixels.
1465
+ x: int, internal x position.
1466
+ y: int, internal y position.
1467
+ Return int, a color value in bgr.
1468
+ r = bgr & 0x0000FF
1469
+ g = (bgr & 0x00FF00) >> 8
1470
+ b = (bgr & 0xFF0000) >> 16
1471
+ """
1472
+ handle = self.NativeWindowHandle
1473
+ if handle:
1474
+ return GetPixelColor(x, y, handle)
1475
+ return None
1476
+
1477
+ def ToBitmap(self, x: int = 0, y: int = 0, width: int = 0, height: int = 0,
1478
+ captureCursor: bool = False) -> Optional[Bitmap]:
1479
+ """
1480
+ Capture control to a `Bitmap` object.
1481
+ x, y: int, the point in control's internal position(from 0,0).
1482
+ width, height: int, image's width and height from x, y, use 0 for entire area.
1483
+ If width(or height) < 0, image size will be control's width(or height) - width(or height).
1484
+ """
1485
+ return Bitmap.FromControl(self, x, y, width, height, captureCursor)
1486
+
1487
+ def CaptureToImage(self, savePath: str, x: int = 0, y: int = 0, width: int = 0, height: int = 0,
1488
+ captureCursor: bool = False) -> bool:
1489
+ """
1490
+ Capture control to a image file.
1491
+ savePath: str, should end with .bmp, .jpg, .jpeg, .png, .gif, .tif, .tiff.
1492
+ x, y: int, the point in control's internal position(from 0,0).
1493
+ width, height: int, image's width and height from x, y, use 0 for entire area.
1494
+ If width(or height) < 0, image size will be control's width(or height) - width(or height).
1495
+ Return bool, True if succeed otherwise False.
1496
+ """
1497
+ bitmap = Bitmap.FromControl(self, x, y, width, height, captureCursor)
1498
+ if bitmap:
1499
+ with bitmap:
1500
+ return bitmap.ToFile(savePath)
1501
+ return False
1502
+
1503
+ def IsTopLevel(self) -> bool:
1504
+ """Determine whether current control is top level."""
1505
+ handle = self.NativeWindowHandle
1506
+ if handle:
1507
+ return GetAncestor(handle, GAFlag.Root) == handle
1508
+ return False
1509
+
1510
+ def GetTopLevelControl(self) -> Optional['Control']:
1511
+ """
1512
+ Get the top level control which current control lays.
1513
+ If current control is top level, return self.
1514
+ If current control is root control, return None.
1515
+ Return `PaneControl` or `WindowControl` or None.
1516
+ """
1517
+ handle = self.NativeWindowHandle
1518
+ if handle:
1519
+ topHandle = GetAncestor(handle, GAFlag.Root)
1520
+ if topHandle:
1521
+ if topHandle == handle:
1522
+ return self
1523
+ else:
1524
+ return ControlFromHandle(topHandle)
1525
+ else:
1526
+ # self is root control
1527
+ pass
1528
+ else:
1529
+ control = self
1530
+ while True:
1531
+ control = control.GetParentControl()
1532
+ if not control:
1533
+ break
1534
+ handle = control.NativeWindowHandle
1535
+ if handle:
1536
+ topHandle = GetAncestor(handle, GAFlag.Root)
1537
+ return ControlFromHandle(topHandle)
1538
+ return None
1539
+
1540
+ def Control(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
1541
+ Name: Optional[str] = None,
1542
+ SubName: Optional[str] = None,
1543
+ RegexName: Optional[str] = None,
1544
+ ClassName: Optional[str] = None,
1545
+ AutomationId: Optional[str] = None,
1546
+ Depth: Optional[int] = None,
1547
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
1548
+ **searchProperties) -> 'Control':
1549
+ return Control(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
1550
+ foundIndex=foundIndex, element=element,
1551
+ Name=Name,
1552
+ SubName=SubName,
1553
+ RegexName=RegexName,
1554
+ ClassName=ClassName,
1555
+ AutomationId=AutomationId,
1556
+ Depth=Depth,
1557
+ Compare=Compare,
1558
+ **searchProperties)
1559
+
1560
+ def ButtonControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
1561
+ Name: Optional[str] = None,
1562
+ SubName: Optional[str] = None,
1563
+ RegexName: Optional[str] = None,
1564
+ ClassName: Optional[str] = None,
1565
+ AutomationId: Optional[str] = None,
1566
+ Depth: Optional[int] = None,
1567
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
1568
+ **searchProperties) -> 'ButtonControl':
1569
+ return ButtonControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
1570
+ foundIndex=foundIndex, element=element,
1571
+ Name=Name,
1572
+ SubName=SubName,
1573
+ RegexName=RegexName,
1574
+ ClassName=ClassName,
1575
+ AutomationId=AutomationId,
1576
+ Depth=Depth,
1577
+ Compare=Compare,
1578
+ **searchProperties)
1579
+
1580
+ def CalendarControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
1581
+ Name: Optional[str] = None,
1582
+ SubName: Optional[str] = None,
1583
+ RegexName: Optional[str] = None,
1584
+ ClassName: Optional[str] = None,
1585
+ AutomationId: Optional[str] = None,
1586
+ Depth: Optional[int] = None,
1587
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
1588
+ **searchProperties) -> 'CalendarControl':
1589
+ return CalendarControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
1590
+ foundIndex=foundIndex, element=element,
1591
+ Name=Name,
1592
+ SubName=SubName,
1593
+ RegexName=RegexName,
1594
+ ClassName=ClassName,
1595
+ AutomationId=AutomationId,
1596
+ Depth=Depth,
1597
+ Compare=Compare,
1598
+ **searchProperties)
1599
+
1600
+ def CheckBoxControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
1601
+ Name: Optional[str] = None,
1602
+ SubName: Optional[str] = None,
1603
+ RegexName: Optional[str] = None,
1604
+ ClassName: Optional[str] = None,
1605
+ AutomationId: Optional[str] = None,
1606
+ Depth: Optional[int] = None,
1607
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
1608
+ **searchProperties) -> 'CheckBoxControl':
1609
+ return CheckBoxControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
1610
+ foundIndex=foundIndex, element=element,
1611
+ Name=Name,
1612
+ SubName=SubName,
1613
+ RegexName=RegexName,
1614
+ ClassName=ClassName,
1615
+ AutomationId=AutomationId,
1616
+ Depth=Depth,
1617
+ Compare=Compare,
1618
+ **searchProperties)
1619
+
1620
+ def ComboBoxControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
1621
+ Name: Optional[str] = None,
1622
+ SubName: Optional[str] = None,
1623
+ RegexName: Optional[str] = None,
1624
+ ClassName: Optional[str] = None,
1625
+ AutomationId: Optional[str] = None,
1626
+ Depth: Optional[int] = None,
1627
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
1628
+ **searchProperties) -> 'ComboBoxControl':
1629
+ return ComboBoxControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
1630
+ foundIndex=foundIndex, element=element,
1631
+ Name=Name,
1632
+ SubName=SubName,
1633
+ RegexName=RegexName,
1634
+ ClassName=ClassName,
1635
+ AutomationId=AutomationId,
1636
+ Depth=Depth,
1637
+ Compare=Compare,
1638
+ **searchProperties)
1639
+
1640
+ def CustomControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
1641
+ Name: Optional[str] = None,
1642
+ SubName: Optional[str] = None,
1643
+ RegexName: Optional[str] = None,
1644
+ ClassName: Optional[str] = None,
1645
+ AutomationId: Optional[str] = None,
1646
+ Depth: Optional[int] = None,
1647
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
1648
+ **searchProperties) -> 'CustomControl':
1649
+ return CustomControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
1650
+ foundIndex=foundIndex, element=element,
1651
+ Name=Name,
1652
+ SubName=SubName,
1653
+ RegexName=RegexName,
1654
+ ClassName=ClassName,
1655
+ AutomationId=AutomationId,
1656
+ Depth=Depth,
1657
+ Compare=Compare,
1658
+ **searchProperties)
1659
+
1660
+ def DataGridControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
1661
+ Name: Optional[str] = None,
1662
+ SubName: Optional[str] = None,
1663
+ RegexName: Optional[str] = None,
1664
+ ClassName: Optional[str] = None,
1665
+ AutomationId: Optional[str] = None,
1666
+ Depth: Optional[int] = None,
1667
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
1668
+ **searchProperties) -> 'DataGridControl':
1669
+ return DataGridControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
1670
+ foundIndex=foundIndex, element=element,
1671
+ Name=Name,
1672
+ SubName=SubName,
1673
+ RegexName=RegexName,
1674
+ ClassName=ClassName,
1675
+ AutomationId=AutomationId,
1676
+ Depth=Depth,
1677
+ Compare=Compare,
1678
+ **searchProperties)
1679
+
1680
+ def DataItemControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
1681
+ Name: Optional[str] = None,
1682
+ SubName: Optional[str] = None,
1683
+ RegexName: Optional[str] = None,
1684
+ ClassName: Optional[str] = None,
1685
+ AutomationId: Optional[str] = None,
1686
+ Depth: Optional[int] = None,
1687
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
1688
+ **searchProperties) -> 'DataItemControl':
1689
+ return DataItemControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
1690
+ foundIndex=foundIndex, element=element,
1691
+ Name=Name,
1692
+ SubName=SubName,
1693
+ RegexName=RegexName,
1694
+ ClassName=ClassName,
1695
+ AutomationId=AutomationId,
1696
+ Depth=Depth,
1697
+ Compare=Compare,
1698
+ **searchProperties)
1699
+
1700
+ def DocumentControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
1701
+ Name: Optional[str] = None,
1702
+ SubName: Optional[str] = None,
1703
+ RegexName: Optional[str] = None,
1704
+ ClassName: Optional[str] = None,
1705
+ AutomationId: Optional[str] = None,
1706
+ Depth: Optional[int] = None,
1707
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
1708
+ **searchProperties) -> 'DocumentControl':
1709
+ return DocumentControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
1710
+ foundIndex=foundIndex, element=element,
1711
+ Name=Name,
1712
+ SubName=SubName,
1713
+ RegexName=RegexName,
1714
+ ClassName=ClassName,
1715
+ AutomationId=AutomationId,
1716
+ Depth=Depth,
1717
+ Compare=Compare,
1718
+ **searchProperties)
1719
+
1720
+ def EditControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
1721
+ Name: Optional[str] = None,
1722
+ SubName: Optional[str] = None,
1723
+ RegexName: Optional[str] = None,
1724
+ ClassName: Optional[str] = None,
1725
+ AutomationId: Optional[str] = None,
1726
+ Depth: Optional[int] = None,
1727
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
1728
+ **searchProperties) -> 'EditControl':
1729
+ return EditControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
1730
+ foundIndex=foundIndex, element=element,
1731
+ Name=Name,
1732
+ SubName=SubName,
1733
+ RegexName=RegexName,
1734
+ ClassName=ClassName,
1735
+ AutomationId=AutomationId,
1736
+ Depth=Depth,
1737
+ Compare=Compare,
1738
+ **searchProperties)
1739
+
1740
+ def GroupControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
1741
+ Name: Optional[str] = None,
1742
+ SubName: Optional[str] = None,
1743
+ RegexName: Optional[str] = None,
1744
+ ClassName: Optional[str] = None,
1745
+ AutomationId: Optional[str] = None,
1746
+ Depth: Optional[int] = None,
1747
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
1748
+ **searchProperties) -> 'GroupControl':
1749
+ return GroupControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
1750
+ foundIndex=foundIndex, element=element,
1751
+ Name=Name,
1752
+ SubName=SubName,
1753
+ RegexName=RegexName,
1754
+ ClassName=ClassName,
1755
+ AutomationId=AutomationId,
1756
+ Depth=Depth,
1757
+ Compare=Compare,
1758
+ **searchProperties)
1759
+
1760
+ def HeaderControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
1761
+ Name: Optional[str] = None,
1762
+ SubName: Optional[str] = None,
1763
+ RegexName: Optional[str] = None,
1764
+ ClassName: Optional[str] = None,
1765
+ AutomationId: Optional[str] = None,
1766
+ Depth: Optional[int] = None,
1767
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
1768
+ **searchProperties) -> 'HeaderControl':
1769
+ return HeaderControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
1770
+ foundIndex=foundIndex, element=element,
1771
+ Name=Name,
1772
+ SubName=SubName,
1773
+ RegexName=RegexName,
1774
+ ClassName=ClassName,
1775
+ AutomationId=AutomationId,
1776
+ Depth=Depth,
1777
+ Compare=Compare,
1778
+ **searchProperties)
1779
+
1780
+ def HeaderItemControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
1781
+ Name: Optional[str] = None,
1782
+ SubName: Optional[str] = None,
1783
+ RegexName: Optional[str] = None,
1784
+ ClassName: Optional[str] = None,
1785
+ AutomationId: Optional[str] = None,
1786
+ Depth: Optional[int] = None,
1787
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
1788
+ **searchProperties) -> 'HeaderItemControl':
1789
+ return HeaderItemControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
1790
+ foundIndex=foundIndex, element=element,
1791
+ Name=Name,
1792
+ SubName=SubName,
1793
+ RegexName=RegexName,
1794
+ ClassName=ClassName,
1795
+ AutomationId=AutomationId,
1796
+ Depth=Depth,
1797
+ Compare=Compare,
1798
+ **searchProperties)
1799
+
1800
+ def HyperlinkControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
1801
+ Name: Optional[str] = None,
1802
+ SubName: Optional[str] = None,
1803
+ RegexName: Optional[str] = None,
1804
+ ClassName: Optional[str] = None,
1805
+ AutomationId: Optional[str] = None,
1806
+ Depth: Optional[int] = None,
1807
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
1808
+ **searchProperties) -> 'HyperlinkControl':
1809
+ return HyperlinkControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
1810
+ foundIndex=foundIndex, element=element,
1811
+ Name=Name,
1812
+ SubName=SubName,
1813
+ RegexName=RegexName,
1814
+ ClassName=ClassName,
1815
+ AutomationId=AutomationId,
1816
+ Depth=Depth,
1817
+ Compare=Compare,
1818
+ **searchProperties)
1819
+
1820
+ def ImageControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
1821
+ Name: Optional[str] = None,
1822
+ SubName: Optional[str] = None,
1823
+ RegexName: Optional[str] = None,
1824
+ ClassName: Optional[str] = None,
1825
+ AutomationId: Optional[str] = None,
1826
+ Depth: Optional[int] = None,
1827
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
1828
+ **searchProperties) -> 'ImageControl':
1829
+ return ImageControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
1830
+ foundIndex=foundIndex, element=element,
1831
+ Name=Name,
1832
+ SubName=SubName,
1833
+ RegexName=RegexName,
1834
+ ClassName=ClassName,
1835
+ AutomationId=AutomationId,
1836
+ Depth=Depth,
1837
+ Compare=Compare,
1838
+ **searchProperties)
1839
+
1840
+ def ListControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
1841
+ Name: Optional[str] = None,
1842
+ SubName: Optional[str] = None,
1843
+ RegexName: Optional[str] = None,
1844
+ ClassName: Optional[str] = None,
1845
+ AutomationId: Optional[str] = None,
1846
+ Depth: Optional[int] = None,
1847
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
1848
+ **searchProperties) -> 'ListControl':
1849
+ return ListControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
1850
+ foundIndex=foundIndex, element=element,
1851
+ Name=Name,
1852
+ SubName=SubName,
1853
+ RegexName=RegexName,
1854
+ ClassName=ClassName,
1855
+ AutomationId=AutomationId,
1856
+ Depth=Depth,
1857
+ Compare=Compare,
1858
+ **searchProperties)
1859
+
1860
+ def ListItemControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
1861
+ Name: Optional[str] = None,
1862
+ SubName: Optional[str] = None,
1863
+ RegexName: Optional[str] = None,
1864
+ ClassName: Optional[str] = None,
1865
+ AutomationId: Optional[str] = None,
1866
+ Depth: Optional[int] = None,
1867
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
1868
+ **searchProperties) -> 'ListItemControl':
1869
+ return ListItemControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
1870
+ foundIndex=foundIndex, element=element,
1871
+ Name=Name,
1872
+ SubName=SubName,
1873
+ RegexName=RegexName,
1874
+ ClassName=ClassName,
1875
+ AutomationId=AutomationId,
1876
+ Depth=Depth,
1877
+ Compare=Compare,
1878
+ **searchProperties)
1879
+
1880
+ def MenuControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
1881
+ Name: Optional[str] = None,
1882
+ SubName: Optional[str] = None,
1883
+ RegexName: Optional[str] = None,
1884
+ ClassName: Optional[str] = None,
1885
+ AutomationId: Optional[str] = None,
1886
+ Depth: Optional[int] = None,
1887
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
1888
+ **searchProperties) -> 'MenuControl':
1889
+ return MenuControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
1890
+ foundIndex=foundIndex, element=element,
1891
+ Name=Name,
1892
+ SubName=SubName,
1893
+ RegexName=RegexName,
1894
+ ClassName=ClassName,
1895
+ AutomationId=AutomationId,
1896
+ Depth=Depth,
1897
+ Compare=Compare,
1898
+ **searchProperties)
1899
+
1900
+ def MenuBarControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
1901
+ Name: Optional[str] = None,
1902
+ SubName: Optional[str] = None,
1903
+ RegexName: Optional[str] = None,
1904
+ ClassName: Optional[str] = None,
1905
+ AutomationId: Optional[str] = None,
1906
+ Depth: Optional[int] = None,
1907
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
1908
+ **searchProperties) -> 'MenuBarControl':
1909
+ return MenuBarControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
1910
+ foundIndex=foundIndex, element=element,
1911
+ Name=Name,
1912
+ SubName=SubName,
1913
+ RegexName=RegexName,
1914
+ ClassName=ClassName,
1915
+ AutomationId=AutomationId,
1916
+ Depth=Depth,
1917
+ Compare=Compare,
1918
+ **searchProperties)
1919
+
1920
+ def MenuItemControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
1921
+ Name: Optional[str] = None,
1922
+ SubName: Optional[str] = None,
1923
+ RegexName: Optional[str] = None,
1924
+ ClassName: Optional[str] = None,
1925
+ AutomationId: Optional[str] = None,
1926
+ Depth: Optional[int] = None,
1927
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
1928
+ **searchProperties) -> 'MenuItemControl':
1929
+ return MenuItemControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
1930
+ foundIndex=foundIndex, element=element,
1931
+ Name=Name,
1932
+ SubName=SubName,
1933
+ RegexName=RegexName,
1934
+ ClassName=ClassName,
1935
+ AutomationId=AutomationId,
1936
+ Depth=Depth,
1937
+ Compare=Compare,
1938
+ **searchProperties)
1939
+
1940
+ def PaneControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
1941
+ Name: Optional[str] = None,
1942
+ SubName: Optional[str] = None,
1943
+ RegexName: Optional[str] = None,
1944
+ ClassName: Optional[str] = None,
1945
+ AutomationId: Optional[str] = None,
1946
+ Depth: Optional[int] = None,
1947
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
1948
+ **searchProperties) -> 'PaneControl':
1949
+ return PaneControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
1950
+ foundIndex=foundIndex, element=element,
1951
+ Name=Name,
1952
+ SubName=SubName,
1953
+ RegexName=RegexName,
1954
+ ClassName=ClassName,
1955
+ AutomationId=AutomationId,
1956
+ Depth=Depth,
1957
+ Compare=Compare,
1958
+ **searchProperties)
1959
+
1960
+ def ProgressBarControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
1961
+ Name: Optional[str] = None,
1962
+ SubName: Optional[str] = None,
1963
+ RegexName: Optional[str] = None,
1964
+ ClassName: Optional[str] = None,
1965
+ AutomationId: Optional[str] = None,
1966
+ Depth: Optional[int] = None,
1967
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
1968
+ **searchProperties) -> 'ProgressBarControl':
1969
+ return ProgressBarControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
1970
+ foundIndex=foundIndex, element=element,
1971
+ Name=Name,
1972
+ SubName=SubName,
1973
+ RegexName=RegexName,
1974
+ ClassName=ClassName,
1975
+ AutomationId=AutomationId,
1976
+ Depth=Depth,
1977
+ Compare=Compare,
1978
+ **searchProperties)
1979
+
1980
+ def RadioButtonControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
1981
+ Name: Optional[str] = None,
1982
+ SubName: Optional[str] = None,
1983
+ RegexName: Optional[str] = None,
1984
+ ClassName: Optional[str] = None,
1985
+ AutomationId: Optional[str] = None,
1986
+ Depth: Optional[int] = None,
1987
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
1988
+ **searchProperties) -> 'RadioButtonControl':
1989
+ return RadioButtonControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
1990
+ foundIndex=foundIndex, element=element,
1991
+ Name=Name,
1992
+ SubName=SubName,
1993
+ RegexName=RegexName,
1994
+ ClassName=ClassName,
1995
+ AutomationId=AutomationId,
1996
+ Depth=Depth,
1997
+ Compare=Compare,
1998
+ **searchProperties)
1999
+
2000
+ def ScrollBarControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
2001
+ Name: Optional[str] = None,
2002
+ SubName: Optional[str] = None,
2003
+ RegexName: Optional[str] = None,
2004
+ ClassName: Optional[str] = None,
2005
+ AutomationId: Optional[str] = None,
2006
+ Depth: Optional[int] = None,
2007
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2008
+ **searchProperties) -> 'ScrollBarControl':
2009
+ return ScrollBarControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
2010
+ foundIndex=foundIndex, element=element,
2011
+ Name=Name,
2012
+ SubName=SubName,
2013
+ RegexName=RegexName,
2014
+ ClassName=ClassName,
2015
+ AutomationId=AutomationId,
2016
+ Depth=Depth,
2017
+ Compare=Compare,
2018
+ **searchProperties)
2019
+
2020
+ def SemanticZoomControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
2021
+ Name: Optional[str] = None,
2022
+ SubName: Optional[str] = None,
2023
+ RegexName: Optional[str] = None,
2024
+ ClassName: Optional[str] = None,
2025
+ AutomationId: Optional[str] = None,
2026
+ Depth: Optional[int] = None,
2027
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2028
+ **searchProperties) -> 'SemanticZoomControl':
2029
+ return SemanticZoomControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
2030
+ foundIndex=foundIndex, element=element,
2031
+ Name=Name,
2032
+ SubName=SubName,
2033
+ RegexName=RegexName,
2034
+ ClassName=ClassName,
2035
+ AutomationId=AutomationId,
2036
+ Depth=Depth,
2037
+ Compare=Compare,
2038
+ **searchProperties)
2039
+
2040
+ def SeparatorControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
2041
+ Name: Optional[str] = None,
2042
+ SubName: Optional[str] = None,
2043
+ RegexName: Optional[str] = None,
2044
+ ClassName: Optional[str] = None,
2045
+ AutomationId: Optional[str] = None,
2046
+ Depth: Optional[int] = None,
2047
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2048
+ **searchProperties) -> 'SeparatorControl':
2049
+ return SeparatorControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
2050
+ foundIndex=foundIndex, element=element,
2051
+ Name=Name,
2052
+ SubName=SubName,
2053
+ RegexName=RegexName,
2054
+ ClassName=ClassName,
2055
+ AutomationId=AutomationId,
2056
+ Depth=Depth,
2057
+ Compare=Compare,
2058
+ **searchProperties)
2059
+
2060
+ def SliderControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
2061
+ Name: Optional[str] = None,
2062
+ SubName: Optional[str] = None,
2063
+ RegexName: Optional[str] = None,
2064
+ ClassName: Optional[str] = None,
2065
+ AutomationId: Optional[str] = None,
2066
+ Depth: Optional[int] = None,
2067
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2068
+ **searchProperties) -> 'SliderControl':
2069
+ return SliderControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
2070
+ foundIndex=foundIndex, element=element,
2071
+ Name=Name,
2072
+ SubName=SubName,
2073
+ RegexName=RegexName,
2074
+ ClassName=ClassName,
2075
+ AutomationId=AutomationId,
2076
+ Depth=Depth,
2077
+ Compare=Compare,
2078
+ **searchProperties)
2079
+
2080
+ def SpinnerControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
2081
+ Name: Optional[str] = None,
2082
+ SubName: Optional[str] = None,
2083
+ RegexName: Optional[str] = None,
2084
+ ClassName: Optional[str] = None,
2085
+ AutomationId: Optional[str] = None,
2086
+ Depth: Optional[int] = None,
2087
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2088
+ **searchProperties) -> 'SpinnerControl':
2089
+ return SpinnerControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
2090
+ foundIndex=foundIndex, element=element,
2091
+ Name=Name,
2092
+ SubName=SubName,
2093
+ RegexName=RegexName,
2094
+ ClassName=ClassName,
2095
+ AutomationId=AutomationId,
2096
+ Depth=Depth,
2097
+ Compare=Compare,
2098
+ **searchProperties)
2099
+
2100
+ def SplitButtonControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
2101
+ Name: Optional[str] = None,
2102
+ SubName: Optional[str] = None,
2103
+ RegexName: Optional[str] = None,
2104
+ ClassName: Optional[str] = None,
2105
+ AutomationId: Optional[str] = None,
2106
+ Depth: Optional[int] = None,
2107
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2108
+ **searchProperties) -> 'SplitButtonControl':
2109
+ return SplitButtonControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
2110
+ foundIndex=foundIndex, element=element,
2111
+ Name=Name,
2112
+ SubName=SubName,
2113
+ RegexName=RegexName,
2114
+ ClassName=ClassName,
2115
+ AutomationId=AutomationId,
2116
+ Depth=Depth,
2117
+ Compare=Compare,
2118
+ **searchProperties)
2119
+
2120
+ def StatusBarControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
2121
+ Name: Optional[str] = None,
2122
+ SubName: Optional[str] = None,
2123
+ RegexName: Optional[str] = None,
2124
+ ClassName: Optional[str] = None,
2125
+ AutomationId: Optional[str] = None,
2126
+ Depth: Optional[int] = None,
2127
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2128
+ **searchProperties) -> 'StatusBarControl':
2129
+ return StatusBarControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
2130
+ foundIndex=foundIndex, element=element,
2131
+ Name=Name,
2132
+ SubName=SubName,
2133
+ RegexName=RegexName,
2134
+ ClassName=ClassName,
2135
+ AutomationId=AutomationId,
2136
+ Depth=Depth,
2137
+ Compare=Compare,
2138
+ **searchProperties)
2139
+
2140
+ def TabControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
2141
+ Name: Optional[str] = None,
2142
+ SubName: Optional[str] = None,
2143
+ RegexName: Optional[str] = None,
2144
+ ClassName: Optional[str] = None,
2145
+ AutomationId: Optional[str] = None,
2146
+ Depth: Optional[int] = None,
2147
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2148
+ **searchProperties) -> 'TabControl':
2149
+ return TabControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
2150
+ foundIndex=foundIndex, element=element,
2151
+ Name=Name,
2152
+ SubName=SubName,
2153
+ RegexName=RegexName,
2154
+ ClassName=ClassName,
2155
+ AutomationId=AutomationId,
2156
+ Depth=Depth,
2157
+ Compare=Compare,
2158
+ **searchProperties)
2159
+
2160
+ def TabItemControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
2161
+ Name: Optional[str] = None,
2162
+ SubName: Optional[str] = None,
2163
+ RegexName: Optional[str] = None,
2164
+ ClassName: Optional[str] = None,
2165
+ AutomationId: Optional[str] = None,
2166
+ Depth: Optional[int] = None,
2167
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2168
+ **searchProperties) -> 'TabItemControl':
2169
+ return TabItemControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
2170
+ foundIndex=foundIndex, element=element,
2171
+ Name=Name,
2172
+ SubName=SubName,
2173
+ RegexName=RegexName,
2174
+ ClassName=ClassName,
2175
+ AutomationId=AutomationId,
2176
+ Depth=Depth,
2177
+ Compare=Compare,
2178
+ **searchProperties)
2179
+
2180
+ def TableControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
2181
+ Name: Optional[str] = None,
2182
+ SubName: Optional[str] = None,
2183
+ RegexName: Optional[str] = None,
2184
+ ClassName: Optional[str] = None,
2185
+ AutomationId: Optional[str] = None,
2186
+ Depth: Optional[int] = None,
2187
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2188
+ **searchProperties) -> 'TableControl':
2189
+ return TableControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
2190
+ foundIndex=foundIndex, element=element,
2191
+ Name=Name,
2192
+ SubName=SubName,
2193
+ RegexName=RegexName,
2194
+ ClassName=ClassName,
2195
+ AutomationId=AutomationId,
2196
+ Depth=Depth,
2197
+ Compare=Compare,
2198
+ **searchProperties)
2199
+
2200
+ def TextControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
2201
+ Name: Optional[str] = None,
2202
+ SubName: Optional[str] = None,
2203
+ RegexName: Optional[str] = None,
2204
+ ClassName: Optional[str] = None,
2205
+ AutomationId: Optional[str] = None,
2206
+ Depth: Optional[int] = None,
2207
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2208
+ **searchProperties) -> 'TextControl':
2209
+ return TextControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
2210
+ foundIndex=foundIndex, element=element,
2211
+ Name=Name,
2212
+ SubName=SubName,
2213
+ RegexName=RegexName,
2214
+ ClassName=ClassName,
2215
+ AutomationId=AutomationId,
2216
+ Depth=Depth,
2217
+ Compare=Compare,
2218
+ **searchProperties)
2219
+
2220
+ def ThumbControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
2221
+ Name: Optional[str] = None,
2222
+ SubName: Optional[str] = None,
2223
+ RegexName: Optional[str] = None,
2224
+ ClassName: Optional[str] = None,
2225
+ AutomationId: Optional[str] = None,
2226
+ Depth: Optional[int] = None,
2227
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2228
+ **searchProperties) -> 'ThumbControl':
2229
+ return ThumbControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
2230
+ foundIndex=foundIndex, element=element,
2231
+ Name=Name,
2232
+ SubName=SubName,
2233
+ RegexName=RegexName,
2234
+ ClassName=ClassName,
2235
+ AutomationId=AutomationId,
2236
+ Depth=Depth,
2237
+ Compare=Compare,
2238
+ **searchProperties)
2239
+
2240
+ def TitleBarControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
2241
+ Name: Optional[str] = None,
2242
+ SubName: Optional[str] = None,
2243
+ RegexName: Optional[str] = None,
2244
+ ClassName: Optional[str] = None,
2245
+ AutomationId: Optional[str] = None,
2246
+ Depth: Optional[int] = None,
2247
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2248
+ **searchProperties) -> 'TitleBarControl':
2249
+ return TitleBarControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
2250
+ foundIndex=foundIndex, element=element,
2251
+ Name=Name,
2252
+ SubName=SubName,
2253
+ RegexName=RegexName,
2254
+ ClassName=ClassName,
2255
+ AutomationId=AutomationId,
2256
+ Depth=Depth,
2257
+ Compare=Compare,
2258
+ **searchProperties)
2259
+
2260
+ def ToolBarControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
2261
+ Name: Optional[str] = None,
2262
+ SubName: Optional[str] = None,
2263
+ RegexName: Optional[str] = None,
2264
+ ClassName: Optional[str] = None,
2265
+ AutomationId: Optional[str] = None,
2266
+ Depth: Optional[int] = None,
2267
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2268
+ **searchProperties) -> 'ToolBarControl':
2269
+ return ToolBarControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
2270
+ foundIndex=foundIndex, element=element,
2271
+ Name=Name,
2272
+ SubName=SubName,
2273
+ RegexName=RegexName,
2274
+ ClassName=ClassName,
2275
+ AutomationId=AutomationId,
2276
+ Depth=Depth,
2277
+ Compare=Compare,
2278
+ **searchProperties)
2279
+
2280
+ def ToolTipControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
2281
+ Name: Optional[str] = None,
2282
+ SubName: Optional[str] = None,
2283
+ RegexName: Optional[str] = None,
2284
+ ClassName: Optional[str] = None,
2285
+ AutomationId: Optional[str] = None,
2286
+ Depth: Optional[int] = None,
2287
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2288
+ **searchProperties) -> 'ToolTipControl':
2289
+ return ToolTipControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
2290
+ foundIndex=foundIndex, element=element,
2291
+ Name=Name,
2292
+ SubName=SubName,
2293
+ RegexName=RegexName,
2294
+ ClassName=ClassName,
2295
+ AutomationId=AutomationId,
2296
+ Depth=Depth,
2297
+ Compare=Compare,
2298
+ **searchProperties)
2299
+
2300
+ def TreeControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
2301
+ Name: Optional[str] = None,
2302
+ SubName: Optional[str] = None,
2303
+ RegexName: Optional[str] = None,
2304
+ ClassName: Optional[str] = None,
2305
+ AutomationId: Optional[str] = None,
2306
+ Depth: Optional[int] = None,
2307
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2308
+ **searchProperties) -> 'TreeControl':
2309
+ return TreeControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
2310
+ foundIndex=foundIndex, element=element,
2311
+ Name=Name,
2312
+ SubName=SubName,
2313
+ RegexName=RegexName,
2314
+ ClassName=ClassName,
2315
+ AutomationId=AutomationId,
2316
+ Depth=Depth,
2317
+ Compare=Compare,
2318
+ **searchProperties)
2319
+
2320
+ def TreeItemControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
2321
+ Name: Optional[str] = None,
2322
+ SubName: Optional[str] = None,
2323
+ RegexName: Optional[str] = None,
2324
+ ClassName: Optional[str] = None,
2325
+ AutomationId: Optional[str] = None,
2326
+ Depth: Optional[int] = None,
2327
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2328
+ **searchProperties) -> 'TreeItemControl':
2329
+ return TreeItemControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
2330
+ foundIndex=foundIndex, element=element,
2331
+ Name=Name,
2332
+ SubName=SubName,
2333
+ RegexName=RegexName,
2334
+ ClassName=ClassName,
2335
+ AutomationId=AutomationId,
2336
+ Depth=Depth,
2337
+ Compare=Compare,
2338
+ **searchProperties)
2339
+
2340
+ def WindowControl(self, searchDepth=0xFFFFFFFF, searchInterval=SEARCH_INTERVAL, foundIndex=1, element=0,
2341
+ Name: Optional[str] = None,
2342
+ SubName: Optional[str] = None,
2343
+ RegexName: Optional[str] = None,
2344
+ ClassName: Optional[str] = None,
2345
+ AutomationId: Optional[str] = None,
2346
+ Depth: Optional[int] = None,
2347
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2348
+ **searchProperties) -> 'WindowControl':
2349
+ return WindowControl(searchFromControl=self, searchDepth=searchDepth, searchInterval=searchInterval,
2350
+ foundIndex=foundIndex, element=element,
2351
+ Name=Name,
2352
+ SubName=SubName,
2353
+ RegexName=RegexName,
2354
+ ClassName=ClassName,
2355
+ AutomationId=AutomationId,
2356
+ Depth=Depth,
2357
+ Compare=Compare,
2358
+ **searchProperties)
2359
+
2360
+
2361
+ class AppBarControl(Control):
2362
+ def __init__(self, searchFromControl: Optional[Control] = None,
2363
+ searchDepth: int = 0xFFFFFFFF,
2364
+ searchInterval: float = SEARCH_INTERVAL,
2365
+ foundIndex: int = 1,
2366
+ element=None,
2367
+ Name: Optional[str] = None,
2368
+ SubName: Optional[str] = None,
2369
+ RegexName: Optional[str] = None,
2370
+ ClassName: Optional[str] = None,
2371
+ AutomationId: Optional[str] = None,
2372
+ Depth: Optional[int] = None,
2373
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2374
+ **searchProperties):
2375
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
2376
+ ControlType=ControlType.AppBarControl,
2377
+ Name=Name,
2378
+ SubName=SubName,
2379
+ RegexName=RegexName,
2380
+ ClassName=ClassName,
2381
+ AutomationId=AutomationId,
2382
+ Depth=Depth,
2383
+ Compare=Compare,
2384
+ **searchProperties)
2385
+
2386
+
2387
+ class ButtonControl(Control):
2388
+ def __init__(self, searchFromControl: Optional[Control] = None,
2389
+ searchDepth: int = 0xFFFFFFFF,
2390
+ searchInterval: float = SEARCH_INTERVAL,
2391
+ foundIndex: int = 1,
2392
+ element=None,
2393
+ Name: Optional[str] = None,
2394
+ SubName: Optional[str] = None,
2395
+ RegexName: Optional[str] = None,
2396
+ ClassName: Optional[str] = None,
2397
+ AutomationId: Optional[str] = None,
2398
+ Depth: Optional[int] = None,
2399
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2400
+ **searchProperties):
2401
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
2402
+ ControlType=ControlType.ButtonControl,
2403
+ Name=Name,
2404
+ SubName=SubName,
2405
+ RegexName=RegexName,
2406
+ ClassName=ClassName,
2407
+ AutomationId=AutomationId,
2408
+ Depth=Depth,
2409
+ Compare=Compare,
2410
+ **searchProperties)
2411
+
2412
+ def GetExpandCollapsePattern(self) -> ExpandCollapsePattern:
2413
+ """
2414
+ Return `ExpandCollapsePattern` if it supports the pattern else None(Conditional support according to MSDN).
2415
+ """
2416
+ return self.GetPattern(PatternId.ExpandCollapsePattern)
2417
+
2418
+ def GetInvokePattern(self) -> InvokePattern:
2419
+ """
2420
+ Return `InvokePattern` if it supports the pattern else None(Conditional support according to MSDN).
2421
+ """
2422
+ return self.GetPattern(PatternId.InvokePattern)
2423
+
2424
+ def GetTogglePattern(self) -> TogglePattern:
2425
+ """
2426
+ Return `TogglePattern` if it supports the pattern else None(Conditional support according to MSDN).
2427
+ """
2428
+ return self.GetPattern(PatternId.TogglePattern)
2429
+
2430
+
2431
+ class CalendarControl(Control):
2432
+ def __init__(self, searchFromControl: Optional[Control] = None,
2433
+ searchDepth: int = 0xFFFFFFFF,
2434
+ searchInterval: float = SEARCH_INTERVAL,
2435
+ foundIndex: int = 1,
2436
+ element=None,
2437
+ Name: Optional[str] = None,
2438
+ SubName: Optional[str] = None,
2439
+ RegexName: Optional[str] = None,
2440
+ ClassName: Optional[str] = None,
2441
+ AutomationId: Optional[str] = None,
2442
+ Depth: Optional[int] = None,
2443
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2444
+ **searchProperties):
2445
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
2446
+ ControlType=ControlType.CalendarControl,
2447
+ Name=Name,
2448
+ SubName=SubName,
2449
+ RegexName=RegexName,
2450
+ ClassName=ClassName,
2451
+ AutomationId=AutomationId,
2452
+ Depth=Depth,
2453
+ Compare=Compare,
2454
+ **searchProperties)
2455
+
2456
+ def GetGridPattern(self) -> GridPattern:
2457
+ """
2458
+ Return `GridPattern` if it supports the pattern else None(Must support according to MSDN).
2459
+ """
2460
+ return self.GetPattern(PatternId.GridPattern)
2461
+
2462
+ def GetTablePattern(self) -> TablePattern:
2463
+ """
2464
+ Return `TablePattern` if it supports the pattern else None(Must support according to MSDN).
2465
+ """
2466
+ return self.GetPattern(PatternId.TablePattern)
2467
+
2468
+ def GetScrollPattern(self) -> ScrollPattern:
2469
+ """
2470
+ Return `ScrollPattern` if it supports the pattern else None(Conditional support according to MSDN).
2471
+ """
2472
+ return self.GetPattern(PatternId.ScrollPattern)
2473
+
2474
+ def GetSelectionPattern(self) -> SelectionPattern:
2475
+ """
2476
+ Return `SelectionPattern` if it supports the pattern else None(Conditional support according to MSDN).
2477
+ """
2478
+ return self.GetPattern(PatternId.SelectionPattern)
2479
+
2480
+
2481
+ class CheckBoxControl(Control):
2482
+ def __init__(self, searchFromControl: Optional[Control] = None,
2483
+ searchDepth: int = 0xFFFFFFFF,
2484
+ searchInterval: float = SEARCH_INTERVAL,
2485
+ foundIndex: int = 1,
2486
+ element=None,
2487
+ Name: Optional[str] = None,
2488
+ SubName: Optional[str] = None,
2489
+ RegexName: Optional[str] = None,
2490
+ ClassName: Optional[str] = None,
2491
+ AutomationId: Optional[str] = None,
2492
+ Depth: Optional[int] = None,
2493
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2494
+ **searchProperties):
2495
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
2496
+ ControlType=ControlType.CheckBoxControl,
2497
+ Name=Name,
2498
+ SubName=SubName,
2499
+ RegexName=RegexName,
2500
+ ClassName=ClassName,
2501
+ AutomationId=AutomationId,
2502
+ Depth=Depth,
2503
+ Compare=Compare,
2504
+ **searchProperties)
2505
+
2506
+ def GetTogglePattern(self) -> TogglePattern:
2507
+ """
2508
+ Return `TogglePattern` if it supports the pattern else None(Must support according to MSDN).
2509
+ """
2510
+ return self.GetPattern(PatternId.TogglePattern)
2511
+
2512
+ def SetChecked(self, checked: bool) -> bool:
2513
+ '''Return True if set successfully'''
2514
+ tp = self.GetTogglePattern()
2515
+ if tp:
2516
+ return tp.SetToggleState(ToggleState.On if checked else ToggleState.Off)
2517
+ return False
2518
+
2519
+
2520
+ class ComboBoxControl(Control):
2521
+ def __init__(self, searchFromControl: Optional[Control] = None,
2522
+ searchDepth: int = 0xFFFFFFFF,
2523
+ searchInterval: float = SEARCH_INTERVAL,
2524
+ foundIndex: int = 1,
2525
+ element=None,
2526
+ Name: Optional[str] = None,
2527
+ SubName: Optional[str] = None,
2528
+ RegexName: Optional[str] = None,
2529
+ ClassName: Optional[str] = None,
2530
+ AutomationId: Optional[str] = None,
2531
+ Depth: Optional[int] = None,
2532
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2533
+ **searchProperties):
2534
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
2535
+ ControlType=ControlType.ComboBoxControl,
2536
+ Name=Name,
2537
+ SubName=SubName,
2538
+ RegexName=RegexName,
2539
+ ClassName=ClassName,
2540
+ AutomationId=AutomationId,
2541
+ Depth=Depth,
2542
+ Compare=Compare,
2543
+ **searchProperties)
2544
+
2545
+ def GetExpandCollapsePattern(self) -> ExpandCollapsePattern:
2546
+ """
2547
+ Return `ExpandCollapsePattern` if it supports the pattern else None(Must support according to MSDN).
2548
+ """
2549
+ return self.GetPattern(PatternId.ExpandCollapsePattern)
2550
+
2551
+ def GetSelectionPattern(self) -> SelectionPattern:
2552
+ """
2553
+ Return `SelectionPattern` if it supports the pattern else None(Conditional support according to MSDN).
2554
+ """
2555
+ return self.GetPattern(PatternId.SelectionPattern)
2556
+
2557
+ def GetValuePattern(self) -> ValuePattern:
2558
+ """
2559
+ Return `ValuePattern` if it supports the pattern else None(Conditional support according to MSDN).
2560
+ """
2561
+ return self.GetPattern(PatternId.ValuePattern)
2562
+
2563
+ def Select(self, itemName: str = '', condition: Optional[Callable[[str], bool]] = None, simulateMove: bool = True, waitTime: float = OPERATION_WAIT_TIME) -> bool:
2564
+ """
2565
+ Show combobox's popup menu and select a item by name.
2566
+ itemName: str.
2567
+ condition: Callable[[str], bool], function(comboBoxItemName: str) -> bool, if condition is valid, ignore itemName.
2568
+ waitTime: float.
2569
+ Some comboboxs doesn't support SelectionPattern, here is a workaround.
2570
+ This method tries to add selection support.
2571
+ It may not work for some comboboxes, such as comboboxes in older Qt version.
2572
+ If it doesn't work, you should write your own version Select, or it doesn't support selection at all.
2573
+ """
2574
+ expandCollapsePattern = self.GetExpandCollapsePattern()
2575
+ if expandCollapsePattern:
2576
+ expandCollapsePattern.Expand()
2577
+ else:
2578
+ # Windows Form's ComboBoxControl doesn't support ExpandCollapsePattern
2579
+ self.Click(x=-10, ratioY=0.5, simulateMove=simulateMove)
2580
+ find = False
2581
+ if condition:
2582
+ listItemControl = self.ListItemControl(Compare=lambda c, d: condition(c.Name))
2583
+ else:
2584
+ listItemControl = self.ListItemControl(Name=itemName)
2585
+ if listItemControl.Exists(1):
2586
+ scrollItemPattern = listItemControl.GetScrollItemPattern()
2587
+ if scrollItemPattern:
2588
+ scrollItemPattern.ScrollIntoView(waitTime=0.1)
2589
+ listItemControl.Click(simulateMove=simulateMove, waitTime=waitTime)
2590
+ find = True
2591
+ else:
2592
+ # some ComboBox's popup window is a child of root control
2593
+ listControl = ListControl(searchDepth=1)
2594
+ if listControl.Exists(1):
2595
+ if condition:
2596
+ listItemControl = listControl.ListItemControl(Compare=lambda c, d: condition(c.Name))
2597
+ else:
2598
+ listItemControl = listControl.ListItemControl(Name=itemName)
2599
+ if listItemControl.Exists(0, 0):
2600
+ scrollItemPattern = listItemControl.GetScrollItemPattern()
2601
+ if scrollItemPattern:
2602
+ scrollItemPattern.ScrollIntoView(waitTime=0.1)
2603
+ listItemControl.Click(simulateMove=simulateMove, waitTime=waitTime)
2604
+ find = True
2605
+ if not find:
2606
+ Logger.ColorfullyLog('Can\'t find <Color=Cyan>{}</Color> in ComboBoxControl or it does not support selection.'.format(itemName), ConsoleColor.Yellow)
2607
+ if expandCollapsePattern:
2608
+ expandCollapsePattern.Collapse(waitTime)
2609
+ else:
2610
+ self.Click(x=-10, ratioY=0.5, simulateMove=simulateMove, waitTime=waitTime)
2611
+ return find
2612
+
2613
+
2614
+ class CustomControl(Control):
2615
+ def __init__(self, searchFromControl: Optional[Control] = None,
2616
+ searchDepth: int = 0xFFFFFFFF,
2617
+ searchInterval: float = SEARCH_INTERVAL,
2618
+ foundIndex: int = 1,
2619
+ element=None,
2620
+ Name: Optional[str] = None,
2621
+ SubName: Optional[str] = None,
2622
+ RegexName: Optional[str] = None,
2623
+ ClassName: Optional[str] = None,
2624
+ AutomationId: Optional[str] = None,
2625
+ Depth: Optional[int] = None,
2626
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2627
+ **searchProperties):
2628
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
2629
+ ControlType=ControlType.CustomControl,
2630
+ Name=Name,
2631
+ SubName=SubName,
2632
+ RegexName=RegexName,
2633
+ ClassName=ClassName,
2634
+ AutomationId=AutomationId,
2635
+ Depth=Depth,
2636
+ Compare=Compare,
2637
+ **searchProperties)
2638
+
2639
+
2640
+ class DataGridControl(Control):
2641
+ def __init__(self, searchFromControl: Optional[Control] = None,
2642
+ searchDepth: int = 0xFFFFFFFF,
2643
+ searchInterval: float = SEARCH_INTERVAL,
2644
+ foundIndex: int = 1,
2645
+ element=None,
2646
+ Name: Optional[str] = None,
2647
+ SubName: Optional[str] = None,
2648
+ RegexName: Optional[str] = None,
2649
+ ClassName: Optional[str] = None,
2650
+ AutomationId: Optional[str] = None,
2651
+ Depth: Optional[int] = None,
2652
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2653
+ **searchProperties):
2654
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
2655
+ ControlType=ControlType.DataGridControl,
2656
+ Name=Name,
2657
+ SubName=SubName,
2658
+ RegexName=RegexName,
2659
+ ClassName=ClassName,
2660
+ AutomationId=AutomationId,
2661
+ Depth=Depth,
2662
+ Compare=Compare,
2663
+ **searchProperties)
2664
+
2665
+ def GetGridPattern(self) -> GridPattern:
2666
+ """
2667
+ Return `GridPattern` if it supports the pattern else None(Must support according to MSDN).
2668
+ """
2669
+ return self.GetPattern(PatternId.GridPattern)
2670
+
2671
+ def GetScrollPattern(self) -> ScrollPattern:
2672
+ """
2673
+ Return `ScrollPattern` if it supports the pattern else None(Conditional support according to MSDN).
2674
+ """
2675
+ return self.GetPattern(PatternId.ScrollPattern)
2676
+
2677
+ def GetSelectionPattern(self) -> SelectionPattern:
2678
+ """
2679
+ Return `SelectionPattern` if it supports the pattern else None(Conditional support according to MSDN).
2680
+ """
2681
+ return self.GetPattern(PatternId.SelectionPattern)
2682
+
2683
+ def GetTablePattern(self) -> TablePattern:
2684
+ """
2685
+ Return `TablePattern` if it supports the pattern else None(Conditional support according to MSDN).
2686
+ """
2687
+ return self.GetPattern(PatternId.TablePattern)
2688
+
2689
+
2690
+ class DataItemControl(Control):
2691
+ def __init__(self, searchFromControl: Optional[Control] = None,
2692
+ searchDepth: int = 0xFFFFFFFF,
2693
+ searchInterval: float = SEARCH_INTERVAL,
2694
+ foundIndex: int = 1,
2695
+ element=None,
2696
+ Name: Optional[str] = None,
2697
+ SubName: Optional[str] = None,
2698
+ RegexName: Optional[str] = None,
2699
+ ClassName: Optional[str] = None,
2700
+ AutomationId: Optional[str] = None,
2701
+ Depth: Optional[int] = None,
2702
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2703
+ **searchProperties):
2704
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
2705
+ ControlType=ControlType.DataItemControl,
2706
+ Name=Name,
2707
+ SubName=SubName,
2708
+ RegexName=RegexName,
2709
+ ClassName=ClassName,
2710
+ AutomationId=AutomationId,
2711
+ Depth=Depth,
2712
+ Compare=Compare,
2713
+ **searchProperties)
2714
+
2715
+ def GetSelectionItemPattern(self) -> SelectionItemPattern:
2716
+ """
2717
+ Return `SelectionItemPattern` if it supports the pattern else None(Must support according to MSDN).
2718
+ """
2719
+ return self.GetPattern(PatternId.SelectionItemPattern)
2720
+
2721
+ def GetExpandCollapsePattern(self) -> ExpandCollapsePattern:
2722
+ """
2723
+ Return `ExpandCollapsePattern` if it supports the pattern else None(Conditional support according to MSDN).
2724
+ """
2725
+ return self.GetPattern(PatternId.ExpandCollapsePattern)
2726
+
2727
+ def GetGridItemPattern(self) -> GridItemPattern:
2728
+ """
2729
+ Return `GridItemPattern` if it supports the pattern else None(Conditional support according to MSDN).
2730
+ """
2731
+ return self.GetPattern(PatternId.GridItemPattern)
2732
+
2733
+ def GetScrollItemPattern(self) -> ScrollItemPattern:
2734
+ """
2735
+ Return `ScrollItemPattern` if it supports the pattern else None(Conditional support according to MSDN).
2736
+ """
2737
+ return self.GetPattern(PatternId.ScrollItemPattern)
2738
+
2739
+ def GetTableItemPattern(self) -> TableItemPattern:
2740
+ """
2741
+ Return `TableItemPattern` if it supports the pattern else None(Conditional support according to MSDN).
2742
+ """
2743
+ return self.GetPattern(PatternId.TableItemPattern)
2744
+
2745
+ def GetTogglePattern(self) -> TogglePattern:
2746
+ """
2747
+ Return `TogglePattern` if it supports the pattern else None(Conditional support according to MSDN).
2748
+ """
2749
+ return self.GetPattern(PatternId.TogglePattern)
2750
+
2751
+ def GetValuePattern(self) -> ValuePattern:
2752
+ """
2753
+ Return `ValuePattern` if it supports the pattern else None(Conditional support according to MSDN).
2754
+ """
2755
+ return self.GetPattern(PatternId.ValuePattern)
2756
+
2757
+
2758
+ class DocumentControl(Control):
2759
+ def __init__(self, searchFromControl: Optional[Control] = None,
2760
+ searchDepth: int = 0xFFFFFFFF,
2761
+ searchInterval: float = SEARCH_INTERVAL,
2762
+ foundIndex: int = 1,
2763
+ element=None,
2764
+ Name: Optional[str] = None,
2765
+ SubName: Optional[str] = None,
2766
+ RegexName: Optional[str] = None,
2767
+ ClassName: Optional[str] = None,
2768
+ AutomationId: Optional[str] = None,
2769
+ Depth: Optional[int] = None,
2770
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2771
+ **searchProperties):
2772
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
2773
+ ControlType=ControlType.DocumentControl,
2774
+ Name=Name,
2775
+ SubName=SubName,
2776
+ RegexName=RegexName,
2777
+ ClassName=ClassName,
2778
+ AutomationId=AutomationId,
2779
+ Depth=Depth,
2780
+ Compare=Compare,
2781
+ **searchProperties)
2782
+
2783
+ def GetTextPattern(self) -> TextPattern:
2784
+ """
2785
+ Return `TextPattern` if it supports the pattern else None(Must support according to MSDN).
2786
+ """
2787
+ return self.GetPattern(PatternId.TextPattern)
2788
+
2789
+ def GetScrollPattern(self) -> ScrollPattern:
2790
+ """
2791
+ Return `ScrollPattern` if it supports the pattern else None(Conditional support according to MSDN).
2792
+ """
2793
+ return self.GetPattern(PatternId.ScrollPattern)
2794
+
2795
+ def GetValuePattern(self) -> ValuePattern:
2796
+ """
2797
+ Return `ValuePattern` if it supports the pattern else None(Conditional support according to MSDN).
2798
+ """
2799
+ return self.GetPattern(PatternId.ValuePattern)
2800
+
2801
+
2802
+ class EditControl(Control):
2803
+ def __init__(self, searchFromControl: Optional[Control] = None,
2804
+ searchDepth: int = 0xFFFFFFFF,
2805
+ searchInterval: float = SEARCH_INTERVAL,
2806
+ foundIndex: int = 1,
2807
+ element=None,
2808
+ Name: Optional[str] = None,
2809
+ SubName: Optional[str] = None,
2810
+ RegexName: Optional[str] = None,
2811
+ ClassName: Optional[str] = None,
2812
+ AutomationId: Optional[str] = None,
2813
+ Depth: Optional[int] = None,
2814
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2815
+ **searchProperties):
2816
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
2817
+ ControlType=ControlType.EditControl,
2818
+ Name=Name,
2819
+ SubName=SubName,
2820
+ RegexName=RegexName,
2821
+ ClassName=ClassName,
2822
+ AutomationId=AutomationId,
2823
+ Depth=Depth,
2824
+ Compare=Compare,
2825
+ **searchProperties)
2826
+
2827
+ def GetRangeValuePattern(self) -> RangeValuePattern:
2828
+ """
2829
+ Return `RangeValuePattern` if it supports the pattern else None(Conditional support according to MSDN).
2830
+ """
2831
+ return self.GetPattern(PatternId.RangeValuePattern)
2832
+
2833
+ def GetTextPattern(self) -> TextPattern:
2834
+ """
2835
+ Return `TextPattern` if it supports the pattern else None(Conditional support according to MSDN).
2836
+ """
2837
+ return self.GetPattern(PatternId.TextPattern)
2838
+
2839
+ def GetValuePattern(self) -> ValuePattern:
2840
+ """
2841
+ Return `ValuePattern` if it supports the pattern else None(Conditional support according to MSDN).
2842
+ """
2843
+ return self.GetPattern(PatternId.ValuePattern)
2844
+
2845
+
2846
+ class GroupControl(Control):
2847
+ def __init__(self, searchFromControl: Optional[Control] = None,
2848
+ searchDepth: int = 0xFFFFFFFF,
2849
+ searchInterval: float = SEARCH_INTERVAL,
2850
+ foundIndex: int = 1,
2851
+ element=None,
2852
+ Name: Optional[str] = None,
2853
+ SubName: Optional[str] = None,
2854
+ RegexName: Optional[str] = None,
2855
+ ClassName: Optional[str] = None,
2856
+ AutomationId: Optional[str] = None,
2857
+ Depth: Optional[int] = None,
2858
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2859
+ **searchProperties):
2860
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
2861
+ ControlType=ControlType.GroupControl,
2862
+ Name=Name,
2863
+ SubName=SubName,
2864
+ RegexName=RegexName,
2865
+ ClassName=ClassName,
2866
+ AutomationId=AutomationId,
2867
+ Depth=Depth,
2868
+ Compare=Compare,
2869
+ **searchProperties)
2870
+
2871
+ def GetExpandCollapsePattern(self) -> ExpandCollapsePattern:
2872
+ """
2873
+ Return `ExpandCollapsePattern` if it supports the pattern else None(Conditional support according to MSDN).
2874
+ """
2875
+ return self.GetPattern(PatternId.ExpandCollapsePattern)
2876
+
2877
+
2878
+ class HeaderControl(Control):
2879
+ def __init__(self, searchFromControl: Optional[Control] = None,
2880
+ searchDepth: int = 0xFFFFFFFF,
2881
+ searchInterval: float = SEARCH_INTERVAL,
2882
+ foundIndex: int = 1,
2883
+ element=None,
2884
+ Name: Optional[str] = None,
2885
+ SubName: Optional[str] = None,
2886
+ RegexName: Optional[str] = None,
2887
+ ClassName: Optional[str] = None,
2888
+ AutomationId: Optional[str] = None,
2889
+ Depth: Optional[int] = None,
2890
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2891
+ **searchProperties):
2892
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
2893
+ ControlType=ControlType.HeaderControl,
2894
+ Name=Name,
2895
+ SubName=SubName,
2896
+ RegexName=RegexName,
2897
+ ClassName=ClassName,
2898
+ AutomationId=AutomationId,
2899
+ Depth=Depth,
2900
+ Compare=Compare,
2901
+ **searchProperties)
2902
+
2903
+ def GetTransformPattern(self) -> TransformPattern:
2904
+ """
2905
+ Return `TransformPattern` if it supports the pattern else None(Conditional support according to MSDN).
2906
+ """
2907
+ return self.GetPattern(PatternId.TransformPattern)
2908
+
2909
+
2910
+ class HeaderItemControl(Control):
2911
+ def __init__(self, searchFromControl: Optional[Control] = None,
2912
+ searchDepth: int = 0xFFFFFFFF,
2913
+ searchInterval: float = SEARCH_INTERVAL,
2914
+ foundIndex: int = 1,
2915
+ element=None,
2916
+ Name: Optional[str] = None,
2917
+ SubName: Optional[str] = None,
2918
+ RegexName: Optional[str] = None,
2919
+ ClassName: Optional[str] = None,
2920
+ AutomationId: Optional[str] = None,
2921
+ Depth: Optional[int] = None,
2922
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2923
+ **searchProperties):
2924
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
2925
+ ControlType=ControlType.HeaderItemControl,
2926
+ Name=Name,
2927
+ SubName=SubName,
2928
+ RegexName=RegexName,
2929
+ ClassName=ClassName,
2930
+ AutomationId=AutomationId,
2931
+ Depth=Depth,
2932
+ Compare=Compare,
2933
+ **searchProperties)
2934
+
2935
+ def GetInvokePattern(self) -> InvokePattern:
2936
+ """
2937
+ Return `InvokePattern` if it supports the pattern else None(Conditional support according to MSDN).
2938
+ """
2939
+ return self.GetPattern(PatternId.InvokePattern)
2940
+
2941
+ def GetTransformPattern(self) -> TransformPattern:
2942
+ """
2943
+ Return `TransformPattern` if it supports the pattern else None(Conditional support according to MSDN).
2944
+ """
2945
+ return self.GetPattern(PatternId.TransformPattern)
2946
+
2947
+
2948
+ class HyperlinkControl(Control):
2949
+ def __init__(self, searchFromControl: Optional[Control] = None,
2950
+ searchDepth: int = 0xFFFFFFFF,
2951
+ searchInterval: float = SEARCH_INTERVAL,
2952
+ foundIndex: int = 1,
2953
+ element=None,
2954
+ Name: Optional[str] = None,
2955
+ SubName: Optional[str] = None,
2956
+ RegexName: Optional[str] = None,
2957
+ ClassName: Optional[str] = None,
2958
+ AutomationId: Optional[str] = None,
2959
+ Depth: Optional[int] = None,
2960
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2961
+ **searchProperties):
2962
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
2963
+ ControlType=ControlType.HyperlinkControl,
2964
+ Name=Name,
2965
+ SubName=SubName,
2966
+ RegexName=RegexName,
2967
+ ClassName=ClassName,
2968
+ AutomationId=AutomationId,
2969
+ Depth=Depth,
2970
+ Compare=Compare,
2971
+ **searchProperties)
2972
+
2973
+ def GetInvokePattern(self) -> InvokePattern:
2974
+ """
2975
+ Return `InvokePattern` if it supports the pattern else None(Must support according to MSDN).
2976
+ """
2977
+ return self.GetPattern(PatternId.InvokePattern)
2978
+
2979
+ def GetValuePattern(self) -> ValuePattern:
2980
+ """
2981
+ Return `ValuePattern` if it supports the pattern else None(Conditional support according to MSDN).
2982
+ """
2983
+ return self.GetPattern(PatternId.ValuePattern)
2984
+
2985
+
2986
+ class ImageControl(Control):
2987
+ def __init__(self, searchFromControl: Optional[Control] = None,
2988
+ searchDepth: int = 0xFFFFFFFF,
2989
+ searchInterval: float = SEARCH_INTERVAL,
2990
+ foundIndex: int = 1,
2991
+ element=None,
2992
+ Name: Optional[str] = None,
2993
+ SubName: Optional[str] = None,
2994
+ RegexName: Optional[str] = None,
2995
+ ClassName: Optional[str] = None,
2996
+ AutomationId: Optional[str] = None,
2997
+ Depth: Optional[int] = None,
2998
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
2999
+ **searchProperties):
3000
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
3001
+ ControlType=ControlType.ImageControl,
3002
+ Name=Name,
3003
+ SubName=SubName,
3004
+ RegexName=RegexName,
3005
+ ClassName=ClassName,
3006
+ AutomationId=AutomationId,
3007
+ Depth=Depth,
3008
+ Compare=Compare,
3009
+ **searchProperties)
3010
+
3011
+ def GetGridItemPattern(self) -> GridItemPattern:
3012
+ """
3013
+ Return `GridItemPattern` if it supports the pattern else None(Conditional support according to MSDN).
3014
+ """
3015
+ return self.GetPattern(PatternId.GridItemPattern)
3016
+
3017
+ def GetTableItemPattern(self) -> TableItemPattern:
3018
+ """
3019
+ Return `TableItemPattern` if it supports the pattern else None(Conditional support according to MSDN).
3020
+ """
3021
+ return self.GetPattern(PatternId.TableItemPattern)
3022
+
3023
+
3024
+ class ListControl(Control):
3025
+ def __init__(self, searchFromControl: Optional[Control] = None,
3026
+ searchDepth: int = 0xFFFFFFFF,
3027
+ searchInterval: float = SEARCH_INTERVAL,
3028
+ foundIndex: int = 1,
3029
+ element=None,
3030
+ Name: Optional[str] = None,
3031
+ SubName: Optional[str] = None,
3032
+ RegexName: Optional[str] = None,
3033
+ ClassName: Optional[str] = None,
3034
+ AutomationId: Optional[str] = None,
3035
+ Depth: Optional[int] = None,
3036
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
3037
+ **searchProperties):
3038
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
3039
+ ControlType=ControlType.ListControl,
3040
+ Name=Name,
3041
+ SubName=SubName,
3042
+ RegexName=RegexName,
3043
+ ClassName=ClassName,
3044
+ AutomationId=AutomationId,
3045
+ Depth=Depth,
3046
+ Compare=Compare,
3047
+ **searchProperties)
3048
+
3049
+ def GetGridPattern(self) -> GridPattern:
3050
+ """
3051
+ Return `GridPattern` if it supports the pattern else None(Conditional support according to MSDN).
3052
+ """
3053
+ return self.GetPattern(PatternId.GridPattern)
3054
+
3055
+ def GetMultipleViewPattern(self) -> MultipleViewPattern:
3056
+ """
3057
+ Return `MultipleViewPattern` if it supports the pattern else None(Conditional support according to MSDN).
3058
+ """
3059
+ return self.GetPattern(PatternId.MultipleViewPattern)
3060
+
3061
+ def GetScrollPattern(self) -> ScrollPattern:
3062
+ """
3063
+ Return `ScrollPattern` if it supports the pattern else None(Conditional support according to MSDN).
3064
+ """
3065
+ return self.GetPattern(PatternId.ScrollPattern)
3066
+
3067
+ def GetSelectionPattern(self) -> SelectionPattern:
3068
+ """
3069
+ Return `SelectionPattern` if it supports the pattern else None(Conditional support according to MSDN).
3070
+ """
3071
+ return self.GetPattern(PatternId.SelectionPattern)
3072
+
3073
+
3074
+ class ListItemControl(Control):
3075
+ def __init__(self, searchFromControl: Optional[Control] = None,
3076
+ searchDepth: int = 0xFFFFFFFF,
3077
+ searchInterval: float = SEARCH_INTERVAL,
3078
+ foundIndex: int = 1,
3079
+ element=None,
3080
+ Name: Optional[str] = None,
3081
+ SubName: Optional[str] = None,
3082
+ RegexName: Optional[str] = None,
3083
+ ClassName: Optional[str] = None,
3084
+ AutomationId: Optional[str] = None,
3085
+ Depth: Optional[int] = None,
3086
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
3087
+ **searchProperties):
3088
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
3089
+ ControlType=ControlType.ListItemControl,
3090
+ Name=Name,
3091
+ SubName=SubName,
3092
+ RegexName=RegexName,
3093
+ ClassName=ClassName,
3094
+ AutomationId=AutomationId,
3095
+ Depth=Depth,
3096
+ Compare=Compare,
3097
+ **searchProperties)
3098
+
3099
+ def GetSelectionItemPattern(self) -> SelectionItemPattern:
3100
+ """
3101
+ Return `SelectionItemPattern` if it supports the pattern else None(Must support according to MSDN).
3102
+ """
3103
+ return self.GetPattern(PatternId.SelectionItemPattern)
3104
+
3105
+ def GetExpandCollapsePattern(self) -> ExpandCollapsePattern:
3106
+ """
3107
+ Return `ExpandCollapsePattern` if it supports the pattern else None(Conditional support according to MSDN).
3108
+ """
3109
+ return self.GetPattern(PatternId.ExpandCollapsePattern)
3110
+
3111
+ def GetGridItemPattern(self) -> GridItemPattern:
3112
+ """
3113
+ Return `GridItemPattern` if it supports the pattern else None(Conditional support according to MSDN).
3114
+ """
3115
+ return self.GetPattern(PatternId.GridItemPattern)
3116
+
3117
+ def GetInvokePattern(self) -> InvokePattern:
3118
+ """
3119
+ Return `InvokePattern` if it supports the pattern else None(Conditional support according to MSDN).
3120
+ """
3121
+ return self.GetPattern(PatternId.InvokePattern)
3122
+
3123
+ def GetScrollItemPattern(self) -> ScrollItemPattern:
3124
+ """
3125
+ Return `ScrollItemPattern` if it supports the pattern else None(Conditional support according to MSDN).
3126
+ """
3127
+ return self.GetPattern(PatternId.ScrollItemPattern)
3128
+
3129
+ def GetTogglePattern(self) -> TogglePattern:
3130
+ """
3131
+ Return `TogglePattern` if it supports the pattern else None(Conditional support according to MSDN).
3132
+ """
3133
+ return self.GetPattern(PatternId.TogglePattern)
3134
+
3135
+ def GetValuePattern(self) -> ValuePattern:
3136
+ """
3137
+ Return `ValuePattern` if it supports the pattern else None(Conditional support according to MSDN).
3138
+ """
3139
+ return self.GetPattern(PatternId.ValuePattern)
3140
+
3141
+
3142
+ class MenuControl(Control):
3143
+ def __init__(self, searchFromControl: Optional[Control] = None,
3144
+ searchDepth: int = 0xFFFFFFFF,
3145
+ searchInterval: float = SEARCH_INTERVAL,
3146
+ foundIndex: int = 1,
3147
+ element=None,
3148
+ Name: Optional[str] = None,
3149
+ SubName: Optional[str] = None,
3150
+ RegexName: Optional[str] = None,
3151
+ ClassName: Optional[str] = None,
3152
+ AutomationId: Optional[str] = None,
3153
+ Depth: Optional[int] = None,
3154
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
3155
+ **searchProperties):
3156
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
3157
+ ControlType=ControlType.MenuControl,
3158
+ Name=Name,
3159
+ SubName=SubName,
3160
+ RegexName=RegexName,
3161
+ ClassName=ClassName,
3162
+ AutomationId=AutomationId,
3163
+ Depth=Depth,
3164
+ Compare=Compare,
3165
+ **searchProperties)
3166
+
3167
+
3168
+ class MenuBarControl(Control):
3169
+ def __init__(self, searchFromControl: Optional[Control] = None,
3170
+ searchDepth: int = 0xFFFFFFFF,
3171
+ searchInterval: float = SEARCH_INTERVAL,
3172
+ foundIndex: int = 1,
3173
+ element=None,
3174
+ Name: Optional[str] = None,
3175
+ SubName: Optional[str] = None,
3176
+ RegexName: Optional[str] = None,
3177
+ ClassName: Optional[str] = None,
3178
+ AutomationId: Optional[str] = None,
3179
+ Depth: Optional[int] = None,
3180
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
3181
+ **searchProperties):
3182
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
3183
+ ControlType=ControlType.MenuBarControl,
3184
+ Name=Name,
3185
+ SubName=SubName,
3186
+ RegexName=RegexName,
3187
+ ClassName=ClassName,
3188
+ AutomationId=AutomationId,
3189
+ Depth=Depth,
3190
+ Compare=Compare,
3191
+ **searchProperties)
3192
+
3193
+ def GetDockPattern(self) -> DockPattern:
3194
+ """
3195
+ Return `DockPattern` if it supports the pattern else None(Conditional support according to MSDN).
3196
+ """
3197
+ return self.GetPattern(PatternId.DockPattern)
3198
+
3199
+ def GetExpandCollapsePattern(self) -> ExpandCollapsePattern:
3200
+ """
3201
+ Return `ExpandCollapsePattern` if it supports the pattern else None(Conditional support according to MSDN).
3202
+ """
3203
+ return self.GetPattern(PatternId.ExpandCollapsePattern)
3204
+
3205
+ def GetTransformPattern(self) -> TransformPattern:
3206
+ """
3207
+ Return `TransformPattern` if it supports the pattern else None(Conditional support according to MSDN).
3208
+ """
3209
+ return self.GetPattern(PatternId.TransformPattern)
3210
+
3211
+
3212
+ class MenuItemControl(Control):
3213
+ def __init__(self, searchFromControl: Optional[Control] = None,
3214
+ searchDepth: int = 0xFFFFFFFF,
3215
+ searchInterval: float = SEARCH_INTERVAL,
3216
+ foundIndex: int = 1,
3217
+ element=None,
3218
+ Name: Optional[str] = None,
3219
+ SubName: Optional[str] = None,
3220
+ RegexName: Optional[str] = None,
3221
+ ClassName: Optional[str] = None,
3222
+ AutomationId: Optional[str] = None,
3223
+ Depth: Optional[int] = None,
3224
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
3225
+ **searchProperties):
3226
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
3227
+ ControlType=ControlType.MenuItemControl,
3228
+ Name=Name,
3229
+ SubName=SubName,
3230
+ RegexName=RegexName,
3231
+ ClassName=ClassName,
3232
+ AutomationId=AutomationId,
3233
+ Depth=Depth,
3234
+ Compare=Compare,
3235
+ **searchProperties)
3236
+
3237
+ def GetExpandCollapsePattern(self) -> ExpandCollapsePattern:
3238
+ """
3239
+ Return `ExpandCollapsePattern` if it supports the pattern else None(Conditional support according to MSDN).
3240
+ """
3241
+ return self.GetPattern(PatternId.ExpandCollapsePattern)
3242
+
3243
+ def GetInvokePattern(self) -> InvokePattern:
3244
+ """
3245
+ Return `InvokePattern` if it supports the pattern else None(Conditional support according to MSDN).
3246
+ """
3247
+ return self.GetPattern(PatternId.InvokePattern)
3248
+
3249
+ def GetSelectionItemPattern(self) -> SelectionItemPattern:
3250
+ """
3251
+ Return `SelectionItemPattern` if it supports the pattern else None(Conditional support according to MSDN).
3252
+ """
3253
+ return self.GetPattern(PatternId.SelectionItemPattern)
3254
+
3255
+ def GetTogglePattern(self) -> TogglePattern:
3256
+ """
3257
+ Return `TogglePattern` if it supports the pattern else None(Conditional support according to MSDN).
3258
+ """
3259
+ return self.GetPattern(PatternId.TogglePattern)
3260
+
3261
+
3262
+ class TopLevel():
3263
+ """Class TopLevel"""
3264
+
3265
+ def SetTopmost(self, isTopmost: bool = True, waitTime: float = OPERATION_WAIT_TIME) -> bool:
3266
+ """
3267
+ Set top level window topmost.
3268
+ isTopmost: bool.
3269
+ waitTime: float.
3270
+ """
3271
+ if self.IsTopLevel():
3272
+ ret = SetWindowTopmost(self.NativeWindowHandle, isTopmost)
3273
+ time.sleep(waitTime)
3274
+ return ret
3275
+ return False
3276
+
3277
+ def IsTopmost(self) -> bool:
3278
+ if self.IsTopLevel():
3279
+ WS_EX_TOPMOST = 0x00000008
3280
+ return bool(GetWindowLong(self.NativeWindowHandle, GWL.ExStyle) & WS_EX_TOPMOST)
3281
+ return False
3282
+
3283
+ def SwitchToThisWindow(self, waitTime: float = OPERATION_WAIT_TIME) -> None:
3284
+ if self.IsTopLevel():
3285
+ SwitchToThisWindow(self.NativeWindowHandle)
3286
+ time.sleep(waitTime)
3287
+
3288
+ def Maximize(self, waitTime: float = OPERATION_WAIT_TIME) -> bool:
3289
+ """
3290
+ Set top level window maximize.
3291
+ """
3292
+ if self.IsTopLevel():
3293
+ return self.ShowWindow(SW.ShowMaximized, waitTime)
3294
+ return False
3295
+
3296
+ def IsMaximize(self) -> bool:
3297
+ if self.IsTopLevel():
3298
+ return bool(IsZoomed(self.NativeWindowHandle))
3299
+ return False
3300
+
3301
+ def Minimize(self, waitTime: float = OPERATION_WAIT_TIME) -> bool:
3302
+ if self.IsTopLevel():
3303
+ return self.ShowWindow(SW.Minimize, waitTime)
3304
+ return False
3305
+
3306
+ def IsMinimize(self) -> bool:
3307
+ if self.IsTopLevel():
3308
+ return bool(IsIconic(self.NativeWindowHandle))
3309
+ return False
3310
+
3311
+ def Restore(self, waitTime: float = OPERATION_WAIT_TIME) -> bool:
3312
+ """
3313
+ Restore window to normal state.
3314
+ Similar to SwitchToThisWindow.
3315
+ """
3316
+ if self.IsTopLevel():
3317
+ return self.ShowWindow(SW.Restore, waitTime)
3318
+ return False
3319
+
3320
+ def MoveToCenter(self) -> bool:
3321
+ """
3322
+ Move window to screen center.
3323
+ """
3324
+ if self.IsTopLevel():
3325
+ rect = self.BoundingRectangle
3326
+ screenWidth, screenHeight = GetScreenSize()
3327
+ x, y = (screenWidth - rect.width()) // 2, (screenHeight - rect.height()) // 2
3328
+ if x < 0:
3329
+ x = 0
3330
+ if y < 0:
3331
+ y = 0
3332
+ return SetWindowPos(self.NativeWindowHandle, SWP.HWND_Top, x, y, 0, 0, SWP.SWP_NoSize)
3333
+ return False
3334
+
3335
+ def SetActive(self, waitTime: float = OPERATION_WAIT_TIME) -> bool:
3336
+ """Set top level window active."""
3337
+ if self.IsTopLevel():
3338
+ handle = self.NativeWindowHandle
3339
+ if IsIconic(handle):
3340
+ ret = ShowWindow(handle, SW.Restore)
3341
+ elif not IsWindowVisible(handle):
3342
+ ret = ShowWindow(handle, SW.Show)
3343
+ ret = SetForegroundWindow(handle) # may fail if foreground windows's process is not python
3344
+ time.sleep(waitTime)
3345
+ return ret
3346
+ return False
3347
+
3348
+
3349
+ class PaneControl(Control, TopLevel):
3350
+ def __init__(self, searchFromControl: Optional[Control] = None,
3351
+ searchDepth: int = 0xFFFFFFFF,
3352
+ searchInterval: float = SEARCH_INTERVAL,
3353
+ foundIndex: int = 1,
3354
+ element=None,
3355
+ Name: Optional[str] = None,
3356
+ SubName: Optional[str] = None,
3357
+ RegexName: Optional[str] = None,
3358
+ ClassName: Optional[str] = None,
3359
+ AutomationId: Optional[str] = None,
3360
+ Depth: Optional[int] = None,
3361
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
3362
+ **searchProperties):
3363
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
3364
+ ControlType=ControlType.PaneControl,
3365
+ Name=Name,
3366
+ SubName=SubName,
3367
+ RegexName=RegexName,
3368
+ ClassName=ClassName,
3369
+ AutomationId=AutomationId,
3370
+ Depth=Depth,
3371
+ Compare=Compare,
3372
+ **searchProperties)
3373
+
3374
+ def GetDockPattern(self) -> DockPattern:
3375
+ """
3376
+ Return `DockPattern` if it supports the pattern else None(Conditional support according to MSDN).
3377
+ """
3378
+ return self.GetPattern(PatternId.DockPattern)
3379
+
3380
+ def GetScrollPattern(self) -> ScrollPattern:
3381
+ """
3382
+ Return `ScrollPattern` if it supports the pattern else None(Conditional support according to MSDN).
3383
+ """
3384
+ return self.GetPattern(PatternId.ScrollPattern)
3385
+
3386
+ def GetTransformPattern(self) -> TransformPattern:
3387
+ """
3388
+ Return `TransformPattern` if it supports the pattern else None(Conditional support according to MSDN).
3389
+ """
3390
+ return self.GetPattern(PatternId.TransformPattern)
3391
+
3392
+
3393
+ class ProgressBarControl(Control):
3394
+ def __init__(self, searchFromControl: Optional[Control] = None,
3395
+ searchDepth: int = 0xFFFFFFFF,
3396
+ searchInterval: float = SEARCH_INTERVAL,
3397
+ foundIndex: int = 1,
3398
+ element=None,
3399
+ Name: Optional[str] = None,
3400
+ SubName: Optional[str] = None,
3401
+ RegexName: Optional[str] = None,
3402
+ ClassName: Optional[str] = None,
3403
+ AutomationId: Optional[str] = None,
3404
+ Depth: Optional[int] = None,
3405
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
3406
+ **searchProperties):
3407
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
3408
+ ControlType=ControlType.ProgressBarControl,
3409
+ Name=Name,
3410
+ SubName=SubName,
3411
+ RegexName=RegexName,
3412
+ ClassName=ClassName,
3413
+ AutomationId=AutomationId,
3414
+ Depth=Depth,
3415
+ Compare=Compare,
3416
+ **searchProperties)
3417
+
3418
+ def GetRangeValuePattern(self) -> RangeValuePattern:
3419
+ """
3420
+ Return `RangeValuePattern` if it supports the pattern else None(Conditional support according to MSDN).
3421
+ """
3422
+ return self.GetPattern(PatternId.RangeValuePattern)
3423
+
3424
+ def GetValuePattern(self) -> ValuePattern:
3425
+ """
3426
+ Return `ValuePattern` if it supports the pattern else None(Conditional support according to MSDN).
3427
+ """
3428
+ return self.GetPattern(PatternId.ValuePattern)
3429
+
3430
+
3431
+ class RadioButtonControl(Control):
3432
+ def __init__(self, searchFromControl: Optional[Control] = None,
3433
+ searchDepth: int = 0xFFFFFFFF,
3434
+ searchInterval: float = SEARCH_INTERVAL,
3435
+ foundIndex: int = 1,
3436
+ element=None,
3437
+ Name: Optional[str] = None,
3438
+ SubName: Optional[str] = None,
3439
+ RegexName: Optional[str] = None,
3440
+ ClassName: Optional[str] = None,
3441
+ AutomationId: Optional[str] = None,
3442
+ Depth: Optional[int] = None,
3443
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
3444
+ **searchProperties):
3445
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
3446
+ ControlType=ControlType.RadioButtonControl,
3447
+ Name=Name,
3448
+ SubName=SubName,
3449
+ RegexName=RegexName,
3450
+ ClassName=ClassName,
3451
+ AutomationId=AutomationId,
3452
+ Depth=Depth,
3453
+ Compare=Compare,
3454
+ **searchProperties)
3455
+
3456
+ def GetSelectionItemPattern(self) -> SelectionItemPattern:
3457
+ """
3458
+ Return `SelectionItemPattern` if it supports the pattern else None(Must support according to MSDN).
3459
+ """
3460
+ return self.GetPattern(PatternId.SelectionItemPattern)
3461
+
3462
+
3463
+ class ScrollBarControl(Control):
3464
+ def __init__(self, searchFromControl: Optional[Control] = None,
3465
+ searchDepth: int = 0xFFFFFFFF,
3466
+ searchInterval: float = SEARCH_INTERVAL,
3467
+ foundIndex: int = 1,
3468
+ element=None,
3469
+ Name: Optional[str] = None,
3470
+ SubName: Optional[str] = None,
3471
+ RegexName: Optional[str] = None,
3472
+ ClassName: Optional[str] = None,
3473
+ AutomationId: Optional[str] = None,
3474
+ Depth: Optional[int] = None,
3475
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
3476
+ **searchProperties):
3477
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
3478
+ ControlType=ControlType.ScrollBarControl,
3479
+ Name=Name,
3480
+ SubName=SubName,
3481
+ RegexName=RegexName,
3482
+ ClassName=ClassName,
3483
+ AutomationId=AutomationId,
3484
+ Depth=Depth,
3485
+ Compare=Compare,
3486
+ **searchProperties)
3487
+
3488
+ def GetRangeValuePattern(self) -> RangeValuePattern:
3489
+ """
3490
+ Return `RangeValuePattern` if it supports the pattern else None(Conditional support according to MSDN).
3491
+ """
3492
+ return self.GetPattern(PatternId.RangeValuePattern)
3493
+
3494
+
3495
+ class SemanticZoomControl(Control):
3496
+ def __init__(self, searchFromControl: Optional[Control] = None,
3497
+ searchDepth: int = 0xFFFFFFFF,
3498
+ searchInterval: float = SEARCH_INTERVAL,
3499
+ foundIndex: int = 1,
3500
+ element=None,
3501
+ Name: Optional[str] = None,
3502
+ SubName: Optional[str] = None,
3503
+ RegexName: Optional[str] = None,
3504
+ ClassName: Optional[str] = None,
3505
+ AutomationId: Optional[str] = None,
3506
+ Depth: Optional[int] = None,
3507
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
3508
+ **searchProperties):
3509
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
3510
+ ControlType=ControlType.SemanticZoomControl,
3511
+ Name=Name,
3512
+ SubName=SubName,
3513
+ RegexName=RegexName,
3514
+ ClassName=ClassName,
3515
+ AutomationId=AutomationId,
3516
+ Depth=Depth,
3517
+ Compare=Compare,
3518
+ **searchProperties)
3519
+
3520
+
3521
+ class SeparatorControl(Control):
3522
+ def __init__(self, searchFromControl: Optional[Control] = None,
3523
+ searchDepth: int = 0xFFFFFFFF,
3524
+ searchInterval: float = SEARCH_INTERVAL,
3525
+ foundIndex: int = 1,
3526
+ element=None,
3527
+ Name: Optional[str] = None,
3528
+ SubName: Optional[str] = None,
3529
+ RegexName: Optional[str] = None,
3530
+ ClassName: Optional[str] = None,
3531
+ AutomationId: Optional[str] = None,
3532
+ Depth: Optional[int] = None,
3533
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
3534
+ **searchProperties):
3535
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
3536
+ ControlType=ControlType.SeparatorControl,
3537
+ Name=Name,
3538
+ SubName=SubName,
3539
+ RegexName=RegexName,
3540
+ ClassName=ClassName,
3541
+ AutomationId=AutomationId,
3542
+ Depth=Depth,
3543
+ Compare=Compare,
3544
+ **searchProperties)
3545
+
3546
+
3547
+ class SliderControl(Control):
3548
+ def __init__(self, searchFromControl: Optional[Control] = None,
3549
+ searchDepth: int = 0xFFFFFFFF,
3550
+ searchInterval: float = SEARCH_INTERVAL,
3551
+ foundIndex: int = 1,
3552
+ element=None,
3553
+ Name: Optional[str] = None,
3554
+ SubName: Optional[str] = None,
3555
+ RegexName: Optional[str] = None,
3556
+ ClassName: Optional[str] = None,
3557
+ AutomationId: Optional[str] = None,
3558
+ Depth: Optional[int] = None,
3559
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
3560
+ **searchProperties):
3561
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
3562
+ ControlType=ControlType.SliderControl,
3563
+ Name=Name,
3564
+ SubName=SubName,
3565
+ RegexName=RegexName,
3566
+ ClassName=ClassName,
3567
+ AutomationId=AutomationId,
3568
+ Depth=Depth,
3569
+ Compare=Compare,
3570
+ **searchProperties)
3571
+
3572
+ def GetRangeValuePattern(self) -> RangeValuePattern:
3573
+ """
3574
+ Return `RangeValuePattern` if it supports the pattern else None(Conditional support according to MSDN).
3575
+ """
3576
+ return self.GetPattern(PatternId.RangeValuePattern)
3577
+
3578
+ def GetSelectionPattern(self) -> SelectionPattern:
3579
+ """
3580
+ Return `SelectionPattern` if it supports the pattern else None(Conditional support according to MSDN).
3581
+ """
3582
+ return self.GetPattern(PatternId.SelectionPattern)
3583
+
3584
+ def GetValuePattern(self) -> ValuePattern:
3585
+ """
3586
+ Return `ValuePattern` if it supports the pattern else None(Conditional support according to MSDN).
3587
+ """
3588
+ return self.GetPattern(PatternId.ValuePattern)
3589
+
3590
+
3591
+ class SpinnerControl(Control):
3592
+ def __init__(self, searchFromControl: Optional[Control] = None,
3593
+ searchDepth: int = 0xFFFFFFFF,
3594
+ searchInterval: float = SEARCH_INTERVAL,
3595
+ foundIndex: int = 1,
3596
+ element=None,
3597
+ Name: Optional[str] = None,
3598
+ SubName: Optional[str] = None,
3599
+ RegexName: Optional[str] = None,
3600
+ ClassName: Optional[str] = None,
3601
+ AutomationId: Optional[str] = None,
3602
+ Depth: Optional[int] = None,
3603
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
3604
+ **searchProperties):
3605
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
3606
+ ControlType=ControlType.SpinnerControl,
3607
+ Name=Name,
3608
+ SubName=SubName,
3609
+ RegexName=RegexName,
3610
+ ClassName=ClassName,
3611
+ AutomationId=AutomationId,
3612
+ Depth=Depth,
3613
+ Compare=Compare,
3614
+ **searchProperties)
3615
+
3616
+ def GetRangeValuePattern(self) -> RangeValuePattern:
3617
+ """
3618
+ Return `RangeValuePattern` if it supports the pattern else None(Conditional support according to MSDN).
3619
+ """
3620
+ return self.GetPattern(PatternId.RangeValuePattern)
3621
+
3622
+ def GetSelectionPattern(self) -> SelectionPattern:
3623
+ """
3624
+ Return `SelectionPattern` if it supports the pattern else None(Conditional support according to MSDN).
3625
+ """
3626
+ return self.GetPattern(PatternId.SelectionPattern)
3627
+
3628
+ def GetValuePattern(self) -> ValuePattern:
3629
+ """
3630
+ Return `ValuePattern` if it supports the pattern else None(Conditional support according to MSDN).
3631
+ """
3632
+ return self.GetPattern(PatternId.ValuePattern)
3633
+
3634
+
3635
+ class SplitButtonControl(Control):
3636
+ def __init__(self, searchFromControl: Optional[Control] = None,
3637
+ searchDepth: int = 0xFFFFFFFF,
3638
+ searchInterval: float = SEARCH_INTERVAL,
3639
+ foundIndex: int = 1,
3640
+ element=None,
3641
+ Name: Optional[str] = None,
3642
+ SubName: Optional[str] = None,
3643
+ RegexName: Optional[str] = None,
3644
+ ClassName: Optional[str] = None,
3645
+ AutomationId: Optional[str] = None,
3646
+ Depth: Optional[int] = None,
3647
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
3648
+ **searchProperties):
3649
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
3650
+ ControlType=ControlType.SplitButtonControl,
3651
+ Name=Name,
3652
+ SubName=SubName,
3653
+ RegexName=RegexName,
3654
+ ClassName=ClassName,
3655
+ AutomationId=AutomationId,
3656
+ Depth=Depth,
3657
+ Compare=Compare,
3658
+ **searchProperties)
3659
+
3660
+ def GetExpandCollapsePattern(self) -> ExpandCollapsePattern:
3661
+ """
3662
+ Return `ExpandCollapsePattern` if it supports the pattern else None(Must support according to MSDN).
3663
+ """
3664
+ return self.GetPattern(PatternId.ExpandCollapsePattern)
3665
+
3666
+ def GetInvokePattern(self) -> InvokePattern:
3667
+ """
3668
+ Return `InvokePattern` if it supports the pattern else None(Must support according to MSDN).
3669
+ """
3670
+ return self.GetPattern(PatternId.InvokePattern)
3671
+
3672
+
3673
+ class StatusBarControl(Control):
3674
+ def __init__(self, searchFromControl: Optional[Control] = None,
3675
+ searchDepth: int = 0xFFFFFFFF,
3676
+ searchInterval: float = SEARCH_INTERVAL,
3677
+ foundIndex: int = 1,
3678
+ element=None,
3679
+ Name: Optional[str] = None,
3680
+ SubName: Optional[str] = None,
3681
+ RegexName: Optional[str] = None,
3682
+ ClassName: Optional[str] = None,
3683
+ AutomationId: Optional[str] = None,
3684
+ Depth: Optional[int] = None,
3685
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
3686
+ **searchProperties):
3687
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
3688
+ ControlType=ControlType.StatusBarControl,
3689
+ Name=Name,
3690
+ SubName=SubName,
3691
+ RegexName=RegexName,
3692
+ ClassName=ClassName,
3693
+ AutomationId=AutomationId,
3694
+ Depth=Depth,
3695
+ Compare=Compare,
3696
+ **searchProperties)
3697
+
3698
+ def GetGridPattern(self) -> GridPattern:
3699
+ """
3700
+ Return `GridPattern` if it supports the pattern else None(Conditional support according to MSDN).
3701
+ """
3702
+ return self.GetPattern(PatternId.GridPattern)
3703
+
3704
+
3705
+ class TabControl(Control):
3706
+ def __init__(self, searchFromControl: Optional[Control] = None,
3707
+ searchDepth: int = 0xFFFFFFFF,
3708
+ searchInterval: float = SEARCH_INTERVAL,
3709
+ foundIndex: int = 1,
3710
+ element=None,
3711
+ Name: Optional[str] = None,
3712
+ SubName: Optional[str] = None,
3713
+ RegexName: Optional[str] = None,
3714
+ ClassName: Optional[str] = None,
3715
+ AutomationId: Optional[str] = None,
3716
+ Depth: Optional[int] = None,
3717
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
3718
+ **searchProperties):
3719
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
3720
+ ControlType=ControlType.TabControl,
3721
+ Name=Name,
3722
+ SubName=SubName,
3723
+ RegexName=RegexName,
3724
+ ClassName=ClassName,
3725
+ AutomationId=AutomationId,
3726
+ Depth=Depth,
3727
+ Compare=Compare,
3728
+ **searchProperties)
3729
+
3730
+ def GetSelectionPattern(self) -> SelectionPattern:
3731
+ """
3732
+ Return `SelectionPattern` if it supports the pattern else None(Must support according to MSDN).
3733
+ """
3734
+ return self.GetPattern(PatternId.SelectionPattern)
3735
+
3736
+ def GetScrollPattern(self) -> ScrollPattern:
3737
+ """
3738
+ Return `ScrollPattern` if it supports the pattern else None(Conditional support according to MSDN).
3739
+ """
3740
+ return self.GetPattern(PatternId.ScrollPattern)
3741
+
3742
+
3743
+ class TabItemControl(Control):
3744
+ def __init__(self, searchFromControl: Optional[Control] = None,
3745
+ searchDepth: int = 0xFFFFFFFF,
3746
+ searchInterval: float = SEARCH_INTERVAL,
3747
+ foundIndex: int = 1,
3748
+ element=None,
3749
+ Name: Optional[str] = None,
3750
+ SubName: Optional[str] = None,
3751
+ RegexName: Optional[str] = None,
3752
+ ClassName: Optional[str] = None,
3753
+ AutomationId: Optional[str] = None,
3754
+ Depth: Optional[int] = None,
3755
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
3756
+ **searchProperties):
3757
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
3758
+ ControlType=ControlType.TabItemControl,
3759
+ Name=Name,
3760
+ SubName=SubName,
3761
+ RegexName=RegexName,
3762
+ ClassName=ClassName,
3763
+ AutomationId=AutomationId,
3764
+ Depth=Depth,
3765
+ Compare=Compare,
3766
+ **searchProperties)
3767
+
3768
+ def GetSelectionItemPattern(self) -> SelectionItemPattern:
3769
+ """
3770
+ Return `SelectionItemPattern` if it supports the pattern else None(Must support according to MSDN).
3771
+ """
3772
+ return self.GetPattern(PatternId.SelectionItemPattern)
3773
+
3774
+
3775
+ class TableControl(Control):
3776
+ def __init__(self, searchFromControl: Optional[Control] = None,
3777
+ searchDepth: int = 0xFFFFFFFF,
3778
+ searchInterval: float = SEARCH_INTERVAL,
3779
+ foundIndex: int = 1,
3780
+ element=None,
3781
+ Name: Optional[str] = None,
3782
+ SubName: Optional[str] = None,
3783
+ RegexName: Optional[str] = None,
3784
+ ClassName: Optional[str] = None,
3785
+ AutomationId: Optional[str] = None,
3786
+ Depth: Optional[int] = None,
3787
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
3788
+ **searchProperties):
3789
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
3790
+ ControlType=ControlType.TableControl,
3791
+ Name=Name,
3792
+ SubName=SubName,
3793
+ RegexName=RegexName,
3794
+ ClassName=ClassName,
3795
+ AutomationId=AutomationId,
3796
+ Depth=Depth,
3797
+ Compare=Compare,
3798
+ **searchProperties)
3799
+
3800
+ def GetGridPattern(self) -> GridPattern:
3801
+ """
3802
+ Return `GridPattern` if it supports the pattern else None(Must support according to MSDN).
3803
+ """
3804
+ return self.GetPattern(PatternId.GridPattern)
3805
+
3806
+ def GetGridItemPattern(self) -> GridItemPattern:
3807
+ """
3808
+ Return `GridItemPattern` if it supports the pattern else None(Must support according to MSDN).
3809
+ """
3810
+ return self.GetPattern(PatternId.GridItemPattern)
3811
+
3812
+ def GetTablePattern(self) -> TablePattern:
3813
+ """
3814
+ Return `TablePattern` if it supports the pattern else None(Must support according to MSDN).
3815
+ """
3816
+ return self.GetPattern(PatternId.TablePattern)
3817
+
3818
+ def GetTableItemPattern(self) -> TableItemPattern:
3819
+ """
3820
+ Return `TableItemPattern` if it supports the pattern else None(Must support according to MSDN).
3821
+ """
3822
+ return self.GetPattern(PatternId.TableItemPattern)
3823
+
3824
+ def GetTableItemsValue(self, row: int = -1, column: int = -1):
3825
+ """
3826
+ Get the value of a table
3827
+ row: int. Position of the row in the table
3828
+ column: int. Position of the column in the table
3829
+ Return a list with values in the table.
3830
+ If a row and column is specified, return a cell value.
3831
+ If only a row is specified, return a list with row values
3832
+ """
3833
+ table = []
3834
+ for item in self.GetChildren():
3835
+ table.append([cell.GetLegacyIAccessiblePattern().Value for cell in item.GetChildren()])
3836
+ if row > 0 and column > 0:
3837
+ return table[row][column]
3838
+ if row > 0:
3839
+ return table[row]
3840
+ return table
3841
+
3842
+
3843
+ class TextControl(Control):
3844
+ def __init__(self, searchFromControl: Optional[Control] = None,
3845
+ searchDepth: int = 0xFFFFFFFF,
3846
+ searchInterval: float = SEARCH_INTERVAL,
3847
+ foundIndex: int = 1,
3848
+ element=None,
3849
+ Name: Optional[str] = None,
3850
+ SubName: Optional[str] = None,
3851
+ RegexName: Optional[str] = None,
3852
+ ClassName: Optional[str] = None,
3853
+ AutomationId: Optional[str] = None,
3854
+ Depth: Optional[int] = None,
3855
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
3856
+ **searchProperties):
3857
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
3858
+ ControlType=ControlType.TextControl,
3859
+ Name=Name,
3860
+ SubName=SubName,
3861
+ RegexName=RegexName,
3862
+ ClassName=ClassName,
3863
+ AutomationId=AutomationId,
3864
+ Depth=Depth,
3865
+ Compare=Compare,
3866
+ **searchProperties)
3867
+
3868
+ def GetGridItemPattern(self) -> GridItemPattern:
3869
+ """
3870
+ Return `GridItemPattern` if it supports the pattern else None(Conditional support according to MSDN).
3871
+ """
3872
+ return self.GetPattern(PatternId.GridItemPattern)
3873
+
3874
+ def GetTableItemPattern(self) -> TableItemPattern:
3875
+ """
3876
+ Return `TableItemPattern` if it supports the pattern else None(Conditional support according to MSDN).
3877
+ """
3878
+ return self.GetPattern(PatternId.TableItemPattern)
3879
+
3880
+ def GetTextPattern(self) -> TextPattern:
3881
+ """
3882
+ Return `TextPattern` if it supports the pattern else None(Conditional support according to MSDN).
3883
+ """
3884
+ return self.GetPattern(PatternId.TextPattern)
3885
+
3886
+
3887
+ class ThumbControl(Control):
3888
+ def __init__(self, searchFromControl: Optional[Control] = None,
3889
+ searchDepth: int = 0xFFFFFFFF,
3890
+ searchInterval: float = SEARCH_INTERVAL,
3891
+ foundIndex: int = 1,
3892
+ element=None,
3893
+ Name: Optional[str] = None,
3894
+ SubName: Optional[str] = None,
3895
+ RegexName: Optional[str] = None,
3896
+ ClassName: Optional[str] = None,
3897
+ AutomationId: Optional[str] = None,
3898
+ Depth: Optional[int] = None,
3899
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
3900
+ **searchProperties):
3901
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
3902
+ ControlType=ControlType.ThumbControl,
3903
+ Name=Name,
3904
+ SubName=SubName,
3905
+ RegexName=RegexName,
3906
+ ClassName=ClassName,
3907
+ AutomationId=AutomationId,
3908
+ Depth=Depth,
3909
+ Compare=Compare,
3910
+ **searchProperties)
3911
+
3912
+ def GetTransformPattern(self) -> TransformPattern:
3913
+ """
3914
+ Return `TransformPattern` if it supports the pattern else None(Must support according to MSDN).
3915
+ """
3916
+ return self.GetPattern(PatternId.TransformPattern)
3917
+
3918
+
3919
+ class TitleBarControl(Control):
3920
+ def __init__(self, searchFromControl: Optional[Control] = None,
3921
+ searchDepth: int = 0xFFFFFFFF,
3922
+ searchInterval: float = SEARCH_INTERVAL,
3923
+ foundIndex: int = 1,
3924
+ element=None,
3925
+ Name: Optional[str] = None,
3926
+ SubName: Optional[str] = None,
3927
+ RegexName: Optional[str] = None,
3928
+ ClassName: Optional[str] = None,
3929
+ AutomationId: Optional[str] = None,
3930
+ Depth: Optional[int] = None,
3931
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
3932
+ **searchProperties):
3933
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
3934
+ ControlType=ControlType.TitleBarControl,
3935
+ Name=Name,
3936
+ SubName=SubName,
3937
+ RegexName=RegexName,
3938
+ ClassName=ClassName,
3939
+ AutomationId=AutomationId,
3940
+ Depth=Depth,
3941
+ Compare=Compare,
3942
+ **searchProperties)
3943
+
3944
+
3945
+ class ToolBarControl(Control):
3946
+ def __init__(self, searchFromControl: Optional[Control] = None,
3947
+ searchDepth: int = 0xFFFFFFFF,
3948
+ searchInterval: float = SEARCH_INTERVAL,
3949
+ foundIndex: int = 1,
3950
+ element=None,
3951
+ Name: Optional[str] = None,
3952
+ SubName: Optional[str] = None,
3953
+ RegexName: Optional[str] = None,
3954
+ ClassName: Optional[str] = None,
3955
+ AutomationId: Optional[str] = None,
3956
+ Depth: Optional[int] = None,
3957
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
3958
+ **searchProperties):
3959
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
3960
+ ControlType=ControlType.ToolBarControl,
3961
+ Name=Name,
3962
+ SubName=SubName,
3963
+ RegexName=RegexName,
3964
+ ClassName=ClassName,
3965
+ AutomationId=AutomationId,
3966
+ Depth=Depth,
3967
+ Compare=Compare,
3968
+ **searchProperties)
3969
+
3970
+ def GetDockPattern(self) -> DockPattern:
3971
+ """
3972
+ Return `DockPattern` if it supports the pattern else None(Conditional support according to MSDN).
3973
+ """
3974
+ return self.GetPattern(PatternId.DockPattern)
3975
+
3976
+ def GetExpandCollapsePattern(self) -> ExpandCollapsePattern:
3977
+ """
3978
+ Return `ExpandCollapsePattern` if it supports the pattern else None(Conditional support according to MSDN).
3979
+ """
3980
+ return self.GetPattern(PatternId.ExpandCollapsePattern)
3981
+
3982
+ def GetTransformPattern(self) -> TransformPattern:
3983
+ """
3984
+ Return `TransformPattern` if it supports the pattern else None(Conditional support according to MSDN).
3985
+ """
3986
+ return self.GetPattern(PatternId.TransformPattern)
3987
+
3988
+
3989
+ class ToolTipControl(Control):
3990
+ def __init__(self, searchFromControl: Optional[Control] = None,
3991
+ searchDepth: int = 0xFFFFFFFF,
3992
+ searchInterval: float = SEARCH_INTERVAL,
3993
+ foundIndex: int = 1,
3994
+ element=None,
3995
+ Name: Optional[str] = None,
3996
+ SubName: Optional[str] = None,
3997
+ RegexName: Optional[str] = None,
3998
+ ClassName: Optional[str] = None,
3999
+ AutomationId: Optional[str] = None,
4000
+ Depth: Optional[int] = None,
4001
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
4002
+ **searchProperties):
4003
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
4004
+ ControlType=ControlType.ToolTipControl,
4005
+ Name=Name,
4006
+ SubName=SubName,
4007
+ RegexName=RegexName,
4008
+ ClassName=ClassName,
4009
+ AutomationId=AutomationId,
4010
+ Depth=Depth,
4011
+ Compare=Compare,
4012
+ **searchProperties)
4013
+
4014
+ def GetTextPattern(self) -> TextPattern:
4015
+ """
4016
+ Return `TextPattern` if it supports the pattern else None(Conditional support according to MSDN).
4017
+ """
4018
+ return self.GetPattern(PatternId.TextPattern)
4019
+
4020
+ def GetWindowPattern(self) -> WindowPattern:
4021
+ """
4022
+ Return `WindowPattern` if it supports the pattern else None(Conditional support according to MSDN).
4023
+ """
4024
+ return self.GetPattern(PatternId.WindowPattern)
4025
+
4026
+
4027
+ class TreeControl(Control):
4028
+ def __init__(self, searchFromControl: Optional[Control] = None,
4029
+ searchDepth: int = 0xFFFFFFFF,
4030
+ searchInterval: float = SEARCH_INTERVAL,
4031
+ foundIndex: int = 1,
4032
+ element=None,
4033
+ Name: Optional[str] = None,
4034
+ SubName: Optional[str] = None,
4035
+ RegexName: Optional[str] = None,
4036
+ ClassName: Optional[str] = None,
4037
+ AutomationId: Optional[str] = None,
4038
+ Depth: Optional[int] = None,
4039
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
4040
+ **searchProperties):
4041
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
4042
+ ControlType=ControlType.TreeControl,
4043
+ Name=Name,
4044
+ SubName=SubName,
4045
+ RegexName=RegexName,
4046
+ ClassName=ClassName,
4047
+ AutomationId=AutomationId,
4048
+ Depth=Depth,
4049
+ Compare=Compare,
4050
+ **searchProperties)
4051
+
4052
+ def GetScrollPattern(self) -> ScrollPattern:
4053
+ """
4054
+ Return `ScrollPattern` if it supports the pattern else None(Conditional support according to MSDN).
4055
+ """
4056
+ return self.GetPattern(PatternId.ScrollPattern)
4057
+
4058
+ def GetSelectionPattern(self) -> SelectionPattern:
4059
+ """
4060
+ Return `SelectionPattern` if it supports the pattern else None(Conditional support according to MSDN).
4061
+ """
4062
+ return self.GetPattern(PatternId.SelectionPattern)
4063
+
4064
+
4065
+ class TreeItemControl(Control):
4066
+ def __init__(self, searchFromControl: Optional[Control] = None,
4067
+ searchDepth: int = 0xFFFFFFFF,
4068
+ searchInterval: float = SEARCH_INTERVAL,
4069
+ foundIndex: int = 1,
4070
+ element=None,
4071
+ Name: Optional[str] = None,
4072
+ SubName: Optional[str] = None,
4073
+ RegexName: Optional[str] = None,
4074
+ ClassName: Optional[str] = None,
4075
+ AutomationId: Optional[str] = None,
4076
+ Depth: Optional[int] = None,
4077
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
4078
+ **searchProperties):
4079
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
4080
+ ControlType=ControlType.TreeItemControl,
4081
+ Name=Name,
4082
+ SubName=SubName,
4083
+ RegexName=RegexName,
4084
+ ClassName=ClassName,
4085
+ AutomationId=AutomationId,
4086
+ Depth=Depth,
4087
+ Compare=Compare,
4088
+ **searchProperties)
4089
+
4090
+ def GetExpandCollapsePattern(self) -> ExpandCollapsePattern:
4091
+ """
4092
+ Return `ExpandCollapsePattern` if it supports the pattern else None(Must support according to MSDN).
4093
+ """
4094
+ return self.GetPattern(PatternId.ExpandCollapsePattern)
4095
+
4096
+ def GetInvokePattern(self) -> InvokePattern:
4097
+ """
4098
+ Return `InvokePattern` if it supports the pattern else None(Conditional support according to MSDN).
4099
+ """
4100
+ return self.GetPattern(PatternId.InvokePattern)
4101
+
4102
+ def GetScrollItemPattern(self) -> ScrollItemPattern:
4103
+ """
4104
+ Return `ScrollItemPattern` if it supports the pattern else None(Conditional support according to MSDN).
4105
+ """
4106
+ return self.GetPattern(PatternId.ScrollItemPattern)
4107
+
4108
+ def GetSelectionItemPattern(self) -> SelectionItemPattern:
4109
+ """
4110
+ Return `SelectionItemPattern` if it supports the pattern else None(Conditional support according to MSDN).
4111
+ """
4112
+ return self.GetPattern(PatternId.SelectionItemPattern)
4113
+
4114
+ def GetTogglePattern(self) -> TogglePattern:
4115
+ """
4116
+ Return `TogglePattern` if it supports the pattern else None(Conditional support according to MSDN).
4117
+ """
4118
+ return self.GetPattern(PatternId.TogglePattern)
4119
+
4120
+
4121
+ class WindowControl(Control, TopLevel):
4122
+ def __init__(self, searchFromControl: Optional[Control] = None,
4123
+ searchDepth: int = 0xFFFFFFFF,
4124
+ searchInterval: float = SEARCH_INTERVAL,
4125
+ foundIndex: int = 1,
4126
+ element=None,
4127
+ Name: Optional[str] = None,
4128
+ SubName: Optional[str] = None,
4129
+ RegexName: Optional[str] = None,
4130
+ ClassName: Optional[str] = None,
4131
+ AutomationId: Optional[str] = None,
4132
+ Depth: Optional[int] = None,
4133
+ Compare: Optional[Callable[[TreeNode], bool]] = None,
4134
+ **searchProperties):
4135
+ Control.__init__(self, searchFromControl, searchDepth, searchInterval, foundIndex, element,
4136
+ ControlType=ControlType.WindowControl,
4137
+ Name=Name,
4138
+ SubName=SubName,
4139
+ RegexName=RegexName,
4140
+ ClassName=ClassName,
4141
+ AutomationId=AutomationId,
4142
+ Depth=Depth,
4143
+ Compare=Compare,
4144
+ **searchProperties)
4145
+ self._DockPattern = None
4146
+ self._TransformPattern = None
4147
+
4148
+ def GetTransformPattern(self) -> TransformPattern:
4149
+ """
4150
+ Return `TransformPattern` if it supports the pattern else None(Must support according to MSDN).
4151
+ """
4152
+ return self.GetPattern(PatternId.TransformPattern)
4153
+
4154
+ def GetWindowPattern(self) -> WindowPattern:
4155
+ """
4156
+ Return `WindowPattern` if it supports the pattern else None(Must support according to MSDN).
4157
+ """
4158
+ return self.GetPattern(PatternId.WindowPattern)
4159
+
4160
+ def GetDockPattern(self) -> DockPattern:
4161
+ """
4162
+ Return `DockPattern` if it supports the pattern else None(Conditional support according to MSDN).
4163
+ """
4164
+ return self.GetPattern(PatternId.DockPattern)
4165
+
4166
+ def MetroClose(self, waitTime: float = OPERATION_WAIT_TIME) -> None:
4167
+ """
4168
+ Only work on Windows 8/8.1, if current window is Metro UI.
4169
+ waitTime: float.
4170
+ """
4171
+ if self.ClassName == METRO_WINDOW_CLASS_NAME:
4172
+ screenWidth, screenHeight = GetScreenSize()
4173
+ MoveTo(screenWidth // 2, 0, waitTime=0)
4174
+ DragDrop(screenWidth // 2, 0, screenWidth // 2, screenHeight, waitTime=waitTime)
4175
+ else:
4176
+ Logger.WriteLine('Window is not Metro!', ConsoleColor.Yellow)
4177
+
4178
+
4179
+ ControlConstructors = {
4180
+ ControlType.AppBarControl: AppBarControl,
4181
+ ControlType.ButtonControl: ButtonControl,
4182
+ ControlType.CalendarControl: CalendarControl,
4183
+ ControlType.CheckBoxControl: CheckBoxControl,
4184
+ ControlType.ComboBoxControl: ComboBoxControl,
4185
+ ControlType.CustomControl: CustomControl,
4186
+ ControlType.DataGridControl: DataGridControl,
4187
+ ControlType.DataItemControl: DataItemControl,
4188
+ ControlType.DocumentControl: DocumentControl,
4189
+ ControlType.EditControl: EditControl,
4190
+ ControlType.GroupControl: GroupControl,
4191
+ ControlType.HeaderControl: HeaderControl,
4192
+ ControlType.HeaderItemControl: HeaderItemControl,
4193
+ ControlType.HyperlinkControl: HyperlinkControl,
4194
+ ControlType.ImageControl: ImageControl,
4195
+ ControlType.ListControl: ListControl,
4196
+ ControlType.ListItemControl: ListItemControl,
4197
+ ControlType.MenuBarControl: MenuBarControl,
4198
+ ControlType.MenuControl: MenuControl,
4199
+ ControlType.MenuItemControl: MenuItemControl,
4200
+ ControlType.PaneControl: PaneControl,
4201
+ ControlType.ProgressBarControl: ProgressBarControl,
4202
+ ControlType.RadioButtonControl: RadioButtonControl,
4203
+ ControlType.ScrollBarControl: ScrollBarControl,
4204
+ ControlType.SemanticZoomControl: SemanticZoomControl,
4205
+ ControlType.SeparatorControl: SeparatorControl,
4206
+ ControlType.SliderControl: SliderControl,
4207
+ ControlType.SpinnerControl: SpinnerControl,
4208
+ ControlType.SplitButtonControl: SplitButtonControl,
4209
+ ControlType.StatusBarControl: StatusBarControl,
4210
+ ControlType.TabControl: TabControl,
4211
+ ControlType.TabItemControl: TabItemControl,
4212
+ ControlType.TableControl: TableControl,
4213
+ ControlType.TextControl: TextControl,
4214
+ ControlType.ThumbControl: ThumbControl,
4215
+ ControlType.TitleBarControl: TitleBarControl,
4216
+ ControlType.ToolBarControl: ToolBarControl,
4217
+ ControlType.ToolTipControl: ToolTipControl,
4218
+ ControlType.TreeControl: TreeControl,
4219
+ ControlType.TreeItemControl: TreeItemControl,
4220
+ ControlType.WindowControl: WindowControl,
4221
+ }
4222
+
4223
+
4224
+ class UIAutomationInitializerInThread:
4225
+ def __init__(self, debug: bool = False):
4226
+ self.debug = debug
4227
+ InitializeUIAutomationInCurrentThread()
4228
+ self.inited = True
4229
+ if self.debug:
4230
+ th = threading.currentThread()
4231
+ print('\ncall InitializeUIAutomationInCurrentThread in {}, inited {}'.format(th, self.inited))
4232
+
4233
+ def __del__(self):
4234
+ self.Uninitialize()
4235
+
4236
+ def __enter__(self):
4237
+ return self
4238
+
4239
+ def __exit__(self, exceptionType, exceptionValue, exceptionTraceback):
4240
+ self.Uninitialize()
4241
+
4242
+ def Uninitialize(self):
4243
+ if self.inited:
4244
+ UninitializeUIAutomationInCurrentThread()
4245
+ self.inited = False
4246
+ if self.debug:
4247
+ th = threading.currentThread()
4248
+ print('\ncall UninitializeUIAutomationInCurrentThread in {}'.format(th))
4249
+
4250
+
4251
+ def InitializeUIAutomationInCurrentThread() -> None:
4252
+ """
4253
+ Initialize UIAutomation in a new thread.
4254
+ If you want to use functionalities related to Controls and Patterns in a new thread.
4255
+ You must call this function first in the new thread.
4256
+ But you can't use use a Control or a Pattern created in a different thread.
4257
+ So you can't create a Control or a Pattern in main thread and then pass it to a new thread and use it.
4258
+ """
4259
+ comtypes.CoInitializeEx()
4260
+
4261
+
4262
+ def UninitializeUIAutomationInCurrentThread() -> None:
4263
+ """
4264
+ Uninitialize UIAutomation in a new thread after calling InitializeUIAutomationInCurrentThread.
4265
+ You must call this function when the new thread exits if you have called InitializeUIAutomationInCurrentThread in the same thread.
4266
+ """
4267
+ comtypes.CoUninitialize()
4268
+
4269
+
4270
+ def SetGlobalSearchTimeout(seconds: float) -> None:
4271
+ """
4272
+ seconds: float.
4273
+ To make this available, you need explicitly import uiautomation:
4274
+ from uiautomation import uiautomation as auto
4275
+ auto.SetGlobalSearchTimeout(10)
4276
+ """
4277
+ global TIME_OUT_SECOND
4278
+ TIME_OUT_SECOND = seconds
4279
+
4280
+
4281
+ def WaitForExist(control: Control, timeout: float) -> bool:
4282
+ """
4283
+ Check if control exists in timeout seconds.
4284
+ control: `Control` or its subclass.
4285
+ timeout: float.
4286
+ Return bool.
4287
+ """
4288
+ return control.Exists(timeout, 1)
4289
+
4290
+
4291
+ def WaitForDisappear(control: Control, timeout: float) -> bool:
4292
+ """
4293
+ Check if control disappears in timeout seconds.
4294
+ control: `Control` or its subclass.
4295
+ timeout: float.
4296
+ Return bool.
4297
+ """
4298
+ return control.Disappears(timeout, 1)
4299
+
4300
+
4301
+ def WalkTree(top, getChildren: Optional[Callable[[TreeNode], List[TreeNode]]] = None,
4302
+ getFirstChild: Optional[Callable[[TreeNode], TreeNode]] = None, getNextSibling: Optional[Callable[[TreeNode], TreeNode]] = None,
4303
+ yieldCondition: Optional[Callable[[TreeNode, int], bool]] = None, includeTop: bool = False, maxDepth: int = 0xFFFFFFFF):
4304
+ """
4305
+ Walk a tree not using recursive algorithm.
4306
+ top: a tree node.
4307
+ getChildren: Callable[[TreeNode], List[TreeNode]], function(treeNode: TreeNode) -> List[TreeNode].
4308
+ getNextSibling: Callable[[TreeNode], TreeNode], function(treeNode: TreeNode) -> TreeNode.
4309
+ getNextSibling: Callable[[TreeNode], TreeNode], function(treeNode: TreeNode) -> TreeNode.
4310
+ yieldCondition: Callable[[TreeNode, int], bool], function(treeNode: TreeNode, depth: int) -> bool.
4311
+ includeTop: bool, if True yield top first.
4312
+ maxDepth: int, enum depth.
4313
+
4314
+ If getChildren is valid, ignore getFirstChild and getNextSibling,
4315
+ yield 3 items tuple: (treeNode, depth, remain children count in current depth).
4316
+ If getChildren is not valid, using getFirstChild and getNextSibling,
4317
+ yield 2 items tuple: (treeNode, depth).
4318
+ If yieldCondition is not None, only yield tree nodes that yieldCondition(treeNode: TreeNode, depth: int)->bool returns True.
4319
+
4320
+ For example:
4321
+ def GetDirChildren(dir_):
4322
+ if os.path.isdir(dir_):
4323
+ return [os.path.join(dir_, it) for it in os.listdir(dir_)]
4324
+ for it, depth, leftCount in WalkTree('D:\\', getChildren= GetDirChildren):
4325
+ print(it, depth, leftCount)
4326
+ """
4327
+ if maxDepth <= 0:
4328
+ return
4329
+ depth = 0
4330
+ if getChildren:
4331
+ if includeTop:
4332
+ if not yieldCondition or yieldCondition(top, 0):
4333
+ yield top, 0, 0
4334
+ children = getChildren(top)
4335
+ childList = [children]
4336
+ while depth >= 0: # or while childList:
4337
+ lastItems = childList[-1]
4338
+ if lastItems:
4339
+ if not yieldCondition or yieldCondition(lastItems[0], depth + 1):
4340
+ yield lastItems[0], depth + 1, len(lastItems) - 1
4341
+ if depth + 1 < maxDepth:
4342
+ children = getChildren(lastItems[0])
4343
+ if children:
4344
+ depth += 1
4345
+ childList.append(children)
4346
+ del lastItems[0]
4347
+ else:
4348
+ del childList[depth]
4349
+ depth -= 1
4350
+ elif getFirstChild and getNextSibling:
4351
+ if includeTop:
4352
+ if not yieldCondition or yieldCondition(top, 0):
4353
+ yield top, 0
4354
+ child = getFirstChild(top)
4355
+ childList = [child]
4356
+ while depth >= 0: # or while childList:
4357
+ lastItem = childList[-1]
4358
+ if lastItem:
4359
+ if not yieldCondition or yieldCondition(lastItem, depth + 1):
4360
+ yield lastItem, depth + 1
4361
+ child = getNextSibling(lastItem)
4362
+ childList[depth] = child
4363
+ if depth + 1 < maxDepth:
4364
+ child = getFirstChild(lastItem)
4365
+ if child:
4366
+ depth += 1
4367
+ childList.append(child)
4368
+ else:
4369
+ del childList[depth]
4370
+ depth -= 1
4371
+
4372
+
4373
+ def GetRootControl() -> PaneControl:
4374
+ """
4375
+ Get root control, the Desktop window.
4376
+ Return `PaneControl`.
4377
+ """
4378
+ control = Control.CreateControlFromElement(_AutomationClient.instance().IUIAutomation.GetRootElement())
4379
+ if isinstance(control, PaneControl):
4380
+ return control
4381
+
4382
+ if control is None:
4383
+ raise AssertionError('Expected valid root element')
4384
+ raise AssertionError('Expected root element to be a PaneControl. Found: %s (%s)' % (type(control), control))
4385
+
4386
+
4387
+ def GetFocusedControl() -> Optional[Control]:
4388
+ """Return `Control` subclass."""
4389
+ return Control.CreateControlFromElement(_AutomationClient.instance().IUIAutomation.GetFocusedElement())
4390
+
4391
+
4392
+ def GetForegroundControl() -> Control:
4393
+ """Return `Control` subclass."""
4394
+ return ControlFromHandle(GetForegroundWindow())
4395
+ # another implement
4396
+ #focusedControl = GetFocusedControl()
4397
+ #parentControl = focusedControl
4398
+ #controlList = []
4399
+ # while parentControl:
4400
+ #controlList.insert(0, parentControl)
4401
+ #parentControl = parentControl.GetParentControl()
4402
+ # if len(controlList) == 1:
4403
+ #parentControl = controlList[0]
4404
+ # else:
4405
+ #parentControl = controlList[1]
4406
+ # return parentControl
4407
+
4408
+
4409
+ def GetConsoleWindow() -> Optional[WindowControl]:
4410
+ """Return `WindowControl` or None, a console window that runs python."""
4411
+ consoleWindow = ControlFromHandle(ctypes.windll.kernel32.GetConsoleWindow())
4412
+ if consoleWindow and consoleWindow.ClassName == 'PseudoConsoleWindow':
4413
+ # Windows Terminal
4414
+ consoleWindow = consoleWindow.GetParentControl()
4415
+ return consoleWindow
4416
+
4417
+
4418
+ def ControlFromPoint(x: int, y: int) -> Optional[Control]:
4419
+ """
4420
+ Call IUIAutomation ElementFromPoint x,y. May return None if mouse is over cmd's title bar icon.
4421
+ Return `Control` subclass or None.
4422
+ """
4423
+ element = _AutomationClient.instance().IUIAutomation.ElementFromPoint(ctypes.wintypes.POINT(x, y))
4424
+ return Control.CreateControlFromElement(element)
4425
+
4426
+
4427
+ def ControlFromPoint2(x: int, y: int) -> Optional[Control]:
4428
+ """
4429
+ Get a native handle from point x,y and call IUIAutomation.ElementFromHandle.
4430
+ Return `Control` subclass.
4431
+ """
4432
+ return Control.CreateControlFromElement(_AutomationClient.instance().IUIAutomation.ElementFromHandle(WindowFromPoint(x, y)))
4433
+
4434
+
4435
+ def ControlFromCursor() -> Optional[Control]:
4436
+ """
4437
+ Call ControlFromPoint with current cursor point.
4438
+ Return `Control` subclass.
4439
+ """
4440
+ x, y = GetCursorPos()
4441
+ return ControlFromPoint(x, y)
4442
+
4443
+
4444
+ def ControlFromCursor2() -> Optional[Control]:
4445
+ """
4446
+ Call ControlFromPoint2 with current cursor point.
4447
+ Return `Control` subclass.
4448
+ """
4449
+ x, y = GetCursorPos()
4450
+ return ControlFromPoint2(x, y)
4451
+
4452
+
4453
+ def ControlFromHandle(handle: int) -> Optional[Control]:
4454
+ """
4455
+ Call IUIAutomation.ElementFromHandle with a native handle.
4456
+ handle: int, a native window handle.
4457
+ Return `Control` subclass or None.
4458
+ """
4459
+ if handle:
4460
+ return Control.CreateControlFromElement(_AutomationClient.instance().IUIAutomation.ElementFromHandle(handle))
4461
+ return None
4462
+
4463
+
4464
+ def ControlsAreSame(control1: Control, control2: Control) -> bool:
4465
+ """
4466
+ control1: `Control` or its subclass.
4467
+ control2: `Control` or its subclass.
4468
+ Return bool, True if control1 and control2 represent the same control otherwise False.
4469
+ """
4470
+ return bool(_AutomationClient.instance().IUIAutomation.CompareElements(control1.Element, control2.Element))
4471
+
4472
+
4473
+ def WalkControl(control: Control, includeTop: bool = False, maxDepth: int = 0xFFFFFFFF) -> Generator[Tuple[Control, int], None, None]:
4474
+ """
4475
+ control: `Control` or its subclass.
4476
+ includeTop: bool, if True, yield (control, 0) first.
4477
+ maxDepth: int, enum depth.
4478
+ Yield 2 items tuple (control: Control, depth: int).
4479
+ """
4480
+ if includeTop:
4481
+ yield control, 0
4482
+ if maxDepth <= 0:
4483
+ return
4484
+ depth = 0
4485
+ child = control.GetFirstChildControl()
4486
+ controlList = [child]
4487
+ while depth >= 0:
4488
+ lastControl = controlList[-1]
4489
+ if lastControl:
4490
+ yield lastControl, depth + 1
4491
+ child = lastControl.GetNextSiblingControl()
4492
+ controlList[depth] = child
4493
+ if depth + 1 < maxDepth:
4494
+ child = lastControl.GetFirstChildControl()
4495
+ if child:
4496
+ depth += 1
4497
+ controlList.append(child)
4498
+ else:
4499
+ del controlList[depth]
4500
+ depth -= 1
4501
+
4502
+
4503
+ def LogControl(control: Control, depth: int = 0, showAllName: bool = True, showPid: bool = False) -> None:
4504
+ """
4505
+ Print and log control's properties.
4506
+ control: `Control` or its subclass.
4507
+ depth: int, current depth.
4508
+ showAllName: bool, if False, print the first 30 characters of control.Name.
4509
+ """
4510
+ indent = ' ' * depth * 4
4511
+ Logger.Write('{0}ControlType: '.format(indent))
4512
+ Logger.Write(control.ControlTypeName, ConsoleColor.DarkGreen)
4513
+ Logger.Write(' ClassName: ')
4514
+ Logger.Write(control.ClassName, ConsoleColor.DarkGreen)
4515
+ Logger.Write(' AutomationId: ')
4516
+ Logger.Write(control.AutomationId, ConsoleColor.DarkGreen)
4517
+ Logger.Write(' Rect: ')
4518
+ Logger.Write(control.BoundingRectangle, ConsoleColor.DarkGreen)
4519
+ Logger.Write(' Name: ')
4520
+ Logger.Write(control.Name, ConsoleColor.DarkGreen, printTruncateLen=0 if showAllName else 30)
4521
+ Logger.Write(' Handle: ')
4522
+ Logger.Write('0x{0:X}({0})'.format(control.NativeWindowHandle), ConsoleColor.DarkGreen)
4523
+ Logger.Write(' Depth: ')
4524
+ Logger.Write(depth, ConsoleColor.DarkGreen)
4525
+ if showPid:
4526
+ Logger.Write(' ProcessId: ')
4527
+ Logger.Write(control.ProcessId, ConsoleColor.DarkGreen)
4528
+ supportedPatterns = list(filter(lambda t: t[0], ((control.GetPattern(id_), name) for id_, name in PatternIdNames.items())))
4529
+ for pt, name in supportedPatterns:
4530
+ if isinstance(pt, ValuePattern):
4531
+ Logger.Write(' ValuePattern.Value: ')
4532
+ Logger.Write(repr(pt.Value), ConsoleColor.DarkGreen, printTruncateLen=0 if showAllName else 30)
4533
+ elif isinstance(pt, RangeValuePattern):
4534
+ Logger.Write(' RangeValuePattern.Value: ')
4535
+ Logger.Write(pt.Value, ConsoleColor.DarkGreen)
4536
+ elif isinstance(pt, TogglePattern):
4537
+ Logger.Write(' TogglePattern.ToggleState: ')
4538
+ Logger.Write('ToggleState.' + _GetDictKeyName(ToggleState.__dict__, pt.ToggleState), ConsoleColor.DarkGreen)
4539
+ elif isinstance(pt, SelectionItemPattern):
4540
+ Logger.Write(' SelectionItemPattern.IsSelected: ')
4541
+ Logger.Write(pt.IsSelected, ConsoleColor.DarkGreen)
4542
+ elif isinstance(pt, ExpandCollapsePattern):
4543
+ Logger.Write(' ExpandCollapsePattern.ExpandCollapseState: ')
4544
+ Logger.Write('ExpandCollapseState.' + _GetDictKeyName(ExpandCollapseState.__dict__, pt.ExpandCollapseState), ConsoleColor.DarkGreen)
4545
+ elif isinstance(pt, ScrollPattern):
4546
+ Logger.Write(' ScrollPattern.HorizontalScrollPercent: ')
4547
+ Logger.Write(pt.HorizontalScrollPercent, ConsoleColor.DarkGreen)
4548
+ Logger.Write(' ScrollPattern.VerticalScrollPercent: ')
4549
+ Logger.Write(pt.VerticalScrollPercent, ConsoleColor.DarkGreen)
4550
+ elif isinstance(pt, GridPattern):
4551
+ Logger.Write(' GridPattern.RowCount: ')
4552
+ Logger.Write(pt.RowCount, ConsoleColor.DarkGreen)
4553
+ Logger.Write(' GridPattern.ColumnCount: ')
4554
+ Logger.Write(pt.ColumnCount, ConsoleColor.DarkGreen)
4555
+ elif isinstance(pt, GridItemPattern):
4556
+ Logger.Write(' GridItemPattern.Row: ')
4557
+ Logger.Write(pt.Row, ConsoleColor.DarkGreen)
4558
+ Logger.Write(' GridItemPattern.Column: ')
4559
+ Logger.Write(pt.Column, ConsoleColor.DarkGreen)
4560
+ elif isinstance(pt, TextPattern):
4561
+ # issue 49: CEF Control as DocumentControl have no "TextPattern.Text" property, skip log this part.
4562
+ # https://docs.microsoft.com/en-us/windows/win32/api/uiautomationclient/nf-uiautomationclient-iuiautomationtextpattern-get_documentrange
4563
+ try:
4564
+ Logger.Write(' TextPattern.Text: ')
4565
+ Logger.Write(repr(pt.DocumentRange.GetText(30)), ConsoleColor.DarkGreen)
4566
+ except comtypes.COMError as ex:
4567
+ pass
4568
+ Logger.Write(' SupportedPattern:')
4569
+ for pt, name in supportedPatterns:
4570
+ Logger.Write(' ' + name, ConsoleColor.DarkGreen)
4571
+ Logger.Write('\n')
4572
+
4573
+
4574
+ def EnumAndLogControl(control: Control, maxDepth: int = 0xFFFFFFFF, showAllName: bool = True, showPid: bool = False, startDepth: int = 0) -> None:
4575
+ """
4576
+ Print and log control and its descendants' propertyies.
4577
+ control: `Control` or its subclass.
4578
+ maxDepth: int, enum depth.
4579
+ showAllName: bool, if False, print the first 30 characters of control.Name.
4580
+ startDepth: int, control's current depth.
4581
+ """
4582
+ for c, d in WalkControl(control, True, maxDepth):
4583
+ LogControl(c, d + startDepth, showAllName, showPid)
4584
+
4585
+
4586
+ def EnumAndLogControlAncestors(control: Control, showAllName: bool = True, showPid: bool = False) -> None:
4587
+ """
4588
+ Print and log control and its ancestors' propertyies.
4589
+ control: `Control` or its subclass.
4590
+ showAllName: bool, if False, print the first 30 characters of control.Name.
4591
+ """
4592
+ curr = control
4593
+ lists = []
4594
+ while curr:
4595
+ lists.insert(0, curr)
4596
+ curr = curr.GetParentControl()
4597
+ for i, curr in enumerate(lists):
4598
+ LogControl(curr, i, showAllName, showPid)
4599
+
4600
+
4601
+ def FindControl(control: Optional[Control], compare: Callable[[Control, int], bool], maxDepth: int = 0xFFFFFFFF, findFromSelf: bool = False, foundIndex: int = 1) -> Optional[Control]:
4602
+ """
4603
+ control: `Control` or its subclass.
4604
+ compare: Callable[[Control, int], bool], function(control: Control, depth: int) -> bool.
4605
+ maxDepth: int, enum depth.
4606
+ findFromSelf: bool, if False, do not compare self.
4607
+ foundIndex: int, starts with 1, >= 1.
4608
+ Return `Control` subclass or None if not find.
4609
+ """
4610
+ foundCount = 0
4611
+ if not control:
4612
+ control = GetRootControl()
4613
+ traverseCount = 0
4614
+ for child, depth in WalkControl(control, findFromSelf, maxDepth):
4615
+ traverseCount += 1
4616
+ if compare(child, depth):
4617
+ foundCount += 1
4618
+ if foundCount == foundIndex:
4619
+ child.traverseCount = traverseCount
4620
+ return child
4621
+ return None
4622
+
4623
+
4624
+ def ShowDesktop(waitTime: float = 1) -> None:
4625
+ """Show Desktop by pressing win + d"""
4626
+ SendKeys('{Win}d', waitTime=waitTime)
4627
+ # another implement
4628
+ #paneTray = PaneControl(searchDepth = 1, ClassName = 'Shell_TrayWnd')
4629
+ # if paneTray.Exists():
4630
+ #WM_COMMAND = 0x111
4631
+ #MIN_ALL = 419
4632
+ #MIN_ALL_UNDO = 416
4633
+ #PostMessage(paneTray.NativeWindowHandle, WM_COMMAND, MIN_ALL, 0)
4634
+ # time.sleep(1)
4635
+
4636
+
4637
+ def WaitHotKeyReleased(hotkey: Tuple[int, int]) -> None:
4638
+ """hotkey: Tuple[int, int], two ints tuple (modifierKey, key)"""
4639
+ mod = {ModifierKey.Alt: Keys.VK_MENU,
4640
+ ModifierKey.Control: Keys.VK_CONTROL,
4641
+ ModifierKey.Shift: Keys.VK_SHIFT,
4642
+ ModifierKey.Win: Keys.VK_LWIN
4643
+ }
4644
+ while True:
4645
+ time.sleep(0.05)
4646
+ if IsKeyPressed(hotkey[1]):
4647
+ continue
4648
+ for k, v in mod.items():
4649
+ if k & hotkey[0]:
4650
+ if IsKeyPressed(v):
4651
+ break
4652
+ else:
4653
+ break
4654
+
4655
+
4656
+ def RunByHotKey(keyFunctions: Dict[Tuple[int, int], Callable], stopHotKey: Optional[Tuple[int, int]] = None, exitHotKey: Tuple[int, int] = (ModifierKey.Control, Keys.VK_D), waitHotKeyReleased: bool = True) -> None:
4657
+ """
4658
+ Bind functions with hotkeys, the function will be run or stopped in another thread when the hotkey is pressed.
4659
+ keyFunctions: Dict[Tuple[int, int], Callable], such as {(uiautomation.ModifierKey.Control, uiautomation.Keys.VK_1) : function}
4660
+ stopHotKey: hotkey tuple
4661
+ exitHotKey: hotkey tuple
4662
+ waitHotKeyReleased: bool, if True, hotkey function will be triggered after the hotkey is released
4663
+
4664
+ def main(stopEvent):
4665
+ while True:
4666
+ if stopEvent.is_set(): # must check stopEvent.is_set() if you want to stop when stop hotkey is pressed
4667
+ break
4668
+ print(n)
4669
+ n += 1
4670
+ stopEvent.wait(1)
4671
+ print('main exit')
4672
+
4673
+ uiautomation.RunByHotKey({(uiautomation.ModifierKey.Control, uiautomation.Keys.VK_1) : main}
4674
+ , (uiautomation.ModifierKey.Control | uiautomation.ModifierKey.Shift, uiautomation.Keys.VK_2))
4675
+ """
4676
+ import traceback
4677
+
4678
+ def getModName(theDict, theValue):
4679
+ name = ''
4680
+ for key in theDict:
4681
+ if isinstance(theDict[key], int) and theValue & theDict[key]:
4682
+ if name:
4683
+ name += '|'
4684
+ name += key
4685
+ return name
4686
+
4687
+ def releaseAllKeys():
4688
+ for key, value in Keys.__dict__.items():
4689
+ if isinstance(value, int) and key.startswith('VK'):
4690
+ if IsKeyPressed(value):
4691
+ ReleaseKey(value)
4692
+
4693
+ def threadFunc(function, stopEvent, hotkey, hotkeyName):
4694
+ if waitHotKeyReleased:
4695
+ WaitHotKeyReleased(hotkey)
4696
+ try:
4697
+ function(stopEvent)
4698
+ except Exception as ex:
4699
+ Logger.ColorfullyWrite('Catch an exception <Color=Red>{}</Color> in thread for hotkey <Color=DarkCyan>{}</Color>\n'.format(
4700
+ ex.__class__.__name__, hotkeyName), writeToFile=False)
4701
+ print(traceback.format_exc())
4702
+ finally:
4703
+ releaseAllKeys() # need to release keys if some keys were pressed
4704
+ Logger.ColorfullyWrite('{} for function <Color=DarkCyan>{}</Color> exits, hotkey <Color=DarkCyan>{}</Color>\n'.format(
4705
+ threading.currentThread(), function.__name__, hotkeyName), ConsoleColor.DarkYellow, writeToFile=False)
4706
+
4707
+ stopHotKeyId = 1
4708
+ exitHotKeyId = 2
4709
+ hotKeyId = 3
4710
+ registed = True
4711
+ id2HotKey = {}
4712
+ id2Function = {}
4713
+ id2Thread = {}
4714
+ id2Name = {}
4715
+ for hotkey in keyFunctions:
4716
+ id2HotKey[hotKeyId] = hotkey
4717
+ id2Function[hotKeyId] = keyFunctions[hotkey]
4718
+ id2Thread[hotKeyId] = None
4719
+ modName = getModName(ModifierKey.__dict__, hotkey[0])
4720
+ keyName = _GetDictKeyName(Keys.__dict__, hotkey[1])
4721
+ id2Name[hotKeyId] = str((modName, keyName))
4722
+ if ctypes.windll.user32.RegisterHotKey(0, hotKeyId, hotkey[0], hotkey[1]):
4723
+ Logger.ColorfullyWrite('Register hotkey <Color=Cyan>{}</Color> successfully\n'.format((modName, keyName)), writeToFile=False)
4724
+ else:
4725
+ registed = False
4726
+ Logger.ColorfullyWrite('Register hotkey <Color=Cyan>{}</Color> unsuccessfully, maybe it was allready registered by another program\n'.format((modName, keyName)), writeToFile=False)
4727
+ hotKeyId += 1
4728
+ if stopHotKey and len(stopHotKey) == 2:
4729
+ modName = getModName(ModifierKey.__dict__, stopHotKey[0])
4730
+ keyName = _GetDictKeyName(Keys.__dict__, stopHotKey[1])
4731
+ if ctypes.windll.user32.RegisterHotKey(0, stopHotKeyId, stopHotKey[0], stopHotKey[1]):
4732
+ Logger.ColorfullyWrite('Register stop hotkey <Color=DarkYellow>{}</Color> successfully\n'.format((modName, keyName)), writeToFile=False)
4733
+ else:
4734
+ registed = False
4735
+ Logger.ColorfullyWrite('Register stop hotkey <Color=DarkYellow>{}</Color> unsuccessfully, maybe it was allready registered by another program\n'.format((modName, keyName)), writeToFile=False)
4736
+ if not registed:
4737
+ return
4738
+ if exitHotKey and len(exitHotKey) == 2:
4739
+ modName = getModName(ModifierKey.__dict__, exitHotKey[0])
4740
+ keyName = _GetDictKeyName(Keys.__dict__, exitHotKey[1])
4741
+ if ctypes.windll.user32.RegisterHotKey(0, exitHotKeyId, exitHotKey[0], exitHotKey[1]):
4742
+ Logger.ColorfullyWrite('Register exit hotkey <Color=DarkYellow>{}</Color> successfully\n'.format((modName, keyName)), writeToFile=False)
4743
+ else:
4744
+ Logger.ColorfullyWrite('Register exit hotkey <Color=DarkYellow>{}</Color> unsuccessfully\n'.format((modName, keyName)), writeToFile=False)
4745
+ funcThread = None
4746
+ livingThreads = []
4747
+ stopEvent = threading.Event()
4748
+ msg = ctypes.wintypes.MSG()
4749
+ while ctypes.windll.user32.GetMessageW(ctypes.byref(msg), ctypes.c_void_p(0), ctypes.c_uint(0), ctypes.c_uint(0)) != 0:
4750
+ if msg.message == 0x0312: # WM_HOTKEY=0x0312
4751
+ if msg.wParam in id2HotKey:
4752
+ if msg.lParam & 0x0000FFFF == id2HotKey[msg.wParam][0] and msg.lParam >> 16 & 0x0000FFFF == id2HotKey[msg.wParam][1]:
4753
+ Logger.ColorfullyWrite('----------hotkey <Color=Cyan>{}</Color> pressed----------\n'.format(id2Name[msg.wParam]), writeToFile=False)
4754
+ if not id2Thread[msg.wParam]:
4755
+ stopEvent.clear()
4756
+ funcThread = threading.Thread(None, threadFunc, args=(id2Function[msg.wParam], stopEvent, id2HotKey[msg.wParam], id2Name[msg.wParam]))
4757
+ funcThread.start()
4758
+ id2Thread[msg.wParam] = funcThread
4759
+ else:
4760
+ if id2Thread[msg.wParam].is_alive():
4761
+ Logger.WriteLine('There is a {} that is already running for hotkey {}'.format(id2Thread[msg.wParam], id2Name[msg.wParam]), ConsoleColor.Yellow, writeToFile=False)
4762
+ else:
4763
+ stopEvent.clear()
4764
+ funcThread = threading.Thread(None, threadFunc, args=(id2Function[msg.wParam], stopEvent, id2HotKey[msg.wParam], id2Name[msg.wParam]))
4765
+ funcThread.start()
4766
+ id2Thread[msg.wParam] = funcThread
4767
+ elif stopHotKeyId == msg.wParam:
4768
+ if msg.lParam & 0x0000FFFF == stopHotKey[0] and msg.lParam >> 16 & 0x0000FFFF == stopHotKey[1]:
4769
+ Logger.Write('----------stop hotkey pressed----------\n', ConsoleColor.DarkYellow, writeToFile=False)
4770
+ stopEvent.set()
4771
+ for id_ in id2Thread:
4772
+ if id2Thread[id_]:
4773
+ if id2Thread[id_].is_alive():
4774
+ livingThreads.append((id2Thread[id_], id2Name[id_]))
4775
+ id2Thread[id_] = None
4776
+ elif exitHotKeyId == msg.wParam:
4777
+ if msg.lParam & 0x0000FFFF == exitHotKey[0] and msg.lParam >> 16 & 0x0000FFFF == exitHotKey[1]:
4778
+ Logger.Write('Exit hotkey pressed. Exit\n', ConsoleColor.DarkYellow, writeToFile=False)
4779
+ stopEvent.set()
4780
+ for id_ in id2Thread:
4781
+ if id2Thread[id_]:
4782
+ if id2Thread[id_].is_alive():
4783
+ livingThreads.append((id2Thread[id_], id2Name[id_]))
4784
+ id2Thread[id_] = None
4785
+ break
4786
+ for thread, hotkeyName in livingThreads:
4787
+ if thread.is_alive():
4788
+ Logger.Write('join {} triggered by hotkey {}\n'.format(thread, hotkeyName), ConsoleColor.DarkYellow, writeToFile=False)
4789
+ thread.join(2)
4790
+ exit()