batframework 1.0.8a8__py3-none-any.whl → 1.0.8a10__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.
- batFramework/__init__.py +68 -51
- batFramework/action.py +126 -99
- batFramework/actionContainer.py +53 -9
- batFramework/animatedSprite.py +141 -82
- batFramework/audioManager.py +69 -26
- batFramework/camera.py +259 -69
- batFramework/character.py +27 -0
- batFramework/constants.py +16 -54
- batFramework/cutscene.py +39 -29
- batFramework/cutsceneBlocks.py +36 -43
- batFramework/dynamicEntity.py +18 -9
- batFramework/easingController.py +58 -0
- batFramework/entity.py +48 -97
- batFramework/enums.py +113 -0
- batFramework/fontManager.py +65 -0
- batFramework/gui/__init__.py +10 -2
- batFramework/gui/button.py +9 -78
- batFramework/gui/clickableWidget.py +220 -0
- batFramework/gui/constraints/__init__.py +1 -0
- batFramework/gui/constraints/constraints.py +815 -0
- batFramework/gui/container.py +174 -32
- batFramework/gui/debugger.py +131 -43
- batFramework/gui/dialogueBox.py +99 -0
- batFramework/gui/draggableWidget.py +40 -0
- batFramework/gui/image.py +56 -20
- batFramework/gui/indicator.py +38 -21
- batFramework/gui/interactiveWidget.py +192 -13
- batFramework/gui/label.py +309 -74
- batFramework/gui/layout.py +231 -63
- batFramework/gui/meter.py +74 -0
- batFramework/gui/radioButton.py +84 -0
- batFramework/gui/root.py +134 -38
- batFramework/gui/shape.py +237 -57
- batFramework/gui/slider.py +240 -0
- batFramework/gui/style.py +10 -0
- batFramework/gui/styleManager.py +48 -0
- batFramework/gui/textInput.py +247 -0
- batFramework/gui/toggle.py +101 -51
- batFramework/gui/widget.py +358 -250
- batFramework/manager.py +52 -19
- batFramework/object.py +123 -0
- batFramework/particle.py +115 -0
- batFramework/renderGroup.py +67 -0
- batFramework/resourceManager.py +100 -0
- batFramework/scene.py +281 -123
- batFramework/sceneManager.py +178 -116
- batFramework/scrollingSprite.py +114 -0
- batFramework/sprite.py +51 -0
- batFramework/stateMachine.py +11 -8
- batFramework/templates/__init__.py +2 -0
- batFramework/templates/character.py +44 -0
- batFramework/templates/states.py +166 -0
- batFramework/tileset.py +46 -0
- batFramework/time.py +145 -58
- batFramework/transition.py +195 -124
- batFramework/triggerZone.py +1 -1
- batFramework/utils.py +112 -147
- batframework-1.0.8a10.dist-info/LICENCE +21 -0
- batframework-1.0.8a10.dist-info/METADATA +43 -0
- batframework-1.0.8a10.dist-info/RECORD +62 -0
- batFramework/debugger.py +0 -48
- batFramework/easing.py +0 -71
- batFramework/gui/constraints.py +0 -204
- batFramework/gui/frame.py +0 -19
- batFramework/particles.py +0 -77
- batFramework/transitionManager.py +0 -0
- batframework-1.0.8a8.dist-info/METADATA +0 -53
- batframework-1.0.8a8.dist-info/RECORD +0 -42
- {batframework-1.0.8a8.dist-info → batframework-1.0.8a10.dist-info}/WHEEL +0 -0
- {batframework-1.0.8a8.dist-info → batframework-1.0.8a10.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,815 @@
|
|
1
|
+
from ..widget import Widget
|
2
|
+
import batFramework as bf
|
3
|
+
import pygame
|
4
|
+
|
5
|
+
|
6
|
+
class Constraint:
|
7
|
+
def __init__(self, name:str|None=None, priority=0):
|
8
|
+
self.priority = priority
|
9
|
+
self.name = name if name is not None else self.__class__.__name__
|
10
|
+
|
11
|
+
def on_removal(self,child_widget: Widget)->None:
|
12
|
+
pass
|
13
|
+
|
14
|
+
def set_priority(self, priority) -> "Constraint":
|
15
|
+
self.priority = priority
|
16
|
+
return self
|
17
|
+
|
18
|
+
def __str__(self) -> str:
|
19
|
+
return f"{self.name.upper()}"
|
20
|
+
|
21
|
+
def evaluate(self, parent_widget: Widget, child_widget: Widget) -> bool:
|
22
|
+
raise NotImplementedError("Subclasses must implement evaluate method")
|
23
|
+
|
24
|
+
def apply(self, parent_widget: Widget, child_widget: Widget = None) -> bool:
|
25
|
+
if not self.evaluate(parent_widget, child_widget):
|
26
|
+
self.apply_constraint(parent_widget, child_widget)
|
27
|
+
return False
|
28
|
+
return True
|
29
|
+
|
30
|
+
def apply_constraint(self, parent_widget: Widget, child_widget: Widget):
|
31
|
+
raise NotImplementedError("Subclasses must implement apply_constraint method")
|
32
|
+
|
33
|
+
def __eq__(self,other:"Constraint")->bool:
|
34
|
+
if not isinstance(other,self.__class__):
|
35
|
+
return False
|
36
|
+
return other.name == self.name
|
37
|
+
|
38
|
+
class MinWidth(Constraint):
|
39
|
+
def __init__(self, width: float):
|
40
|
+
super().__init__()
|
41
|
+
self.min_width = width
|
42
|
+
|
43
|
+
def on_removal(self, child_widget: Widget) -> None:
|
44
|
+
child_widget.set_autoresize_w(False)
|
45
|
+
|
46
|
+
def evaluate(self, parent_widget, child_widget):
|
47
|
+
res = child_widget.rect.width >= self.min_width
|
48
|
+
if not res:
|
49
|
+
child_widget.set_autoresize_w(False)
|
50
|
+
return res
|
51
|
+
|
52
|
+
def apply_constraint(self, parent_widget, child_widget):
|
53
|
+
child_widget.set_autoresize_w(True)
|
54
|
+
child_widget.set_size((self.min_width, None))
|
55
|
+
|
56
|
+
def __eq__(self,other:"Constraint")->bool:
|
57
|
+
if not isinstance(other,self.__class__):
|
58
|
+
return False
|
59
|
+
return (
|
60
|
+
other.name == self.name and
|
61
|
+
other.min_width == self.min_width
|
62
|
+
)
|
63
|
+
|
64
|
+
class MinHeight(Constraint):
|
65
|
+
def __init__(self, height: float):
|
66
|
+
super().__init__()
|
67
|
+
self.min_height = height
|
68
|
+
|
69
|
+
def on_removal(self, child_widget: Widget) -> None:
|
70
|
+
child_widget.set_autoresize_h(False)
|
71
|
+
|
72
|
+
def evaluate(self, parent_widget, child_widget):
|
73
|
+
res = child_widget.rect.h >= self.min_height
|
74
|
+
if not res:
|
75
|
+
child_widget.set_autoresize_w(False)
|
76
|
+
return res
|
77
|
+
|
78
|
+
def apply_constraint(self, parent_widget, child_widget):
|
79
|
+
child_widget.set_size((None, self.min_height))
|
80
|
+
|
81
|
+
def __eq__(self,other:"Constraint")->bool:
|
82
|
+
if not isinstance(other,self.__class__):
|
83
|
+
return False
|
84
|
+
return (
|
85
|
+
other.name == self.name and
|
86
|
+
other.min_height == self.min_height
|
87
|
+
)
|
88
|
+
|
89
|
+
class MaxWidth(Constraint):
|
90
|
+
def __init__(self, width: float):
|
91
|
+
super().__init__()
|
92
|
+
self.max_width = width
|
93
|
+
|
94
|
+
def on_removal(self, child_widget: Widget) -> None:
|
95
|
+
child_widget.set_autoresize_w(False)
|
96
|
+
|
97
|
+
def evaluate(self, parent_widget, child_widget):
|
98
|
+
res = child_widget.rect.width <= self.max_width
|
99
|
+
if not res:
|
100
|
+
child_widget.set_autoresize_w(False)
|
101
|
+
return res
|
102
|
+
|
103
|
+
def apply_constraint(self, parent_widget, child_widget):
|
104
|
+
child_widget.set_autoresize_w(True)
|
105
|
+
current_height = child_widget.rect.height
|
106
|
+
child_widget.set_size((self.max_width, current_height))
|
107
|
+
|
108
|
+
def __eq__(self, other: "Constraint") -> bool:
|
109
|
+
if not isinstance(other, self.__class__):
|
110
|
+
return False
|
111
|
+
return other.max_width == self.max_width
|
112
|
+
|
113
|
+
|
114
|
+
class MaxHeight(Constraint):
|
115
|
+
def __init__(self, height: float):
|
116
|
+
super().__init__()
|
117
|
+
self.max_height = height
|
118
|
+
|
119
|
+
def on_removal(self, child_widget: Widget) -> None:
|
120
|
+
child_widget.set_autoresize_h(False)
|
121
|
+
|
122
|
+
def evaluate(self, parent_widget, child_widget):
|
123
|
+
res = child_widget.rect.height <= self.max_height
|
124
|
+
if not res:
|
125
|
+
child_widget.set_autoresize_h(False)
|
126
|
+
return res
|
127
|
+
|
128
|
+
def apply_constraint(self, parent_widget, child_widget):
|
129
|
+
child_widget.set_autoresize_h(True)
|
130
|
+
current_width = child_widget.rect.width
|
131
|
+
child_widget.set_size((current_width, self.max_height))
|
132
|
+
|
133
|
+
def __eq__(self, other: "Constraint") -> bool:
|
134
|
+
if not isinstance(other, self.__class__):
|
135
|
+
return False
|
136
|
+
return other.max_height == self.max_height
|
137
|
+
|
138
|
+
|
139
|
+
|
140
|
+
class CenterX(Constraint):
|
141
|
+
def __init__(self):
|
142
|
+
super().__init__()
|
143
|
+
|
144
|
+
def evaluate(self, parent_widget, child_widget):
|
145
|
+
return (
|
146
|
+
int(child_widget.rect.centerx - parent_widget.get_padded_center()[0]) == 0
|
147
|
+
)
|
148
|
+
|
149
|
+
def apply_constraint(self, parent_widget, child_widget):
|
150
|
+
child_widget.set_center(
|
151
|
+
parent_widget.get_padded_center()[0], child_widget.rect.centery
|
152
|
+
)
|
153
|
+
|
154
|
+
|
155
|
+
class CenterY(Constraint):
|
156
|
+
def __init__(self):
|
157
|
+
super().__init__()
|
158
|
+
|
159
|
+
def evaluate(self, parent_widget, child_widget):
|
160
|
+
return (
|
161
|
+
int(child_widget.rect.centery - parent_widget.get_padded_center()[1]) == 0
|
162
|
+
)
|
163
|
+
|
164
|
+
def apply_constraint(self, parent_widget, child_widget):
|
165
|
+
child_widget.set_center(
|
166
|
+
child_widget.rect.centerx, parent_widget.get_padded_center()[1]
|
167
|
+
)
|
168
|
+
|
169
|
+
|
170
|
+
class Center(Constraint):
|
171
|
+
def __init__(self):
|
172
|
+
super().__init__()
|
173
|
+
|
174
|
+
def evaluate(self, parent_widget, child_widget):
|
175
|
+
return (
|
176
|
+
int(child_widget.rect.centerx - parent_widget.get_padded_center()[0]) == 0
|
177
|
+
and int(child_widget.rect.centery - parent_widget.get_padded_center()[1])
|
178
|
+
== 0
|
179
|
+
)
|
180
|
+
|
181
|
+
def apply_constraint(self, parent_widget, child_widget):
|
182
|
+
child_widget.set_center(*parent_widget.get_padded_center())
|
183
|
+
|
184
|
+
|
185
|
+
class PercentageWidth(Constraint):
|
186
|
+
def __init__(self, percentage: float, keep_autoresize: bool = False):
|
187
|
+
super().__init__()
|
188
|
+
self.percentage: float = percentage
|
189
|
+
self.keep_autoresize: bool = keep_autoresize
|
190
|
+
|
191
|
+
def on_removal(self, child_widget: Widget) -> None:
|
192
|
+
child_widget.set_autoresize_w(True)
|
193
|
+
|
194
|
+
def __str__(self) -> str:
|
195
|
+
return f"{super().__str__()}.[{self.percentage*100}%,keep_autoresize={self.keep_autoresize}]"
|
196
|
+
|
197
|
+
def evaluate(self, parent_widget, child_widget):
|
198
|
+
return child_widget.rect.width == round(
|
199
|
+
parent_widget.get_padded_width() * self.percentage
|
200
|
+
)
|
201
|
+
|
202
|
+
def apply_constraint(self, parent_widget, child_widget):
|
203
|
+
if child_widget.autoresize_w:
|
204
|
+
if self.keep_autoresize:
|
205
|
+
print(
|
206
|
+
f"WARNING: Constraint on {child_widget.__str__()} can't resize, autoresize set to True"
|
207
|
+
)
|
208
|
+
return
|
209
|
+
child_widget.set_autoresize_w(False)
|
210
|
+
|
211
|
+
child_widget.set_size(
|
212
|
+
(round(parent_widget.get_padded_width() * self.percentage), None)
|
213
|
+
)
|
214
|
+
|
215
|
+
def __eq__(self,other:"Constraint")->bool:
|
216
|
+
if not isinstance(other,self.__class__):
|
217
|
+
return False
|
218
|
+
return (
|
219
|
+
other.name == self.name and
|
220
|
+
other.percentage == self.percentage
|
221
|
+
)
|
222
|
+
|
223
|
+
|
224
|
+
class PercentageHeight(Constraint):
|
225
|
+
def __init__(self, percentage: float, keep_autoresize: bool = False):
|
226
|
+
super().__init__()
|
227
|
+
self.percentage: float = percentage
|
228
|
+
self.keep_autoresize: bool = keep_autoresize
|
229
|
+
|
230
|
+
def on_removal(self, child_widget: Widget) -> None:
|
231
|
+
child_widget.set_autoresize_h(True)
|
232
|
+
|
233
|
+
def evaluate(self, parent_widget, child_widget):
|
234
|
+
return child_widget.rect.height == round(
|
235
|
+
parent_widget.get_padded_height() * self.percentage
|
236
|
+
)
|
237
|
+
|
238
|
+
def __str__(self) -> str:
|
239
|
+
return f"{super().__str__()}.[{self.percentage*100}%,keep_autoresize={self.keep_autoresize}]"
|
240
|
+
|
241
|
+
def apply_constraint(self, parent_widget, child_widget):
|
242
|
+
if child_widget.autoresize_h:
|
243
|
+
if self.keep_autoresize:
|
244
|
+
print(
|
245
|
+
f"WARNING: Constraint on {child_widget} can't resize, autoresize set to True"
|
246
|
+
)
|
247
|
+
return
|
248
|
+
child_widget.set_autoresize_h(False)
|
249
|
+
child_widget.set_size(
|
250
|
+
(None, round(parent_widget.get_padded_height() * self.percentage))
|
251
|
+
)
|
252
|
+
|
253
|
+
def __eq__(self,other:"Constraint")->bool:
|
254
|
+
if not isinstance(other,self.__class__):
|
255
|
+
return False
|
256
|
+
return (
|
257
|
+
other.name == self.name and
|
258
|
+
other.percentage == self.percentage
|
259
|
+
)
|
260
|
+
|
261
|
+
class FillX(PercentageWidth):
|
262
|
+
def __init__(self, keep_autoresize: bool = False):
|
263
|
+
super().__init__(1, keep_autoresize)
|
264
|
+
self.name = "FillX"
|
265
|
+
|
266
|
+
def __eq__(self, other: Constraint) -> bool:
|
267
|
+
return Constraint.__eq__(self,other)
|
268
|
+
|
269
|
+
class FillY(PercentageHeight):
|
270
|
+
def __init__(self, keep_autoresize: bool = False):
|
271
|
+
super().__init__(1, keep_autoresize)
|
272
|
+
self.name = "FillY"
|
273
|
+
|
274
|
+
def __eq__(self, other: Constraint) -> bool:
|
275
|
+
return Constraint.__eq__(self,other)
|
276
|
+
|
277
|
+
|
278
|
+
class PercentageRectHeight(Constraint):
|
279
|
+
def __init__(self, percentage: float, keep_autoresize: bool = False):
|
280
|
+
super().__init__()
|
281
|
+
self.percentage: float = percentage
|
282
|
+
self.keep_autoresize: bool = keep_autoresize
|
283
|
+
|
284
|
+
def on_removal(self, child_widget: Widget) -> None:
|
285
|
+
child_widget.set_autoresize_h(True)
|
286
|
+
|
287
|
+
def evaluate(self, parent_widget, child_widget):
|
288
|
+
return child_widget.rect.height == round(
|
289
|
+
parent_widget.rect.height * self.percentage
|
290
|
+
)
|
291
|
+
|
292
|
+
def __str__(self) -> str:
|
293
|
+
return f"{super().__str__()}.[{self.percentage*100}%, keep_autoresize={self.keep_autoresize}]"
|
294
|
+
|
295
|
+
def apply_constraint(self, parent_widget, child_widget):
|
296
|
+
if child_widget.autoresize_h:
|
297
|
+
if self.keep_autoresize:
|
298
|
+
print(
|
299
|
+
f"WARNING: Constraint on {child_widget} can't resize, autoresize set to True"
|
300
|
+
)
|
301
|
+
return
|
302
|
+
child_widget.set_autoresize_h(False)
|
303
|
+
child_widget.set_size(
|
304
|
+
(None, round(parent_widget.rect.height * self.percentage))
|
305
|
+
)
|
306
|
+
|
307
|
+
def __eq__(self,other:"Constraint")->bool:
|
308
|
+
if not isinstance(other,self.__class__):
|
309
|
+
return False
|
310
|
+
return (
|
311
|
+
other.name == self.name and
|
312
|
+
other.percentage == self.percentage
|
313
|
+
)
|
314
|
+
|
315
|
+
class PercentageRectWidth(Constraint):
|
316
|
+
def __init__(self, percentage: float, keep_autoresize: bool = False):
|
317
|
+
super().__init__()
|
318
|
+
self.percentage: float = percentage
|
319
|
+
self.keep_autoresize: bool = keep_autoresize
|
320
|
+
|
321
|
+
def on_removal(self, child_widget: Widget) -> None:
|
322
|
+
child_widget.set_autoresize_w(True)
|
323
|
+
|
324
|
+
def evaluate(self, parent_widget, child_widget):
|
325
|
+
return child_widget.rect.width == round(
|
326
|
+
parent_widget.rect.width * self.percentage
|
327
|
+
)
|
328
|
+
|
329
|
+
def __str__(self) -> str:
|
330
|
+
return f"{super().__str__()}.[{self.percentage*100}%, keep_autoresize={self.keep_autoresize}]"
|
331
|
+
|
332
|
+
def apply_constraint(self, parent_widget, child_widget):
|
333
|
+
if child_widget.autoresize_w:
|
334
|
+
if self.keep_autoresize:
|
335
|
+
print(
|
336
|
+
f"WARNING: Constraint on {child_widget} can't resize, autoresize set to True"
|
337
|
+
)
|
338
|
+
return
|
339
|
+
child_widget.set_autoresize_w(False)
|
340
|
+
child_widget.set_size((round(parent_widget.rect.width * self.percentage), None))
|
341
|
+
|
342
|
+
def __eq__(self,other:"Constraint")->bool:
|
343
|
+
if not isinstance(other,self.__class__):
|
344
|
+
return False
|
345
|
+
return (
|
346
|
+
other.name == self.name and
|
347
|
+
other.percentage == self.percentage
|
348
|
+
)
|
349
|
+
|
350
|
+
class FillRectX(PercentageRectWidth):
|
351
|
+
def __init__(self, keep_autoresize: bool = False):
|
352
|
+
super().__init__(1, keep_autoresize)
|
353
|
+
self.name = "fill_rect_x"
|
354
|
+
|
355
|
+
|
356
|
+
class FillRectY(PercentageRectHeight):
|
357
|
+
def __init__(self, keep_autoresize: bool = False):
|
358
|
+
super().__init__(1, keep_autoresize)
|
359
|
+
self.name = "fill_rect_y"
|
360
|
+
|
361
|
+
|
362
|
+
class AspectRatio(Constraint):
|
363
|
+
def __init__(
|
364
|
+
self,
|
365
|
+
ratio: int | float | pygame.rect.FRectType = 1,
|
366
|
+
reference_axis: bf.axis = bf.axis.HORIZONTAL,
|
367
|
+
keep_autoresize=False,
|
368
|
+
):
|
369
|
+
super().__init__()
|
370
|
+
self.ref_axis: bf.axis = reference_axis
|
371
|
+
self.keep_autoresize: bool = keep_autoresize
|
372
|
+
|
373
|
+
if isinstance(ratio, float | int):
|
374
|
+
self.ratio = ratio
|
375
|
+
elif isinstance(ratio, pygame.rect.FRect):
|
376
|
+
self.ratio = (
|
377
|
+
(ratio.w / ratio.h)
|
378
|
+
if reference_axis == bf.axis.HORIZONTAL
|
379
|
+
else (ratio.h / ratio.w)
|
380
|
+
)
|
381
|
+
else:
|
382
|
+
raise TypeError(f"Ratio must be float or FRect")
|
383
|
+
|
384
|
+
def on_removal(self, child_widget: Widget) -> None:
|
385
|
+
child_widget.set_autoresize(True)
|
386
|
+
|
387
|
+
|
388
|
+
def evaluate(self, parent_widget, child_widget):
|
389
|
+
if self.ref_axis == bf.axis.HORIZONTAL:
|
390
|
+
return self.ratio == child_widget.rect.h / child_widget.rect.w
|
391
|
+
if self.ref_axis == bf.axis.VERTICAL:
|
392
|
+
return self.ratio == child_widget.rect.w / child_widget.rect.h
|
393
|
+
|
394
|
+
|
395
|
+
def apply_constraint(self, parent_widget, child_widget):
|
396
|
+
|
397
|
+
if self.ref_axis == bf.axis.VERTICAL:
|
398
|
+
if child_widget.autoresize_w:
|
399
|
+
if self.keep_autoresize:
|
400
|
+
print(
|
401
|
+
f"WARNING: Constraint on {str(child_widget)} can't resize, autoresize set to True"
|
402
|
+
)
|
403
|
+
return
|
404
|
+
child_widget.set_autoresize_w(False)
|
405
|
+
child_widget.set_size((child_widget.rect.h * self.ratio, None))
|
406
|
+
|
407
|
+
if self.ref_axis == bf.axis.HORIZONTAL:
|
408
|
+
if child_widget.autoresize_h:
|
409
|
+
if self.keep_autoresize:
|
410
|
+
print(
|
411
|
+
f"WARNING: Constraint on {str(child_widget)} can't resize, autoresize set to True"
|
412
|
+
)
|
413
|
+
return
|
414
|
+
child_widget.set_autoresize_h(False)
|
415
|
+
|
416
|
+
child_widget.set_size((None, child_widget.rect.w * self.ratio))
|
417
|
+
|
418
|
+
def __eq__(self,other:"Constraint")->bool:
|
419
|
+
if not isinstance(other,self.__class__):
|
420
|
+
return False
|
421
|
+
return (
|
422
|
+
other.name == self.name and
|
423
|
+
other.ratio == self.ratio and
|
424
|
+
other.ref_axis == self.ref_axis
|
425
|
+
)
|
426
|
+
|
427
|
+
class AnchorBottom(Constraint):
|
428
|
+
def __init__(self):
|
429
|
+
super().__init__()
|
430
|
+
|
431
|
+
def evaluate(self, parent_widget, child_widget):
|
432
|
+
return (
|
433
|
+
child_widget.rect.bottom
|
434
|
+
== parent_widget.get_padded_bottom()
|
435
|
+
)
|
436
|
+
|
437
|
+
def apply_constraint(self, parent_widget, child_widget):
|
438
|
+
child_widget.set_position(
|
439
|
+
child_widget.rect.x, parent_widget.get_padded_bottom() - child_widget.rect.h
|
440
|
+
)
|
441
|
+
|
442
|
+
class AnchorTop(Constraint):
|
443
|
+
def __init__(self):
|
444
|
+
super().__init__()
|
445
|
+
|
446
|
+
def evaluate(self, parent_widget, child_widget):
|
447
|
+
return (child_widget.rect.top == parent_widget.get_padded_top())
|
448
|
+
|
449
|
+
def apply_constraint(self, parent_widget, child_widget):
|
450
|
+
child_widget.set_position(child_widget.rect.x, parent_widget.get_padded_top())
|
451
|
+
|
452
|
+
|
453
|
+
class AnchorTopRight(Constraint):
|
454
|
+
def __init__(self):
|
455
|
+
super().__init__()
|
456
|
+
|
457
|
+
def evaluate(self, parent_widget, child_widget):
|
458
|
+
return child_widget.rect.topright == parent_widget.get_padded_rect().topright
|
459
|
+
|
460
|
+
def apply_constraint(self, parent_widget, child_widget):
|
461
|
+
# print("before",child_widget.rect.topright, parent_widget.get_padded_rect().topright)
|
462
|
+
topright = parent_widget.get_padded_rect().topright
|
463
|
+
child_widget.set_position(topright[0] - child_widget.rect.w,topright[1])
|
464
|
+
# print("after",child_widget.rect.topright, parent_widget.get_padded_rect().topright)
|
465
|
+
|
466
|
+
|
467
|
+
class AnchorBottomRight(Constraint):
|
468
|
+
def __init__(self):
|
469
|
+
super().__init__()
|
470
|
+
|
471
|
+
def evaluate(self, parent_widget, child_widget):
|
472
|
+
return (
|
473
|
+
child_widget.rect.bottomright == parent_widget.get_padded_rect().bottomright
|
474
|
+
)
|
475
|
+
|
476
|
+
def apply_constraint(self, parent_widget, child_widget):
|
477
|
+
bottomright = parent_widget.get_padded_rect().bottomright
|
478
|
+
|
479
|
+
child_widget.set_position(
|
480
|
+
bottomright[0] - child_widget.rect.w,
|
481
|
+
bottomright[1] - child_widget.rect.h,
|
482
|
+
)
|
483
|
+
|
484
|
+
|
485
|
+
class AnchorRight(Constraint):
|
486
|
+
def __init__(self):
|
487
|
+
super().__init__()
|
488
|
+
|
489
|
+
def evaluate(self, parent_widget, child_widget):
|
490
|
+
return child_widget.rect.right == parent_widget.get_padded_right()
|
491
|
+
|
492
|
+
def apply_constraint(self, parent_widget, child_widget):
|
493
|
+
child_widget.set_position(
|
494
|
+
parent_widget.get_padded_right() - child_widget.rect.w,
|
495
|
+
child_widget.rect.top,
|
496
|
+
)
|
497
|
+
|
498
|
+
|
499
|
+
class AnchorLeft(Constraint):
|
500
|
+
def __init__(self):
|
501
|
+
super().__init__()
|
502
|
+
|
503
|
+
def evaluate(self, parent_widget, child_widget):
|
504
|
+
return child_widget.rect.left == parent_widget.get_padded_left()
|
505
|
+
|
506
|
+
def apply_constraint(self, parent_widget, child_widget):
|
507
|
+
child_widget.set_position(
|
508
|
+
parent_widget.get_padded_left(), child_widget.rect.top
|
509
|
+
)
|
510
|
+
|
511
|
+
|
512
|
+
class MarginBottom(Constraint):
|
513
|
+
def __init__(self, margin: float):
|
514
|
+
super().__init__()
|
515
|
+
self.margin = margin
|
516
|
+
|
517
|
+
def evaluate(self, parent_widget, child_widget):
|
518
|
+
return (
|
519
|
+
child_widget.rect.bottom == parent_widget.get_padded_bottom() - self.margin
|
520
|
+
)
|
521
|
+
|
522
|
+
def apply_constraint(self, parent_widget, child_widget):
|
523
|
+
child_widget.set_position(
|
524
|
+
child_widget.rect.x,
|
525
|
+
parent_widget.get_padded_bottom() - child_widget.rect.h - self.margin,
|
526
|
+
)
|
527
|
+
|
528
|
+
def __eq__(self,other:"Constraint")->bool:
|
529
|
+
if not isinstance(other,self.__class__):
|
530
|
+
return False
|
531
|
+
return (
|
532
|
+
other.name == self.name and
|
533
|
+
other.margin == self.margin
|
534
|
+
)
|
535
|
+
|
536
|
+
class MarginTop(Constraint):
|
537
|
+
def __init__(self, margin: float):
|
538
|
+
super().__init__()
|
539
|
+
self.margin = margin
|
540
|
+
|
541
|
+
def evaluate(self, parent_widget, child_widget):
|
542
|
+
return child_widget.rect.top == parent_widget.get_padded_top() + self.margin
|
543
|
+
|
544
|
+
def apply_constraint(self, parent_widget, child_widget):
|
545
|
+
child_widget.set_position(
|
546
|
+
child_widget.rect.x, parent_widget.get_padded_top() + self.margin
|
547
|
+
)
|
548
|
+
|
549
|
+
def __eq__(self,other:"Constraint")->bool:
|
550
|
+
if not isinstance(other,self.__class__):
|
551
|
+
return False
|
552
|
+
return (
|
553
|
+
other.name == self.name and
|
554
|
+
other.margin == self.margin
|
555
|
+
)
|
556
|
+
|
557
|
+
class MarginLeft(Constraint):
|
558
|
+
def __init__(self, margin: float):
|
559
|
+
super().__init__()
|
560
|
+
self.margin = margin
|
561
|
+
|
562
|
+
def evaluate(self, parent_widget, child_widget):
|
563
|
+
return child_widget.rect.left == parent_widget.get_padded_left() + self.margin
|
564
|
+
|
565
|
+
def apply_constraint(self, parent_widget, child_widget):
|
566
|
+
if not self.evaluate(parent_widget, child_widget):
|
567
|
+
child_widget.set_position(
|
568
|
+
parent_widget.get_padded_left() + self.margin, child_widget.rect.y
|
569
|
+
)
|
570
|
+
|
571
|
+
def __eq__(self,other:"Constraint")->bool:
|
572
|
+
if not isinstance(other,self.__class__):
|
573
|
+
return False
|
574
|
+
return (
|
575
|
+
other.name == self.name and
|
576
|
+
other.margin == self.margin
|
577
|
+
)
|
578
|
+
|
579
|
+
class MarginRight(Constraint):
|
580
|
+
def __init__(self, margin: float):
|
581
|
+
super().__init__()
|
582
|
+
self.margin = margin
|
583
|
+
|
584
|
+
def evaluate(self, parent_widget, child_widget):
|
585
|
+
return child_widget.rect.right == parent_widget.get_padded_right() - self.margin
|
586
|
+
|
587
|
+
def apply_constraint(self, parent_widget, child_widget):
|
588
|
+
child_widget.set_position(
|
589
|
+
parent_widget.get_padded_right() - child_widget.rect.w - self.margin,
|
590
|
+
child_widget.rect.y,
|
591
|
+
)
|
592
|
+
|
593
|
+
def __eq__(self,other:"Constraint")->bool:
|
594
|
+
if not isinstance(other,self.__class__):
|
595
|
+
return False
|
596
|
+
return (
|
597
|
+
other.name == self.name and
|
598
|
+
other.margin == self.margin
|
599
|
+
)
|
600
|
+
|
601
|
+
class PercentageMarginBottom(Constraint):
|
602
|
+
def __init__(self, margin: float):
|
603
|
+
super().__init__()
|
604
|
+
self.margin = margin
|
605
|
+
|
606
|
+
def evaluate(self, parent_widget, child_widget):
|
607
|
+
return (
|
608
|
+
child_widget.rect.bottom
|
609
|
+
== parent_widget.get_padded_top()
|
610
|
+
+ parent_widget.get_padded_height() * self.margin
|
611
|
+
)
|
612
|
+
|
613
|
+
def apply_constraint(self, parent_widget, child_widget):
|
614
|
+
child_widget.set_position(
|
615
|
+
child_widget.rect.x,
|
616
|
+
parent_widget.get_padded_bottom()
|
617
|
+
- child_widget.rect.h
|
618
|
+
- parent_widget.get_padded_height() * self.margin,
|
619
|
+
)
|
620
|
+
|
621
|
+
def __eq__(self,other:"Constraint")->bool:
|
622
|
+
if not isinstance(other,self.__class__):
|
623
|
+
return False
|
624
|
+
return (
|
625
|
+
other.name == self.name and
|
626
|
+
other.margin == self.margin
|
627
|
+
)
|
628
|
+
|
629
|
+
class PercentageMarginTop(Constraint):
|
630
|
+
def __init__(self, margin: float):
|
631
|
+
super().__init__()
|
632
|
+
self.margin = margin
|
633
|
+
|
634
|
+
def evaluate(self, parent_widget, child_widget):
|
635
|
+
return (
|
636
|
+
child_widget.rect.top
|
637
|
+
== parent_widget.get_padded_top()
|
638
|
+
+ parent_widget.get_padded_height() * self.margin
|
639
|
+
)
|
640
|
+
|
641
|
+
def apply_constraint(self, parent_widget, child_widget):
|
642
|
+
child_widget.set_position(
|
643
|
+
child_widget.rect.x,
|
644
|
+
parent_widget.get_padded_top()
|
645
|
+
+ parent_widget.get_padded_height() * self.margin,
|
646
|
+
)
|
647
|
+
|
648
|
+
def __eq__(self,other:"Constraint")->bool:
|
649
|
+
if not isinstance(other,self.__class__):
|
650
|
+
return False
|
651
|
+
return (
|
652
|
+
other.name == self.name and
|
653
|
+
other.margin == self.margin
|
654
|
+
)
|
655
|
+
|
656
|
+
class PercentageMarginLeft(Constraint):
|
657
|
+
def __init__(self, margin: float):
|
658
|
+
super().__init__()
|
659
|
+
self.margin = margin
|
660
|
+
|
661
|
+
def evaluate(self, parent_widget, child_widget):
|
662
|
+
return (
|
663
|
+
child_widget.rect.left
|
664
|
+
== parent_widget.get_padded_left()
|
665
|
+
+ parent_widget.get_padded_width() * self.margin
|
666
|
+
)
|
667
|
+
|
668
|
+
def apply_constraint(self, parent_widget, child_widget):
|
669
|
+
if not self.evaluate(parent_widget, child_widget):
|
670
|
+
child_widget.set_position(
|
671
|
+
parent_widget.get_padded_left()
|
672
|
+
+ parent_widget.get_padded_width() * self.margin,
|
673
|
+
child_widget.rect.y,
|
674
|
+
)
|
675
|
+
|
676
|
+
def __eq__(self,other:"Constraint")->bool:
|
677
|
+
if not isinstance(other,self.__class__):
|
678
|
+
return False
|
679
|
+
return (
|
680
|
+
other.name == self.name and
|
681
|
+
other.margin == self.margin
|
682
|
+
)
|
683
|
+
|
684
|
+
class PercentageMarginRight(Constraint):
|
685
|
+
def __init__(self, margin: float):
|
686
|
+
super().__init__()
|
687
|
+
self.margin = margin
|
688
|
+
|
689
|
+
def evaluate(self, parent_widget, child_widget):
|
690
|
+
return (
|
691
|
+
child_widget.rect.right
|
692
|
+
== parent_widget.get_padded_right()
|
693
|
+
- parent_widget.get_padded_width() * self.margin
|
694
|
+
)
|
695
|
+
|
696
|
+
def apply_constraint(self, parent_widget, child_widget):
|
697
|
+
child_widget.set_position(
|
698
|
+
parent_widget.get_padded_right()
|
699
|
+
- child_widget.rect.w
|
700
|
+
- parent_widget.get_padded_width() * self.margin,
|
701
|
+
child_widget.rect.y,
|
702
|
+
)
|
703
|
+
|
704
|
+
def __eq__(self,other:"Constraint")->bool:
|
705
|
+
if not isinstance(other,self.__class__):
|
706
|
+
return False
|
707
|
+
return (
|
708
|
+
other.name == self.name and
|
709
|
+
other.margin == self.margin
|
710
|
+
)
|
711
|
+
|
712
|
+
class PercentageRectMarginBottom(Constraint):
|
713
|
+
def __init__(self, margin: float):
|
714
|
+
super().__init__()
|
715
|
+
self.margin = margin
|
716
|
+
|
717
|
+
def evaluate(self, parent_widget, child_widget):
|
718
|
+
return (
|
719
|
+
child_widget.rect.bottom
|
720
|
+
== parent_widget.rect.top + parent_widget.rect.height * self.margin
|
721
|
+
)
|
722
|
+
|
723
|
+
def apply_constraint(self, parent_widget, child_widget):
|
724
|
+
child_widget.set_position(
|
725
|
+
child_widget.rect.x,
|
726
|
+
parent_widget.rect.bottom
|
727
|
+
- child_widget.rect.height
|
728
|
+
- parent_widget.rect.height * self.margin,
|
729
|
+
)
|
730
|
+
|
731
|
+
def __eq__(self,other:"Constraint")->bool:
|
732
|
+
if not isinstance(other,self.__class__):
|
733
|
+
return False
|
734
|
+
return (
|
735
|
+
other.name == self.name and
|
736
|
+
other.margin == self.margin
|
737
|
+
)
|
738
|
+
|
739
|
+
class PercentageRectMarginTop(Constraint):
|
740
|
+
def __init__(self, margin: float):
|
741
|
+
super().__init__()
|
742
|
+
self.margin = margin
|
743
|
+
|
744
|
+
def evaluate(self, parent_widget, child_widget):
|
745
|
+
return (
|
746
|
+
child_widget.rect.top
|
747
|
+
== parent_widget.rect.top + parent_widget.rect.height * self.margin
|
748
|
+
)
|
749
|
+
|
750
|
+
def apply_constraint(self, parent_widget, child_widget):
|
751
|
+
child_widget.set_position(
|
752
|
+
child_widget.rect.x,
|
753
|
+
parent_widget.rect.top + parent_widget.rect.height * self.margin,
|
754
|
+
)
|
755
|
+
|
756
|
+
def __eq__(self,other:"Constraint")->bool:
|
757
|
+
if not isinstance(other,self.__class__):
|
758
|
+
return False
|
759
|
+
return (
|
760
|
+
other.name == self.name and
|
761
|
+
other.margin == self.margin
|
762
|
+
)
|
763
|
+
|
764
|
+
class PercentageRectMarginLeft(Constraint):
|
765
|
+
def __init__(self, margin: float):
|
766
|
+
super().__init__()
|
767
|
+
self.margin = margin
|
768
|
+
|
769
|
+
def evaluate(self, parent_widget, child_widget):
|
770
|
+
return (
|
771
|
+
child_widget.rect.left
|
772
|
+
== parent_widget.rect.left + parent_widget.rect.width * self.margin
|
773
|
+
)
|
774
|
+
|
775
|
+
def apply_constraint(self, parent_widget, child_widget):
|
776
|
+
if not self.evaluate(parent_widget, child_widget):
|
777
|
+
child_widget.set_position(
|
778
|
+
parent_widget.rect.left + parent_widget.rect.width * self.margin,
|
779
|
+
child_widget.rect.y,
|
780
|
+
)
|
781
|
+
|
782
|
+
def __eq__(self,other:"Constraint")->bool:
|
783
|
+
if not isinstance(other,self.__class__):
|
784
|
+
return False
|
785
|
+
return (
|
786
|
+
other.name == self.name and
|
787
|
+
other.margin == self.margin
|
788
|
+
)
|
789
|
+
|
790
|
+
class PercentageRectMarginRight(Constraint):
|
791
|
+
def __init__(self, margin: float):
|
792
|
+
super().__init__()
|
793
|
+
self.margin = margin
|
794
|
+
|
795
|
+
def evaluate(self, parent_widget, child_widget):
|
796
|
+
return (
|
797
|
+
child_widget.rect.right
|
798
|
+
== parent_widget.rect.right - parent_widget.rect.width * self.margin
|
799
|
+
)
|
800
|
+
|
801
|
+
def apply_constraint(self, parent_widget, child_widget):
|
802
|
+
child_widget.set_position(
|
803
|
+
parent_widget.rect.right
|
804
|
+
- child_widget.rect.width
|
805
|
+
- parent_widget.rect.width * self.margin,
|
806
|
+
child_widget.rect.y,
|
807
|
+
)
|
808
|
+
|
809
|
+
def __eq__(self,other:"Constraint")->bool:
|
810
|
+
if not isinstance(other,self.__class__):
|
811
|
+
return False
|
812
|
+
return (
|
813
|
+
other.name == self.name and
|
814
|
+
other.margin == self.margin
|
815
|
+
)
|