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.
Files changed (122) hide show
  1. autohelper/AutoHelper.py +116 -0
  2. autohelper/__init__.py +0 -0
  3. autohelper/capture/BaseCaptureMethod.py +30 -0
  4. autohelper/capture/HwndWindow.py +138 -0
  5. autohelper/capture/__init__.py +0 -0
  6. autohelper/capture/adb/ADBCaptureMethod.py +29 -0
  7. autohelper/capture/adb/DeviceManager.py +209 -0
  8. autohelper/capture/adb/__init__.py +0 -0
  9. autohelper/capture/adb/bin/__init__.py +0 -0
  10. autohelper/capture/adb/targets.py +61 -0
  11. autohelper/capture/adb/vbox.py +140 -0
  12. autohelper/capture/windows/WindowsGraphicsCaptureMethod.py +228 -0
  13. autohelper/capture/windows/__init__.py +0 -0
  14. autohelper/capture/windows/d3d11.py +74 -0
  15. autohelper/capture/windows/utils.py +149 -0
  16. autohelper/capture/windows/window.py +36 -0
  17. autohelper/color/Color.py +41 -0
  18. autohelper/color/__init__.py +0 -0
  19. autohelper/config/Config.py +79 -0
  20. autohelper/config/InfoDict.py +16 -0
  21. autohelper/config/__init__.py +0 -0
  22. autohelper/feature/Box.py +199 -0
  23. autohelper/feature/Feature.py +20 -0
  24. autohelper/feature/FeatureSet.py +207 -0
  25. autohelper/feature/FindFeature.py +52 -0
  26. autohelper/feature/__init__.py +0 -0
  27. autohelper/gui/App.py +120 -0
  28. autohelper/gui/Communicate.py +22 -0
  29. autohelper/gui/MainWindow.py +69 -0
  30. autohelper/gui/TabTitles.py +56 -0
  31. autohelper/gui/__init__.py +5 -0
  32. autohelper/gui/debug/AspectRatioWidget.py +31 -0
  33. autohelper/gui/debug/DebugTab.py +37 -0
  34. autohelper/gui/debug/FrameWidget.py +125 -0
  35. autohelper/gui/debug/InfoWidget.py +40 -0
  36. autohelper/gui/debug/LoggerWidget.py +74 -0
  37. autohelper/gui/debug/__init__.py +0 -0
  38. autohelper/gui/i18n/__init__.py +0 -0
  39. autohelper/gui/i18n/path.py +3 -0
  40. autohelper/gui/icon/__init__.py +0 -0
  41. autohelper/gui/icon/icon.py +6 -0
  42. autohelper/gui/loading/LoadingWindow.py +142 -0
  43. autohelper/gui/loading/__init__.py +0 -0
  44. autohelper/gui/overlay/OverlayWindow.py +34 -0
  45. autohelper/gui/overlay/__init__.py +0 -0
  46. autohelper/gui/resources.py +485 -0
  47. autohelper/gui/tasks/ConfigItemFactory.py +14 -0
  48. autohelper/gui/tasks/StartButton.py +47 -0
  49. autohelper/gui/tasks/TaskOpButton.py +33 -0
  50. autohelper/gui/tasks/TaskTab.py +121 -0
  51. autohelper/gui/tasks/TooltipTableWidget.py +39 -0
  52. autohelper/gui/tasks/__init__.py +0 -0
  53. autohelper/gui/util/Alert.py +20 -0
  54. autohelper/gui/util/InitWorker.py +17 -0
  55. autohelper/gui/util/__init__.py +0 -0
  56. autohelper/gui/widget/ListTableWidgetItem.py +27 -0
  57. autohelper/gui/widget/NumericTableWidgetItem.py +33 -0
  58. autohelper/gui/widget/RoundCornerContainer.py +59 -0
  59. autohelper/gui/widget/TabWidget.py +30 -0
  60. autohelper/gui/widget/UpdateConfigWidgetItem.py +16 -0
  61. autohelper/gui/widget/YesNonWidgetItem.py +23 -0
  62. autohelper/gui/widget/__init__.py +0 -0
  63. autohelper/interaction/ADBInteraction.py +33 -0
  64. autohelper/interaction/BaseInteraction.py +36 -0
  65. autohelper/interaction/Win32Interaction.py +56 -0
  66. autohelper/interaction/__init__.py +0 -0
  67. autohelper/logging/Logger.py +103 -0
  68. autohelper/logging/__init__.py +0 -0
  69. autohelper/ocr/OCR.py +50 -0
  70. autohelper/ocr/__init__.py +0 -0
  71. autohelper/predict/__init__.py +0 -0
  72. autohelper/predict/predict.py +45 -0
  73. autohelper/rotypes/Windows/Foundation/Collections.py +60 -0
  74. autohelper/rotypes/Windows/Foundation/__init__.py +153 -0
  75. autohelper/rotypes/Windows/Globalization/__init__.py +25 -0
  76. autohelper/rotypes/Windows/Graphics/Capture/__init__.py +110 -0
  77. autohelper/rotypes/Windows/Graphics/DirectX/Direct3D11/__init__.py +41 -0
  78. autohelper/rotypes/Windows/Graphics/DirectX/__init__.py +167 -0
  79. autohelper/rotypes/Windows/Graphics/Imaging/__init__.py +34 -0
  80. autohelper/rotypes/Windows/Graphics/__init__.py +5 -0
  81. autohelper/rotypes/Windows/Media/Ocr/__init__.py +76 -0
  82. autohelper/rotypes/Windows/Media/__init__.py +0 -0
  83. autohelper/rotypes/Windows/Security/Cryptography/__init__.py +18 -0
  84. autohelper/rotypes/Windows/Security/__init__.py +0 -0
  85. autohelper/rotypes/Windows/Storage/Streams/__init__.py +27 -0
  86. autohelper/rotypes/Windows/Storage/__init__.py +0 -0
  87. autohelper/rotypes/Windows/__init__.py +0 -0
  88. autohelper/rotypes/__init__.py +4 -0
  89. autohelper/rotypes/delegate.py +105 -0
  90. autohelper/rotypes/export.py +21 -0
  91. autohelper/rotypes/idldsl.py +272 -0
  92. autohelper/rotypes/inspectable.py +79 -0
  93. autohelper/rotypes/roapi.py +30 -0
  94. autohelper/rotypes/types.py +77 -0
  95. autohelper/rotypes/winstring.py +44 -0
  96. autohelper/save/BlackBarProcessor.py +25 -0
  97. autohelper/save/PostProcessor.py +6 -0
  98. autohelper/save/SaveByInterval.py +30 -0
  99. autohelper/save/SaveByKeyPress.py +27 -0
  100. autohelper/save/SaveMethodBase.py +46 -0
  101. autohelper/save/__init__.py +0 -0
  102. autohelper/scene/FeatureScene.py +14 -0
  103. autohelper/scene/Scene.py +21 -0
  104. autohelper/scene/__init__.py +0 -0
  105. autohelper/stats/StreamStats.py +34 -0
  106. autohelper/stats/__init__.py +0 -0
  107. autohelper/task/BaseTask.py +109 -0
  108. autohelper/task/ExecutorOperation.py +119 -0
  109. autohelper/task/FindFeatureTask.py +6 -0
  110. autohelper/task/TaskExecutor.py +249 -0
  111. autohelper/task/__init__.py +0 -0
  112. autohelper/util/__init__.py +0 -0
  113. autohelper/util/json.py +27 -0
  114. autohelper/util/list.py +2 -0
  115. autohelper/util/path.py +37 -0
  116. autohelper/util/thread.py +12 -0
  117. autohelper/util/win32_process.py +86 -0
  118. autohelper/util/yaml.py +28 -0
  119. ok_script-0.0.7.dist-info/METADATA +64 -0
  120. ok_script-0.0.7.dist-info/RECORD +122 -0
  121. ok_script-0.0.7.dist-info/WHEEL +5 -0
  122. ok_script-0.0.7.dist-info/top_level.txt +1 -0
@@ -0,0 +1,167 @@
1
+ from autohelper.rotypes.idldsl import CtypesEnum
2
+
3
+
4
+ class DirectXAlphaMode(CtypesEnum):
5
+ Unspecified = 0
6
+ Premultiplied = 1
7
+ Straight = 2
8
+ Ignore = 3
9
+
10
+
11
+ class DirectXColorSpace(CtypesEnum):
12
+ RgbFullG22NoneP709 = 0
13
+ RgbFullG10NoneP709 = 1
14
+ RgbStudioG22NoneP709 = 2
15
+ RgbStudioG22NoneP2020 = 3
16
+ Reserved = 4
17
+ YccFullG22NoneP709X601 = 5
18
+ YccStudioG22LeftP601 = 6
19
+ YccFullG22LeftP601 = 7
20
+ YccStudioG22LeftP709 = 8
21
+ YccFullG22LeftP709 = 9
22
+ YccStudioG22LeftP2020 = 10
23
+ YccFullG22LeftP2020 = 11
24
+ RgbFullG2084NoneP2020 = 12
25
+ YccStudioG2084LeftP2020 = 13
26
+ RgbStudioG2084NoneP2020 = 14
27
+ YccStudioG22TopLeftP2020 = 15
28
+ YccStudioG2084TopLeftP2020 = 16
29
+ RgbFullG22NoneP2020 = 17
30
+ YccStudioGHlgTopLeftP2020 = 18
31
+ YccFullGHlgTopLeftP2020 = 19
32
+ RgbStudioG24NoneP709 = 20
33
+ RgbStudioG24NoneP2020 = 21
34
+ YccStudioG24LeftP709 = 22
35
+ YccStudioG24LeftP2020 = 23
36
+ YccStudioG24TopLeftP2020 = 24
37
+
38
+
39
+ class DirectXPixelFormat(CtypesEnum):
40
+ Unknown = 0
41
+ R32G32B32A32Typeless = 1
42
+ R32G32B32A32Float = 2
43
+ R32G32B32A32UInt = 3
44
+ R32G32B32A32Int = 4
45
+ R32G32B32Typeless = 5
46
+ R32G32B32Float = 6
47
+ R32G32B32UInt = 7
48
+ R32G32B32Int = 8
49
+ R16G16B16A16Typeless = 9
50
+ R16G16B16A16Float = 10
51
+ R16G16B16A16UIntNormalized = 11
52
+ R16G16B16A16UInt = 12
53
+ R16G16B16A16IntNormalized = 13
54
+ R16G16B16A16Int = 14
55
+ R32G32Typeless = 15
56
+ R32G32Float = 16
57
+ R32G32UInt = 17
58
+ R32G32Int = 18
59
+ R32G8X24Typeless = 19
60
+ D32FloatS8X24UInt = 20
61
+ R32FloatX8X24Typeless = 21
62
+ X32TypelessG8X24UInt = 22
63
+ R10G10B10A2Typeless = 23
64
+ R10G10B10A2UIntNormalized = 24
65
+ R10G10B10A2UInt = 25
66
+ R11G11B10Float = 26
67
+ R8G8B8A8Typeless = 27
68
+ R8G8B8A8UIntNormalized = 28
69
+ R8G8B8A8UIntNormalizedSrgb = 29
70
+ R8G8B8A8UInt = 30
71
+ R8G8B8A8IntNormalized = 31
72
+ R8G8B8A8Int = 32
73
+ R16G16Typeless = 33
74
+ R16G16Float = 34
75
+ R16G16UIntNormalized = 35
76
+ R16G16UInt = 36
77
+ R16G16IntNormalized = 37
78
+ R16G16Int = 38
79
+ R32Typeless = 39
80
+ D32Float = 40
81
+ R32Float = 41
82
+ R32UInt = 42
83
+ R32Int = 43
84
+ R24G8Typeless = 44
85
+ D24UIntNormalizedS8UInt = 45
86
+ R24UIntNormalizedX8Typeless = 46
87
+ X24TypelessG8UInt = 47
88
+ R8G8Typeless = 48
89
+ R8G8UIntNormalized = 49
90
+ R8G8UInt = 50
91
+ R8G8IntNormalized = 51
92
+ R8G8Int = 52
93
+ R16Typeless = 53
94
+ R16Float = 54
95
+ D16UIntNormalized = 55
96
+ R16UIntNormalized = 56
97
+ R16UInt = 57
98
+ R16IntNormalized = 58
99
+ R16Int = 59
100
+ R8Typeless = 60
101
+ R8UIntNormalized = 61
102
+ R8UInt = 62
103
+ R8IntNormalized = 63
104
+ R8Int = 64
105
+ A8UIntNormalized = 65
106
+ R1UIntNormalized = 66
107
+ R9G9B9E5SharedExponent = 67
108
+ R8G8B8G8UIntNormalized = 68
109
+ G8R8G8B8UIntNormalized = 69
110
+ BC1Typeless = 70
111
+ BC1UIntNormalized = 71
112
+ BC1UIntNormalizedSrgb = 72
113
+ BC2Typeless = 73
114
+ BC2UIntNormalized = 74
115
+ BC2UIntNormalizedSrgb = 75
116
+ BC3Typeless = 76
117
+ BC3UIntNormalized = 77
118
+ BC3UIntNormalizedSrgb = 78
119
+ BC4Typeless = 79
120
+ BC4UIntNormalized = 80
121
+ BC4IntNormalized = 81
122
+ BC5Typeless = 82
123
+ BC5UIntNormalized = 83
124
+ BC5IntNormalized = 84
125
+ B5G6R5UIntNormalized = 85
126
+ B5G5R5A1UIntNormalized = 86
127
+ B8G8R8A8UIntNormalized = 87
128
+ B8G8R8X8UIntNormalized = 88
129
+ R10G10B10XRBiasA2UIntNormalized = 89
130
+ B8G8R8A8Typeless = 90
131
+ B8G8R8A8UIntNormalizedSrgb = 91
132
+ B8G8R8X8Typeless = 92
133
+ B8G8R8X8UIntNormalizedSrgb = 93
134
+ BC6HTypeless = 94
135
+ BC6H16UnsignedFloat = 95
136
+ BC6H16Float = 96
137
+ BC7Typeless = 97
138
+ BC7UIntNormalized = 98
139
+ BC7UIntNormalizedSrgb = 99
140
+ Ayuv = 100
141
+ Y410 = 101
142
+ Y416 = 102
143
+ NV12 = 103
144
+ P010 = 104
145
+ P016 = 105
146
+ Opaque420 = 106
147
+ Yuy2 = 107
148
+ Y210 = 108
149
+ Y216 = 109
150
+ NV11 = 110
151
+ AI44 = 111
152
+ IA44 = 112
153
+ P8 = 113
154
+ A8P8 = 114
155
+ B4G4R4A4UIntNormalized = 115
156
+ P208 = 130
157
+ V208 = 131
158
+ V408 = 132
159
+
160
+
161
+ class DirectXPrimitiveTopology(CtypesEnum):
162
+ Undefined = 0
163
+ PointList = 1
164
+ LineList = 2
165
+ LineStrip = 3
166
+ TriangleList = 4
167
+ TriangleStrip = 5
@@ -0,0 +1,34 @@
1
+ from ctypes import c_int, c_int32
2
+
3
+ import autohelper.rotypes.Windows.Storage.Streams
4
+ from autohelper.rotypes.Windows.Foundation import IClosable
5
+ from autohelper.rotypes.idldsl import define_winrt_com_method, _static_method, runtimeclass, GUID
6
+ from autohelper.rotypes.inspectable import IInspectable
7
+
8
+
9
+ @GUID('689e0708-7eef-483f-963f-da938818e073')
10
+ class ISoftwareBitmap(IClosable, IInspectable):
11
+ pass
12
+
13
+
14
+ class BitmapPixelFormat(c_int):
15
+ Rgba8 = 30
16
+
17
+
18
+ class BitmapAlphaMode(c_int):
19
+ Straight = 1
20
+
21
+
22
+ @GUID('DF0385DB-672F-4A9D-806E-C2442F343E86')
23
+ class ISoftwareBitmapStatics(IInspectable):
24
+ pass
25
+
26
+
27
+ class SoftwareBitmap(runtimeclass, ISoftwareBitmap):
28
+ CreateCopyWithAlphaFromBuffer = _static_method(ISoftwareBitmapStatics, 'CreateCopyWithAlphaFromBuffer')
29
+
30
+
31
+ define_winrt_com_method(ISoftwareBitmapStatics, "CreateCopyWithAlphaFromBuffer",
32
+ autohelper.rotypes.Windows.Storage.Streams.IBuffer, BitmapPixelFormat, c_int32, c_int32,
33
+ BitmapAlphaMode,
34
+ retval=SoftwareBitmap, vtbl=10)
@@ -0,0 +1,5 @@
1
+ import ctypes
2
+
3
+
4
+ class SizeInt32(ctypes.Structure):
5
+ _fields_ = [('Width', ctypes.c_int32), ('Height', ctypes.c_int32)]
@@ -0,0 +1,76 @@
1
+ from ctypes import c_uint32, c_bool, c_double
2
+
3
+ from autohelper.rotypes.Windows.Foundation import IReference, Rect, IAsyncOperation
4
+ from autohelper.rotypes.Windows.Foundation.Collections import IVectorView
5
+ from autohelper.rotypes.Windows.Globalization import Language
6
+ from autohelper.rotypes.Windows.Graphics.Imaging import SoftwareBitmap
7
+ from autohelper.rotypes.idldsl import define_winrt_com_method, _static_propget, _static_method, _non_activatable_init, \
8
+ runtimeclass, GUID
9
+ from autohelper.rotypes.inspectable import IInspectable
10
+ from autohelper.rotypes.winstring import HSTRING
11
+
12
+
13
+ @GUID('3C2A477A-5CD9-3525-BA2A-23D1E0A68A1D')
14
+ class IOcrWord(IInspectable):
15
+ pass
16
+
17
+
18
+ @GUID('0043A16F-E31F-3A24-899C-D444BD088124')
19
+ class IOcrLine(IInspectable):
20
+ pass
21
+
22
+
23
+ @GUID('9BD235B2-175B-3D6A-92E2-388C206E2F63')
24
+ class IOcrResult(IInspectable):
25
+ pass
26
+
27
+
28
+ @GUID('5A14BC41-5B76-3140-B680-8825562683AC')
29
+ class IOcrEngine(IInspectable):
30
+ pass
31
+
32
+
33
+ @GUID('5BFFA85A-3384-3540-9940-699120D428A8')
34
+ class IOcrEngineStatics(IInspectable):
35
+ pass
36
+
37
+
38
+ class OcrWord(runtimeclass, IOcrWord):
39
+ pass
40
+
41
+
42
+ class OcrLine(runtimeclass, IOcrLine):
43
+ pass
44
+
45
+
46
+ class OcrResult(runtimeclass, IOcrResult):
47
+ pass
48
+
49
+
50
+ class OcrEngine(runtimeclass, IOcrEngine):
51
+ __init__ = _non_activatable_init
52
+ MaxImageDimension = _static_propget(IOcrEngineStatics, 'MaxImageDimension')
53
+ AvailableRecognizerLanguages = _static_propget(IOcrEngineStatics, 'AvailableRecognizerLanguages')
54
+ IsLanguageSupported = _static_method(IOcrEngineStatics, 'IsLanguageSupported')
55
+ TryCreateFromLanguage = _static_method(IOcrEngineStatics, 'TryCreateFromLanguage')
56
+ TryCreateFromUserProfileLanguages = _static_method(IOcrEngineStatics, 'TryCreateFromUserProfileLanguages')
57
+
58
+
59
+ define_winrt_com_method(IOcrWord, 'get_BoundingRect', propget=Rect, vtbl=6)
60
+ define_winrt_com_method(IOcrWord, 'get_Text', propget=HSTRING, vtbl=7)
61
+
62
+ define_winrt_com_method(IOcrLine, 'get_Words', propget=IVectorView(OcrWord), vtbl=6)
63
+ define_winrt_com_method(IOcrLine, 'get_Text', propget=HSTRING, vtbl=7)
64
+
65
+ define_winrt_com_method(IOcrResult, 'get_Lines', propget=IVectorView(OcrLine), vtbl=6)
66
+ define_winrt_com_method(IOcrResult, 'get_TextAngle', propget=IReference(c_double), vtbl=7)
67
+ define_winrt_com_method(IOcrResult, 'get_Text', propget=HSTRING, vtbl=8)
68
+
69
+ define_winrt_com_method(IOcrEngine, 'RecognizeAsync', SoftwareBitmap, retval=IAsyncOperation(OcrResult), vtbl=6)
70
+ define_winrt_com_method(IOcrEngine, 'get_RecognizerLanguage', propget=Language, vtbl=7)
71
+
72
+ define_winrt_com_method(IOcrEngineStatics, 'get_MaxImageDimension', propget=c_uint32, vtbl=6)
73
+ define_winrt_com_method(IOcrEngineStatics, 'get_AvailableRecognizerLanguages', propget=IVectorView(Language), vtbl=7)
74
+ define_winrt_com_method(IOcrEngineStatics, 'IsLanguageSupported', Language, retval=c_bool, vtbl=8)
75
+ define_winrt_com_method(IOcrEngineStatics, 'TryCreateFromLanguage', Language, retval=IOcrEngine, vtbl=9)
76
+ define_winrt_com_method(IOcrEngineStatics, 'TryCreateFromUserProfileLanguages', retval=IOcrEngine, vtbl=10)
File without changes
@@ -0,0 +1,18 @@
1
+ from ctypes import c_uint32, c_void_p
2
+
3
+ from autohelper.rotypes.idldsl import define_winrt_com_method, _non_activatable_init, _static_method, runtimeclass, GUID
4
+ from autohelper.rotypes.inspectable import IInspectable
5
+
6
+
7
+ @GUID('320B7E22-3CB0-4CDF-8663-1D28910065EB')
8
+ class ICryptographicBufferStatics(IInspectable):
9
+ pass
10
+
11
+
12
+ class CryptographicBuffer(runtimeclass):
13
+ __init__ = _non_activatable_init
14
+ CreateFromByteArray = _static_method(ICryptographicBufferStatics, 'CreateFromByteArray')
15
+
16
+
17
+ define_winrt_com_method(ICryptographicBufferStatics, 'CreateFromByteArray', c_uint32, c_void_p,
18
+ retval=rotypes.Windows.Storage.Streams.IBuffer, vtbl=9)
File without changes
@@ -0,0 +1,27 @@
1
+ from ctypes import c_uint32, c_void_p, string_at
2
+
3
+ from autohelper.rotypes.idldsl import define_winrt_com_method, GUID
4
+ from autohelper.rotypes.inspectable import IInspectable, IUnknown
5
+
6
+
7
+ @GUID('905a0fef-bc53-11df-8c49-001e4fc686da')
8
+ class IBufferByteAccess(IUnknown):
9
+ pass
10
+
11
+
12
+ @GUID('905A0FE0-BC53-11DF-8C49-001E4FC686DA')
13
+ class IBuffer(IInspectable):
14
+ def __len__(self):
15
+ return self.Length
16
+
17
+ def __bytes__(self):
18
+ byteaccess = self.astype(IBufferByteAccess)
19
+ ptr = byteaccess.Buffer()
20
+ return string_at(ptr, len(self))
21
+
22
+
23
+ define_winrt_com_method(IBufferByteAccess, 'Buffer', retval=c_void_p)
24
+
25
+ define_winrt_com_method(IBuffer, 'get_Capacity', propget=c_uint32)
26
+ define_winrt_com_method(IBuffer, 'get_Length', propget=c_uint32)
27
+ define_winrt_com_method(IBuffer, 'put_Length', propput=c_uint32)
File without changes
File without changes
@@ -0,0 +1,4 @@
1
+ from .types import HRESULT, GUID, REFGUID
2
+ from . import roapi
3
+ from .winstring import HSTRING
4
+ from .inspectable import IUnknown, IInspectable
@@ -0,0 +1,105 @@
1
+ from ctypes import WINFUNCTYPE, HRESULT, POINTER, Structure, c_void_p, cast, pointer
2
+ import traceback
3
+ from .inspectable import IUnknown
4
+ from .types import REFGUID, VOIDPP, ULONG, GUID, E_NOINTERFACE, S_OK, E_FAIL
5
+
6
+ _refmap = {}
7
+
8
+ _typeof_QueryInterface = WINFUNCTYPE(HRESULT, c_void_p, REFGUID, VOIDPP)
9
+ _typeof_AddRef = WINFUNCTYPE(ULONG, c_void_p)
10
+ _typeof_Release = WINFUNCTYPE(ULONG, c_void_p)
11
+
12
+
13
+ class _impl_delegate_vtbl(Structure):
14
+ _fields_ = [('QueryInterface', _typeof_QueryInterface), ('AddRef', _typeof_AddRef), ('Release', _typeof_Release),
15
+ ('Invoke', c_void_p)]
16
+
17
+
18
+ class _impl_delegate(Structure):
19
+ _fields_ = [('vtbl', POINTER(_impl_delegate_vtbl))]
20
+
21
+
22
+ def proto(*argtypes, retval=None):
23
+ if retval is not None:
24
+ argtypes = (*argtypes, POINTER(retval))
25
+ proto = WINFUNCTYPE(HRESULT, *argtypes)
26
+ proto._retval = retval
27
+ return proto
28
+
29
+
30
+ IID_IAgileObject = GUID('94ea2b94-e9cc-49e0-c0ff-ee64ca8f5b90')
31
+
32
+
33
+ class delegatebase:
34
+ @classmethod
35
+ def delegate(cls, func):
36
+ vtbl = _impl_delegate_vtbl()
37
+ iid = cls.GUID
38
+
39
+ def impl_AddRef(this):
40
+ refcnt = _refmap[this][1] + 1
41
+ _refmap[this][1] = refcnt
42
+ return refcnt
43
+
44
+ def impl_QueryInterface(this, refiid, ppunk):
45
+ try:
46
+ wantiid = refiid.contents
47
+ if wantiid == IUnknown.GUID or wantiid == IID_IAgileObject or wantiid == iid:
48
+ impl_AddRef(this)
49
+ ppunk[0] = this
50
+ return S_OK
51
+ ppunk[0] = None
52
+ return E_NOINTERFACE
53
+ except Exception:
54
+ return E_FAIL
55
+
56
+ def impl_Release(this):
57
+ refcnt = _refmap[this][1] - 1
58
+ _refmap[this][1] = refcnt
59
+ if refcnt == 0:
60
+ del _refmap[this]
61
+ return refcnt
62
+
63
+ proto = cls._funcproto
64
+ if proto._retval is not None:
65
+ def impl_Invoke(this, *args):
66
+ try:
67
+ for arg in args:
68
+ if isinstance(arg, IUnknown) and arg.value is not None:
69
+ arg._AddRef()
70
+ retval = func(*args[:-1])
71
+ args[-1][0] = retval
72
+ return S_OK
73
+ except Exception:
74
+ traceback.print_exc()
75
+ return E_FAIL
76
+ else:
77
+ def impl_Invoke(this, *args, **kwargs):
78
+ if isinstance(this, IUnknown):
79
+ this._AddRef()
80
+ try:
81
+ for arg in args:
82
+ if isinstance(arg, IUnknown) and arg.value is not None:
83
+ arg._AddRef()
84
+ func(*args, **kwargs)
85
+ return S_OK
86
+ except Exception:
87
+ traceback.print_exc()
88
+ return E_FAIL
89
+
90
+ cb = proto(impl_Invoke)
91
+
92
+ vtbl.QueryInterface = _typeof_QueryInterface(impl_QueryInterface)
93
+ vtbl.AddRef = _typeof_AddRef(impl_AddRef)
94
+ vtbl.Release = _typeof_Release(impl_Release)
95
+ vtbl.Invoke = cast(cb, c_void_p)
96
+
97
+ obj = _impl_delegate()
98
+ obj.vtbl = pointer(vtbl)
99
+ objptr = pointer(obj)
100
+
101
+ objptrval = cast(objptr, c_void_p).value
102
+
103
+ keepref = (objptr, obj, vtbl, cb, func)
104
+ _refmap[objptrval] = [keepref, 1]
105
+ return cast(objptr, cls) # reference #1
@@ -0,0 +1,21 @@
1
+ import ctypes
2
+
3
+
4
+ class ExportObject:
5
+ def __init__(self, obj, *interfaces):
6
+ self.interfaces = interfaces
7
+ self.vtbls = []
8
+ self.vtbl_array = ctypes.c_void_p * len(self.vtbls)
9
+ self.obj = obj
10
+ self._refcnt = 1
11
+ ctypes.pythonapi.Py_IncRef(ctypes.py_object(self))
12
+
13
+ def AddRef(self):
14
+ self._refcnt += 1
15
+ return self._refcnt
16
+
17
+ def Release(self):
18
+ self._refcnt -= 1
19
+ if self._refcnt == 0:
20
+ ctypes.pythonapi.Py_DecRef(ctypes.py_object(self))
21
+ return self._refcnt