amulet-core 2.0a5__cp311-cp311-macosx_10_9_universal2.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.

Potentially problematic release.


This version of amulet-core might be problematic. Click here for more details.

Files changed (210) hide show
  1. amulet/__init__.cpython-311-darwin.so +0 -0
  2. amulet/__init__.pyi +30 -0
  3. amulet/__pyinstaller/__init__.py +2 -0
  4. amulet/__pyinstaller/hook-amulet.py +4 -0
  5. amulet/_init.py +28 -0
  6. amulet/_version.py +21 -0
  7. amulet/biome.cpp +36 -0
  8. amulet/biome.hpp +43 -0
  9. amulet/biome.pyi +77 -0
  10. amulet/block.cpp +435 -0
  11. amulet/block.hpp +119 -0
  12. amulet/block.pyi +273 -0
  13. amulet/block_entity.cpp +12 -0
  14. amulet/block_entity.hpp +56 -0
  15. amulet/block_entity.pyi +80 -0
  16. amulet/chunk.cpp +16 -0
  17. amulet/chunk.hpp +99 -0
  18. amulet/chunk.pyi +30 -0
  19. amulet/chunk_/components/biome.py +155 -0
  20. amulet/chunk_/components/block_entity.py +117 -0
  21. amulet/chunk_/components/entity.py +64 -0
  22. amulet/chunk_/components/height_2d.py +16 -0
  23. amulet/chunk_components.pyi +95 -0
  24. amulet/collections.pyi +37 -0
  25. amulet/data_types.py +29 -0
  26. amulet/entity.py +180 -0
  27. amulet/errors.py +63 -0
  28. amulet/game/__init__.py +7 -0
  29. amulet/game/_game.py +152 -0
  30. amulet/game/_universal/__init__.py +1 -0
  31. amulet/game/_universal/_biome.py +17 -0
  32. amulet/game/_universal/_block.py +47 -0
  33. amulet/game/_universal/_version.py +68 -0
  34. amulet/game/abc/__init__.py +22 -0
  35. amulet/game/abc/_block_specification.py +150 -0
  36. amulet/game/abc/biome.py +213 -0
  37. amulet/game/abc/block.py +331 -0
  38. amulet/game/abc/game_version_container.py +25 -0
  39. amulet/game/abc/json_interface.py +27 -0
  40. amulet/game/abc/version.py +44 -0
  41. amulet/game/bedrock/__init__.py +1 -0
  42. amulet/game/bedrock/_biome.py +35 -0
  43. amulet/game/bedrock/_block.py +42 -0
  44. amulet/game/bedrock/_version.py +165 -0
  45. amulet/game/java/__init__.py +2 -0
  46. amulet/game/java/_biome.py +35 -0
  47. amulet/game/java/_block.py +60 -0
  48. amulet/game/java/_version.py +176 -0
  49. amulet/game/translate/__init__.py +12 -0
  50. amulet/game/translate/_functions/__init__.py +15 -0
  51. amulet/game/translate/_functions/_code_functions/__init__.py +0 -0
  52. amulet/game/translate/_functions/_code_functions/_text.py +553 -0
  53. amulet/game/translate/_functions/_code_functions/banner_pattern.py +67 -0
  54. amulet/game/translate/_functions/_code_functions/bedrock_chest_connection.py +152 -0
  55. amulet/game/translate/_functions/_code_functions/bedrock_moving_block_pos.py +88 -0
  56. amulet/game/translate/_functions/_code_functions/bedrock_sign.py +152 -0
  57. amulet/game/translate/_functions/_code_functions/bedrock_skull_rotation.py +16 -0
  58. amulet/game/translate/_functions/_code_functions/custom_name.py +146 -0
  59. amulet/game/translate/_functions/_frozen.py +66 -0
  60. amulet/game/translate/_functions/_state.py +54 -0
  61. amulet/game/translate/_functions/_typing.py +98 -0
  62. amulet/game/translate/_functions/abc.py +116 -0
  63. amulet/game/translate/_functions/carry_nbt.py +160 -0
  64. amulet/game/translate/_functions/carry_properties.py +80 -0
  65. amulet/game/translate/_functions/code.py +143 -0
  66. amulet/game/translate/_functions/map_block_name.py +66 -0
  67. amulet/game/translate/_functions/map_nbt.py +111 -0
  68. amulet/game/translate/_functions/map_properties.py +93 -0
  69. amulet/game/translate/_functions/multiblock.py +112 -0
  70. amulet/game/translate/_functions/new_block.py +42 -0
  71. amulet/game/translate/_functions/new_entity.py +43 -0
  72. amulet/game/translate/_functions/new_nbt.py +206 -0
  73. amulet/game/translate/_functions/new_properties.py +64 -0
  74. amulet/game/translate/_functions/sequence.py +51 -0
  75. amulet/game/translate/_functions/walk_input_nbt.py +331 -0
  76. amulet/game/translate/_translator.py +433 -0
  77. amulet/item.py +75 -0
  78. amulet/level/__init__.pyi +27 -0
  79. amulet/level/_load.py +100 -0
  80. amulet/level/abc/__init__.py +12 -0
  81. amulet/level/abc/_chunk_handle.py +335 -0
  82. amulet/level/abc/_dimension.py +86 -0
  83. amulet/level/abc/_history/__init__.py +1 -0
  84. amulet/level/abc/_history/_cache.py +224 -0
  85. amulet/level/abc/_history/_history_manager.py +291 -0
  86. amulet/level/abc/_level/__init__.py +5 -0
  87. amulet/level/abc/_level/_compactable_level.py +10 -0
  88. amulet/level/abc/_level/_creatable_level.py +29 -0
  89. amulet/level/abc/_level/_disk_level.py +17 -0
  90. amulet/level/abc/_level/_level.py +453 -0
  91. amulet/level/abc/_level/_loadable_level.py +42 -0
  92. amulet/level/abc/_player_storage.py +7 -0
  93. amulet/level/abc/_raw_level.py +187 -0
  94. amulet/level/abc/_registry.py +40 -0
  95. amulet/level/bedrock/__init__.py +2 -0
  96. amulet/level/bedrock/_chunk_handle.py +19 -0
  97. amulet/level/bedrock/_dimension.py +22 -0
  98. amulet/level/bedrock/_level.py +187 -0
  99. amulet/level/bedrock/_raw/__init__.py +5 -0
  100. amulet/level/bedrock/_raw/_actor_counter.py +53 -0
  101. amulet/level/bedrock/_raw/_chunk.py +54 -0
  102. amulet/level/bedrock/_raw/_chunk_decode.py +668 -0
  103. amulet/level/bedrock/_raw/_chunk_encode.py +602 -0
  104. amulet/level/bedrock/_raw/_constant.py +9 -0
  105. amulet/level/bedrock/_raw/_dimension.py +343 -0
  106. amulet/level/bedrock/_raw/_level.py +463 -0
  107. amulet/level/bedrock/_raw/_level_dat.py +90 -0
  108. amulet/level/bedrock/_raw/_typing.py +6 -0
  109. amulet/level/bedrock/_raw/leveldb_chunk_versions.py +83 -0
  110. amulet/level/bedrock/chunk/__init__.py +1 -0
  111. amulet/level/bedrock/chunk/_chunk.py +126 -0
  112. amulet/level/bedrock/chunk/components/__init__.py +0 -0
  113. amulet/level/bedrock/chunk/components/chunk_version.py +12 -0
  114. amulet/level/bedrock/chunk/components/finalised_state.py +13 -0
  115. amulet/level/bedrock/chunk/components/raw_chunk.py +15 -0
  116. amulet/level/construction/__init__.py +0 -0
  117. amulet/level/java/__init__.pyi +21 -0
  118. amulet/level/java/_chunk_handle.py +17 -0
  119. amulet/level/java/_chunk_handle.pyi +15 -0
  120. amulet/level/java/_dimension.py +20 -0
  121. amulet/level/java/_dimension.pyi +13 -0
  122. amulet/level/java/_level.py +184 -0
  123. amulet/level/java/_level.pyi +120 -0
  124. amulet/level/java/_raw/__init__.pyi +19 -0
  125. amulet/level/java/_raw/_chunk.pyi +23 -0
  126. amulet/level/java/_raw/_chunk_decode.py +561 -0
  127. amulet/level/java/_raw/_chunk_encode.py +463 -0
  128. amulet/level/java/_raw/_constant.py +9 -0
  129. amulet/level/java/_raw/_constant.pyi +20 -0
  130. amulet/level/java/_raw/_data_pack/__init__.py +2 -0
  131. amulet/level/java/_raw/_data_pack/__init__.pyi +8 -0
  132. amulet/level/java/_raw/_data_pack/data_pack.py +241 -0
  133. amulet/level/java/_raw/_data_pack/data_pack.pyi +197 -0
  134. amulet/level/java/_raw/_data_pack/data_pack_manager.py +77 -0
  135. amulet/level/java/_raw/_data_pack/data_pack_manager.pyi +75 -0
  136. amulet/level/java/_raw/_dimension.py +86 -0
  137. amulet/level/java/_raw/_dimension.pyi +72 -0
  138. amulet/level/java/_raw/_level.py +507 -0
  139. amulet/level/java/_raw/_level.pyi +238 -0
  140. amulet/level/java/_raw/_typing.py +3 -0
  141. amulet/level/java/_raw/_typing.pyi +5 -0
  142. amulet/level/java/anvil/__init__.py +2 -0
  143. amulet/level/java/anvil/__init__.pyi +11 -0
  144. amulet/level/java/anvil/_dimension.py +170 -0
  145. amulet/level/java/anvil/_dimension.pyi +109 -0
  146. amulet/level/java/anvil/_region.py +421 -0
  147. amulet/level/java/anvil/_region.pyi +197 -0
  148. amulet/level/java/anvil/_sector_manager.py +223 -0
  149. amulet/level/java/anvil/_sector_manager.pyi +142 -0
  150. amulet/level/java/chunk.pyi +81 -0
  151. amulet/level/java/chunk_/_chunk.py +260 -0
  152. amulet/level/java/chunk_/components/inhabited_time.py +12 -0
  153. amulet/level/java/chunk_/components/last_update.py +12 -0
  154. amulet/level/java/chunk_/components/legacy_version.py +12 -0
  155. amulet/level/java/chunk_/components/light_populated.py +12 -0
  156. amulet/level/java/chunk_/components/named_height_2d.py +37 -0
  157. amulet/level/java/chunk_/components/status.py +11 -0
  158. amulet/level/java/chunk_/components/terrain_populated.py +12 -0
  159. amulet/level/java/chunk_components.pyi +22 -0
  160. amulet/level/java/long_array.pyi +38 -0
  161. amulet/level/java_forge/__init__.py +0 -0
  162. amulet/level/mcstructure/__init__.py +0 -0
  163. amulet/level/nbt/__init__.py +0 -0
  164. amulet/level/schematic/__init__.py +0 -0
  165. amulet/level/sponge_schematic/__init__.py +0 -0
  166. amulet/level/temporary_level/__init__.py +1 -0
  167. amulet/level/temporary_level/_level.py +16 -0
  168. amulet/palette/__init__.pyi +8 -0
  169. amulet/palette/biome_palette.pyi +45 -0
  170. amulet/palette/block_palette.pyi +45 -0
  171. amulet/player.py +64 -0
  172. amulet/py.typed +0 -0
  173. amulet/selection/__init__.py +2 -0
  174. amulet/selection/abstract_selection.py +342 -0
  175. amulet/selection/box.py +852 -0
  176. amulet/selection/group.py +481 -0
  177. amulet/utils/__init__.pyi +28 -0
  178. amulet/utils/call_spec/__init__.py +24 -0
  179. amulet/utils/call_spec/__init__.pyi +53 -0
  180. amulet/utils/call_spec/_call_spec.py +262 -0
  181. amulet/utils/call_spec/_call_spec.pyi +272 -0
  182. amulet/utils/format_utils.py +41 -0
  183. amulet/utils/generator.py +18 -0
  184. amulet/utils/matrix.py +243 -0
  185. amulet/utils/matrix.pyi +177 -0
  186. amulet/utils/numpy.pyi +11 -0
  187. amulet/utils/numpy_helpers.py +19 -0
  188. amulet/utils/shareable_lock.py +335 -0
  189. amulet/utils/shareable_lock.pyi +190 -0
  190. amulet/utils/signal/__init__.py +10 -0
  191. amulet/utils/signal/__init__.pyi +25 -0
  192. amulet/utils/signal/_signal.py +228 -0
  193. amulet/utils/signal/_signal.pyi +84 -0
  194. amulet/utils/task_manager.py +235 -0
  195. amulet/utils/task_manager.pyi +168 -0
  196. amulet/utils/typed_property.py +111 -0
  197. amulet/utils/typing.py +4 -0
  198. amulet/utils/typing.pyi +6 -0
  199. amulet/utils/weakref.py +70 -0
  200. amulet/utils/weakref.pyi +50 -0
  201. amulet/utils/world_utils.py +102 -0
  202. amulet/utils/world_utils.pyi +109 -0
  203. amulet/version.cpp +136 -0
  204. amulet/version.hpp +142 -0
  205. amulet/version.pyi +94 -0
  206. amulet_core-2.0a5.dist-info/METADATA +103 -0
  207. amulet_core-2.0a5.dist-info/RECORD +210 -0
  208. amulet_core-2.0a5.dist-info/WHEEL +5 -0
  209. amulet_core-2.0a5.dist-info/entry_points.txt +2 -0
  210. amulet_core-2.0a5.dist-info/top_level.txt +1 -0
@@ -0,0 +1,228 @@
1
+ from __future__ import annotations
2
+
3
+ import logging
4
+ from typing import (
5
+ Callable,
6
+ Any,
7
+ overload,
8
+ Protocol,
9
+ TYPE_CHECKING,
10
+ TypeVarTuple,
11
+ Generic,
12
+ )
13
+ from collections.abc import Sequence
14
+ from weakref import WeakMethod
15
+ from inspect import ismethod
16
+
17
+
18
+ if TYPE_CHECKING:
19
+ import PySide6.QtCore # type: ignore # noqa
20
+
21
+
22
+ CallArgs = TypeVarTuple("CallArgs")
23
+
24
+
25
+ class SignalInstance(Protocol[*CallArgs]):
26
+ def connect(
27
+ self,
28
+ slot: Callable[[*CallArgs], None] | SignalInstance[*CallArgs] | None,
29
+ type: PySide6.QtCore.Qt.ConnectionType | None = ...,
30
+ ) -> None: ...
31
+
32
+ def disconnect(
33
+ self,
34
+ slot: Callable[[*CallArgs], None] | SignalInstance[*CallArgs] | None = None,
35
+ ) -> None: ...
36
+
37
+ def emit(self, *args: *CallArgs) -> None: ...
38
+
39
+
40
+ _signal_instance_constructor: SignalInstanceConstructor | None = None
41
+
42
+
43
+ # TODO: https://github.com/python/typing/issues/1216
44
+
45
+
46
+ def create_signal_instance(
47
+ *types: type, instance: Any, name: str = "", arguments: Sequence[str] = ()
48
+ ) -> SignalInstance[*CallArgs]:
49
+ """Create a new signal instance"""
50
+ if _signal_instance_constructor is None:
51
+ set_signal_instance_constructor(get_fallback_signal_instance_constructor())
52
+ assert _signal_instance_constructor is not None
53
+ return _signal_instance_constructor(
54
+ types=types,
55
+ name=name,
56
+ arguments=arguments,
57
+ instance=instance,
58
+ )
59
+
60
+
61
+ SignalInstanceCacheName = "_SignalCache"
62
+
63
+
64
+ def _get_signal_instances(instance: Any) -> dict[Signal, SignalInstance]:
65
+ signal_instances: dict[Any, SignalInstance]
66
+ try:
67
+ signal_instances = getattr(instance, SignalInstanceCacheName)
68
+ except AttributeError:
69
+ signal_instances = {}
70
+ setattr(instance, SignalInstanceCacheName, signal_instances)
71
+ return signal_instances
72
+
73
+
74
+ class Signal(Generic[*CallArgs]):
75
+ def __init__(self, *types: type, name: str = "", arguments: Sequence[str] = ()):
76
+ self._types = types
77
+ self._name = name
78
+ self._arguments = arguments
79
+
80
+ @overload
81
+ def __get__(self, instance: None, owner: Any | None) -> Signal[*CallArgs]: ...
82
+
83
+ @overload
84
+ def __get__(
85
+ self, instance: Any, owner: Any | None
86
+ ) -> SignalInstance[*CallArgs]: ...
87
+
88
+ def __get__(self, instance: Any, owner: Any) -> Any:
89
+ if instance is None:
90
+ return self
91
+ signal_instances = _get_signal_instances(instance)
92
+ if self not in signal_instances:
93
+ signal_instances[self] = create_signal_instance(
94
+ *self._types,
95
+ name=self._name,
96
+ arguments=self._arguments,
97
+ instance=instance,
98
+ )
99
+ return signal_instances[self]
100
+
101
+
102
+ class SignalInstanceConstructor(Protocol[*CallArgs]):
103
+ def __call__(
104
+ self,
105
+ *,
106
+ types: tuple[type, ...],
107
+ name: str,
108
+ arguments: Sequence[str],
109
+ instance: Any,
110
+ ) -> SignalInstance[*CallArgs]: ...
111
+
112
+
113
+ def set_signal_instance_constructor(constructor: SignalInstanceConstructor) -> None:
114
+ global _signal_instance_constructor
115
+ if _signal_instance_constructor is not None:
116
+ raise RuntimeError("Signal instance constructor has already been set.")
117
+ _signal_instance_constructor = constructor
118
+
119
+
120
+ def get_fallback_signal_instance_constructor() -> SignalInstanceConstructor:
121
+ class FallbackSignalInstance(SignalInstance[*CallArgs]):
122
+ _callbacks: set[
123
+ Callable[[*CallArgs], None]
124
+ | WeakMethod[Callable[[*CallArgs], None]]
125
+ | FallbackSignalInstance[*CallArgs]
126
+ ]
127
+
128
+ def __init__(self, *types: type):
129
+ self._types = types
130
+ self._callbacks = set()
131
+
132
+ @staticmethod
133
+ def _wrap_slot(
134
+ slot: Callable[[*CallArgs], None] | SignalInstance[*CallArgs] | None
135
+ ) -> (
136
+ Callable[[*CallArgs], None]
137
+ | WeakMethod[Callable[[*CallArgs], None]]
138
+ | FallbackSignalInstance[*CallArgs]
139
+ ):
140
+ if ismethod(slot):
141
+ return WeakMethod(slot) # type: ignore
142
+ elif isinstance(slot, FallbackSignalInstance) or callable(slot):
143
+ return slot # type: ignore
144
+ else:
145
+ raise RuntimeError(f"{slot} is not a supported slot type.")
146
+
147
+ def connect(
148
+ self,
149
+ slot: Callable[[*CallArgs], None] | SignalInstance[*CallArgs] | None,
150
+ type: PySide6.QtCore.Qt.ConnectionType | None = None,
151
+ ) -> None:
152
+ if type is not None:
153
+ logging.warning(
154
+ "FallbackSignalInstance does not support custom connection types. Using DirectConnection"
155
+ )
156
+ self._callbacks.add(self._wrap_slot(slot))
157
+
158
+ def disconnect(
159
+ self,
160
+ slot: Callable[[*CallArgs], None] | SignalInstance[*CallArgs] | None = None,
161
+ ) -> None:
162
+ self._callbacks.remove(self._wrap_slot(slot))
163
+
164
+ def emit(self, *args: *CallArgs) -> None:
165
+ if len(args) != len(self._types):
166
+ raise TypeError(
167
+ f"SignalInstance{self._types}.emit expected {len(self._types)} argument(s), {len(args)} given."
168
+ )
169
+ for slot in self._callbacks:
170
+ try:
171
+ if isinstance(slot, FallbackSignalInstance):
172
+ slot.emit(*args) # type: ignore
173
+ elif isinstance(slot, WeakMethod):
174
+ method = slot()
175
+ if method is not None:
176
+ method(*args)
177
+ else:
178
+ slot(*args)
179
+ except Exception as e:
180
+ logging.error(e)
181
+
182
+ def fallback_signal_instance_constructor(
183
+ *,
184
+ types: tuple[type, ...],
185
+ name: str,
186
+ arguments: Sequence[str],
187
+ instance: Any,
188
+ ) -> FallbackSignalInstance[*CallArgs]:
189
+ return FallbackSignalInstance(*types)
190
+
191
+ return fallback_signal_instance_constructor
192
+
193
+
194
+ def get_pyside6_signal_instance_constructor() -> SignalInstanceConstructor:
195
+ try:
196
+ from PySide6.QtCore import (
197
+ QObject,
198
+ Signal as PySide6_Signal,
199
+ SignalInstance as PySide6_SignalInstance,
200
+ )
201
+ except ImportError as e:
202
+ raise ImportError("Could not import PySide6") from e
203
+
204
+ QObjectCacheName = "_QObjectCache"
205
+
206
+ def pyside6_signal_instance_constructor(
207
+ *,
208
+ types: tuple[type, ...],
209
+ name: str,
210
+ arguments: Sequence[str],
211
+ instance: Any,
212
+ ) -> PySide6_SignalInstance:
213
+ if isinstance(instance, QObject):
214
+ return PySide6_Signal(
215
+ *types, name=name, arguments=list(arguments) if arguments else None
216
+ ).__get__(instance, QObject)
217
+ else:
218
+ signal_instances = _get_signal_instances(instance)
219
+ if QObjectCacheName not in signal_instances:
220
+ signal_instances[QObjectCacheName] = QObject() # type: ignore
221
+ obj = signal_instances[QObjectCacheName] # type: ignore
222
+ if not isinstance(obj, QObject):
223
+ raise RuntimeError
224
+ return PySide6_Signal(*types, name=name, arguments=arguments).__get__(
225
+ obj, QObject
226
+ )
227
+
228
+ return pyside6_signal_instance_constructor # type: ignore
@@ -0,0 +1,84 @@
1
+ from __future__ import annotations
2
+
3
+ import logging as logging
4
+ import typing
5
+ from collections.abc import Sequence
6
+ from inspect import ismethod
7
+ from typing import Any, Generic, Protocol, TypeVarTuple, overload
8
+ from weakref import WeakMethod
9
+
10
+ __all__ = [
11
+ "Any",
12
+ "CallArgs",
13
+ "Generic",
14
+ "Protocol",
15
+ "Sequence",
16
+ "Signal",
17
+ "SignalInstance",
18
+ "SignalInstanceCacheName",
19
+ "SignalInstanceConstructor",
20
+ "TypeVarTuple",
21
+ "WeakMethod",
22
+ "create_signal_instance",
23
+ "get_fallback_signal_instance_constructor",
24
+ "get_pyside6_signal_instance_constructor",
25
+ "ismethod",
26
+ "logging",
27
+ "overload",
28
+ "set_signal_instance_constructor",
29
+ ]
30
+
31
+ class Signal(typing.Generic):
32
+ def __get__(self, instance: typing.Any, owner: typing.Any) -> typing.Any: ...
33
+ def __init__(
34
+ self, *types: type, name: str, arguments: typing.Sequence[str] = tuple()
35
+ ): ...
36
+
37
+ class SignalInstance(typing.Protocol):
38
+ @classmethod
39
+ def __subclasshook__(cls, other): ...
40
+ def __init__(self, *args, **kwargs): ...
41
+ def connect(
42
+ self,
43
+ slot: typing.Callable[[*CallArgs], None] | SignalInstance[*CallArgs,] | None,
44
+ type: PySide6.QtCore.Qt.ConnectionType | None = ...,
45
+ ) -> None: ...
46
+ def disconnect(
47
+ self,
48
+ slot: (
49
+ typing.Callable[[*CallArgs], None] | SignalInstance[*CallArgs,] | None
50
+ ) = None,
51
+ ) -> None: ...
52
+ def emit(self, *args: *CallArgs) -> None: ...
53
+
54
+ class SignalInstanceConstructor(typing.Protocol):
55
+ @classmethod
56
+ def __subclasshook__(cls, other): ...
57
+ def __call__(
58
+ self,
59
+ *,
60
+ types: tuple[type, ...],
61
+ name: str,
62
+ arguments: typing.Sequence[str],
63
+ instance: typing.Any,
64
+ ) -> SignalInstance[*CallArgs,]: ...
65
+ def __init__(self, *args, **kwargs): ...
66
+
67
+ def _get_signal_instances(instance: typing.Any) -> dict[Signal, SignalInstance]: ...
68
+ def create_signal_instance(
69
+ *types: type,
70
+ instance: typing.Any,
71
+ name: str,
72
+ arguments: typing.Sequence[str] = tuple(),
73
+ ) -> SignalInstance[*CallArgs,]:
74
+ """
75
+ Create a new signal instance
76
+ """
77
+
78
+ def get_fallback_signal_instance_constructor() -> SignalInstanceConstructor: ...
79
+ def get_pyside6_signal_instance_constructor() -> SignalInstanceConstructor: ...
80
+ def set_signal_instance_constructor(constructor: SignalInstanceConstructor) -> None: ...
81
+
82
+ CallArgs: typing.TypeVarTuple # value = CallArgs
83
+ SignalInstanceCacheName: str
84
+ _signal_instance_constructor = None
@@ -0,0 +1,235 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Generic, TypeVar, Callable
4
+ from abc import ABC, abstractmethod
5
+
6
+ from .signal import Signal, SignalInstance
7
+
8
+
9
+ T = TypeVar("T")
10
+
11
+
12
+ class TaskCancelled(Exception):
13
+ """Exception to be raised by the callee when a task is cancelled.
14
+
15
+ The callee may define a custom return instead of using this.
16
+ """
17
+
18
+
19
+ class AbstractCancelManager(ABC):
20
+ @abstractmethod
21
+ def cancel(self) -> None:
22
+ """Request the operation be canceled.
23
+
24
+ It is down to the operation to implement support for this.
25
+ """
26
+ raise NotImplementedError
27
+
28
+ @abstractmethod
29
+ def is_cancel_requested(self) -> bool:
30
+ """Has cancel been called to signal that the operation should be canceled."""
31
+ raise NotImplementedError
32
+
33
+ @abstractmethod
34
+ def register_on_cancel(self, callback: Callable[[], None]) -> None:
35
+ """Register a function to get called when :meth:`cancel` is called."""
36
+ raise NotImplementedError
37
+
38
+ @abstractmethod
39
+ def unregister_on_cancel(self, callback: Callable[[], None]) -> None:
40
+ """Unregister a registered function from being called when :meth:`cancel` is called."""
41
+ raise NotImplementedError
42
+
43
+
44
+ class VoidCancelManager(AbstractCancelManager):
45
+ def cancel(self) -> None:
46
+ pass
47
+
48
+ def is_cancel_requested(self) -> bool:
49
+ return False
50
+
51
+ def register_on_cancel(self, callback: Callable[[], None]) -> None:
52
+ pass
53
+
54
+ def unregister_on_cancel(self, callback: Callable[[], None]) -> None:
55
+ pass
56
+
57
+
58
+ class Pointer(Generic[T]):
59
+ value: T
60
+
61
+ def __init__(self, value: T) -> None:
62
+ self.value = value
63
+
64
+
65
+ class _CancelManager(AbstractCancelManager):
66
+ def __init__(
67
+ self,
68
+ cancelled: Pointer[bool],
69
+ cancel_signal: SignalInstance[()],
70
+ ) -> None:
71
+ self._cancelled = cancelled
72
+ self._on_cancel = cancel_signal
73
+
74
+ def cancel(self) -> None:
75
+ self._cancelled.value = True
76
+ self._on_cancel.emit()
77
+
78
+ def is_cancel_requested(self) -> bool:
79
+ return self._cancelled.value
80
+
81
+ def register_on_cancel(self, callback: Callable[[], None]) -> None:
82
+ self._on_cancel.connect(callback)
83
+
84
+ def unregister_on_cancel(self, callback: Callable[[], None]) -> None:
85
+ self._on_cancel.disconnect(callback)
86
+
87
+
88
+ class CancelManager(_CancelManager):
89
+ _cancel_signal = Signal[()]()
90
+
91
+ def __init__(self) -> None:
92
+ super().__init__(
93
+ Pointer[bool](False),
94
+ self._cancel_signal,
95
+ )
96
+
97
+
98
+ class AbstractProgressManager(ABC):
99
+ @abstractmethod
100
+ def update_progress(self, progress: float) -> None:
101
+ """Notify the caller of the updated progress.
102
+
103
+ :param progress: The new progress to relay to the caller. 0.0-1.0
104
+ """
105
+ raise NotImplementedError
106
+
107
+ @abstractmethod
108
+ def update_progress_text(self, text: str) -> None:
109
+ """Notify the caller of the updated progress.
110
+
111
+ :param text: The new message to relay to the caller.
112
+ """
113
+ raise NotImplementedError
114
+
115
+ @abstractmethod
116
+ def get_child(
117
+ self, progress_min: float, progress_max: float
118
+ ) -> AbstractProgressManager:
119
+ """Get a child ExecutionContext.
120
+
121
+ If calling multiple functions, this allows segmenting the reported time.
122
+
123
+ :param progress_min: The minimum progress for the child to use 0.0-1.0
124
+ :param progress_max: The maximum progress for the child to use 0.0-1.0
125
+ :return: A new ExecutionContext
126
+ """
127
+ raise NotImplementedError
128
+
129
+
130
+ class VoidProgressManager(AbstractProgressManager):
131
+ def update_progress(self, progress: float) -> None:
132
+ pass
133
+
134
+ def update_progress_text(self, text: str) -> None:
135
+ pass
136
+
137
+ def get_child(
138
+ self, progress_min: float, progress_max: float
139
+ ) -> VoidProgressManager:
140
+ return self
141
+
142
+
143
+ class _ProgressManager(AbstractProgressManager):
144
+ def __init__(
145
+ self,
146
+ progress_change: SignalInstance[float],
147
+ progress_text_change: SignalInstance[str],
148
+ progress_min: float,
149
+ progress_max: float,
150
+ ) -> None:
151
+ self._progress_change = progress_change
152
+ self._progress_text_change = progress_text_change
153
+ assert 0.0 <= progress_min <= progress_max <= 1.0
154
+ self._progress_min = progress_min
155
+ self._progress_delta = progress_max - progress_min
156
+
157
+ def update_progress(self, progress: float) -> None:
158
+ assert 0.0 <= progress <= 1.0
159
+ self._progress_change.emit(self._progress_min + progress * self._progress_delta)
160
+
161
+ def update_progress_text(self, text: str) -> None:
162
+ self._progress_text_change.emit(text)
163
+
164
+ def get_child(self, progress_min: float, progress_max: float) -> _ProgressManager:
165
+ assert 0.0 <= progress_min <= progress_max <= 1.0
166
+ return _ProgressManager(
167
+ self._progress_change,
168
+ self._progress_text_change,
169
+ self._progress_min + progress_min * self._progress_delta,
170
+ self._progress_min + progress_max * self._progress_delta,
171
+ )
172
+
173
+
174
+ class ProgressManager(_ProgressManager):
175
+ progress_change = Signal[float](float)
176
+ progress_text_change = Signal[str](str)
177
+
178
+ def __init__(self) -> None:
179
+ super().__init__(
180
+ self.progress_change,
181
+ self.progress_text_change,
182
+ 0.0,
183
+ 1.0,
184
+ )
185
+
186
+
187
+ class AbstractTaskManager(AbstractCancelManager, AbstractProgressManager, ABC):
188
+ pass
189
+
190
+
191
+ class VoidTaskManager(VoidCancelManager, VoidProgressManager, AbstractTaskManager):
192
+ """An empty Execution Context that ignores all calls."""
193
+
194
+
195
+ class _TaskManager(CancelManager, ProgressManager, AbstractTaskManager):
196
+ def __init__(
197
+ self,
198
+ cancelled: Pointer[bool],
199
+ cancel_signal: SignalInstance[()],
200
+ progress_change: SignalInstance[float],
201
+ progress_text_change: SignalInstance[str],
202
+ progress_min: float,
203
+ progress_max: float,
204
+ ) -> None:
205
+ _CancelManager.__init__(self, cancelled, cancel_signal)
206
+ _ProgressManager.__init__(
207
+ self,
208
+ progress_change,
209
+ progress_text_change,
210
+ progress_min,
211
+ progress_max,
212
+ )
213
+
214
+ def get_child(self, progress_min: float, progress_max: float) -> _TaskManager:
215
+ assert 0.0 <= progress_min <= progress_max <= 1.0
216
+ return _TaskManager(
217
+ self._cancelled,
218
+ self._on_cancel,
219
+ self._progress_change,
220
+ self._progress_text_change,
221
+ self._progress_min + progress_min * self._progress_delta,
222
+ self._progress_min + progress_max * self._progress_delta,
223
+ )
224
+
225
+
226
+ class TaskManager(_TaskManager):
227
+ def __init__(self) -> None:
228
+ super().__init__(
229
+ Pointer[bool](False),
230
+ self._cancel_signal,
231
+ self.progress_change,
232
+ self.progress_text_change,
233
+ 0.0,
234
+ 1.0,
235
+ )
@@ -0,0 +1,168 @@
1
+ from __future__ import annotations
2
+
3
+ import abc
4
+ import typing
5
+ from abc import ABC, abstractmethod
6
+ from typing import Generic, TypeVar
7
+
8
+ from amulet.utils.signal._signal import Signal, SignalInstance
9
+
10
+ __all__ = [
11
+ "ABC",
12
+ "AbstractCancelManager",
13
+ "AbstractProgressManager",
14
+ "AbstractTaskManager",
15
+ "CancelManager",
16
+ "Generic",
17
+ "Pointer",
18
+ "ProgressManager",
19
+ "Signal",
20
+ "SignalInstance",
21
+ "T",
22
+ "TaskCancelled",
23
+ "TaskManager",
24
+ "TypeVar",
25
+ "VoidCancelManager",
26
+ "VoidProgressManager",
27
+ "VoidTaskManager",
28
+ "abstractmethod",
29
+ ]
30
+
31
+ class AbstractCancelManager(abc.ABC):
32
+ def cancel(self) -> None:
33
+ """
34
+ Request the operation be canceled.
35
+
36
+ It is down to the operation to implement support for this.
37
+
38
+ """
39
+
40
+ def is_cancel_requested(self) -> bool:
41
+ """
42
+ Has cancel been called to signal that the operation should be canceled.
43
+ """
44
+
45
+ def register_on_cancel(self, callback: typing.Callable[[], None]) -> None:
46
+ """
47
+ Register a function to get called when :meth:`cancel` is called.
48
+ """
49
+
50
+ def unregister_on_cancel(self, callback: typing.Callable[[], None]) -> None:
51
+ """
52
+ Unregister a registered function from being called when :meth:`cancel` is called.
53
+ """
54
+
55
+ class AbstractProgressManager(abc.ABC):
56
+ def get_child(
57
+ self, progress_min: float, progress_max: float
58
+ ) -> AbstractProgressManager:
59
+ """
60
+ Get a child ExecutionContext.
61
+
62
+ If calling multiple functions, this allows segmenting the reported time.
63
+
64
+ :param progress_min: The minimum progress for the child to use 0.0-1.0
65
+ :param progress_max: The maximum progress for the child to use 0.0-1.0
66
+ :return: A new ExecutionContext
67
+
68
+ """
69
+
70
+ def update_progress(self, progress: float) -> None:
71
+ """
72
+ Notify the caller of the updated progress.
73
+
74
+ :param progress: The new progress to relay to the caller. 0.0-1.0
75
+
76
+ """
77
+
78
+ def update_progress_text(self, text: str) -> None:
79
+ """
80
+ Notify the caller of the updated progress.
81
+
82
+ :param text: The new message to relay to the caller.
83
+
84
+ """
85
+
86
+ class AbstractTaskManager(AbstractCancelManager, AbstractProgressManager, abc.ABC):
87
+ pass
88
+
89
+ class CancelManager(_CancelManager):
90
+ @staticmethod
91
+ def _cancel_signal(*args, **kwargs): ...
92
+ def __init__(self) -> None: ...
93
+
94
+ class Pointer(typing.Generic):
95
+ def __init__(self, value: T) -> None: ...
96
+
97
+ class ProgressManager(_ProgressManager):
98
+ @staticmethod
99
+ def progress_change(*args, **kwargs): ...
100
+ @staticmethod
101
+ def progress_text_change(*args, **kwargs): ...
102
+ def __init__(self) -> None: ...
103
+
104
+ class TaskCancelled(Exception):
105
+ """
106
+ Exception to be raised by the callee when a task is cancelled.
107
+
108
+ The callee may define a custom return instead of using this.
109
+
110
+ """
111
+
112
+ class TaskManager(_TaskManager):
113
+ def __init__(self) -> None: ...
114
+
115
+ class VoidCancelManager(AbstractCancelManager):
116
+ def cancel(self) -> None: ...
117
+ def is_cancel_requested(self) -> bool: ...
118
+ def register_on_cancel(self, callback: typing.Callable[[], None]) -> None: ...
119
+ def unregister_on_cancel(self, callback: typing.Callable[[], None]) -> None: ...
120
+
121
+ class VoidProgressManager(AbstractProgressManager):
122
+ def get_child(
123
+ self, progress_min: float, progress_max: float
124
+ ) -> VoidProgressManager: ...
125
+ def update_progress(self, progress: float) -> None: ...
126
+ def update_progress_text(self, text: str) -> None: ...
127
+
128
+ class VoidTaskManager(VoidCancelManager, VoidProgressManager, AbstractTaskManager):
129
+ """
130
+ An empty Execution Context that ignores all calls.
131
+ """
132
+
133
+ class _CancelManager(AbstractCancelManager):
134
+ def __init__(
135
+ self, cancelled: Pointer[bool], cancel_signal: SignalInstance[()]
136
+ ) -> None: ...
137
+ def cancel(self) -> None: ...
138
+ def is_cancel_requested(self) -> bool: ...
139
+ def register_on_cancel(self, callback: typing.Callable[[], None]) -> None: ...
140
+ def unregister_on_cancel(self, callback: typing.Callable[[], None]) -> None: ...
141
+
142
+ class _ProgressManager(AbstractProgressManager):
143
+ def __init__(
144
+ self,
145
+ progress_change: SignalInstance[float],
146
+ progress_text_change: SignalInstance[str],
147
+ progress_min: float,
148
+ progress_max: float,
149
+ ) -> None: ...
150
+ def get_child(
151
+ self, progress_min: float, progress_max: float
152
+ ) -> _ProgressManager: ...
153
+ def update_progress(self, progress: float) -> None: ...
154
+ def update_progress_text(self, text: str) -> None: ...
155
+
156
+ class _TaskManager(CancelManager, ProgressManager, AbstractTaskManager):
157
+ def __init__(
158
+ self,
159
+ cancelled: Pointer[bool],
160
+ cancel_signal: SignalInstance[()],
161
+ progress_change: SignalInstance[float],
162
+ progress_text_change: SignalInstance[str],
163
+ progress_min: float,
164
+ progress_max: float,
165
+ ) -> None: ...
166
+ def get_child(self, progress_min: float, progress_max: float) -> _TaskManager: ...
167
+
168
+ T: typing.TypeVar # value = ~T