batframework 1.0.8a3__py3-none-any.whl → 1.0.8a6__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 (44) hide show
  1. batFramework/__init__.py +16 -2
  2. batFramework/animatedSprite.py +94 -85
  3. batFramework/audioManager.py +2 -2
  4. batFramework/character.py +27 -0
  5. batFramework/cutscene.py +5 -2
  6. batFramework/cutsceneBlocks.py +3 -5
  7. batFramework/dynamicEntity.py +11 -4
  8. batFramework/enums.py +2 -2
  9. batFramework/fontManager.py +2 -2
  10. batFramework/gui/clickableWidget.py +10 -9
  11. batFramework/gui/constraints/constraints.py +282 -57
  12. batFramework/gui/image.py +14 -14
  13. batFramework/gui/interactiveWidget.py +16 -1
  14. batFramework/gui/label.py +58 -37
  15. batFramework/gui/layout.py +23 -14
  16. batFramework/gui/meter.py +10 -7
  17. batFramework/gui/radioButton.py +1 -1
  18. batFramework/gui/root.py +7 -1
  19. batFramework/gui/shape.py +21 -37
  20. batFramework/gui/slider.py +52 -58
  21. batFramework/gui/textInput.py +161 -51
  22. batFramework/gui/toggle.py +27 -41
  23. batFramework/gui/widget.py +68 -35
  24. batFramework/manager.py +17 -5
  25. batFramework/object.py +17 -8
  26. batFramework/particle.py +22 -8
  27. batFramework/resourceManager.py +18 -2
  28. batFramework/scene.py +50 -20
  29. batFramework/sceneManager.py +52 -28
  30. batFramework/scrollingSprite.py +7 -8
  31. batFramework/stateMachine.py +9 -6
  32. batFramework/templates/__init__.py +2 -0
  33. batFramework/templates/character.py +44 -0
  34. batFramework/templates/states.py +166 -0
  35. batFramework/time.py +54 -28
  36. batFramework/transition.py +25 -12
  37. batFramework/triggerZone.py +1 -1
  38. batFramework/utils.py +92 -2
  39. {batframework-1.0.8a3.dist-info → batframework-1.0.8a6.dist-info}/METADATA +3 -15
  40. batframework-1.0.8a6.dist-info/RECORD +62 -0
  41. {batframework-1.0.8a3.dist-info → batframework-1.0.8a6.dist-info}/WHEEL +1 -1
  42. batframework-1.0.8a3.dist-info/RECORD +0 -58
  43. {batframework-1.0.8a3.dist-info → batframework-1.0.8a6.dist-info}/LICENCE +0 -0
  44. {batframework-1.0.8a3.dist-info → batframework-1.0.8a6.dist-info}/top_level.txt +0 -0
@@ -4,9 +4,12 @@ import pygame
4
4
 
5
5
 
6
6
  class Constraint:
7
- def __init__(self, name="Constraint", priority=0):
7
+ def __init__(self, name:str|None=None, priority=0):
8
8
  self.priority = priority
9
- self.name = name
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
10
13
 
11
14
  def set_priority(self, priority) -> "Constraint":
12
15
  self.priority = priority
@@ -26,35 +29,117 @@ class Constraint:
26
29
 
27
30
  def apply_constraint(self, parent_widget: Widget, child_widget: Widget):
28
31
  raise NotImplementedError("Subclasses must implement apply_constraint method")
29
-
32
+
33
+ def __eq__(self,other:"Constraint")->bool:
34
+ if not isinstance(other,self.__class__):
35
+ return False
36
+ return other.name == self.name
30
37
 
31
38
  class MinWidth(Constraint):
32
39
  def __init__(self, width: float):
33
- super().__init__(name="min_width")
40
+ super().__init__()
34
41
  self.min_width = width
35
42
 
43
+ def on_removal(self, child_widget: Widget) -> None:
44
+ child_widget.set_autoresize_w(False)
45
+
36
46
  def evaluate(self, parent_widget, child_widget):
37
- return child_widget.rect.width >= self.min_width
47
+ res = child_widget.rect.width >= self.min_width
48
+ if not res:
49
+ child_widget.set_autoresize_w(False)
50
+ return res
38
51
 
39
52
  def apply_constraint(self, parent_widget, child_widget):
53
+ child_widget.set_autoresize_w(True)
40
54
  child_widget.set_size((self.min_width, None))
41
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
+ )
42
63
 
43
64
  class MinHeight(Constraint):
44
65
  def __init__(self, height: float):
45
- super().__init__(name="min_height")
66
+ super().__init__()
46
67
  self.min_height = height
47
68
 
69
+ def on_removal(self, child_widget: Widget) -> None:
70
+ child_widget.set_autoresize_h(False)
71
+
48
72
  def evaluate(self, parent_widget, child_widget):
49
- return child_widget.rect.h >= self.min_height
73
+ res = child_widget.rect.h >= self.min_height
74
+ if not res:
75
+ child_widget.set_autoresize_w(False)
76
+ return res
50
77
 
51
78
  def apply_constraint(self, parent_widget, child_widget):
52
79
  child_widget.set_size((None, self.min_height))
53
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
+
54
139
 
55
140
  class CenterX(Constraint):
56
141
  def __init__(self):
57
- super().__init__(name="centerx")
142
+ super().__init__()
58
143
 
59
144
  def evaluate(self, parent_widget, child_widget):
60
145
  return (
@@ -69,7 +154,7 @@ class CenterX(Constraint):
69
154
 
70
155
  class CenterY(Constraint):
71
156
  def __init__(self):
72
- super().__init__(name="centery")
157
+ super().__init__()
73
158
 
74
159
  def evaluate(self, parent_widget, child_widget):
75
160
  return (
@@ -84,7 +169,7 @@ class CenterY(Constraint):
84
169
 
85
170
  class Center(Constraint):
86
171
  def __init__(self):
87
- super().__init__(name="center")
172
+ super().__init__()
88
173
 
89
174
  def evaluate(self, parent_widget, child_widget):
90
175
  return (
@@ -99,10 +184,13 @@ class Center(Constraint):
99
184
 
100
185
  class PercentageWidth(Constraint):
101
186
  def __init__(self, percentage: float, keep_autoresize: bool = False):
102
- super().__init__(name="percentage_width")
187
+ super().__init__()
103
188
  self.percentage: float = percentage
104
189
  self.keep_autoresize: bool = keep_autoresize
105
190
 
191
+ def on_removal(self, child_widget: Widget) -> None:
192
+ child_widget.set_autoresize_w(True)
193
+
106
194
  def __str__(self) -> str:
107
195
  return f"{super().__str__()}.[{self.percentage*100}%,keep_autoresize={self.keep_autoresize}]"
108
196
 
@@ -124,13 +212,24 @@ class PercentageWidth(Constraint):
124
212
  (round(parent_widget.get_padded_width() * self.percentage), None)
125
213
  )
126
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
+
127
223
 
128
224
  class PercentageHeight(Constraint):
129
225
  def __init__(self, percentage: float, keep_autoresize: bool = False):
130
- super().__init__(name="percentage_height")
226
+ super().__init__()
131
227
  self.percentage: float = percentage
132
228
  self.keep_autoresize: bool = keep_autoresize
133
229
 
230
+ def on_removal(self, child_widget: Widget) -> None:
231
+ child_widget.set_autoresize_h(True)
232
+
134
233
  def evaluate(self, parent_widget, child_widget):
135
234
  return child_widget.rect.height == round(
136
235
  parent_widget.get_padded_height() * self.percentage
@@ -151,25 +250,40 @@ class PercentageHeight(Constraint):
151
250
  (None, round(parent_widget.get_padded_height() * self.percentage))
152
251
  )
153
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
+ )
154
260
 
155
261
  class FillX(PercentageWidth):
156
262
  def __init__(self, keep_autoresize: bool = False):
157
263
  super().__init__(1, keep_autoresize)
158
- self.name = "fill_x"
264
+ self.name = "FillX"
159
265
 
266
+ def __eq__(self, other: Constraint) -> bool:
267
+ return Constraint.__eq__(self,other)
160
268
 
161
269
  class FillY(PercentageHeight):
162
270
  def __init__(self, keep_autoresize: bool = False):
163
271
  super().__init__(1, keep_autoresize)
164
- self.name = "fill_y"
272
+ self.name = "FillY"
273
+
274
+ def __eq__(self, other: Constraint) -> bool:
275
+ return Constraint.__eq__(self,other)
165
276
 
166
277
 
167
278
  class PercentageRectHeight(Constraint):
168
279
  def __init__(self, percentage: float, keep_autoresize: bool = False):
169
- super().__init__(name="percentage_rect_height")
280
+ super().__init__()
170
281
  self.percentage: float = percentage
171
282
  self.keep_autoresize: bool = keep_autoresize
172
283
 
284
+ def on_removal(self, child_widget: Widget) -> None:
285
+ child_widget.set_autoresize_h(True)
286
+
173
287
  def evaluate(self, parent_widget, child_widget):
174
288
  return child_widget.rect.height == round(
175
289
  parent_widget.rect.height * self.percentage
@@ -190,13 +304,23 @@ class PercentageRectHeight(Constraint):
190
304
  (None, round(parent_widget.rect.height * self.percentage))
191
305
  )
192
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
+ )
193
314
 
194
315
  class PercentageRectWidth(Constraint):
195
316
  def __init__(self, percentage: float, keep_autoresize: bool = False):
196
- super().__init__(name="percentage_rect_width")
317
+ super().__init__()
197
318
  self.percentage: float = percentage
198
319
  self.keep_autoresize: bool = keep_autoresize
199
320
 
321
+ def on_removal(self, child_widget: Widget) -> None:
322
+ child_widget.set_autoresize_w(True)
323
+
200
324
  def evaluate(self, parent_widget, child_widget):
201
325
  return child_widget.rect.width == round(
202
326
  parent_widget.rect.width * self.percentage
@@ -215,6 +339,13 @@ class PercentageRectWidth(Constraint):
215
339
  child_widget.set_autoresize_w(False)
216
340
  child_widget.set_size((round(parent_widget.rect.width * self.percentage), None))
217
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
+ )
218
349
 
219
350
  class FillRectX(PercentageRectWidth):
220
351
  def __init__(self, keep_autoresize: bool = False):
@@ -235,7 +366,7 @@ class AspectRatio(Constraint):
235
366
  reference_axis: bf.axis = bf.axis.HORIZONTAL,
236
367
  keep_autoresize=False,
237
368
  ):
238
- super().__init__(name="aspect_ratio")
369
+ super().__init__()
239
370
  self.ref_axis: bf.axis = reference_axis
240
371
  self.keep_autoresize: bool = keep_autoresize
241
372
 
@@ -250,11 +381,16 @@ class AspectRatio(Constraint):
250
381
  else:
251
382
  raise TypeError(f"Ratio must be float or FRect")
252
383
 
384
+ def on_removal(self, child_widget: Widget) -> None:
385
+ child_widget.set_autoresize(True)
386
+
387
+
253
388
  def evaluate(self, parent_widget, child_widget):
254
389
  if self.ref_axis == bf.axis.HORIZONTAL:
255
- return self.ratio == child_widget.rect.w / child_widget.rect.h
256
- if self.ref_axis == bf.axis.VERTICAL:
257
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
+
258
394
 
259
395
  def apply_constraint(self, parent_widget, child_widget):
260
396
 
@@ -262,7 +398,7 @@ class AspectRatio(Constraint):
262
398
  if child_widget.autoresize_w:
263
399
  if self.keep_autoresize:
264
400
  print(
265
- f"WARNING: Constraint on {child_widget.__str__()} can't resize, autoresize set to True"
401
+ f"WARNING: Constraint on {str(child_widget)} can't resize, autoresize set to True"
266
402
  )
267
403
  return
268
404
  child_widget.set_autoresize_w(False)
@@ -272,22 +408,30 @@ class AspectRatio(Constraint):
272
408
  if child_widget.autoresize_h:
273
409
  if self.keep_autoresize:
274
410
  print(
275
- f"WARNING: Constraint on {child_widget.__str__()} can't resize, autoresize set to True"
411
+ f"WARNING: Constraint on {str(child_widget)} can't resize, autoresize set to True"
276
412
  )
277
413
  return
278
414
  child_widget.set_autoresize_h(False)
279
- print("HERE")
415
+
280
416
  child_widget.set_size((None, child_widget.rect.w * self.ratio))
281
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
+ )
282
426
 
283
427
  class AnchorBottom(Constraint):
284
428
  def __init__(self):
285
- super().__init__(name="anchor_bottom")
429
+ super().__init__()
286
430
 
287
431
  def evaluate(self, parent_widget, child_widget):
288
432
  return (
289
- child_widget.rect.top
290
- == parent_widget.get_padded_bottom() - child_widget.rect.h
433
+ child_widget.rect.bottom
434
+ == parent_widget.get_padded_bottom()
291
435
  )
292
436
 
293
437
  def apply_constraint(self, parent_widget, child_widget):
@@ -295,40 +439,34 @@ class AnchorBottom(Constraint):
295
439
  child_widget.rect.x, parent_widget.get_padded_bottom() - child_widget.rect.h
296
440
  )
297
441
 
298
-
299
- class AnchorBottom(Constraint):
442
+ class AnchorTop(Constraint):
300
443
  def __init__(self):
301
- super().__init__(name="anchor_bottom")
444
+ super().__init__()
302
445
 
303
446
  def evaluate(self, parent_widget, child_widget):
304
- return (
305
- child_widget.rect.top
306
- == parent_widget.get_padded_bottom() - child_widget.rect.h
307
- )
447
+ return (child_widget.rect.top == parent_widget.get_padded_top())
308
448
 
309
449
  def apply_constraint(self, parent_widget, child_widget):
310
- child_widget.set_position(
311
- child_widget.rect.x, parent_widget.get_padded_bottom() - child_widget.rect.h
312
- )
450
+ child_widget.set_position(child_widget.rect.x, parent_widget.get_padded_top())
313
451
 
314
452
 
315
453
  class AnchorTopRight(Constraint):
316
454
  def __init__(self):
317
- super().__init__(name="anchor_topright")
455
+ super().__init__()
318
456
 
319
457
  def evaluate(self, parent_widget, child_widget):
320
458
  return child_widget.rect.topright == parent_widget.get_padded_rect().topright
321
459
 
322
460
  def apply_constraint(self, parent_widget, child_widget):
323
- child_widget.set_position(
324
- parent_widget.get_padded_right() - child_widget.rect.w,
325
- parent_widget.get_padded_top(),
326
- )
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)
327
465
 
328
466
 
329
467
  class AnchorBottomRight(Constraint):
330
468
  def __init__(self):
331
- super().__init__(name="anchor_bottomright")
469
+ super().__init__()
332
470
 
333
471
  def evaluate(self, parent_widget, child_widget):
334
472
  return (
@@ -336,15 +474,17 @@ class AnchorBottomRight(Constraint):
336
474
  )
337
475
 
338
476
  def apply_constraint(self, parent_widget, child_widget):
477
+ bottomright = parent_widget.get_padded_rect().bottomright
478
+
339
479
  child_widget.set_position(
340
- parent_widget.get_padded_right() - child_widget.rect.w,
341
- parent_widget.get_padded_bottom() - child_widget.rect.h,
480
+ bottomright[0] - child_widget.rect.w,
481
+ bottomright[1] - child_widget.rect.h,
342
482
  )
343
483
 
344
484
 
345
485
  class AnchorRight(Constraint):
346
486
  def __init__(self):
347
- super().__init__(name="anchor_right")
487
+ super().__init__()
348
488
 
349
489
  def evaluate(self, parent_widget, child_widget):
350
490
  return child_widget.rect.right == parent_widget.get_padded_right()
@@ -358,7 +498,7 @@ class AnchorRight(Constraint):
358
498
 
359
499
  class AnchorLeft(Constraint):
360
500
  def __init__(self):
361
- super().__init__(name="anchor_left")
501
+ super().__init__()
362
502
 
363
503
  def evaluate(self, parent_widget, child_widget):
364
504
  return child_widget.rect.left == parent_widget.get_padded_left()
@@ -371,7 +511,7 @@ class AnchorLeft(Constraint):
371
511
 
372
512
  class MarginBottom(Constraint):
373
513
  def __init__(self, margin: float):
374
- super().__init__(name="margin_bottom")
514
+ super().__init__()
375
515
  self.margin = margin
376
516
 
377
517
  def evaluate(self, parent_widget, child_widget):
@@ -385,10 +525,17 @@ class MarginBottom(Constraint):
385
525
  parent_widget.get_padded_bottom() - child_widget.rect.h - self.margin,
386
526
  )
387
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
+ )
388
535
 
389
536
  class MarginTop(Constraint):
390
537
  def __init__(self, margin: float):
391
- super().__init__(name="margin_top")
538
+ super().__init__()
392
539
  self.margin = margin
393
540
 
394
541
  def evaluate(self, parent_widget, child_widget):
@@ -399,10 +546,17 @@ class MarginTop(Constraint):
399
546
  child_widget.rect.x, parent_widget.get_padded_top() + self.margin
400
547
  )
401
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
+ )
402
556
 
403
557
  class MarginLeft(Constraint):
404
558
  def __init__(self, margin: float):
405
- super().__init__(name="margin_left")
559
+ super().__init__()
406
560
  self.margin = margin
407
561
 
408
562
  def evaluate(self, parent_widget, child_widget):
@@ -414,10 +568,17 @@ class MarginLeft(Constraint):
414
568
  parent_widget.get_padded_left() + self.margin, child_widget.rect.y
415
569
  )
416
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
+ )
417
578
 
418
579
  class MarginRight(Constraint):
419
580
  def __init__(self, margin: float):
420
- super().__init__(name="margin_right")
581
+ super().__init__()
421
582
  self.margin = margin
422
583
 
423
584
  def evaluate(self, parent_widget, child_widget):
@@ -429,10 +590,17 @@ class MarginRight(Constraint):
429
590
  child_widget.rect.y,
430
591
  )
431
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
+ )
432
600
 
433
601
  class PercentageMarginBottom(Constraint):
434
602
  def __init__(self, margin: float):
435
- super().__init__(name="percentage_margin_bottom")
603
+ super().__init__()
436
604
  self.margin = margin
437
605
 
438
606
  def evaluate(self, parent_widget, child_widget):
@@ -450,10 +618,17 @@ class PercentageMarginBottom(Constraint):
450
618
  - parent_widget.get_padded_height() * self.margin,
451
619
  )
452
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
+ )
453
628
 
454
629
  class PercentageMarginTop(Constraint):
455
630
  def __init__(self, margin: float):
456
- super().__init__(name="percentage_margin_top")
631
+ super().__init__()
457
632
  self.margin = margin
458
633
 
459
634
  def evaluate(self, parent_widget, child_widget):
@@ -470,10 +645,17 @@ class PercentageMarginTop(Constraint):
470
645
  + parent_widget.get_padded_height() * self.margin,
471
646
  )
472
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
+ )
473
655
 
474
656
  class PercentageMarginLeft(Constraint):
475
657
  def __init__(self, margin: float):
476
- super().__init__(name="percentage_margin_left")
658
+ super().__init__()
477
659
  self.margin = margin
478
660
 
479
661
  def evaluate(self, parent_widget, child_widget):
@@ -491,10 +673,17 @@ class PercentageMarginLeft(Constraint):
491
673
  child_widget.rect.y,
492
674
  )
493
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
+ )
494
683
 
495
684
  class PercentageMarginRight(Constraint):
496
685
  def __init__(self, margin: float):
497
- super().__init__(name="percentage_margin_right")
686
+ super().__init__()
498
687
  self.margin = margin
499
688
 
500
689
  def evaluate(self, parent_widget, child_widget):
@@ -512,10 +701,17 @@ class PercentageMarginRight(Constraint):
512
701
  child_widget.rect.y,
513
702
  )
514
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
+ )
515
711
 
516
712
  class PercentageRectMarginBottom(Constraint):
517
713
  def __init__(self, margin: float):
518
- super().__init__(name="percentage_rect_margin_bottom")
714
+ super().__init__()
519
715
  self.margin = margin
520
716
 
521
717
  def evaluate(self, parent_widget, child_widget):
@@ -532,10 +728,17 @@ class PercentageRectMarginBottom(Constraint):
532
728
  - parent_widget.rect.height * self.margin,
533
729
  )
534
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
+ )
535
738
 
536
739
  class PercentageRectMarginTop(Constraint):
537
740
  def __init__(self, margin: float):
538
- super().__init__(name="percentage_rect_margin_top")
741
+ super().__init__()
539
742
  self.margin = margin
540
743
 
541
744
  def evaluate(self, parent_widget, child_widget):
@@ -550,10 +753,17 @@ class PercentageRectMarginTop(Constraint):
550
753
  parent_widget.rect.top + parent_widget.rect.height * self.margin,
551
754
  )
552
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
+ )
553
763
 
554
764
  class PercentageRectMarginLeft(Constraint):
555
765
  def __init__(self, margin: float):
556
- super().__init__(name="percentage_rect_margin_left")
766
+ super().__init__()
557
767
  self.margin = margin
558
768
 
559
769
  def evaluate(self, parent_widget, child_widget):
@@ -569,10 +779,17 @@ class PercentageRectMarginLeft(Constraint):
569
779
  child_widget.rect.y,
570
780
  )
571
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
+ )
572
789
 
573
790
  class PercentageRectMarginRight(Constraint):
574
791
  def __init__(self, margin: float):
575
- super().__init__(name="percentage_rect_margin_right")
792
+ super().__init__()
576
793
  self.margin = margin
577
794
 
578
795
  def evaluate(self, parent_widget, child_widget):
@@ -588,3 +805,11 @@ class PercentageRectMarginRight(Constraint):
588
805
  - parent_widget.rect.width * self.margin,
589
806
  child_widget.rect.y,
590
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
+ )