ok-script 0.0.7__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.
- autohelper/AutoHelper.py +116 -0
- autohelper/__init__.py +0 -0
- autohelper/capture/BaseCaptureMethod.py +30 -0
- autohelper/capture/HwndWindow.py +138 -0
- autohelper/capture/__init__.py +0 -0
- autohelper/capture/adb/ADBCaptureMethod.py +29 -0
- autohelper/capture/adb/DeviceManager.py +209 -0
- autohelper/capture/adb/__init__.py +0 -0
- autohelper/capture/adb/bin/__init__.py +0 -0
- autohelper/capture/adb/targets.py +61 -0
- autohelper/capture/adb/vbox.py +140 -0
- autohelper/capture/windows/WindowsGraphicsCaptureMethod.py +228 -0
- autohelper/capture/windows/__init__.py +0 -0
- autohelper/capture/windows/d3d11.py +74 -0
- autohelper/capture/windows/utils.py +149 -0
- autohelper/capture/windows/window.py +36 -0
- autohelper/color/Color.py +41 -0
- autohelper/color/__init__.py +0 -0
- autohelper/config/Config.py +79 -0
- autohelper/config/InfoDict.py +16 -0
- autohelper/config/__init__.py +0 -0
- autohelper/feature/Box.py +199 -0
- autohelper/feature/Feature.py +20 -0
- autohelper/feature/FeatureSet.py +207 -0
- autohelper/feature/FindFeature.py +52 -0
- autohelper/feature/__init__.py +0 -0
- autohelper/gui/App.py +120 -0
- autohelper/gui/Communicate.py +22 -0
- autohelper/gui/MainWindow.py +69 -0
- autohelper/gui/TabTitles.py +56 -0
- autohelper/gui/__init__.py +5 -0
- autohelper/gui/debug/AspectRatioWidget.py +31 -0
- autohelper/gui/debug/DebugTab.py +37 -0
- autohelper/gui/debug/FrameWidget.py +125 -0
- autohelper/gui/debug/InfoWidget.py +40 -0
- autohelper/gui/debug/LoggerWidget.py +74 -0
- autohelper/gui/debug/__init__.py +0 -0
- autohelper/gui/i18n/__init__.py +0 -0
- autohelper/gui/i18n/path.py +3 -0
- autohelper/gui/icon/__init__.py +0 -0
- autohelper/gui/icon/icon.py +6 -0
- autohelper/gui/loading/LoadingWindow.py +142 -0
- autohelper/gui/loading/__init__.py +0 -0
- autohelper/gui/overlay/OverlayWindow.py +34 -0
- autohelper/gui/overlay/__init__.py +0 -0
- autohelper/gui/resources.py +485 -0
- autohelper/gui/tasks/ConfigItemFactory.py +14 -0
- autohelper/gui/tasks/StartButton.py +47 -0
- autohelper/gui/tasks/TaskOpButton.py +33 -0
- autohelper/gui/tasks/TaskTab.py +121 -0
- autohelper/gui/tasks/TooltipTableWidget.py +39 -0
- autohelper/gui/tasks/__init__.py +0 -0
- autohelper/gui/util/Alert.py +20 -0
- autohelper/gui/util/InitWorker.py +17 -0
- autohelper/gui/util/__init__.py +0 -0
- autohelper/gui/widget/ListTableWidgetItem.py +27 -0
- autohelper/gui/widget/NumericTableWidgetItem.py +33 -0
- autohelper/gui/widget/RoundCornerContainer.py +59 -0
- autohelper/gui/widget/TabWidget.py +30 -0
- autohelper/gui/widget/UpdateConfigWidgetItem.py +16 -0
- autohelper/gui/widget/YesNonWidgetItem.py +23 -0
- autohelper/gui/widget/__init__.py +0 -0
- autohelper/interaction/ADBInteraction.py +33 -0
- autohelper/interaction/BaseInteraction.py +36 -0
- autohelper/interaction/Win32Interaction.py +56 -0
- autohelper/interaction/__init__.py +0 -0
- autohelper/logging/Logger.py +103 -0
- autohelper/logging/__init__.py +0 -0
- autohelper/ocr/OCR.py +50 -0
- autohelper/ocr/__init__.py +0 -0
- autohelper/predict/__init__.py +0 -0
- autohelper/predict/predict.py +45 -0
- autohelper/rotypes/Windows/Foundation/Collections.py +60 -0
- autohelper/rotypes/Windows/Foundation/__init__.py +153 -0
- autohelper/rotypes/Windows/Globalization/__init__.py +25 -0
- autohelper/rotypes/Windows/Graphics/Capture/__init__.py +110 -0
- autohelper/rotypes/Windows/Graphics/DirectX/Direct3D11/__init__.py +41 -0
- autohelper/rotypes/Windows/Graphics/DirectX/__init__.py +167 -0
- autohelper/rotypes/Windows/Graphics/Imaging/__init__.py +34 -0
- autohelper/rotypes/Windows/Graphics/__init__.py +5 -0
- autohelper/rotypes/Windows/Media/Ocr/__init__.py +76 -0
- autohelper/rotypes/Windows/Media/__init__.py +0 -0
- autohelper/rotypes/Windows/Security/Cryptography/__init__.py +18 -0
- autohelper/rotypes/Windows/Security/__init__.py +0 -0
- autohelper/rotypes/Windows/Storage/Streams/__init__.py +27 -0
- autohelper/rotypes/Windows/Storage/__init__.py +0 -0
- autohelper/rotypes/Windows/__init__.py +0 -0
- autohelper/rotypes/__init__.py +4 -0
- autohelper/rotypes/delegate.py +105 -0
- autohelper/rotypes/export.py +21 -0
- autohelper/rotypes/idldsl.py +272 -0
- autohelper/rotypes/inspectable.py +79 -0
- autohelper/rotypes/roapi.py +30 -0
- autohelper/rotypes/types.py +77 -0
- autohelper/rotypes/winstring.py +44 -0
- autohelper/save/BlackBarProcessor.py +25 -0
- autohelper/save/PostProcessor.py +6 -0
- autohelper/save/SaveByInterval.py +30 -0
- autohelper/save/SaveByKeyPress.py +27 -0
- autohelper/save/SaveMethodBase.py +46 -0
- autohelper/save/__init__.py +0 -0
- autohelper/scene/FeatureScene.py +14 -0
- autohelper/scene/Scene.py +21 -0
- autohelper/scene/__init__.py +0 -0
- autohelper/stats/StreamStats.py +34 -0
- autohelper/stats/__init__.py +0 -0
- autohelper/task/BaseTask.py +109 -0
- autohelper/task/ExecutorOperation.py +119 -0
- autohelper/task/FindFeatureTask.py +6 -0
- autohelper/task/TaskExecutor.py +249 -0
- autohelper/task/__init__.py +0 -0
- autohelper/util/__init__.py +0 -0
- autohelper/util/json.py +27 -0
- autohelper/util/list.py +2 -0
- autohelper/util/path.py +37 -0
- autohelper/util/thread.py +12 -0
- autohelper/util/win32_process.py +86 -0
- autohelper/util/yaml.py +28 -0
- ok_script-0.0.7.dist-info/METADATA +64 -0
- ok_script-0.0.7.dist-info/RECORD +122 -0
- ok_script-0.0.7.dist-info/WHEEL +5 -0
- ok_script-0.0.7.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
from _ctypes import _SimpleCData
|
|
2
|
+
from functools import lru_cache
|
|
3
|
+
import enum
|
|
4
|
+
|
|
5
|
+
from . import roapi
|
|
6
|
+
from .types import *
|
|
7
|
+
|
|
8
|
+
class CtypesEnum(enum.IntEnum):
|
|
9
|
+
"""A ctypes-compatible IntEnum superclass."""
|
|
10
|
+
@classmethod
|
|
11
|
+
def from_param(cls, obj):
|
|
12
|
+
return int(obj)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def STDMETHOD(index, name, *argtypes):
|
|
16
|
+
proto = WINFUNCTYPE(check_hresult, *argtypes)
|
|
17
|
+
func = proto(index, name)
|
|
18
|
+
return func
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def define_winrt_com_method(interface, name, *argtypes, retval=None, propget=None, propput=None, vtbl: int = next):
|
|
22
|
+
if vtbl is next:
|
|
23
|
+
vtbl = interface._vtblend + 1
|
|
24
|
+
if getattr(interface, '_method_defs', None) is None:
|
|
25
|
+
setattr(interface, '_method_defs', [])
|
|
26
|
+
if interface._method_defs is getattr(interface.__mro__[1], '_method_defs', None):
|
|
27
|
+
setattr(interface, '_method_defs', [])
|
|
28
|
+
if retval is not None:
|
|
29
|
+
comfunc = STDMETHOD(vtbl, name, *argtypes, POINTER(retval))
|
|
30
|
+
if retval.__mro__[1] is _SimpleCData: # if return type is primitive type
|
|
31
|
+
def func(this, *args, **kwargs):
|
|
32
|
+
obj = this.astype(interface)
|
|
33
|
+
result = retval()
|
|
34
|
+
comfunc(obj, *args, byref(result), **kwargs)
|
|
35
|
+
return result.value
|
|
36
|
+
else:
|
|
37
|
+
def func(this, *args, **kwargs):
|
|
38
|
+
obj = this.astype(interface)
|
|
39
|
+
result = _new_rtobj(retval)
|
|
40
|
+
comfunc(obj, *args, byref(result), **kwargs)
|
|
41
|
+
return result
|
|
42
|
+
interface._method_defs.append((vtbl, name, comfunc))
|
|
43
|
+
setattr(interface, '_' + name, comfunc)
|
|
44
|
+
setattr(interface, name, func)
|
|
45
|
+
elif propget is not None: # name = "get_Something"
|
|
46
|
+
comgetter = STDMETHOD(vtbl, name, *argtypes, POINTER(propget))
|
|
47
|
+
setattr(interface, name, comgetter)
|
|
48
|
+
interface._method_defs.append((vtbl, name, comgetter))
|
|
49
|
+
if name.startswith('get_'):
|
|
50
|
+
propname = name[4:]
|
|
51
|
+
if propname in interface.__dict__:
|
|
52
|
+
setter = interface.__dict__[propname].fset
|
|
53
|
+
else:
|
|
54
|
+
setter = None
|
|
55
|
+
|
|
56
|
+
if propget.__mro__[1] is _SimpleCData: # if return type is primitive type
|
|
57
|
+
def getter(this, *args, **kwargs):
|
|
58
|
+
obj = this.astype(interface)
|
|
59
|
+
result = propget()
|
|
60
|
+
comgetter(obj, *args, byref(result), **kwargs)
|
|
61
|
+
return result.value
|
|
62
|
+
else:
|
|
63
|
+
def getter(this, *args, **kwargs):
|
|
64
|
+
obj = this.astype(interface)
|
|
65
|
+
result = _new_rtobj(propget)
|
|
66
|
+
comgetter(obj, *args, byref(result), **kwargs)
|
|
67
|
+
return result
|
|
68
|
+
setattr(interface, propname, property(getter, setter))
|
|
69
|
+
|
|
70
|
+
elif propput is not None: # name = 'put_Something'
|
|
71
|
+
comsetter = STDMETHOD(vtbl, name, *argtypes, propput)
|
|
72
|
+
interface._method_defs.append((vtbl, name, comsetter))
|
|
73
|
+
setattr(interface, name, comsetter)
|
|
74
|
+
if name.startswith('put_'):
|
|
75
|
+
propname = name[4:]
|
|
76
|
+
if propname in interface.__dict__:
|
|
77
|
+
getter = interface.__dict__[propname].fget
|
|
78
|
+
else:
|
|
79
|
+
getter = None
|
|
80
|
+
|
|
81
|
+
def setter(this, *args, **kwargs):
|
|
82
|
+
obj = this.astype(interface)
|
|
83
|
+
comsetter(obj, *args, **kwargs)
|
|
84
|
+
|
|
85
|
+
setattr(interface, propname, property(getter, setter))
|
|
86
|
+
else:
|
|
87
|
+
comfunc = STDMETHOD(vtbl, name, *argtypes)
|
|
88
|
+
|
|
89
|
+
def func(this, *args, **kwargs):
|
|
90
|
+
obj = this.astype(interface)
|
|
91
|
+
comfunc(obj, *args, **kwargs)
|
|
92
|
+
|
|
93
|
+
interface._method_defs.append((vtbl, name, comfunc))
|
|
94
|
+
setattr(interface, name, funcwrap(func))
|
|
95
|
+
|
|
96
|
+
if vtbl > interface._vtblend:
|
|
97
|
+
interface._vtblend = vtbl
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
class classproperty(property):
|
|
101
|
+
def __get__(self, obj, type_):
|
|
102
|
+
return self.fget.__get__(None, type_)()
|
|
103
|
+
|
|
104
|
+
def __set__(self, obj, value):
|
|
105
|
+
cls = type(obj)
|
|
106
|
+
return self.fset.__get__(None, cls)(value)
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def _static_propget(interface, propname):
|
|
110
|
+
def getter(cls):
|
|
111
|
+
statics = roapi.GetActivationFactory(cls._runtimeclass_name, interface)
|
|
112
|
+
return getattr(statics, propname)
|
|
113
|
+
|
|
114
|
+
return classproperty(classmethod(getter))
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def _static_method(interface, methodname):
|
|
118
|
+
def func(cls, *args, **kwargs):
|
|
119
|
+
statics = roapi.GetActivationFactory(cls._runtimeclass_name, interface)
|
|
120
|
+
return getattr(statics, methodname)(*args, **kwargs)
|
|
121
|
+
|
|
122
|
+
return classmethod(func)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def funcwrap(f):
|
|
126
|
+
return lambda *args, **kw: f(*args, **kw)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def _non_activatable_init(self):
|
|
130
|
+
raise NotImplementedError('non-activatable runtime class ' + self._runtimeclass_name)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
_predefined_sigs = {
|
|
134
|
+
c_uint8: 'u1',
|
|
135
|
+
c_int32: 'i4',
|
|
136
|
+
c_uint32: 'u4',
|
|
137
|
+
c_int64: 'i8',
|
|
138
|
+
c_uint64: 'u8',
|
|
139
|
+
c_float: 'f4',
|
|
140
|
+
c_double: 'f8',
|
|
141
|
+
c_bool: 'b1',
|
|
142
|
+
str: 'string',
|
|
143
|
+
'char16': 'c2',
|
|
144
|
+
GUID: 'g16',
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _runtimeclass_signature(classname, default_iid):
|
|
149
|
+
return 'rc(%s;{%s})' % (classname, str(default_iid).lower())
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def _get_type_signature(clazz):
|
|
153
|
+
if hasattr(clazz, '_signature'):
|
|
154
|
+
return clazz._signature
|
|
155
|
+
elif isruntimeclass(clazz):
|
|
156
|
+
return _runtimeclass_signature(clazz._runtimeclass_name, clazz.__mro__[2].GUID)
|
|
157
|
+
elif hasattr(clazz, 'GUID'):
|
|
158
|
+
return '{%s}' % str(clazz.GUID).lower()
|
|
159
|
+
elif clazz in _predefined_sigs:
|
|
160
|
+
return _predefined_sigs[clazz]
|
|
161
|
+
else:
|
|
162
|
+
raise TypeError('no signature for type', clazz)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
_runtimeclass_registry = {}
|
|
166
|
+
|
|
167
|
+
class runtimeclass:
|
|
168
|
+
def __init_subclass__(cls):
|
|
169
|
+
mod1 = cls.__module__.split('.')
|
|
170
|
+
mod2 = __name__.split('.')
|
|
171
|
+
i = 0
|
|
172
|
+
for i in range(min(len(mod1), len(mod2))):
|
|
173
|
+
if mod1[i] != mod2[i]:
|
|
174
|
+
break
|
|
175
|
+
name = mod1[i:]
|
|
176
|
+
name.append(cls.__name__)
|
|
177
|
+
clsname = '.'.join(name)
|
|
178
|
+
cls._runtimeclass_name = clsname
|
|
179
|
+
_runtimeclass_registry[clsname] = cls
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def isruntimeclass(clazz):
|
|
183
|
+
return clazz.__mro__[1] is runtimeclass
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def _new_rtobj(clazz):
|
|
187
|
+
if isruntimeclass(clazz): # is a runtimeclass
|
|
188
|
+
return clazz.__mro__[2].__new__(clazz)
|
|
189
|
+
return clazz()
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
def generics_cache(func):
|
|
193
|
+
def wrapped(*types):
|
|
194
|
+
if types in wrapped.known_types:
|
|
195
|
+
return wrapped.known_types[types]
|
|
196
|
+
return func(*types)
|
|
197
|
+
|
|
198
|
+
wrapped.known_types = {}
|
|
199
|
+
return wrapped
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
def _sigoctets_to_uuid(octets):
|
|
203
|
+
import hashlib
|
|
204
|
+
digest = hashlib.sha1()
|
|
205
|
+
digest.update(octets)
|
|
206
|
+
uuidbytes = bytearray(digest.digest()[:16])
|
|
207
|
+
octet6 = uuidbytes[6]
|
|
208
|
+
octet6 = (octet6 & 0b00001111) | 0b01010000
|
|
209
|
+
uuidbytes[6] = octet6
|
|
210
|
+
octet8 = uuidbytes[8]
|
|
211
|
+
octet8 = (octet8 & 0b00111111) | 0b10000000
|
|
212
|
+
uuidbytes[8] = octet8
|
|
213
|
+
return '%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x' % tuple(uuidbytes)
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
@lru_cache()
|
|
217
|
+
def generate_parameterized_attrs(piid, *generics):
|
|
218
|
+
newsig = 'pinterface({%s};%s)' % (piid, ';'.join(map(_get_type_signature, generics)))
|
|
219
|
+
sigoctets = b'\x11\xF4z\xD5{sB\xC0\xAB\xAE\x87\x8B\x1E\x16\xAD\xEE' + newsig.encode('utf-8')
|
|
220
|
+
guid = _sigoctets_to_uuid(sigoctets)
|
|
221
|
+
return {'IID': guid, '_signature': newsig, '_typeparam': generics}
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
def fqn(t):
|
|
225
|
+
return t.__qualname__
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def pinterface_type(name, piid, typeparams, bases):
|
|
229
|
+
attrs = generate_parameterized_attrs(piid, *typeparams)
|
|
230
|
+
cls = type('%s(%s)' % (name, ','.join(map(fqn, typeparams))), bases, attrs)
|
|
231
|
+
return cls
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
def define_winrt_com_delegate(cls, *argtypes, retval=None):
|
|
235
|
+
from . import delegate
|
|
236
|
+
if retval is not None:
|
|
237
|
+
define_winrt_com_method(cls, 'Invoke', *argtypes, POINTER(retval), vtbl=3)
|
|
238
|
+
else:
|
|
239
|
+
define_winrt_com_method(cls, 'Invoke', *argtypes, vtbl=3)
|
|
240
|
+
cls._funcproto = delegate.proto(cls, *argtypes, retval=retval)
|
|
241
|
+
|
|
242
|
+
# def runtimeclass2(cls: type):
|
|
243
|
+
# clsname = getattr(cls, '_runtimeclss_name_', None)
|
|
244
|
+
# if clsname is None:
|
|
245
|
+
# nameparts = cls.__qualname__.split('.')
|
|
246
|
+
# refparts = __name__.split('.')
|
|
247
|
+
# for i in range(min(len(nameparts), len(refparts))):
|
|
248
|
+
# if nameparts[i] != refparts[i]:
|
|
249
|
+
# break
|
|
250
|
+
# clsname = '.'.join(nameparts[i:])
|
|
251
|
+
# props = {'_runtimeclass_name': clsname}
|
|
252
|
+
# bases = [runtimeclass]
|
|
253
|
+
# if (default := getattr(cls, '_default_', None)) is not None:
|
|
254
|
+
# bases.append(default)
|
|
255
|
+
# interfaces = getattr(cls, '_default_', ())
|
|
256
|
+
# bases.extend(interfaces)
|
|
257
|
+
# statics = getattr(cls, '_static_', ())
|
|
258
|
+
# for static_intf in statics:
|
|
259
|
+
# static_intf # TODO
|
|
260
|
+
# newcls = type(clsname, tuple(bases), props)
|
|
261
|
+
# return newcls
|
|
262
|
+
|
|
263
|
+
def runtimeclass_add_statics(cls, interface):
|
|
264
|
+
methods = [x[1] for x in interface._method_defs]
|
|
265
|
+
clsname = cls._runtimeclass_name
|
|
266
|
+
statics = roapi.GetActivationFactory(clsname, interface)
|
|
267
|
+
for method in methods:
|
|
268
|
+
wrapped_method = getattr(statics, method)
|
|
269
|
+
def wrapper(*args, **kwargs):
|
|
270
|
+
return wrapped_method(*args, **kwargs)
|
|
271
|
+
setattr(cls, method, staticmethod(wrapper))
|
|
272
|
+
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
from .idldsl import define_winrt_com_method, funcwrap, _new_rtobj
|
|
2
|
+
from .winstring import HSTRING
|
|
3
|
+
from .types import *
|
|
4
|
+
|
|
5
|
+
CoTaskMemFree = windll.ole32.CoTaskMemFree
|
|
6
|
+
CoTaskMemFree.argtypes = (c_void_p,)
|
|
7
|
+
|
|
8
|
+
# unknwn
|
|
9
|
+
@GUID('00000000-0000-0000-C000-000000000046')
|
|
10
|
+
class IUnknown(c_void_p):
|
|
11
|
+
_method_defs = [
|
|
12
|
+
(0, 'QueryInterface', WINFUNCTYPE(check_hresult, REFGUID, VOIDPP)(0, "QueryInterface")),
|
|
13
|
+
(1, 'AddRef', WINFUNCTYPE(ULONG)(1, "AddRef")),
|
|
14
|
+
(2, 'Release', WINFUNCTYPE(ULONG)(2, "Release"))
|
|
15
|
+
]
|
|
16
|
+
QueryInterface = funcwrap(_method_defs[0][2])
|
|
17
|
+
_AddRef = funcwrap(_method_defs[1][2])
|
|
18
|
+
_Release = funcwrap(_method_defs[2][2])
|
|
19
|
+
_vtblend = 2
|
|
20
|
+
|
|
21
|
+
def _detach(self):
|
|
22
|
+
newptr = cast(self, c_void_p)
|
|
23
|
+
self.value = None
|
|
24
|
+
return newptr
|
|
25
|
+
|
|
26
|
+
def Release(self):
|
|
27
|
+
if self.value is not None:
|
|
28
|
+
self._Release()
|
|
29
|
+
self.value = None
|
|
30
|
+
|
|
31
|
+
def __del__(self):
|
|
32
|
+
self.Release()
|
|
33
|
+
|
|
34
|
+
def astype(self, interface_type):
|
|
35
|
+
iid = interface_type.GUID
|
|
36
|
+
obj = _new_rtobj(interface_type)
|
|
37
|
+
self.QueryInterface(byref(iid), byref(obj))
|
|
38
|
+
return obj
|
|
39
|
+
|
|
40
|
+
def __init_subclass__(cls):
|
|
41
|
+
cls._method_defs = []
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# inspectable
|
|
45
|
+
class TrustLevel:
|
|
46
|
+
_enum_type_ = INT
|
|
47
|
+
BaseTrust = 0
|
|
48
|
+
PartialTrust = 1
|
|
49
|
+
FullTrust = 2
|
|
50
|
+
|
|
51
|
+
@GUID('AF86E2E0-B12D-4c6a-9C5A-D7AA65101E90')
|
|
52
|
+
class IInspectable(IUnknown):
|
|
53
|
+
def __class_getitem__(cls, name):
|
|
54
|
+
return cls
|
|
55
|
+
def __init_subclass__(cls, requires=()):
|
|
56
|
+
super().__init_subclass__()
|
|
57
|
+
|
|
58
|
+
def GetIids(self):
|
|
59
|
+
size = ULONG()
|
|
60
|
+
ptr = REFGUID()
|
|
61
|
+
self._GetIids(byref(size), byref(ptr))
|
|
62
|
+
result = [GUID(str(ptr[i])) for i in range(size.value)]
|
|
63
|
+
CoTaskMemFree(ptr)
|
|
64
|
+
return result
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
define_winrt_com_method(IInspectable, '_GetIids', POINTER(ULONG), POINTER(REFGUID), vtbl=3)
|
|
69
|
+
define_winrt_com_method(IInspectable, 'GetRuntimeClassName', retval=HSTRING, vtbl=4)
|
|
70
|
+
define_winrt_com_method(IInspectable, 'GetTrustLevel', retval=TrustLevel._enum_type_, vtbl=5)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
# activation
|
|
74
|
+
@GUID('00000035-0000-0000-c000-000000000046')
|
|
75
|
+
class IActivationFactory(IInspectable):
|
|
76
|
+
pass
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
define_winrt_com_method(IActivationFactory, 'ActivateInstance', retval=IInspectable, vtbl=6)
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from functools import lru_cache
|
|
2
|
+
|
|
3
|
+
from .inspectable import IInspectable, IActivationFactory
|
|
4
|
+
from .types import *
|
|
5
|
+
from .winstring import HSTRING
|
|
6
|
+
|
|
7
|
+
combase = windll.LoadLibrary('combase.dll')
|
|
8
|
+
RoGetActivationFactory = combase.RoGetActivationFactory
|
|
9
|
+
RoGetActivationFactory.argtypes = (HSTRING, REFGUID, POINTER(IInspectable))
|
|
10
|
+
RoGetActivationFactory.restype = check_hresult
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class RO_INIT_TYPE(INT):
|
|
14
|
+
RO_INIT_SINGLETHREADED = 0
|
|
15
|
+
RO_INIT_MULTITHREADED = 1
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
RoInitialize = combase.RoInitialize
|
|
19
|
+
RoInitialize.argtypes = (RO_INIT_TYPE,)
|
|
20
|
+
RoInitialize.restype = check_hresult
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@lru_cache()
|
|
24
|
+
def GetActivationFactory(classname, interface=IActivationFactory):
|
|
25
|
+
insp = interface()
|
|
26
|
+
RoGetActivationFactory(classname, interface.GUID, byref(insp))
|
|
27
|
+
return insp
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
RoInitialize(RO_INIT_TYPE.RO_INIT_SINGLETHREADED)
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
from ctypes import *
|
|
2
|
+
from ctypes.wintypes import *
|
|
3
|
+
|
|
4
|
+
HRESULT = LONG
|
|
5
|
+
|
|
6
|
+
VOIDPP = POINTER(c_void_p)
|
|
7
|
+
|
|
8
|
+
S_OK = 0
|
|
9
|
+
S_FALSE = 1
|
|
10
|
+
|
|
11
|
+
E_FAIL = -2147467259 # 0x80004005L
|
|
12
|
+
E_NOTIMPL = -2147467263 # 0x80004001L
|
|
13
|
+
E_NOINTERFACE = -2147467262 # 0x80004002L
|
|
14
|
+
E_BOUNDS = -2147483637 # 0x8000000BL
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def check_hresult(hr):
|
|
18
|
+
# print('HRESULT = 0x%08X' % (hr & 0xFFFFFFFF))
|
|
19
|
+
if (hr & 0x80000000) != 0:
|
|
20
|
+
if hr == E_NOTIMPL:
|
|
21
|
+
raise NotImplementedError
|
|
22
|
+
elif hr == E_NOINTERFACE:
|
|
23
|
+
raise TypeError("E_NOINTERFACE")
|
|
24
|
+
elif hr == E_BOUNDS:
|
|
25
|
+
raise IndexError # for old style iterator protocol
|
|
26
|
+
e = OSError("[HRESULT 0x%08X] %s" % (hr & 0xFFFFFFFF, FormatError(hr)))
|
|
27
|
+
e.winerror = hr & 0xFFFFFFFF
|
|
28
|
+
raise e
|
|
29
|
+
return hr
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class GUID(Structure):
|
|
33
|
+
_fields_ = [("Data1", DWORD),
|
|
34
|
+
("Data2", WORD),
|
|
35
|
+
("Data3", WORD),
|
|
36
|
+
("Data4", c_uint8 * 8)]
|
|
37
|
+
|
|
38
|
+
def __init__(self, *initwith):
|
|
39
|
+
if len(initwith) == 1 and isinstance(initwith[0], str):
|
|
40
|
+
strrepr = initwith[0]
|
|
41
|
+
if strrepr.startswith('{'):
|
|
42
|
+
strrepr = strrepr[1:-1]
|
|
43
|
+
part1, part2, part3, part4, part5 = strrepr.split('-', 5)
|
|
44
|
+
self.Data1 = int(part1, 16)
|
|
45
|
+
self.Data2 = int(part2, 16)
|
|
46
|
+
self.Data3 = int(part3, 16)
|
|
47
|
+
self.Data4 = (int(part4[0:2], 16), int(part4[2:4], 16),
|
|
48
|
+
int(part5[0:2], 16), int(part5[2:4], 16), int(part5[4:6], 16), int(part5[6:8], 16),
|
|
49
|
+
int(part5[8:10], 16), int(part5[10:12], 16))
|
|
50
|
+
elif len(initwith) == 4:
|
|
51
|
+
self.Data1, self.Data2, self.Data3, self.Data4 = initwith
|
|
52
|
+
elif len(initwith) == 11:
|
|
53
|
+
self.Data1, self.Data2, self.Data3, self.Data4 = (*initwith[0:3], initwith[3:])
|
|
54
|
+
else:
|
|
55
|
+
raise ArgumentError(len(initwith))
|
|
56
|
+
|
|
57
|
+
def __str__(self):
|
|
58
|
+
return '%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x' % (
|
|
59
|
+
self.Data1, self.Data2, self.Data3, *list(self.Data4))
|
|
60
|
+
|
|
61
|
+
def __repr__(self):
|
|
62
|
+
return 'GUID(%s)' % repr(str(self))
|
|
63
|
+
|
|
64
|
+
def __eq__(self, other):
|
|
65
|
+
return isinstance(other, GUID) and bytes(self) == bytes(other)
|
|
66
|
+
|
|
67
|
+
def __hash__(self):
|
|
68
|
+
# We make GUID instances hashable, although they are mutable.
|
|
69
|
+
return hash(bytes(self))
|
|
70
|
+
|
|
71
|
+
def __call__(self, victim):
|
|
72
|
+
"""for use as class decorator"""
|
|
73
|
+
victim.GUID = self
|
|
74
|
+
return victim
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
REFGUID = POINTER(GUID)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import ctypes
|
|
2
|
+
import weakref
|
|
3
|
+
|
|
4
|
+
from .types import check_hresult
|
|
5
|
+
|
|
6
|
+
combase = ctypes.windll.LoadLibrary("combase.dll")
|
|
7
|
+
WindowsCreateString = combase.WindowsCreateString
|
|
8
|
+
WindowsCreateString.argtypes = (ctypes.c_void_p, ctypes.c_uint32, ctypes.POINTER(ctypes.c_void_p))
|
|
9
|
+
WindowsCreateString.restype = check_hresult
|
|
10
|
+
|
|
11
|
+
WindowsDeleteString = combase.WindowsDeleteString
|
|
12
|
+
WindowsDeleteString.argtypes = (ctypes.c_void_p,)
|
|
13
|
+
WindowsDeleteString.restype = check_hresult
|
|
14
|
+
|
|
15
|
+
WindowsGetStringRawBuffer = combase.WindowsGetStringRawBuffer
|
|
16
|
+
WindowsGetStringRawBuffer.argtypes = (ctypes.c_void_p, ctypes.POINTER(ctypes.c_uint32))
|
|
17
|
+
WindowsGetStringRawBuffer.restype = ctypes.c_void_p
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class HSTRING(ctypes.c_void_p):
|
|
21
|
+
def __init__(self, s=None):
|
|
22
|
+
super().__init__()
|
|
23
|
+
if s is None or len(s) == 0:
|
|
24
|
+
self.value = None
|
|
25
|
+
return
|
|
26
|
+
u16str = s.encode("utf-16-le") + b"\x00\x00"
|
|
27
|
+
u16len = (len(u16str) // 2) - 1
|
|
28
|
+
WindowsCreateString(u16str, ctypes.c_uint32(u16len), ctypes.byref(self))
|
|
29
|
+
self._finalizer = weakref.finalize(self, WindowsDeleteString, self.value)
|
|
30
|
+
# only register finalizer if we created the string
|
|
31
|
+
|
|
32
|
+
def __str__(self):
|
|
33
|
+
if self.value is None:
|
|
34
|
+
return ""
|
|
35
|
+
length = ctypes.c_uint32()
|
|
36
|
+
ptr = WindowsGetStringRawBuffer(self, ctypes.byref(length))
|
|
37
|
+
return ctypes.wstring_at(ptr, length.value)
|
|
38
|
+
|
|
39
|
+
def __repr__(self):
|
|
40
|
+
return "HSTRING(%s)" % repr(str(self))
|
|
41
|
+
|
|
42
|
+
@classmethod
|
|
43
|
+
def from_param(cls, s):
|
|
44
|
+
return cls(s)
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import cv2
|
|
2
|
+
import numpy as np
|
|
3
|
+
|
|
4
|
+
from autohelper.save.PostProcessor import PostProcessor
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class BlackBarProcessor(PostProcessor):
|
|
8
|
+
def __init__(self, x, y, width, height, color=(1, 1, 1)):
|
|
9
|
+
self.x = x
|
|
10
|
+
self.y = y
|
|
11
|
+
self.width = width
|
|
12
|
+
self.height = height
|
|
13
|
+
self.color = color
|
|
14
|
+
|
|
15
|
+
def process(self, image: np.ndarray):
|
|
16
|
+
height, width = image.shape[:2]
|
|
17
|
+
# Calculate absolute coordinates
|
|
18
|
+
x = int(self.x * width)
|
|
19
|
+
y = int(self.y * height)
|
|
20
|
+
abs_width = int(self.width * width)
|
|
21
|
+
abs_height = int(self.height * height)
|
|
22
|
+
|
|
23
|
+
# Draw a black rectangle
|
|
24
|
+
cv2.rectangle(image, (x, y), (x + abs_width, y + abs_height), self.color, -1)
|
|
25
|
+
print(f"cv2.rectangle ({x},{y},{abs_width},{abs_height})")
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import time
|
|
2
|
+
|
|
3
|
+
import cv2
|
|
4
|
+
|
|
5
|
+
from autohelper.capture.windows.WindowsGraphicsCaptureMethod import BaseCaptureMethod
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SaveByInterval:
|
|
9
|
+
|
|
10
|
+
def __init__(self, method: "BaseCaptureMethod", interval=1):
|
|
11
|
+
self.interval = interval
|
|
12
|
+
self.method = method
|
|
13
|
+
|
|
14
|
+
def save(self):
|
|
15
|
+
for i in range(5):
|
|
16
|
+
print(f"Log message {i}")
|
|
17
|
+
frame, err = self.method.get_frame()
|
|
18
|
+
if frame is not None:
|
|
19
|
+
filename = f"images/{i}.jpg"
|
|
20
|
+
# Save the image
|
|
21
|
+
cv2.imwrite(filename, frame)
|
|
22
|
+
time.sleep(1)
|
|
23
|
+
self.method.close()
|
|
24
|
+
print("Thread completed its execution.")
|
|
25
|
+
|
|
26
|
+
def wait_until_done(self):
|
|
27
|
+
# thread = threading.Thread(target=self.save)
|
|
28
|
+
# thread.start()
|
|
29
|
+
# thread.join()
|
|
30
|
+
pass
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
from pynput import keyboard
|
|
2
|
+
|
|
3
|
+
from autohelper.capture.windows.WindowsGraphicsCaptureMethod import BaseCaptureMethod
|
|
4
|
+
from autohelper.save.PostProcessor import PostProcessor
|
|
5
|
+
from autohelper.save.SaveMethodBase import SaveMethodBase
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class SaveByKeyPress(SaveMethodBase):
|
|
9
|
+
|
|
10
|
+
def __init__(self, method: BaseCaptureMethod, image_processor: PostProcessor = None, capture_key="c", stop_key="x"):
|
|
11
|
+
super().__init__(method, image_processor)
|
|
12
|
+
self.capture_key = capture_key
|
|
13
|
+
self.stop_key = stop_key
|
|
14
|
+
listener = keyboard.Listener(on_release=self.on_key_release)
|
|
15
|
+
listener.start()
|
|
16
|
+
|
|
17
|
+
def on_key_release(self, key):
|
|
18
|
+
print(f'Key {key} released')
|
|
19
|
+
try:
|
|
20
|
+
if key.char == self.capture_key:
|
|
21
|
+
print(f'is capture_key call save()')
|
|
22
|
+
self.save()
|
|
23
|
+
elif key.char == self.stop_key:
|
|
24
|
+
self.stop()
|
|
25
|
+
return False
|
|
26
|
+
except AttributeError as e:
|
|
27
|
+
print(f'AttributeError {e} key {key} released')
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import threading
|
|
3
|
+
|
|
4
|
+
import cv2
|
|
5
|
+
|
|
6
|
+
from autohelper.capture.windows.WindowsGraphicsCaptureMethod import BaseCaptureMethod
|
|
7
|
+
from autohelper.save.PostProcessor import PostProcessor
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class SaveMethodBase:
|
|
11
|
+
|
|
12
|
+
def __init__(self, method: BaseCaptureMethod, image_processor: PostProcessor = None):
|
|
13
|
+
self.method = method
|
|
14
|
+
self.image_processor = image_processor
|
|
15
|
+
self.i = 1
|
|
16
|
+
self.thread = threading.Thread(target=self.run)
|
|
17
|
+
self.dir = "images"
|
|
18
|
+
# Check if the directory exists, and create it if it doesn't
|
|
19
|
+
if not os.path.exists(self.dir):
|
|
20
|
+
os.makedirs(self.dir)
|
|
21
|
+
self.thread.start()
|
|
22
|
+
self.exit_event = threading.Event()
|
|
23
|
+
|
|
24
|
+
def save(self):
|
|
25
|
+
frame = self.method.get_frame()
|
|
26
|
+
if frame is not None:
|
|
27
|
+
if self.image_processor is not None:
|
|
28
|
+
self.image_processor.process(frame)
|
|
29
|
+
filename = f"{self.dir}/{self.i}.jpg"
|
|
30
|
+
self.i += 1
|
|
31
|
+
# Save the image
|
|
32
|
+
cv2.imwrite(filename, frame)
|
|
33
|
+
|
|
34
|
+
def run(self):
|
|
35
|
+
print("Thread started")
|
|
36
|
+
while not self.exit_event.is_set():
|
|
37
|
+
# Do some work here
|
|
38
|
+
# print("Thread is running...")
|
|
39
|
+
self.exit_event.wait(1) # Wait for 1 second or until the event is set
|
|
40
|
+
print("Thread exiting")
|
|
41
|
+
|
|
42
|
+
def stop(self):
|
|
43
|
+
self.exit_event.set()
|
|
44
|
+
|
|
45
|
+
def wait_until_done(self):
|
|
46
|
+
self.thread.join()
|
|
File without changes
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
|
|
3
|
+
from autohelper.feature.FindFeature import FindFeature
|
|
4
|
+
from autohelper.scene.Scene import Scene
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class FindFeatureScene(Scene, FindFeature):
|
|
8
|
+
def __init__(self):
|
|
9
|
+
Scene.__init__(self)
|
|
10
|
+
self.feature_set = None
|
|
11
|
+
|
|
12
|
+
@abstractmethod
|
|
13
|
+
def detect(self, frame):
|
|
14
|
+
return False
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
from abc import abstractmethod
|
|
2
|
+
|
|
3
|
+
from autohelper.gui.Communicate import communicate
|
|
4
|
+
from autohelper.logging.Logger import get_logger
|
|
5
|
+
from autohelper.task.ExecutorOperation import ExecutorOperation
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Scene(ExecutorOperation):
|
|
9
|
+
name = None
|
|
10
|
+
|
|
11
|
+
def __init__(self):
|
|
12
|
+
self.name = self.__class__.__name__
|
|
13
|
+
self.logger = get_logger(self.__class__.__name__)
|
|
14
|
+
|
|
15
|
+
@abstractmethod
|
|
16
|
+
def detect(self, frame):
|
|
17
|
+
return False
|
|
18
|
+
|
|
19
|
+
@staticmethod
|
|
20
|
+
def draw_boxes(feature_name, boxes, color="red"):
|
|
21
|
+
communicate.draw_box.emit(feature_name, boxes, color)
|
|
File without changes
|