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.
Files changed (122) hide show
  1. PlatynUI/ButtonKeywords.py +9 -0
  2. PlatynUI/TextKeywords.py +7 -0
  3. PlatynUI/__about__.py +4 -0
  4. PlatynUI/__init__.py +34 -0
  5. PlatynUI/core/__init__.py +13 -0
  6. PlatynUI/core/adapter.py +152 -0
  7. PlatynUI/core/adapterfactory.py +51 -0
  8. PlatynUI/core/adapterproxy.py +168 -0
  9. PlatynUI/core/contextbase.py +586 -0
  10. PlatynUI/core/exceptions.py +77 -0
  11. PlatynUI/core/internal/__init__.py +0 -0
  12. PlatynUI/core/internal/decorator.py +148 -0
  13. PlatynUI/core/locatorbase.py +197 -0
  14. PlatynUI/core/locatorscope.py +17 -0
  15. PlatynUI/core/predicate.py +15 -0
  16. PlatynUI/core/settings.py +63 -0
  17. PlatynUI/core/strategies/__init__.py +1 -0
  18. PlatynUI/core/strategies/strategies.py +26 -0
  19. PlatynUI/core/strategybase.py +8 -0
  20. PlatynUI/core/strategyimpl.py +102 -0
  21. PlatynUI/core/technology.py +25 -0
  22. PlatynUI/core/types.py +421 -0
  23. PlatynUI/core/wait_for.py +47 -0
  24. PlatynUI/core/weight_calculator.py +110 -0
  25. PlatynUI/py.typed +0 -0
  26. PlatynUI/robot/__init__.py +0 -0
  27. PlatynUI/robot/reporting.py +74 -0
  28. PlatynUI/technology/__init__.py +0 -0
  29. PlatynUI/technology/uiautomation/.gitignore +1 -0
  30. PlatynUI/technology/uiautomation/__init__.py +4 -0
  31. PlatynUI/technology/uiautomation/core/adapterfactory.py +88 -0
  32. PlatynUI/technology/uiautomation/core/displaydevice.py +23 -0
  33. PlatynUI/technology/uiautomation/core/impls/__init__.py +2 -0
  34. PlatynUI/technology/uiautomation/core/impls/control.py +31 -0
  35. PlatynUI/technology/uiautomation/core/impls/window.py +83 -0
  36. PlatynUI/technology/uiautomation/core/keyboarddevice.py +21 -0
  37. PlatynUI/technology/uiautomation/core/loader.py +117 -0
  38. PlatynUI/technology/uiautomation/core/mousedevice.py +29 -0
  39. PlatynUI/technology/uiautomation/core/technology.py +61 -0
  40. PlatynUI/technology/uiautomation/core/uiaadapter.py +197 -0
  41. PlatynUI/technology/uiautomation/core/uiabase.py +19 -0
  42. PlatynUI/technology/uiautomation/desktop.py +11 -0
  43. PlatynUI/technology/uiautomation/locator.py +435 -0
  44. PlatynUI/technology/uiautomation/runtime/Caliburn.Micro.Core.dll +0 -0
  45. PlatynUI/technology/uiautomation/runtime/Caliburn.Micro.Platform.Core.dll +0 -0
  46. PlatynUI/technology/uiautomation/runtime/Caliburn.Micro.Platform.dll +0 -0
  47. PlatynUI/technology/uiautomation/runtime/Microsoft.Xaml.Behaviors.dll +0 -0
  48. PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.Spy.deps.json +266 -0
  49. PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.Spy.dll +0 -0
  50. PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.Spy.exe +0 -0
  51. PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.Spy.runtimeconfig.json +19 -0
  52. PlatynUI/technology/uiautomation/runtime/PlatynUI.Technology.UiAutomation.dll +0 -0
  53. PlatynUI/technology/uiautomation/runtime/System.ComponentModel.Composition.dll +0 -0
  54. PlatynUI/technology/uiautomation/spy/__init__.py +0 -0
  55. PlatynUI/technology/uiautomation/spy/__main__.py +24 -0
  56. PlatynUI/ui/__init__.py +65 -0
  57. PlatynUI/ui/application.py +27 -0
  58. PlatynUI/ui/buttons.py +82 -0
  59. PlatynUI/ui/combobox.py +149 -0
  60. PlatynUI/ui/container.py +9 -0
  61. PlatynUI/ui/control.py +49 -0
  62. PlatynUI/ui/core/__init__.py +3 -0
  63. PlatynUI/ui/core/devices/__init__.py +6 -0
  64. PlatynUI/ui/core/devices/basedisplaydevice.py +25 -0
  65. PlatynUI/ui/core/devices/basekeyboarddevice.py +64 -0
  66. PlatynUI/ui/core/devices/basemousedevice.py +30 -0
  67. PlatynUI/ui/core/devices/basescreendevice.py +16 -0
  68. PlatynUI/ui/core/devices/displaydevice.py +113 -0
  69. PlatynUI/ui/core/devices/inputdevice.py +24 -0
  70. PlatynUI/ui/core/devices/keyboarddevice.py +279 -0
  71. PlatynUI/ui/core/devices/keyboardproxy.py +69 -0
  72. PlatynUI/ui/core/devices/mousebutton.py +11 -0
  73. PlatynUI/ui/core/devices/mousedevice.py +279 -0
  74. PlatynUI/ui/core/devices/mouseproxy.py +178 -0
  75. PlatynUI/ui/core/ui_technology.py +31 -0
  76. PlatynUI/ui/core/window_manager.py +59 -0
  77. PlatynUI/ui/desktopbase.py +56 -0
  78. PlatynUI/ui/dialog.py +10 -0
  79. PlatynUI/ui/edit.py +48 -0
  80. PlatynUI/ui/element.py +265 -0
  81. PlatynUI/ui/graphic.py +14 -0
  82. PlatynUI/ui/header.py +33 -0
  83. PlatynUI/ui/item.py +100 -0
  84. PlatynUI/ui/lists.py +37 -0
  85. PlatynUI/ui/menus.py +42 -0
  86. PlatynUI/ui/orientation.py +9 -0
  87. PlatynUI/ui/pane.py +14 -0
  88. PlatynUI/ui/proxies/__init__.py +4 -0
  89. PlatynUI/ui/proxies/standardproxies.py +391 -0
  90. PlatynUI/ui/scrollbar.py +9 -0
  91. PlatynUI/ui/strategies/__init__.py +19 -0
  92. PlatynUI/ui/strategies/activatable.py +27 -0
  93. PlatynUI/ui/strategies/application.py +28 -0
  94. PlatynUI/ui/strategies/closeable.py +22 -0
  95. PlatynUI/ui/strategies/control.py +16 -0
  96. PlatynUI/ui/strategies/editable.py +13 -0
  97. PlatynUI/ui/strategies/element.py +65 -0
  98. PlatynUI/ui/strategies/expandable.py +27 -0
  99. PlatynUI/ui/strategies/hasnativewindowhandle.py +14 -0
  100. PlatynUI/ui/strategies/hasorientation.py +15 -0
  101. PlatynUI/ui/strategies/maximizeable.py +27 -0
  102. PlatynUI/ui/strategies/minimizeable.py +27 -0
  103. PlatynUI/ui/strategies/movable.py +14 -0
  104. PlatynUI/ui/strategies/resizable.py +13 -0
  105. PlatynUI/ui/strategies/restorable.py +13 -0
  106. PlatynUI/ui/strategies/selectable.py +27 -0
  107. PlatynUI/ui/strategies/text.py +55 -0
  108. PlatynUI/ui/strategies/title.py +14 -0
  109. PlatynUI/ui/strategies/toggleable.py +23 -0
  110. PlatynUI/ui/strategies/value.py +15 -0
  111. PlatynUI/ui/table.py +56 -0
  112. PlatynUI/ui/tabs.py +28 -0
  113. PlatynUI/ui/text.py +14 -0
  114. PlatynUI/ui/togglestate.py +12 -0
  115. PlatynUI/ui/tree.py +99 -0
  116. PlatynUI/ui/unknown.py +9 -0
  117. PlatynUI/ui/window.py +177 -0
  118. robotframework_platynui-0.0.1.dist-info/METADATA +49 -0
  119. robotframework_platynui-0.0.1.dist-info/RECORD +122 -0
  120. robotframework_platynui-0.0.1.dist-info/WHEEL +4 -0
  121. robotframework_platynui-0.0.1.dist-info/entry_points.txt +2 -0
  122. robotframework_platynui-0.0.1.dist-info/licenses/LICENSE.txt +73 -0
@@ -0,0 +1,88 @@
1
+ from typing import List, Optional, Type, overload
2
+
3
+ from PlatynUI.core import (
4
+ Adapter,
5
+ AdapterFactory,
6
+ AdapterProxy,
7
+ AdapterProxyFactory,
8
+ ContextBase,
9
+ LocatorBase,
10
+ TContextBase,
11
+ )
12
+ from PlatynUI.core.exceptions import AdapterNotFoundError
13
+
14
+ from ..locator import Locator
15
+ from .impls import * # noqa: F403
16
+ from .loader import DotNetInterface
17
+ from .technology import UiaTechnology
18
+ from .uiaadapter import UiaAdapter
19
+
20
+
21
+ class UiaAdapterFactory(AdapterFactory):
22
+ def __init__(self, technology: UiaTechnology) -> None:
23
+ self._technology = technology
24
+
25
+ @overload
26
+ def get_adapter(
27
+ self,
28
+ locator: "LocatorBase",
29
+ parent: Optional["ContextBase"] = None,
30
+ context_type: Optional[Type["ContextBase"]] = None,
31
+ ) -> Adapter:
32
+ pass
33
+
34
+ @overload
35
+ def get_adapter(
36
+ self,
37
+ locator: "LocatorBase",
38
+ parent: Optional["ContextBase"] = None,
39
+ context_type: Optional[Type["ContextBase"]] = None,
40
+ raise_error: bool = True,
41
+ ) -> Optional["Adapter"]:
42
+ pass
43
+
44
+ def get_adapter(
45
+ self,
46
+ locator: "LocatorBase",
47
+ parent: Optional["ContextBase"] = None,
48
+ context_type: Optional[Type["ContextBase"]] = None,
49
+ raise_error: bool = True,
50
+ ) -> Optional["Adapter"]:
51
+
52
+ if not isinstance(locator, Locator):
53
+ return None
54
+
55
+ parent_adapter = parent.adapter if parent else None
56
+ while parent_adapter is not None and isinstance(parent_adapter, AdapterProxy):
57
+ parent_adapter = parent_adapter.adapter
58
+
59
+ uia_parent = parent_adapter.element if parent_adapter and isinstance(parent_adapter, UiaAdapter) else None
60
+ path = locator.get_path(parent, context_type=context_type)
61
+
62
+ result = None
63
+ try:
64
+ result = DotNetInterface.finder().FindSingleElement(uia_parent, path, False)
65
+ if result is None and raise_error:
66
+ raise AdapterNotFoundError(
67
+ f"Element for '{path}' not found"
68
+ if parent is None
69
+ else f"Element for {path:r} not found in {parent}"
70
+ )
71
+ except AdapterNotFoundError:
72
+ if raise_error:
73
+ raise
74
+
75
+ if result is None:
76
+ return None
77
+
78
+ return AdapterProxyFactory.find_proxy_for(UiaAdapter(result, self._technology))
79
+
80
+ def get_children_adapters(
81
+ self,
82
+ parent: Optional[ContextBase],
83
+ context_type: Optional[Type[TContextBase]],
84
+ locator: LocatorBase,
85
+ raise_error: Optional[bool] = True,
86
+ ) -> List["Adapter"]:
87
+ # TODO
88
+ return []
@@ -0,0 +1,23 @@
1
+ from typing import Optional
2
+
3
+ from PlatynUI.core.types import Rect
4
+ from PlatynUI.ui.core.devices.basedisplaydevice import BaseDisplayDevice
5
+
6
+ from .loader import DotNetInterface
7
+
8
+
9
+ class UiaDisplayDevice(BaseDisplayDevice):
10
+ @property
11
+ def name(self) -> str:
12
+ return "Windows"
13
+
14
+ @property
15
+ def bounding_rectangle(self) -> Rect:
16
+ r = DotNetInterface.display_device().GetBoundingRectangle()
17
+ return Rect(r.X, r.Y, r.Width, r.Height)
18
+
19
+ def highlight_rect(self, rect: Rect, time: float) -> None:
20
+ DotNetInterface.display_device().HighlightRect(rect.left, rect.top, rect.width, rect.height, time)
21
+
22
+ def get_screenshot(self, rect: Rect, format: str, quality: Optional[int]) -> bytearray:
23
+ raise NotImplementedError
@@ -0,0 +1,2 @@
1
+ from .control import *
2
+ from .window import *
@@ -0,0 +1,31 @@
1
+ from typing import cast
2
+
3
+ from PlatynUI.core import Adapter, StrategyImpl, strategy_impl_for
4
+ from PlatynUI.ui.strategies import (
5
+ Control,
6
+ )
7
+
8
+ from ..technology import UiaTechnology
9
+ from ..uiabase import UiaBase
10
+
11
+ __all__ = ["ControlImpl"]
12
+
13
+
14
+ @strategy_impl_for(technology=UiaTechnology)
15
+ class ControlImpl(StrategyImpl, Control):
16
+ def __init__(self, adapter: Adapter):
17
+ self._adapter = adapter
18
+ self._adapter
19
+ self.element = cast(UiaBase, adapter).element
20
+
21
+ @property
22
+ def has_focus(self) -> bool:
23
+ return bool(self.element.CurrentHasKeyboardFocus)
24
+
25
+ def try_ensure_focused(self) -> bool:
26
+ if self.has_focus:
27
+ return True
28
+
29
+ self.element.SetFocus()
30
+
31
+ return self.has_focus
@@ -0,0 +1,83 @@
1
+ from typing import cast
2
+
3
+ from PlatynUI.core import Adapter, StrategyImpl, strategy_impl_for
4
+ from PlatynUI.ui.strategies import (
5
+ Activatable,
6
+ Control,
7
+ HasCanMaximize,
8
+ HasCanMinimize,
9
+ HasIsActive,
10
+ Maximizable,
11
+ Minimizable,
12
+ Restorable,
13
+ )
14
+
15
+ from ..loader import DotNetInterface
16
+ from ..technology import UiaTechnology
17
+ from ..uiabase import UiaBase
18
+
19
+ __all__ = ["WindowPatternImpl"]
20
+
21
+
22
+ @strategy_impl_for(technology=UiaTechnology, properties={"IsWindowPatternAvailable": True})
23
+ @strategy_impl_for(technology=UiaTechnology, role="Window")
24
+ class WindowPatternImpl(
25
+ StrategyImpl,
26
+ Control,
27
+ Minimizable,
28
+ HasCanMinimize,
29
+ HasCanMaximize,
30
+ Maximizable,
31
+ Restorable,
32
+ HasIsActive,
33
+ Activatable,
34
+ ):
35
+ def __init__(self, adapter: Adapter):
36
+ self._adapter = adapter
37
+ self._adapter
38
+ self.element = cast(UiaBase, adapter).element
39
+ self.window_pattern = DotNetInterface().patterns().GetWindowPattern(self.element)
40
+
41
+ @property
42
+ def has_focus(self) -> bool:
43
+ return self.is_active
44
+
45
+ def try_ensure_focused(self) -> bool:
46
+ if self.has_focus:
47
+ return True
48
+
49
+ self.activate()
50
+
51
+ return self.has_focus
52
+
53
+ @property
54
+ def can_minimize(self) -> bool:
55
+ return self.window_pattern.CanMinimize
56
+
57
+ @property
58
+ def is_minimized(self) -> bool:
59
+ return self.window_pattern.IsMinimized
60
+
61
+ def minimize(self) -> None:
62
+ self.window_pattern.Maximize()
63
+
64
+ @property
65
+ def can_maximize(self) -> bool:
66
+ return self.window_pattern.CanMaximize
67
+
68
+ @property
69
+ def is_maximized(self) -> bool:
70
+ return self.window_pattern.IsMaximized
71
+
72
+ def maximize(self) -> None:
73
+ self.window_pattern.Maximize()
74
+
75
+ def restore(self) -> None:
76
+ self.window_pattern.Restore()
77
+
78
+ @property
79
+ def is_active(self) -> bool:
80
+ return self.window_pattern.IsActive
81
+
82
+ def activate(self) -> None:
83
+ self.window_pattern.Activate()
@@ -0,0 +1,21 @@
1
+ from typing import Optional
2
+
3
+ from PlatynUI.ui.core.devices.basekeyboarddevice import BaseKeyboardDevice, BaseKeyCode, InputType, Key
4
+
5
+ from .loader import DotNetInterface
6
+
7
+
8
+ class UiaKeyboardDevice(BaseKeyboardDevice):
9
+ def __init__(self) -> None:
10
+ super().__init__()
11
+ self.input_type: Optional[InputType] = None
12
+
13
+ def key_to_keycode(self, key: Key) -> BaseKeyCode:
14
+ result = DotNetInterface().keyboard_device().KeyToKeyCode(key)
15
+ return BaseKeyCode(result.Key, result.Code, result.Valid, result.ErrorText)
16
+
17
+ def send_keycode(self, keycode: BaseKeyCode, pressed: bool) -> bool:
18
+ if not keycode.valid:
19
+ raise ValueError(f"Invalid key: {keycode}")
20
+
21
+ return DotNetInterface().keyboard_device().SendKeyCode(keycode.code, pressed)
@@ -0,0 +1,117 @@
1
+ from pathlib import Path
2
+ from typing import TYPE_CHECKING, Optional, cast
3
+
4
+ __all__ = ["DotNetInterface"]
5
+
6
+
7
+ # pyright: reportMissingModuleSource=false
8
+
9
+ if TYPE_CHECKING:
10
+ from PlatynUI.Technology.UiAutomation import (
11
+ Adapter,
12
+ DisplayDevice,
13
+ Finder,
14
+ KeyboardDevice,
15
+ MouseDevice,
16
+ Patterns,
17
+ )
18
+
19
+
20
+ class DotNetInterface:
21
+ _adapter: Optional["Adapter"] = None
22
+ _finder: Optional["Finder"] = None
23
+ _mouse_device: Optional["MouseDevice"] = None
24
+ _keyboard_device: Optional["KeyboardDevice"] = None
25
+ _display_device: Optional["DisplayDevice"] = None
26
+ _patterns: Optional["Patterns"] = None
27
+
28
+ __loaded = False
29
+
30
+ @classmethod
31
+ def _ensure_loaded(cls) -> None:
32
+ assembly_name = "PlatynUI.Technology.UiAutomation.dll"
33
+ debug_assembly_path = (
34
+ Path(__file__).parent
35
+ / f"../../../../PlatynUI.Technology.UiAutomation/bin/Debug/net8.0-windows/{assembly_name}"
36
+ # Path(__file__).parent
37
+ # / f"../../../../PlatynUI.Technology.UiAutomation/bin/Debug/net481/{ASSEMBLY_NAME}"
38
+ )
39
+ runtime_assembly_path = Path(__file__).parent.parent / f"runtime/{assembly_name}"
40
+
41
+ if cls.__loaded:
42
+ return
43
+
44
+ cls.__loaded = True
45
+
46
+ import clr
47
+
48
+ if debug_assembly_path.exists():
49
+ clr.AddReference(str(debug_assembly_path))
50
+ elif runtime_assembly_path.exists():
51
+ clr.AddReference(str(runtime_assembly_path))
52
+
53
+ @classmethod
54
+ def adapter(cls) -> "Adapter":
55
+ if cls._adapter is None:
56
+ cls._ensure_loaded()
57
+
58
+ from PlatynUI.Technology.UiAutomation import Adapter
59
+
60
+ cls._adapter = cast("Adapter", Adapter)
61
+
62
+ return cls._adapter
63
+
64
+ @classmethod
65
+ def finder(cls) -> "Finder":
66
+ if cls._finder is None:
67
+ cls._ensure_loaded()
68
+
69
+ from PlatynUI.Technology.UiAutomation import Finder
70
+
71
+ cls._finder = cast("Finder", Finder)
72
+
73
+ return cls._finder
74
+
75
+ @classmethod
76
+ def mouse_device(cls) -> "MouseDevice":
77
+ if cls._mouse_device is None:
78
+ cls._ensure_loaded()
79
+
80
+ from PlatynUI.Technology.UiAutomation import MouseDevice
81
+
82
+ cls._mouse_device = cast("MouseDevice", MouseDevice)
83
+
84
+ return cls._mouse_device
85
+
86
+ @classmethod
87
+ def keyboard_device(cls) -> "KeyboardDevice":
88
+ if cls._keyboard_device is None:
89
+ cls._ensure_loaded()
90
+
91
+ from PlatynUI.Technology.UiAutomation import KeyboardDevice
92
+
93
+ cls._keyboard_device = cast("KeyboardDevice", KeyboardDevice)
94
+
95
+ return cls._keyboard_device
96
+
97
+ @classmethod
98
+ def display_device(cls) -> "DisplayDevice":
99
+ if cls._display_device is None:
100
+ cls._ensure_loaded()
101
+
102
+ from PlatynUI.Technology.UiAutomation import DisplayDevice
103
+
104
+ cls._display_device = cast("DisplayDevice", DisplayDevice)
105
+
106
+ return cls._display_device
107
+
108
+ @classmethod
109
+ def patterns(cls) -> "Patterns":
110
+ if cls._patterns is None:
111
+ cls._ensure_loaded()
112
+
113
+ from PlatynUI.Technology.UiAutomation import Patterns
114
+
115
+ cls._patterns = cast("Patterns", Patterns)
116
+
117
+ return cls._patterns
@@ -0,0 +1,29 @@
1
+ from PlatynUI.core.types import Point, Size
2
+ from PlatynUI.ui.core.devices.basemousedevice import BaseMouseDevice
3
+ from PlatynUI.ui.core.devices.mousebutton import MouseButton
4
+
5
+ from .loader import DotNetInterface
6
+
7
+
8
+ class UiaMouseDevice(BaseMouseDevice):
9
+ @property
10
+ def double_click_time(self) -> float:
11
+ return DotNetInterface.mouse_device().GetDoubleClickTime()
12
+
13
+ @property
14
+ def double_click_size(self) -> Size:
15
+ r = DotNetInterface.mouse_device().GetDoubleClickSize()
16
+ return Size(r.Width, r.Height)
17
+
18
+ def get_position(self) -> Point:
19
+ r = DotNetInterface.mouse_device().GetPosition()
20
+ return Point(r.X, r.Y)
21
+
22
+ def move_to(self, pos: Point) -> None:
23
+ DotNetInterface.mouse_device().Move(pos.x, pos.y)
24
+
25
+ def press(self, button: MouseButton) -> None:
26
+ DotNetInterface.mouse_device().Press(int(button))
27
+
28
+ def release(self, button: MouseButton) -> None:
29
+ DotNetInterface.mouse_device().Release(int(button))
@@ -0,0 +1,61 @@
1
+ import threading
2
+ from functools import cached_property
3
+ from typing import Optional
4
+
5
+ from PlatynUI.core import AdapterFactory
6
+ from PlatynUI.ui.core import UiTechnology, WindowManager
7
+ from PlatynUI.ui.core.devices import (
8
+ DefaultDisplayDevice,
9
+ DefaultKeyboardDevice,
10
+ DefaultMouseDevice,
11
+ DisplayDevice,
12
+ KeyboardDevice,
13
+ MouseDevice,
14
+ )
15
+
16
+ __all__ = ["UiaTechnology", "get_technology"]
17
+
18
+
19
+ class UiaTechnology(UiTechnology):
20
+ def __init__(self) -> None:
21
+ super().__init__()
22
+
23
+ @cached_property
24
+ def adapter_factory(self) -> AdapterFactory:
25
+ from .adapterfactory import UiaAdapterFactory
26
+
27
+ return UiaAdapterFactory(self)
28
+
29
+ @cached_property
30
+ def mouse_device(self) -> MouseDevice:
31
+ from .mousedevice import UiaMouseDevice
32
+
33
+ return DefaultMouseDevice(UiaMouseDevice())
34
+
35
+ @property
36
+ def keyboard_device(self) -> KeyboardDevice:
37
+ from .keyboarddevice import UiaKeyboardDevice
38
+
39
+ return DefaultKeyboardDevice(UiaKeyboardDevice())
40
+
41
+ @property
42
+ def display_device(self) -> DisplayDevice:
43
+ from .displaydevice import UiaDisplayDevice
44
+
45
+ return DefaultDisplayDevice(UiaDisplayDevice())
46
+
47
+ @property
48
+ def window_manager(self) -> WindowManager:
49
+ raise NotImplementedError
50
+
51
+
52
+ __instance: Optional[UiaTechnology] = None
53
+ __lock = threading.Lock()
54
+
55
+
56
+ def get_technology() -> UiaTechnology:
57
+ global __instance
58
+ with __lock:
59
+ if __instance is None:
60
+ __instance = UiaTechnology()
61
+ return __instance
@@ -0,0 +1,197 @@
1
+ from typing import TYPE_CHECKING, Any, Dict, List, Optional, Set, cast
2
+
3
+ from PlatynUI.core import Adapter
4
+ from PlatynUI.core.adapterproxy import AdapterProxyFactory
5
+ from PlatynUI.core.strategies import Properties
6
+ from PlatynUI.core.types import Point, Rect
7
+ from PlatynUI.technology.uiautomation.core.technology import UiaTechnology
8
+ from PlatynUI.ui.strategies import Element
9
+
10
+ from .loader import DotNetInterface
11
+ from .uiabase import UiaBase
12
+
13
+ # pyright: reportMissingModuleSource=false
14
+
15
+ if TYPE_CHECKING:
16
+ from PlatynUI.Technology.UiAutomation.Client import IUIAutomationElement
17
+
18
+
19
+ class UiaElement(Element, UiaBase):
20
+
21
+ @property
22
+ def is_readonly(self) -> bool:
23
+ return DotNetInterface.adapter().IsReadOnly(self.element)
24
+
25
+ @property
26
+ def is_enabled(self) -> bool:
27
+ return self.element.CurrentIsEnabled != 0
28
+
29
+ @property
30
+ def is_visible(self) -> bool:
31
+ return self.element.CurrentIsOffscreen == 0
32
+
33
+ @property
34
+ def is_in_view(self) -> bool:
35
+ if not self.valid:
36
+ return False
37
+
38
+ br = self.bounding_rectangle
39
+ vr = self.visible_rectangle
40
+
41
+ # check if the element is 1/3 visible
42
+ if vr.width < br.width / 3 or vr.height < br.height / 3:
43
+ return False
44
+
45
+ top_level_parent = self.top_level_parent
46
+ if top_level_parent is None or not top_level_parent.supports_strategy(Element):
47
+ # TODO: check screen bounds
48
+ return True
49
+
50
+ center = vr.center
51
+ return bool(center and top_level_parent.get_strategy(Element).bounding_rectangle.contains(center))
52
+
53
+ @property
54
+ def toplevel_parent_is_active(self) -> bool:
55
+ raise NotImplementedError("toplevel_parent_is_active")
56
+
57
+ @property
58
+ def bounding_rectangle(self) -> Rect:
59
+ r = self.element.CurrentBoundingRectangle
60
+ return Rect(r.left, r.top, r.right - r.left, r.bottom - r.top)
61
+
62
+ @property
63
+ def visible_rectangle(self) -> Rect:
64
+ result = self.bounding_rectangle
65
+
66
+ top_level_parent = self.top_level_parent
67
+ if top_level_parent is None or not top_level_parent.supports_strategy(Element):
68
+ return result
69
+
70
+ return top_level_parent.get_strategy(Element).bounding_rectangle.intersected(result)
71
+
72
+ @property
73
+ def default_click_position(self) -> Point:
74
+ p = DotNetInterface.adapter().GetClickablePoint(self.element)
75
+ if p is None:
76
+ return Point()
77
+
78
+ return Point(p.X, p.Y)
79
+
80
+ @property
81
+ def top_level_parent(self) -> Optional[Adapter]:
82
+ result = DotNetInterface.adapter().GetTopLevelParent(self.element)
83
+
84
+ if result is None:
85
+ return None
86
+
87
+ return AdapterProxyFactory.find_proxy_for(UiaAdapter(result, cast(UiaTechnology, self.technology)))
88
+
89
+ def try_ensure_visible(self) -> bool:
90
+ # TODO: Implement this if parent toplevel is out of view
91
+ return self.element.CurrentIsOffscreen == 0
92
+
93
+ def try_ensure_application_is_ready(self) -> bool:
94
+ # TODO: raise NotImplementedError("try_ensure_application_is_ready")
95
+ return True
96
+
97
+ def try_ensure_toplevel_parent_is_active(self) -> bool:
98
+ return DotNetInterface.adapter().TryEnsureTopLevelParentIsActive(self.element)
99
+
100
+ def try_bring_into_view(self) -> bool:
101
+ # TODO: Implement this if element toplevel is out of view and can be scrolled
102
+ return True
103
+
104
+
105
+ class UiaProperties(Properties, UiaBase):
106
+ def get_property_names(self) -> List[str]:
107
+ return list(DotNetInterface.adapter().GetSupportedPropertyNames(self.element))
108
+
109
+ def get_property_value(self, name: str) -> Any:
110
+ return DotNetInterface.adapter().GetPropertyValue(self.element, name)
111
+
112
+
113
+ class UiaAdapter(Adapter, UiaProperties, UiaElement):
114
+ def __init__(self, element: "IUIAutomationElement", technology: UiaTechnology) -> None:
115
+ super().__init__()
116
+ self._element: Optional["IUIAutomationElement"] = element
117
+ self._technology = technology
118
+ self._strategies_cache: Dict[str, Any] = {}
119
+
120
+ @property
121
+ def element(self) -> "IUIAutomationElement":
122
+ if not self.valid or self._element is None:
123
+ raise RuntimeError("element is not valid")
124
+
125
+ return self._element
126
+
127
+ @property
128
+ def valid(self) -> bool:
129
+ if self._element is None:
130
+ return False
131
+
132
+ v = False
133
+ try:
134
+ v = self._element.CurrentProcessId != 0
135
+ except BaseException:
136
+ v = False
137
+
138
+ if not v:
139
+ self.invalidate()
140
+
141
+ return self._element is not None
142
+
143
+ def invalidate(self) -> None:
144
+ print(f"Invalidating element {self}")
145
+ self._element = None
146
+
147
+ @property
148
+ def id(self) -> str:
149
+ raise NotImplementedError("id")
150
+
151
+ @property
152
+ def name(self) -> str:
153
+ return self.element.CurrentName
154
+
155
+ @property
156
+ def class_name(self) -> str:
157
+ return self.element.CurrentClassName
158
+
159
+ @property
160
+ def tag_name(self) -> str:
161
+ return self.role
162
+
163
+ @property
164
+ def role(self) -> str:
165
+ return DotNetInterface.adapter().GetRole(self.element)
166
+
167
+ @property
168
+ def supported_roles(self) -> Set[str]:
169
+ return {self.role, "Control", "Element", "Adapter"}
170
+
171
+ @property
172
+ def type(self) -> str:
173
+ return "element" if self.valid else ""
174
+
175
+ @property
176
+ def supported_types(self) -> Set[str]:
177
+ return {"element", "adapter"} if self.valid else set()
178
+
179
+ @property
180
+ def framework_id(self) -> str:
181
+ return self.element.CurrentFrameworkId
182
+
183
+ @property
184
+ def runtime_id(self) -> str:
185
+ return DotNetInterface.adapter().GetRuntimeId(self.element)
186
+
187
+ @property
188
+ def technology(self) -> UiaTechnology:
189
+ return self._technology
190
+
191
+ @property
192
+ def parent(self) -> Optional["Adapter"]:
193
+ raise NotImplementedError("parent")
194
+
195
+ @property
196
+ def children(self) -> List["Adapter"]:
197
+ raise NotImplementedError("children")
@@ -0,0 +1,19 @@
1
+ from typing import TYPE_CHECKING, Protocol
2
+
3
+ if TYPE_CHECKING:
4
+ from PlatynUI.Technology.UiAutomation.Client import IUIAutomationElement # type: ignore
5
+
6
+ from PlatynUI.core.technology import Technology
7
+
8
+
9
+ class UiaBase(Protocol):
10
+ @property
11
+ def element(self) -> "IUIAutomationElement": ...
12
+
13
+ @property
14
+ def valid(self) -> bool: ...
15
+
16
+ def invalidate(self) -> None: ...
17
+
18
+ @property
19
+ def technology(self) -> Technology: ...
@@ -0,0 +1,11 @@
1
+ from ...core import context
2
+ from ...ui.desktopbase import DesktopBase
3
+ from .locator import locator
4
+
5
+ __all__ = ["Desktop"]
6
+
7
+
8
+ @locator(path="/.")
9
+ @context
10
+ class Desktop(DesktopBase):
11
+ pass