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