robotframework-platynui 0.0.1__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.
- PlatynUI/ButtonKeywords.py +9 -0
- PlatynUI/TextKeywords.py +7 -0
- PlatynUI/__about__.py +4 -0
- PlatynUI/__init__.py +34 -0
- PlatynUI/core/__init__.py +13 -0
- PlatynUI/core/adapter.py +152 -0
- PlatynUI/core/adapterfactory.py +51 -0
- PlatynUI/core/adapterproxy.py +168 -0
- PlatynUI/core/contextbase.py +586 -0
- PlatynUI/core/exceptions.py +77 -0
- PlatynUI/core/internal/__init__.py +0 -0
- PlatynUI/core/internal/decorator.py +148 -0
- PlatynUI/core/locatorbase.py +197 -0
- PlatynUI/core/locatorscope.py +17 -0
- PlatynUI/core/predicate.py +15 -0
- PlatynUI/core/settings.py +63 -0
- PlatynUI/core/strategies/__init__.py +1 -0
- PlatynUI/core/strategies/strategies.py +26 -0
- PlatynUI/core/strategybase.py +8 -0
- PlatynUI/core/strategyimpl.py +102 -0
- PlatynUI/core/technology.py +25 -0
- PlatynUI/core/types.py +421 -0
- PlatynUI/core/wait_for.py +47 -0
- PlatynUI/core/weight_calculator.py +110 -0
- PlatynUI/py.typed +0 -0
- PlatynUI/robot/__init__.py +0 -0
- PlatynUI/robot/reporting.py +74 -0
- PlatynUI/technology/__init__.py +0 -0
- PlatynUI/technology/uiautomation/.gitignore +1 -0
- PlatynUI/technology/uiautomation/__init__.py +4 -0
- PlatynUI/technology/uiautomation/core/adapterfactory.py +88 -0
- PlatynUI/technology/uiautomation/core/displaydevice.py +23 -0
- PlatynUI/technology/uiautomation/core/impls/__init__.py +2 -0
- PlatynUI/technology/uiautomation/core/impls/control.py +31 -0
- PlatynUI/technology/uiautomation/core/impls/window.py +83 -0
- PlatynUI/technology/uiautomation/core/keyboarddevice.py +21 -0
- PlatynUI/technology/uiautomation/core/loader.py +117 -0
- PlatynUI/technology/uiautomation/core/mousedevice.py +29 -0
- PlatynUI/technology/uiautomation/core/technology.py +61 -0
- PlatynUI/technology/uiautomation/core/uiaadapter.py +197 -0
- PlatynUI/technology/uiautomation/core/uiabase.py +19 -0
- PlatynUI/technology/uiautomation/desktop.py +11 -0
- PlatynUI/technology/uiautomation/locator.py +435 -0
- PlatynUI/technology/uiautomation/runtime/Caliburn.Micro.Core.dll +0 -0
- PlatynUI/technology/uiautomation/runtime/Caliburn.Micro.Platform.Core.dll +0 -0
- PlatynUI/technology/uiautomation/runtime/Caliburn.Micro.Platform.dll +0 -0
- PlatynUI/technology/uiautomation/runtime/Microsoft.Xaml.Behaviors.dll +0 -0
- PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.Spy.deps.json +266 -0
- PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.Spy.dll +0 -0
- PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.Spy.exe +0 -0
- PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.Spy.runtimeconfig.json +19 -0
- PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.dll +0 -0
- PlatynUI/technology/uiautomation/runtime/System.ComponentModel.Composition.dll +0 -0
- PlatynUI/technology/uiautomation/spy/__init__.py +0 -0
- PlatynUI/technology/uiautomation/spy/__main__.py +24 -0
- PlatynUI/ui/__init__.py +65 -0
- PlatynUI/ui/application.py +27 -0
- PlatynUI/ui/buttons.py +82 -0
- PlatynUI/ui/combobox.py +149 -0
- PlatynUI/ui/container.py +9 -0
- PlatynUI/ui/control.py +49 -0
- PlatynUI/ui/core/__init__.py +3 -0
- PlatynUI/ui/core/devices/__init__.py +6 -0
- PlatynUI/ui/core/devices/basedisplaydevice.py +25 -0
- PlatynUI/ui/core/devices/basekeyboarddevice.py +64 -0
- PlatynUI/ui/core/devices/basemousedevice.py +30 -0
- PlatynUI/ui/core/devices/basescreendevice.py +16 -0
- PlatynUI/ui/core/devices/displaydevice.py +113 -0
- PlatynUI/ui/core/devices/inputdevice.py +24 -0
- PlatynUI/ui/core/devices/keyboarddevice.py +279 -0
- PlatynUI/ui/core/devices/keyboardproxy.py +69 -0
- PlatynUI/ui/core/devices/mousebutton.py +11 -0
- PlatynUI/ui/core/devices/mousedevice.py +279 -0
- PlatynUI/ui/core/devices/mouseproxy.py +178 -0
- PlatynUI/ui/core/ui_technology.py +31 -0
- PlatynUI/ui/core/window_manager.py +59 -0
- PlatynUI/ui/desktopbase.py +56 -0
- PlatynUI/ui/dialog.py +10 -0
- PlatynUI/ui/edit.py +48 -0
- PlatynUI/ui/element.py +265 -0
- PlatynUI/ui/graphic.py +14 -0
- PlatynUI/ui/header.py +33 -0
- PlatynUI/ui/item.py +100 -0
- PlatynUI/ui/lists.py +37 -0
- PlatynUI/ui/menus.py +42 -0
- PlatynUI/ui/orientation.py +9 -0
- PlatynUI/ui/pane.py +14 -0
- PlatynUI/ui/proxies/__init__.py +4 -0
- PlatynUI/ui/proxies/standardproxies.py +391 -0
- PlatynUI/ui/scrollbar.py +9 -0
- PlatynUI/ui/strategies/__init__.py +19 -0
- PlatynUI/ui/strategies/activatable.py +27 -0
- PlatynUI/ui/strategies/application.py +28 -0
- PlatynUI/ui/strategies/closeable.py +22 -0
- PlatynUI/ui/strategies/control.py +16 -0
- PlatynUI/ui/strategies/editable.py +13 -0
- PlatynUI/ui/strategies/element.py +65 -0
- PlatynUI/ui/strategies/expandable.py +27 -0
- PlatynUI/ui/strategies/hasnativewindowhandle.py +14 -0
- PlatynUI/ui/strategies/hasorientation.py +15 -0
- PlatynUI/ui/strategies/maximizeable.py +27 -0
- PlatynUI/ui/strategies/minimizeable.py +27 -0
- PlatynUI/ui/strategies/movable.py +14 -0
- PlatynUI/ui/strategies/resizable.py +13 -0
- PlatynUI/ui/strategies/restorable.py +13 -0
- PlatynUI/ui/strategies/selectable.py +27 -0
- PlatynUI/ui/strategies/text.py +55 -0
- PlatynUI/ui/strategies/title.py +14 -0
- PlatynUI/ui/strategies/toggleable.py +23 -0
- PlatynUI/ui/strategies/value.py +15 -0
- PlatynUI/ui/table.py +56 -0
- PlatynUI/ui/tabs.py +28 -0
- PlatynUI/ui/text.py +14 -0
- PlatynUI/ui/togglestate.py +12 -0
- PlatynUI/ui/tree.py +99 -0
- PlatynUI/ui/unknown.py +9 -0
- PlatynUI/ui/window.py +177 -0
- robotframework_platynui-0.0.1.dist-info/METADATA +49 -0
- robotframework_platynui-0.0.1.dist-info/RECORD +122 -0
- robotframework_platynui-0.0.1.dist-info/WHEEL +4 -0
- robotframework_platynui-0.0.1.dist-info/entry_points.txt +2 -0
- robotframework_platynui-0.0.1.dist-info/licenses/LICENSE.txt +73 -0
PlatynUI/ui/element.py
ADDED
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
from typing import Optional, cast
|
|
2
|
+
|
|
3
|
+
from ..core import ContextBase, ContextFactory, context
|
|
4
|
+
from ..core.exceptions import NoKeyboardProxyError, NoMouseProxyError
|
|
5
|
+
from ..core.predicate import predicate
|
|
6
|
+
from ..core.settings import Settings
|
|
7
|
+
from ..core.types import Point, Rect
|
|
8
|
+
from ..ui.core import UiTechnology
|
|
9
|
+
from ..ui.core.devices.displaydevice import DisplayDevice
|
|
10
|
+
from ..ui.core.devices.keyboarddevice import KeyboardDevice
|
|
11
|
+
from ..ui.core.devices.keyboardproxy import KeyboardProxy
|
|
12
|
+
from ..ui.core.devices.mousedevice import MouseDevice
|
|
13
|
+
from ..ui.core.devices.mouseproxy import MouseProxy
|
|
14
|
+
from . import strategies
|
|
15
|
+
|
|
16
|
+
__all__ = ["Element"]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@context
|
|
20
|
+
class Element(ContextBase):
|
|
21
|
+
default_prefix = "element"
|
|
22
|
+
|
|
23
|
+
def invalidate(self) -> None:
|
|
24
|
+
super().invalidate()
|
|
25
|
+
self._mouse_proxy = None
|
|
26
|
+
self._keyboard_proxy = None
|
|
27
|
+
|
|
28
|
+
@property
|
|
29
|
+
def is_readonly(self) -> bool:
|
|
30
|
+
self.ensure_that(self._application_is_ready)
|
|
31
|
+
|
|
32
|
+
return self.adapter.get_strategy(strategies.Element).is_readonly
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
def is_enabled(self) -> bool:
|
|
36
|
+
self.ensure_that(self._application_is_ready)
|
|
37
|
+
|
|
38
|
+
return self.adapter.get_strategy(strategies.Element).is_enabled
|
|
39
|
+
|
|
40
|
+
@property
|
|
41
|
+
def is_visible(self) -> bool:
|
|
42
|
+
self.ensure_that(self._application_is_ready)
|
|
43
|
+
|
|
44
|
+
return self.adapter.get_strategy(strategies.Element).is_visible
|
|
45
|
+
|
|
46
|
+
@property
|
|
47
|
+
def is_in_view(self) -> bool:
|
|
48
|
+
self.ensure_that(self._application_is_ready)
|
|
49
|
+
|
|
50
|
+
return self.adapter.get_strategy(strategies.Element).is_in_view
|
|
51
|
+
|
|
52
|
+
@property
|
|
53
|
+
def toplevel_parent_is_active(self) -> bool:
|
|
54
|
+
from .window import Window
|
|
55
|
+
|
|
56
|
+
self.ensure_that(self._application_is_ready)
|
|
57
|
+
top_level_window = self.top_level_parent
|
|
58
|
+
if isinstance(top_level_window, Window):
|
|
59
|
+
return top_level_window.is_active
|
|
60
|
+
|
|
61
|
+
return self.adapter.get_strategy(strategies.Element).toplevel_parent_is_active
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def bounding_rectangle(self) -> Rect:
|
|
65
|
+
self.ensure_that(self._application_is_ready)
|
|
66
|
+
|
|
67
|
+
return self.adapter.get_strategy(strategies.Element).bounding_rectangle
|
|
68
|
+
|
|
69
|
+
@property
|
|
70
|
+
def visible_rectangle(self) -> Rect:
|
|
71
|
+
self.ensure_that(self._application_is_ready)
|
|
72
|
+
|
|
73
|
+
return self.adapter.get_strategy(strategies.Element).visible_rectangle
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def default_click_position(self) -> Point:
|
|
77
|
+
self.ensure_that(self._application_is_ready)
|
|
78
|
+
|
|
79
|
+
return self.adapter.get_strategy(strategies.Element).default_click_position
|
|
80
|
+
|
|
81
|
+
@predicate("element {0} is visible")
|
|
82
|
+
def _element_is_visible(self) -> bool:
|
|
83
|
+
self.ensure_that(self._application_is_ready)
|
|
84
|
+
|
|
85
|
+
return self.adapter.get_strategy(strategies.Element).try_ensure_visible()
|
|
86
|
+
|
|
87
|
+
@predicate("element {0} is enabled")
|
|
88
|
+
def _element_is_enabled(self) -> bool:
|
|
89
|
+
self.ensure_that(self._application_is_ready)
|
|
90
|
+
|
|
91
|
+
return self.adapter.get_strategy(strategies.Element).is_enabled
|
|
92
|
+
|
|
93
|
+
@predicate("element {0} is not readonly")
|
|
94
|
+
def _element_is_not_readonly(self) -> bool:
|
|
95
|
+
self.ensure_that(self._application_is_ready)
|
|
96
|
+
|
|
97
|
+
return not self.adapter.get_strategy(strategies.Element).is_readonly
|
|
98
|
+
|
|
99
|
+
@predicate("application for {0} is ready")
|
|
100
|
+
def _application_is_ready(self) -> bool:
|
|
101
|
+
if not self.is_valid:
|
|
102
|
+
return True
|
|
103
|
+
return self.adapter.get_strategy(strategies.Element).try_ensure_application_is_ready()
|
|
104
|
+
|
|
105
|
+
def is_top_level_element(self) -> bool:
|
|
106
|
+
strategy = self.adapter.get_strategy(strategies.TopLevelElement, False)
|
|
107
|
+
if strategy is None:
|
|
108
|
+
return False
|
|
109
|
+
|
|
110
|
+
return strategy.is_top_level_element
|
|
111
|
+
|
|
112
|
+
@property
|
|
113
|
+
def top_level_parent(self) -> Optional["Element"]:
|
|
114
|
+
self.ensure_that(self._adapter_exists)
|
|
115
|
+
|
|
116
|
+
if not self.is_valid:
|
|
117
|
+
return None
|
|
118
|
+
|
|
119
|
+
parent = self.adapter.get_strategy(strategies.Element).top_level_parent
|
|
120
|
+
if parent is None:
|
|
121
|
+
return None
|
|
122
|
+
|
|
123
|
+
loc = self.locator.create_top_level_locator(parent)
|
|
124
|
+
if loc is None:
|
|
125
|
+
return None
|
|
126
|
+
|
|
127
|
+
result = loc.create_context(None, ContextFactory.find_context_class_for(parent))
|
|
128
|
+
result.adapter = parent
|
|
129
|
+
|
|
130
|
+
return result if isinstance(result, Element) else None
|
|
131
|
+
|
|
132
|
+
@predicate("parent top level parent of element {0} is active")
|
|
133
|
+
def _toplevel_parent_is_active(self) -> bool:
|
|
134
|
+
self.ensure_that(self._application_is_ready)
|
|
135
|
+
|
|
136
|
+
return self.adapter.get_strategy(strategies.Element).try_ensure_toplevel_parent_is_active()
|
|
137
|
+
|
|
138
|
+
def activate_parent_window(self) -> bool:
|
|
139
|
+
return self.ensure_that(self._toplevel_parent_is_active)
|
|
140
|
+
|
|
141
|
+
@predicate("element {0} is in view")
|
|
142
|
+
def _element_is_in_view(self) -> bool:
|
|
143
|
+
self.ensure_that(self._element_is_visible)
|
|
144
|
+
|
|
145
|
+
return self.adapter.get_strategy(strategies.Element).try_bring_into_view()
|
|
146
|
+
|
|
147
|
+
def bring_to_view(self) -> bool:
|
|
148
|
+
return self.ensure_that(self._toplevel_parent_is_active, self._element_is_in_view)
|
|
149
|
+
|
|
150
|
+
def highlight(self, rect: Optional[Rect] = None, time: Optional[float] = None) -> None:
|
|
151
|
+
if time is None:
|
|
152
|
+
time = Settings.current().element_highlight_time
|
|
153
|
+
if rect is None:
|
|
154
|
+
rect = self.bounding_rectangle
|
|
155
|
+
if self.is_visible:
|
|
156
|
+
self.ensure_that(
|
|
157
|
+
self._toplevel_parent_is_active,
|
|
158
|
+
self._element_is_in_view,
|
|
159
|
+
raise_exception=False,
|
|
160
|
+
timeout=Settings.current().element_highlight_ensure_timeout,
|
|
161
|
+
)
|
|
162
|
+
|
|
163
|
+
if self.toplevel_parent_is_active and self.is_in_view:
|
|
164
|
+
cast(UiTechnology, self.adapter.technology).display_device.highlight_rect(rect, time)
|
|
165
|
+
|
|
166
|
+
class _ElementMouseProxy(MouseProxy):
|
|
167
|
+
def __init__(self, element: "Element", mouse_device: MouseDevice):
|
|
168
|
+
super().__init__(mouse_device)
|
|
169
|
+
self._element = element
|
|
170
|
+
|
|
171
|
+
@property
|
|
172
|
+
def base_point(self) -> Point:
|
|
173
|
+
return self._element.bounding_rectangle.top_left
|
|
174
|
+
|
|
175
|
+
@property
|
|
176
|
+
def base_rect(self) -> Rect:
|
|
177
|
+
return self._element.bounding_rectangle
|
|
178
|
+
|
|
179
|
+
@property
|
|
180
|
+
def default_click_position(self) -> Point:
|
|
181
|
+
return self._element.default_click_position
|
|
182
|
+
|
|
183
|
+
def before_action(self, action: MouseProxy.Action) -> None:
|
|
184
|
+
self._element.ensure_that(self._element._toplevel_parent_is_active, self._element._element_is_in_view)
|
|
185
|
+
self.mouse_device.add_context(self._element)
|
|
186
|
+
|
|
187
|
+
def after_action(self, action: MouseProxy.Action) -> None:
|
|
188
|
+
self.mouse_device.remove_context(self._element)
|
|
189
|
+
self._element.ensure_that(self._element._application_is_ready, raise_exception=False)
|
|
190
|
+
|
|
191
|
+
_mouse_proxy: Optional[MouseProxy] = None
|
|
192
|
+
|
|
193
|
+
def _create_mouse_proxy(self, mouse_device: MouseDevice) -> MouseProxy:
|
|
194
|
+
return self._ElementMouseProxy(self, mouse_device)
|
|
195
|
+
|
|
196
|
+
@property
|
|
197
|
+
def mouse(self) -> MouseProxy:
|
|
198
|
+
if self._mouse_proxy is None:
|
|
199
|
+
self._mouse_proxy = self._create_mouse_proxy(cast(UiTechnology, self.adapter.technology).mouse_device)
|
|
200
|
+
|
|
201
|
+
if self._mouse_proxy is None:
|
|
202
|
+
raise NoMouseProxyError("cannot get a valid mouse device")
|
|
203
|
+
|
|
204
|
+
return self._mouse_proxy
|
|
205
|
+
|
|
206
|
+
class _ElementKeyboardProxy(KeyboardProxy):
|
|
207
|
+
def __init__(self, element: "Element", keyboard_device: KeyboardDevice):
|
|
208
|
+
super().__init__(keyboard_device)
|
|
209
|
+
self._element = element
|
|
210
|
+
|
|
211
|
+
def before_action(self, action: KeyboardProxy.Action) -> None:
|
|
212
|
+
self._element.ensure_that(
|
|
213
|
+
self._element._toplevel_parent_is_active,
|
|
214
|
+
self._element._element_is_visible,
|
|
215
|
+
self._element._element_is_in_view,
|
|
216
|
+
)
|
|
217
|
+
self.keyboard_device.add_context(self._element)
|
|
218
|
+
|
|
219
|
+
def after_action(self, action: KeyboardProxy.Action) -> None:
|
|
220
|
+
self.keyboard_device.remove_context(self._element)
|
|
221
|
+
self._element.ensure_that(self._element._application_is_ready, raise_exception=False)
|
|
222
|
+
|
|
223
|
+
_keyboard_proxy: Optional[KeyboardProxy] = None
|
|
224
|
+
|
|
225
|
+
def _create_keyboard_proxy(self, keyboard_device: KeyboardDevice) -> KeyboardProxy:
|
|
226
|
+
return self._ElementKeyboardProxy(self, keyboard_device)
|
|
227
|
+
|
|
228
|
+
@property
|
|
229
|
+
def keyboard(self) -> KeyboardProxy:
|
|
230
|
+
if self._keyboard_proxy is None:
|
|
231
|
+
self._keyboard_proxy = self._create_keyboard_proxy(
|
|
232
|
+
cast(UiTechnology, self.adapter.technology).keyboard_device
|
|
233
|
+
)
|
|
234
|
+
|
|
235
|
+
if self._keyboard_proxy is None:
|
|
236
|
+
raise NoKeyboardProxyError("cannot get a valid keyboard device")
|
|
237
|
+
|
|
238
|
+
return self._keyboard_proxy
|
|
239
|
+
|
|
240
|
+
@property
|
|
241
|
+
def display(self) -> DisplayDevice:
|
|
242
|
+
return cast(UiTechnology, self.adapter.technology).display_device
|
|
243
|
+
|
|
244
|
+
def _before_get_screenshot(self) -> None:
|
|
245
|
+
self.ensure_that(self._toplevel_parent_is_active, self._element_is_in_view)
|
|
246
|
+
|
|
247
|
+
def get_screenshot(
|
|
248
|
+
self, rect: Optional[Rect] = None, format: Optional[str] = None, quality: Optional[int] = None
|
|
249
|
+
) -> bytearray:
|
|
250
|
+
self._before_get_screenshot()
|
|
251
|
+
|
|
252
|
+
return self.display.get_screenshot(rect if rect is not None else self.bounding_rectangle, format, quality)
|
|
253
|
+
|
|
254
|
+
def save_screenshot(
|
|
255
|
+
self,
|
|
256
|
+
filename: Optional[str] = None,
|
|
257
|
+
rect: Optional[Rect] = None,
|
|
258
|
+
format: Optional[str] = None,
|
|
259
|
+
quality: Optional[int] = None,
|
|
260
|
+
) -> str:
|
|
261
|
+
self._before_get_screenshot()
|
|
262
|
+
|
|
263
|
+
return self.display.save_screenshot(
|
|
264
|
+
filename, rect if rect is not None else self.bounding_rectangle, format, quality
|
|
265
|
+
)
|
PlatynUI/ui/graphic.py
ADDED
PlatynUI/ui/header.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from ..core import LocatorScope, context
|
|
4
|
+
from . import strategies
|
|
5
|
+
from .control import Control
|
|
6
|
+
from .item import Item
|
|
7
|
+
from .orientation import Orientation
|
|
8
|
+
|
|
9
|
+
__all__ = ["Header", "HeaderItem", "Orientation"]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@context
|
|
13
|
+
class HeaderItem(Item):
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@context
|
|
18
|
+
class Header(Control):
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
def orientation(self) -> Orientation:
|
|
22
|
+
self.ensure_that(self._application_is_ready)
|
|
23
|
+
|
|
24
|
+
return self.adapter.get_strategy(strategies.HasOrientation).orientation
|
|
25
|
+
|
|
26
|
+
def get_items(self, *args, **kwargs) -> typing.List[HeaderItem]:
|
|
27
|
+
return self.get_all(HeaderItem, scope=LocatorScope.Children, *args, **kwargs)
|
|
28
|
+
|
|
29
|
+
def iter_items(self, *args, **kwargs) -> typing.Iterator[HeaderItem]:
|
|
30
|
+
return self.iter_all(HeaderItem, scope=LocatorScope.Children, *args, **kwargs)
|
|
31
|
+
|
|
32
|
+
def get_item(self, *args, **kwargs) -> HeaderItem:
|
|
33
|
+
return self.get(HeaderItem, scope=LocatorScope.Children, *args, **kwargs)
|
PlatynUI/ui/item.py
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
from ..core import context
|
|
2
|
+
from ..core.predicate import predicate
|
|
3
|
+
from . import strategies
|
|
4
|
+
from .element import Element
|
|
5
|
+
|
|
6
|
+
__all__ = ["Item"]
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@context
|
|
10
|
+
class Item(Element):
|
|
11
|
+
default_prefix = "item"
|
|
12
|
+
|
|
13
|
+
@predicate("item {0} is editable")
|
|
14
|
+
def _item_is_editable(self):
|
|
15
|
+
return not self.is_readonly
|
|
16
|
+
|
|
17
|
+
@property
|
|
18
|
+
def text(self) -> str:
|
|
19
|
+
self.ensure_that(self._application_is_ready)
|
|
20
|
+
|
|
21
|
+
return self.adapter.get_strategy(strategies.Text).text
|
|
22
|
+
|
|
23
|
+
def activate(self):
|
|
24
|
+
if not self.is_active:
|
|
25
|
+
self.ensure_that(self._element_is_enabled, self._element_is_in_view)
|
|
26
|
+
|
|
27
|
+
self.adapter.get_strategy(strategies.Activatable).activate()
|
|
28
|
+
|
|
29
|
+
self.ensure_that(self._application_is_ready, raise_exception=False)
|
|
30
|
+
|
|
31
|
+
def deactivate(self):
|
|
32
|
+
if self.is_active:
|
|
33
|
+
self.ensure_that(self._element_is_enabled, self._element_is_in_view)
|
|
34
|
+
|
|
35
|
+
self.adapter.get_strategy(strategies.Deactivatable).deactivate()
|
|
36
|
+
|
|
37
|
+
self.ensure_that(self._application_is_ready, raise_exception=False)
|
|
38
|
+
|
|
39
|
+
@property
|
|
40
|
+
def is_active(self) -> bool:
|
|
41
|
+
self.ensure_that(self._application_is_ready)
|
|
42
|
+
|
|
43
|
+
return self.adapter.get_strategy(strategies.HasIsActive).is_active
|
|
44
|
+
|
|
45
|
+
def _item_is_active(self) -> bool:
|
|
46
|
+
if not self.is_active:
|
|
47
|
+
self.activate()
|
|
48
|
+
|
|
49
|
+
return False
|
|
50
|
+
return self.is_active
|
|
51
|
+
|
|
52
|
+
@text.setter
|
|
53
|
+
def text(self, value: str):
|
|
54
|
+
self.set_text(value)
|
|
55
|
+
|
|
56
|
+
def set_text(self, value):
|
|
57
|
+
self.ensure_that(self._item_is_editable, self._item_is_active)
|
|
58
|
+
|
|
59
|
+
self.adapter.get_strategy(strategies.HasEditor).open_editor()
|
|
60
|
+
self.adapter.get_strategy(strategies.EditableText).set_text(value)
|
|
61
|
+
self.adapter.get_strategy(strategies.HasEditor).accept()
|
|
62
|
+
|
|
63
|
+
self.ensure_that(self._application_is_ready, raise_exception=False)
|
|
64
|
+
|
|
65
|
+
def clear(self):
|
|
66
|
+
self.ensure_that(self._item_is_editable)
|
|
67
|
+
|
|
68
|
+
self.adapter.get_strategy(strategies.HasEditor).open_editor()
|
|
69
|
+
self.adapter.get_strategy(strategies.Clearable).clear()
|
|
70
|
+
self.adapter.get_strategy(strategies.HasEditor).accept()
|
|
71
|
+
|
|
72
|
+
self.ensure_that(self._application_is_ready, raise_exception=False)
|
|
73
|
+
|
|
74
|
+
@property
|
|
75
|
+
def is_selectable(self) -> bool:
|
|
76
|
+
self.ensure_that(self._application_is_ready)
|
|
77
|
+
|
|
78
|
+
return self.adapter.get_strategy(strategies.HasSelected).is_selectable
|
|
79
|
+
|
|
80
|
+
@predicate("item {0} is selectable")
|
|
81
|
+
def _item_is_selectable(self):
|
|
82
|
+
return self.is_selectable
|
|
83
|
+
|
|
84
|
+
@property
|
|
85
|
+
def is_selected(self) -> bool:
|
|
86
|
+
self.ensure_that(self._application_is_ready)
|
|
87
|
+
|
|
88
|
+
return self.adapter.get_strategy(strategies.HasSelected).is_selected
|
|
89
|
+
|
|
90
|
+
def select(self):
|
|
91
|
+
self.ensure_that(
|
|
92
|
+
self._toplevel_parent_is_active, self._element_is_in_view, self._element_is_enabled, self._item_is_selectable
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
if not self.is_selected:
|
|
96
|
+
self.adapter.get_strategy(strategies.Selectable).select()
|
|
97
|
+
|
|
98
|
+
self.ensure_that(self._application_is_ready, raise_exception=False)
|
|
99
|
+
|
|
100
|
+
self.ensure_that(self._application_is_ready, raise_exception=False)
|
PlatynUI/ui/lists.py
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import typing
|
|
2
|
+
|
|
3
|
+
from ..core import LocatorScope, context
|
|
4
|
+
from . import strategies
|
|
5
|
+
from .control import Control
|
|
6
|
+
from .item import Item
|
|
7
|
+
|
|
8
|
+
__all__ = ["List", "ListItem"]
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@context
|
|
12
|
+
class ListItem(Item):
|
|
13
|
+
def select(self, check_selected: bool = True):
|
|
14
|
+
self.ensure_that(self._toplevel_parent_is_active, self._element_is_in_view, self._element_is_enabled)
|
|
15
|
+
|
|
16
|
+
if not check_selected or not self.is_selected:
|
|
17
|
+
self.adapter.get_strategy(strategies.Selectable).select()
|
|
18
|
+
|
|
19
|
+
self.ensure_that(self._application_is_ready, raise_exception=False)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@context
|
|
23
|
+
class List(Control):
|
|
24
|
+
|
|
25
|
+
def get_items(self, *args, **kwargs) -> typing.List[ListItem]:
|
|
26
|
+
return self.get_all(ListItem, scope=LocatorScope.Children, *args, **kwargs)
|
|
27
|
+
|
|
28
|
+
def iter_items(self, *args, **kwargs) -> typing.Iterator[ListItem]:
|
|
29
|
+
return self.iter_all(ListItem, scope=LocatorScope.Children, *args, **kwargs)
|
|
30
|
+
|
|
31
|
+
def get_item(self, *args, **kwargs) -> ListItem:
|
|
32
|
+
return self.get(ListItem, scope=LocatorScope.Children, *args, **kwargs)
|
|
33
|
+
|
|
34
|
+
def select(self, *args, **kwargs) -> ListItem:
|
|
35
|
+
result = self.get_item(*args, **kwargs)
|
|
36
|
+
result.select(False)
|
|
37
|
+
return result
|
PlatynUI/ui/menus.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
from ..core import ContextBase, context
|
|
4
|
+
from . import strategies
|
|
5
|
+
from .control import Control
|
|
6
|
+
from .desktopbase import DesktopBase
|
|
7
|
+
from .window import Window
|
|
8
|
+
|
|
9
|
+
__all__ = ["Menu", "MenuBar", "MenuItem"]
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@context
|
|
13
|
+
class Menu(Control):
|
|
14
|
+
pass
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
@context
|
|
18
|
+
class MenuBar(Control):
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@context
|
|
23
|
+
class MenuItem(Control):
|
|
24
|
+
|
|
25
|
+
def activate(self) -> None:
|
|
26
|
+
items = []
|
|
27
|
+
p: Optional[ContextBase] = self
|
|
28
|
+
while p is not None and not isinstance(p, (Window, DesktopBase)):
|
|
29
|
+
if isinstance(p, MenuItem):
|
|
30
|
+
items.append(p)
|
|
31
|
+
|
|
32
|
+
p = p.parent
|
|
33
|
+
|
|
34
|
+
for i in reversed(items[1:]):
|
|
35
|
+
if not self.toplevel_parent_is_active:
|
|
36
|
+
i.activate()
|
|
37
|
+
|
|
38
|
+
self.ensure_that(self._toplevel_parent_is_active, self._element_is_in_view)
|
|
39
|
+
try:
|
|
40
|
+
self.adapter.get_strategy(strategies.Activatable).activate()
|
|
41
|
+
finally:
|
|
42
|
+
self.ensure_that(self._application_is_ready, raise_exception=False)
|
PlatynUI/ui/pane.py
ADDED