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,148 @@
1
+ import functools
2
+ import inspect
3
+ from abc import ABCMeta
4
+ from typing import Any, Callable, Optional, TypeVar, Union, overload
5
+
6
+ __all__ = ["Decorator"]
7
+
8
+ TCallable = TypeVar("TCallable", bound=Callable[..., Any])
9
+
10
+
11
+ class Decorator(metaclass=ABCMeta):
12
+ """
13
+ A decorator class that you can be extended that allows you to do normal decorators
14
+ with no arguments, or a decorator with arguments
15
+
16
+ May be invoked as a simple, argument-less decorator (i.e. `@decorator`) or
17
+ with arguments customizing its behavior (e.g. `@decorator(*args, **kwargs)`).
18
+
19
+ To create your own decorators, just extend this class and override the decorate()
20
+ method, the decorate() method should return a method that can call the passed in func
21
+ at some point
22
+
23
+ based off of the task decorator in Fabric
24
+ https://github.com/fabric/fabric/blob/master/fabric/decorators.py#L15
25
+
26
+ with modifications inspired by --
27
+ https://wiki.python.org/moin/PythonDecoratorLibrary#Class_method_decorator_using_instance
28
+ https://wiki.python.org/moin/PythonDecoratorLibrary#Creating_decorator_with_optional_arguments
29
+
30
+ other links --
31
+ http://pythonconquerstheuniverse.wordpress.com/2012/04/29/python-decorators/
32
+ http://stackoverflow.com/questions/739654/
33
+ http://stackoverflow.com/questions/666216/decorator-classes-in-python
34
+ """
35
+
36
+ __wrapped = None
37
+ __wrapped_func = False
38
+ __wrapped_class = False
39
+ __wrapped_instance = False
40
+
41
+ def __new__(cls, *args: Any, **kwargs: Any) -> Any:
42
+ instance = super().__new__(cls)
43
+
44
+ if instance.is_wrapped_arg(*args, **kwargs):
45
+ instance.set_wrapped(args[0])
46
+ args = args[1:]
47
+ instance.args = args
48
+
49
+ else:
50
+ instance.__wrapped = None
51
+ instance.args = args
52
+
53
+ instance.kwargs = kwargs
54
+ # here we do some magic stuff to return the class back in case this is a
55
+ # class decorator, we do this so we don't wrap the class, thus causing
56
+ # things like isinstance() checks to fail, and also not making class
57
+ # variables available
58
+ if instance.__wrapped_class:
59
+ if instance.__wrapped_instance:
60
+ decorate_instance = instance
61
+ class_instance = instance.decorate_class(instance.__wrapped, *instance.args, **instance.kwargs)
62
+
63
+ class ChildClass(class_instance):
64
+ def __init__(self, *args, **kwargs):
65
+ super(ChildClass, self).__init__(*args, **kwargs)
66
+ decorate_instance.decorate_instance(self, *decorate_instance.args, **decorate_instance.kwargs)
67
+
68
+ instance = ChildClass
69
+ instance.__name__ = class_instance.__name__
70
+ instance.__module__ = class_instance.__module__
71
+ # for some reason you can't update a __doc__ on a class
72
+ # http://bugs.python.org/issue12773
73
+
74
+ else:
75
+ instance = instance.decorate_class(instance.__wrapped, *instance.args, **instance.kwargs)
76
+
77
+ return instance
78
+
79
+ @staticmethod
80
+ def is_wrapped_arg(*args: Any, **kwargs: Any) -> bool:
81
+ if len(args) == 1 and len(kwargs) == 0:
82
+ if inspect.isfunction(args[0]) or isinstance(args[0], type) or isinstance(args[0], FuncDecorator):
83
+ return True
84
+
85
+ return False
86
+
87
+ def set_wrapped(self, wrapped: Any) -> None:
88
+ self.__wrapped = wrapped
89
+ functools.update_wrapper(self, self.__wrapped)
90
+ self.__wrapped_func = False
91
+ self.__wrapped_class = False
92
+
93
+ if inspect.isroutine(wrapped):
94
+ self.__wrapped_func = True
95
+
96
+ elif isinstance(wrapped, type):
97
+ self.__wrapped_class = True
98
+
99
+ @overload
100
+ def __call__(self, _func: TCallable, *args: Any, **kwargs: Any) -> TCallable: ...
101
+
102
+ @overload
103
+ def __call__(self, *args: Any, **kwargs: Any) -> Callable[[TCallable], TCallable]: ...
104
+
105
+ def __call__(
106
+ self, _func: Optional[TCallable] = None, *args: Any, **kwargs: Any
107
+ ) -> Union[TCallable, Callable[[TCallable], TCallable]]:
108
+ """call is used when there are (...) on the decorator"""
109
+ invoke = True
110
+ if not self.__wrapped:
111
+ self.set_wrapped(_func)
112
+ args = ()
113
+ invoke = False
114
+
115
+ if self.__wrapped_func:
116
+ ret = self.decorate_func(self.__wrapped, *self.args, **self.kwargs)
117
+
118
+ elif self.__wrapped_class:
119
+ ret = self.decorate_class(self.__wrapped, *self.args, **self.kwargs)
120
+
121
+ else:
122
+ raise ValueError("wrapped is not a class or a function")
123
+
124
+ if invoke:
125
+ ret = ret(*args, **kwargs)
126
+
127
+ if self.__wrapped_instance:
128
+ self.decorate_instance(ret, *self.args, **self.kwargs)
129
+
130
+ return ret
131
+
132
+ def decorate_func(self, func: TCallable, *decorator_args: Any, **decorator_kwargs: Any)-> TCallable:
133
+ """
134
+ override this in a child class with your own logic, it must return a
135
+ function that calls self.func
136
+
137
+ func -- callback -- the function being decorated
138
+ decorator_args -- tuple -- the arguments passed into the decorator (eg, @dec(1, 2))
139
+ decorator_kwargs -- dict -- the named args passed into the decorator (eg, @dec(foo=1))
140
+ """
141
+
142
+ raise RuntimeError("decorator {} does not support function decoration".format(self.__class__.__name__))
143
+
144
+ def decorate_class(self, cls, *decorator_args, **decorator_kwargs):
145
+ raise RuntimeError("decorator {} does not support class decoration".format(self.__class__.__name__))
146
+
147
+ def decorate_instance(self, instance, *decorator_args, **decorator_kwargs):
148
+ raise RuntimeError("decorator {} does not support instance decoration".format(self.__class__.__name__))
@@ -0,0 +1,197 @@
1
+ import inspect
2
+ import typing
3
+ from abc import abstractmethod
4
+ from typing import TYPE_CHECKING, Any, Callable, Dict, Optional, Type, TypeVar, Union, cast, get_origin
5
+
6
+ from .exceptions import NotSupportedError
7
+ from .internal import decorator
8
+ from .technology import Technology
9
+
10
+ if TYPE_CHECKING:
11
+ from .adapter import Adapter
12
+ from .contextbase import ContextBase, TContextBase
13
+
14
+ __all__ = ["LocatorBase"]
15
+
16
+ TCallable = TypeVar("TCallable", bound=Callable[..., Any])
17
+
18
+
19
+ class LocatorBase(decorator.Decorator):
20
+ _default_name = None
21
+
22
+ def __init__(self) -> None:
23
+ self._attributes: Dict[str, Any] = {}
24
+
25
+ @property
26
+ def attributes(self) -> Dict[str, Any]:
27
+ return self._attributes
28
+
29
+ @attributes.setter
30
+ def attributes(self, value: Dict[str, Any]) -> None:
31
+ self._attributes = value
32
+
33
+ def decorate_instance(self, instance: Any, *decorator_args: Any, **decorator_kwargs: Any) -> Any:
34
+ if hasattr(instance, "locator"):
35
+ v = getattr(instance, "locator")
36
+ if v is not None and isinstance(v, type(self)):
37
+ self.copy_from(v)
38
+ return instance
39
+
40
+ def decorate_func(self, func: TCallable, *decorator_args: Any, **decorator_kwargs: Any) -> TCallable:
41
+ self._default_name = func.__name__
42
+ prop_name = "_%s_getter_" % func.__name__
43
+ typ = inspect.signature(func).return_annotation
44
+
45
+ if typ == inspect.Signature.empty:
46
+ typ = None
47
+ else:
48
+ if get_origin(typ) is Union:
49
+ args = typing.get_args(typ)
50
+ if len(args) < 1:
51
+ raise NotSupportedError("unsupported union type {}".format(typ))
52
+
53
+ typ = cast(Type["ContextBase"], args[0])
54
+
55
+ # noinspection PyUnresolvedReferences,PyProtectedMember
56
+ if isinstance(typ, typing.ForwardRef):
57
+ typ = (typ, func)
58
+ elif isinstance(typ, str):
59
+ typ = (typ, func)
60
+ else:
61
+ if not isinstance(typ, type):
62
+ # TODO what to do when typ is str?
63
+ raise NotImplementedError("%s as type %s is not allowed for locator" % (repr(typ), type(typ)))
64
+
65
+ def get_context(context: Any) -> Any:
66
+ if not hasattr(context, prop_name):
67
+ setattr(context, prop_name, self.copy().create_context(context, typ))
68
+ return getattr(context, prop_name)
69
+
70
+ return cast(TCallable, get_context)
71
+
72
+ def decorate_class(self, cls: Type[Any], *decorator_args: Any, **decorator_kwargs: Any) -> Type[Any]:
73
+ if hasattr(cls, "_locator"):
74
+ v = getattr(cls, "_locator")
75
+ if v is not None and isinstance(v, type(self)):
76
+ self.copy_from(v)
77
+
78
+ cls._locator = self
79
+ return cls
80
+
81
+ @abstractmethod
82
+ def __repr__(self) -> str:
83
+ return "LocatorBase()"
84
+
85
+ def create_context(
86
+ self, context_parent: Optional["ContextBase"], context_type: Optional[Type["TContextBase"]]
87
+ ) -> "TContextBase":
88
+
89
+ if context_type is None:
90
+ from .contextbase import UnknownContext
91
+
92
+ context_type = cast(Type["TContextBase"], UnknownContext)
93
+
94
+ if get_origin(context_type) is Union:
95
+ args = typing.get_args(context_type)
96
+ if len(args) < 1:
97
+ raise NotSupportedError("unsupported union type {}".format(context_type))
98
+
99
+ context_type = cast(Type["TContextBase"], args[0])
100
+
101
+ if (
102
+ isinstance(context_type, tuple)
103
+ and len(context_type) == 2
104
+ and isinstance(context_type[0], typing.ForwardRef)
105
+ ):
106
+ context_type = context_type[0]._evaluate(context_type[1].__globals__, None)
107
+
108
+ elif isinstance(context_type, tuple) and len(context_type) == 2 and isinstance(context_type[0], str):
109
+ context_type = eval(context_type[0], context_type[1].__globals__, None)
110
+
111
+ if not isinstance(context_type, type):
112
+ # TODO what to do when typ is str?
113
+ raise NotImplementedError(
114
+ "%s as type %s is not allowed for locator" % (repr(context_type), type(context_type))
115
+ )
116
+
117
+ result = context_type()
118
+
119
+ if hasattr(result, "_locator"):
120
+ v = getattr(result, "_locator")
121
+ if v is not None and isinstance(v, type(self)):
122
+ self.copy_from(v)
123
+
124
+ self.context = result
125
+ result.locator = self
126
+
127
+ result.context_parent = context_parent
128
+
129
+ return result
130
+
131
+ __context: Optional["ContextBase"] = None
132
+
133
+ @property
134
+ def context(self) -> Optional["ContextBase"]:
135
+ return self.__context
136
+
137
+ @context.setter
138
+ def context(self, v: "ContextBase") -> None:
139
+ self.__context = v
140
+
141
+ @abstractmethod
142
+ def copy_from(self, other: Optional["LocatorBase"]) -> "LocatorBase":
143
+ pass
144
+
145
+ @abstractmethod
146
+ def copy(self) -> "LocatorBase":
147
+ pass
148
+
149
+ def get_parent_locator(self) -> Optional["LocatorBase"]:
150
+ return (
151
+ self.context.context_parent.locator
152
+ if self.context is not None
153
+ and self.context.context_parent is not None
154
+ and self.context.context_parent.locator is not None
155
+ and isinstance(self.context.context_parent.locator, LocatorBase)
156
+ else None
157
+ )
158
+
159
+ _technology: Optional[Technology] = None
160
+
161
+ @abstractmethod
162
+ def _create_technology(self) -> Technology: ...
163
+
164
+ @property
165
+ def technology(self) -> Technology:
166
+ if self._technology is None:
167
+ parent_locator = self.get_parent_locator()
168
+
169
+ if parent_locator is not None:
170
+ return parent_locator.technology
171
+
172
+ return self._create_technology()
173
+
174
+ return self._technology
175
+
176
+ @technology.setter
177
+ def technology(self, value: Technology) -> None:
178
+ self._technology = value
179
+
180
+ @abstractmethod
181
+ def create_children_locator(self, *args: Any, **kwargs: Any) -> "LocatorBase":
182
+ pass
183
+
184
+ @abstractmethod
185
+ def create_child_locator(self, adapter: "Adapter") -> "LocatorBase":
186
+ pass
187
+
188
+ @abstractmethod
189
+ def make_unique_locator(self, adapter: "Adapter") -> "LocatorBase":
190
+ pass
191
+
192
+ @abstractmethod
193
+ def create_parent_locator(self, adapter: "Adapter") -> "LocatorBase":
194
+ pass
195
+
196
+ def create_top_level_locator(self, adapter: "Adapter") -> typing.Optional["LocatorBase"]:
197
+ return None
@@ -0,0 +1,17 @@
1
+ from enum import Enum
2
+
3
+ __all__ = ["LocatorScope"]
4
+
5
+
6
+ class LocatorScope(Enum):
7
+ Root = 0
8
+ Descendants = 1
9
+ Children = 2
10
+ Parent = 3
11
+ Ancestor = 4
12
+ AncestorOrSelf = 5
13
+ DescendantsOrSelf = 6
14
+ Following = 7
15
+ FollowingSibling = 8
16
+ Preceding = 9
17
+ PrecedingSibling = 10
@@ -0,0 +1,15 @@
1
+ from typing import Any, Callable, Optional, TypeVar
2
+
3
+ __all__ = ["predicate"]
4
+
5
+ F = TypeVar("F", bound=Callable[..., Any])
6
+
7
+
8
+ def predicate(message: Optional[str] = None, flags: Any = None) -> Callable[[F], F]:
9
+ def decorator(func: F) -> F:
10
+ setattr(func, "__predicate__", True)
11
+ setattr(func, "message", message)
12
+ setattr(func, "flags", flags)
13
+ return func
14
+
15
+ return decorator
@@ -0,0 +1,63 @@
1
+ from dataclasses import dataclass
2
+ from typing import Any, Literal, Optional, TypeVar
3
+
4
+ __all__ = ["Settings"]
5
+
6
+ T = TypeVar("T")
7
+
8
+
9
+ _current: Optional["Settings"] = None
10
+
11
+
12
+ @dataclass
13
+ class Settings:
14
+
15
+ wait_for_timeout: float = 1.0
16
+ wait_for_delay: float = 0.1
17
+
18
+ ensure_timeout: float = 15
19
+ ensure_delay: float = 0.1
20
+ exists_timeout: float = 1.0
21
+
22
+ window_close_timeout: float = 1.0
23
+
24
+ input_after_input_delay: float = 0.0
25
+
26
+ mouse_before_next_click_delay_multiplicator: float = 1.5
27
+
28
+ mouse_after_click_delay: float = 0.010
29
+ mouse_multi_click_delay_multiplicator: float = 0.5
30
+ mouse_press_release_delay: float = 0.010
31
+ mouse_after_move_delay: float = 0.010
32
+ mouse_move_delay: float = 0.001
33
+ mouse_move_time: float = 0.4
34
+
35
+ keyboard_after_press_key_delay: float = 0.001
36
+ keyboard_after_release_key_delay: float = 0.005
37
+ keyboard_after_press_release_delay: float = 0.05
38
+
39
+ display_screenshot_format: str = "png"
40
+ display_screenshot_quality: int = -1
41
+ display_screenshot_basename: str = "screenshot"
42
+
43
+ element_highlight_time: float = 2
44
+ element_highlight_ensure_timeout: float = 2
45
+
46
+ @staticmethod
47
+ def current() -> "Settings":
48
+ global _current
49
+ if _current is None:
50
+ _current = Settings()
51
+ return _current
52
+
53
+ def __enter__(self) -> "Settings":
54
+ global _current
55
+ self._old = _current
56
+ _current = self
57
+ return self
58
+
59
+ def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any) -> Literal[False]:
60
+ global _current
61
+ _current = self._old
62
+ del self._old
63
+ return False
@@ -0,0 +1 @@
1
+ from .strategies import *
@@ -0,0 +1,26 @@
1
+ from abc import abstractmethod
2
+ from typing import Any, ClassVar, List
3
+
4
+ from ..strategybase import StrategyBase
5
+
6
+ __all__ = ["Properties", "NativeProperties"]
7
+
8
+
9
+ class Properties(StrategyBase):
10
+ strategy_name: ClassVar[str] = "io.platynui.strategies.Properties"
11
+
12
+ @abstractmethod
13
+ def get_property_names(self) -> List[str]: ...
14
+
15
+ @abstractmethod
16
+ def get_property_value(self, name: str) -> Any: ...
17
+
18
+
19
+ class NativeProperties(StrategyBase):
20
+ strategy_name: ClassVar[str] = "io.platynui.strategies.NativeProperties"
21
+
22
+ @abstractmethod
23
+ def get_native_property_names(self) -> List[str]: ...
24
+
25
+ @abstractmethod
26
+ def get_native_property_value(self, name: str) -> Any: ...
@@ -0,0 +1,8 @@
1
+ from abc import ABC
2
+ from typing import ClassVar, Optional
3
+
4
+ __all__ = ["StrategyBase"]
5
+
6
+
7
+ class StrategyBase(ABC):
8
+ strategy_name: ClassVar[Optional[str]] = None
@@ -0,0 +1,102 @@
1
+ from collections import defaultdict
2
+ from typing import TYPE_CHECKING, Any, Callable, Dict, List, Optional, Type, TypeVar, cast
3
+
4
+ from .strategybase import StrategyBase
5
+ from .weight_calculator import WeightCalculator
6
+
7
+ if TYPE_CHECKING:
8
+ from .adapter import Adapter
9
+
10
+ __all__ = [
11
+ "StrategyImpl",
12
+ "strategy_impl_for",
13
+ "StrategyImplFactory",
14
+ ]
15
+
16
+
17
+ class StrategyImpl(StrategyBase):
18
+ def __init__(self, adapter: "Adapter"):
19
+ self._adapter = adapter
20
+
21
+ @property
22
+ def adapter(self) -> "Adapter":
23
+ return self._adapter
24
+
25
+ @property
26
+ def valid(self) -> bool:
27
+ return self.adapter.valid
28
+
29
+
30
+ TStrategyImpl = TypeVar("TStrategyImpl", bound=StrategyBase)
31
+
32
+
33
+ class StrategyImplFactory:
34
+ class Entry:
35
+ def __init__(self, proxy_type: Type[StrategyImpl], criterias: Dict[str, object]):
36
+ self.proxy_type = proxy_type
37
+ self.criterias = criterias
38
+
39
+ registered_impls: Dict[str, List[Entry]] = defaultdict(list)
40
+
41
+ @classmethod
42
+ def register_proxy(cls, impl_cls: Type[StrategyImpl], criterias: Dict[str, Any]) -> None:
43
+ strategy_names = set(
44
+ [
45
+ getattr(i, "strategy_name")
46
+ for i in impl_cls.mro()
47
+ if issubclass(i, StrategyBase) and i != StrategyBase and hasattr(i, "strategy_name")
48
+ ]
49
+ )
50
+ for name in strategy_names:
51
+ cls.registered_impls[name].append(StrategyImplFactory.Entry(impl_cls, criterias.copy()))
52
+
53
+ @classmethod
54
+ def find_strategy_impl_for(cls, adapter: "Adapter", strategy_cls: Type[TStrategyImpl]) -> Optional[TStrategyImpl]:
55
+ strategy_name = getattr(strategy_cls, "strategy_name", None)
56
+ if strategy_name is None:
57
+ return None
58
+
59
+ weights = []
60
+ calculator = WeightCalculator(adapter)
61
+
62
+ for e in cls.registered_impls[strategy_name]:
63
+ weights.append((calculator.calculate(e.criterias), e.proxy_type))
64
+
65
+ if len(weights) > 0:
66
+ last = sorted(weights, key=lambda x: x[0])[-1]
67
+
68
+ if last[0] > 0:
69
+ return cast(TStrategyImpl, last[1](adapter))
70
+
71
+ return None
72
+
73
+
74
+ def strategy_impl_for(
75
+ role: Optional[str] = None,
76
+ framework_id: Optional[str] = None,
77
+ class_name: Optional[str] = None,
78
+ tag_name: Optional[str] = None,
79
+ technology: Optional[Type[Any]] = None,
80
+ properties: Optional[Dict[str, Any]] = None,
81
+ native_properties: Optional[Dict[str, Any]] = None,
82
+ **decorator_kwargs: Any,
83
+ ) -> Callable[[Type[StrategyImpl]], Type[StrategyImpl]]:
84
+
85
+ def decorator(cls: Type[StrategyImpl]) -> Type[StrategyImpl]:
86
+
87
+ StrategyImplFactory.register_proxy(
88
+ cls,
89
+ {
90
+ "role": role,
91
+ "framework_id": framework_id,
92
+ "class_name": class_name,
93
+ "tag_name": tag_name,
94
+ "technology": technology,
95
+ "properties": properties,
96
+ "native_properties": native_properties,
97
+ **decorator_kwargs,
98
+ },
99
+ )
100
+ return cls
101
+
102
+ return decorator
@@ -0,0 +1,25 @@
1
+ from abc import ABCMeta, abstractmethod
2
+
3
+ from ..core import adapterfactory
4
+
5
+ __all__ = ["Technology"]
6
+
7
+
8
+ class Technology(metaclass=ABCMeta):
9
+ """
10
+ the base class for Technologies
11
+ """
12
+
13
+ @property
14
+ def name(self) -> str:
15
+ """
16
+ the name of the technology
17
+ """
18
+ return self.__class__.__qualname__
19
+
20
+ @property
21
+ @abstractmethod
22
+ def adapter_factory(self) -> adapterfactory.AdapterFactory:
23
+ """
24
+ get's the adapter factory defined by this technology
25
+ """