batframework 1.0.9a10__py3-none-any.whl → 1.1.0__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 (76) hide show
  1. batFramework/__init__.py +52 -76
  2. batFramework/action.py +99 -126
  3. batFramework/actionContainer.py +9 -53
  4. batFramework/animatedSprite.py +114 -56
  5. batFramework/audioManager.py +36 -82
  6. batFramework/camera.py +69 -263
  7. batFramework/constants.py +53 -29
  8. batFramework/cutscene.py +109 -243
  9. batFramework/cutsceneBlocks.py +176 -0
  10. batFramework/debugger.py +48 -0
  11. batFramework/dynamicEntity.py +9 -16
  12. batFramework/easing.py +71 -0
  13. batFramework/entity.py +85 -92
  14. batFramework/gui/__init__.py +3 -14
  15. batFramework/gui/button.py +78 -12
  16. batFramework/gui/constraints.py +204 -0
  17. batFramework/gui/container.py +31 -183
  18. batFramework/gui/debugger.py +43 -126
  19. batFramework/gui/frame.py +19 -0
  20. batFramework/gui/image.py +20 -55
  21. batFramework/gui/indicator.py +22 -95
  22. batFramework/gui/interactiveWidget.py +12 -229
  23. batFramework/gui/label.py +77 -311
  24. batFramework/gui/layout.py +66 -411
  25. batFramework/gui/root.py +35 -203
  26. batFramework/gui/shape.py +57 -247
  27. batFramework/gui/toggle.py +48 -114
  28. batFramework/gui/widget.py +243 -457
  29. batFramework/manager.py +29 -113
  30. batFramework/particles.py +77 -0
  31. batFramework/scene.py +217 -22
  32. batFramework/sceneManager.py +129 -161
  33. batFramework/stateMachine.py +8 -11
  34. batFramework/time.py +75 -0
  35. batFramework/transition.py +124 -129
  36. batFramework/transitionManager.py +0 -0
  37. batFramework/triggerZone.py +4 -4
  38. batFramework/utils.py +144 -266
  39. {batframework-1.0.9a10.dist-info → batframework-1.1.0.dist-info}/METADATA +24 -22
  40. batframework-1.1.0.dist-info/RECORD +43 -0
  41. batFramework/animation.py +0 -77
  42. batFramework/baseScene.py +0 -240
  43. batFramework/cutsceneManager.py +0 -34
  44. batFramework/drawable.py +0 -77
  45. batFramework/easingController.py +0 -58
  46. batFramework/enums.py +0 -135
  47. batFramework/fontManager.py +0 -65
  48. batFramework/gui/animatedLabel.py +0 -89
  49. batFramework/gui/clickableWidget.py +0 -245
  50. batFramework/gui/constraints/__init__.py +0 -1
  51. batFramework/gui/constraints/constraints.py +0 -980
  52. batFramework/gui/draggableWidget.py +0 -44
  53. batFramework/gui/meter.py +0 -96
  54. batFramework/gui/radioButton.py +0 -35
  55. batFramework/gui/selector.py +0 -250
  56. batFramework/gui/slider.py +0 -397
  57. batFramework/gui/style.py +0 -10
  58. batFramework/gui/styleManager.py +0 -54
  59. batFramework/gui/syncedVar.py +0 -49
  60. batFramework/gui/textInput.py +0 -306
  61. batFramework/gui/tooltip.py +0 -30
  62. batFramework/particle.py +0 -118
  63. batFramework/propertyEaser.py +0 -79
  64. batFramework/renderGroup.py +0 -34
  65. batFramework/resourceManager.py +0 -130
  66. batFramework/sceneLayer.py +0 -138
  67. batFramework/scrollingSprite.py +0 -115
  68. batFramework/sprite.py +0 -51
  69. batFramework/templates/__init__.py +0 -1
  70. batFramework/templates/controller.py +0 -97
  71. batFramework/tileset.py +0 -46
  72. batFramework/timeManager.py +0 -213
  73. batframework-1.0.9a10.dist-info/RECORD +0 -67
  74. {batframework-1.0.9a10.dist-info → batframework-1.1.0.dist-info}/LICENSE +0 -0
  75. {batframework-1.0.9a10.dist-info → batframework-1.1.0.dist-info}/WHEEL +0 -0
  76. {batframework-1.0.9a10.dist-info → batframework-1.1.0.dist-info}/top_level.txt +0 -0
@@ -1,980 +0,0 @@
1
- from abc import ABC, abstractmethod
2
- from ..widget import Widget
3
- import batFramework as bf
4
- import pygame
5
-
6
-
7
- class Constraint:
8
- def __init__(self, name:str|None=None, priority=0):
9
- self.priority = priority
10
- self.name = name if name is not None else self.__class__.__name__
11
- self.old_autoresize_w = None
12
- self.old_autoresize_h = None
13
- self.affects_size : bool = False
14
- self.affects_position : bool = False
15
-
16
-
17
- def on_removal(self,child_widget: Widget)->None:
18
- child_widget.set_autoresize_h(self.old_autoresize_h)
19
- child_widget.set_autoresize_w(self.old_autoresize_w)
20
-
21
-
22
- def set_priority(self, priority) -> "Constraint":
23
- """
24
- Highest priority is used if 2 constraints are in conflict
25
- Default is 0
26
- """
27
- self.priority = priority
28
- return self
29
-
30
- def __str__(self) -> str:
31
- return f"{self.name.upper()}"
32
-
33
- def evaluate(self, parent_widget: Widget, child_widget: Widget) -> bool:
34
- raise NotImplementedError("Subclasses must implement evaluate method")
35
-
36
- def apply(self, parent_widget: Widget, child_widget: Widget = None) -> bool:
37
- if self.old_autoresize_h is None:
38
- self.old_autoresize_h = child_widget.autoresize_h
39
- if self.old_autoresize_w is None:
40
- self.old_autoresize_w = child_widget.autoresize_w
41
-
42
- if not self.evaluate(parent_widget, child_widget):
43
- self.apply_constraint(parent_widget, child_widget)
44
- return False
45
- return True
46
-
47
- def apply_constraint(self, parent_widget: Widget, child_widget: Widget):
48
- raise NotImplementedError("Subclasses must implement apply_constraint method")
49
-
50
- def __eq__(self,other:"Constraint")->bool:
51
- if not isinstance(other,self.__class__):
52
- return False
53
- return other.name == self.name
54
-
55
- class MinWidth(Constraint):
56
- def __init__(self, width: float):
57
- super().__init__()
58
- self.min_width = width
59
- self.affects_size = True
60
-
61
-
62
- def evaluate(self, parent_widget, child_widget):
63
- return child_widget.rect.width >= self.min_width
64
-
65
- def apply_constraint(self, parent_widget, child_widget):
66
- child_widget.set_autoresize_w(False)
67
- child_widget.set_size((self.min_width, None))
68
-
69
- def __eq__(self,other:"Constraint")->bool:
70
- if not isinstance(other,self.__class__):
71
- return False
72
- return (
73
- other.name == self.name and
74
- other.min_width == self.min_width
75
- )
76
-
77
- class MinHeight(Constraint):
78
- def __init__(self, height: float):
79
- super().__init__()
80
- self.min_height = height
81
- self.affects_size = True
82
-
83
-
84
- def evaluate(self, parent_widget, child_widget):
85
- return child_widget.rect.h >= self.min_height
86
-
87
-
88
- def apply_constraint(self, parent_widget, child_widget):
89
- child_widget.set_autoresize_h(False)
90
- child_widget.set_size((None, self.min_height))
91
-
92
- def __eq__(self,other:"Constraint")->bool:
93
- if not isinstance(other,self.__class__):
94
- return False
95
- return (
96
- other.name == self.name and
97
- other.min_height == self.min_height
98
- )
99
-
100
- class MaxWidth(Constraint):
101
- def __init__(self, width: float):
102
- super().__init__()
103
- self.max_width = width
104
- self.affects_size = True
105
-
106
- def on_removal(self, child_widget: Widget) -> None:
107
- child_widget.set_autoresize_w(False)
108
-
109
- def evaluate(self, parent_widget, child_widget):
110
- res = child_widget.rect.width <= self.max_width
111
- if not res:
112
- child_widget.set_autoresize_w(False)
113
- return res
114
-
115
- def apply_constraint(self, parent_widget, child_widget):
116
- child_widget.set_autoresize_w(True)
117
- current_height = child_widget.rect.height
118
- child_widget.set_size((self.max_width, current_height))
119
-
120
- def __eq__(self, other: "Constraint") -> bool:
121
- if not isinstance(other, self.__class__):
122
- return False
123
- return other.max_width == self.max_width
124
-
125
-
126
- class MaxHeight(Constraint):
127
- def __init__(self, height: float):
128
- super().__init__()
129
- self.max_height = height
130
- self.affects_size = True
131
-
132
- def on_removal(self, child_widget: Widget) -> None:
133
- child_widget.set_autoresize_h(False)
134
-
135
- def evaluate(self, parent_widget, child_widget):
136
- res = child_widget.rect.height <= self.max_height
137
- if not res:
138
- child_widget.set_autoresize_h(False)
139
- return res
140
-
141
- def apply_constraint(self, parent_widget, child_widget):
142
- child_widget.set_autoresize_h(True)
143
- current_width = child_widget.rect.width
144
- child_widget.set_size((current_width, self.max_height))
145
-
146
- def __eq__(self, other: "Constraint") -> bool:
147
- if not isinstance(other, self.__class__):
148
- return False
149
- return other.max_height == self.max_height
150
-
151
-
152
-
153
- class CenterX(Constraint):
154
- def __init__(self):
155
- super().__init__()
156
- self.affects_position = True
157
-
158
- def evaluate(self, parent_widget, child_widget):
159
- return (
160
- child_widget.rect.centerx - parent_widget.get_inner_center()[0] == 0
161
- )
162
-
163
- def apply_constraint(self, parent_widget, child_widget):
164
- child_widget.set_center(
165
- parent_widget.get_inner_center()[0], child_widget.rect.centery
166
- )
167
-
168
-
169
- class CenterY(Constraint):
170
- def __init__(self):
171
- super().__init__()
172
- self.affects_position = True
173
-
174
- def evaluate(self, parent_widget, child_widget):
175
- return (
176
- child_widget.rect.centery - parent_widget.get_inner_center()[1] == 0
177
- )
178
-
179
- def apply_constraint(self, parent_widget, child_widget):
180
- child_widget.set_center(
181
- child_widget.rect.centerx, parent_widget.get_inner_center()[1]
182
- )
183
-
184
-
185
- class Center(Constraint):
186
- def __init__(self):
187
- super().__init__()
188
- self.affects_position = True
189
-
190
- def evaluate(self, parent_widget, child_widget):
191
- return (
192
- child_widget.rect.centerx - parent_widget.get_inner_center()[0] == 0
193
- and child_widget.rect.centery - parent_widget.get_inner_center()[1] == 0
194
- )
195
-
196
- def apply_constraint(self, parent_widget, child_widget):
197
- child_widget.set_center(*parent_widget.get_inner_center())
198
-
199
-
200
- class PercentageWidth(Constraint):
201
- def __init__(self, percentage: float):
202
- super().__init__()
203
- self.percentage: float = percentage
204
- self.affects_size = True
205
-
206
- def __str__(self) -> str:
207
- return f"{super().__str__()}.[{self.percentage*100}%]"
208
-
209
- def evaluate(self, parent_widget, child_widget):
210
- return child_widget.rect.width == round(
211
- parent_widget.get_inner_width() * self.percentage
212
- )
213
-
214
- def apply_constraint(self, parent_widget, child_widget):
215
- if child_widget.autoresize_w:
216
- child_widget.set_autoresize_w(False)
217
- child_widget.set_size(
218
- (round(parent_widget.get_inner_width() * self.percentage), None)
219
- )
220
-
221
- def __eq__(self,other:"Constraint")->bool:
222
- if not isinstance(other,self.__class__):
223
- return False
224
- return (
225
- other.name == self.name and
226
- other.percentage == self.percentage
227
- )
228
-
229
-
230
- class PercentageHeight(Constraint):
231
- def __init__(self, percentage: float):
232
- super().__init__()
233
- self.percentage: float = percentage
234
- self.affects_size = True
235
-
236
-
237
- def evaluate(self, parent_widget, child_widget):
238
- return child_widget.rect.height == round(
239
- parent_widget.get_inner_height() * self.percentage
240
- )
241
-
242
- def __str__(self) -> str:
243
- return f"{super().__str__()}.[{self.percentage*100}%]"
244
-
245
- def apply_constraint(self, parent_widget, child_widget):
246
- if child_widget.autoresize_h:
247
- child_widget.set_autoresize_h(False)
248
- child_widget.set_size(
249
- (None, round(parent_widget.get_inner_height() * self.percentage))
250
- )
251
-
252
- def __eq__(self,other:"Constraint")->bool:
253
- if not isinstance(other,self.__class__):
254
- return False
255
- return (
256
- other.name == self.name and
257
- other.percentage == self.percentage
258
- )
259
-
260
- class FillX(PercentageWidth):
261
- def __init__(self):
262
- super().__init__(1)
263
- self.name = "FillX"
264
- self.affects_size = True
265
-
266
- def __eq__(self, other: Constraint) -> bool:
267
- return Constraint.__eq__(self,other)
268
-
269
- class FillY(PercentageHeight):
270
- def __init__(self):
271
- super().__init__(1)
272
- self.name = "FillY"
273
- self.affects_size = True
274
-
275
- def __eq__(self, other: Constraint) -> bool:
276
- return Constraint.__eq__(self,other)
277
-
278
-
279
- class PercentageRectHeight(Constraint):
280
- def __init__(self, percentage: float):
281
- super().__init__()
282
- self.percentage: float = percentage
283
- self.affects_size = True
284
-
285
- def evaluate(self, parent_widget, child_widget):
286
- return child_widget.rect.height == round(
287
- parent_widget.rect.height * self.percentage
288
- )
289
-
290
- def __str__(self) -> str:
291
- return f"{super().__str__()}.[{self.percentage*100}%]"
292
-
293
- def apply_constraint(self, parent_widget, child_widget):
294
- if child_widget.autoresize_h:
295
- child_widget.set_autoresize_h(False)
296
- child_widget.set_size(
297
- (None, round(parent_widget.rect.height * self.percentage))
298
- )
299
-
300
- def __eq__(self,other:"Constraint")->bool:
301
- if not isinstance(other,self.__class__):
302
- return False
303
- return (
304
- other.name == self.name and
305
- other.percentage == self.percentage
306
- )
307
-
308
- class PercentageRectWidth(Constraint):
309
- def __init__(self, percentage: float):
310
- super().__init__()
311
- self.percentage: float = percentage
312
- self.affects_size = True
313
-
314
- def on_removal(self, child_widget: Widget) -> None:
315
- child_widget.set_autoresize_w(True)
316
-
317
- def evaluate(self, parent_widget, child_widget):
318
- return child_widget.rect.width == round(
319
- parent_widget.rect.width * self.percentage
320
- )
321
-
322
- def __str__(self) -> str:
323
- return f"{super().__str__()}.[{self.percentage*100}%]"
324
-
325
- def apply_constraint(self, parent_widget, child_widget):
326
- if child_widget.autoresize_w:
327
- child_widget.set_autoresize_w(False)
328
- child_widget.set_size((round(parent_widget.rect.width * self.percentage), None))
329
-
330
- def __eq__(self,other:"Constraint")->bool:
331
- if not isinstance(other,self.__class__):
332
- return False
333
- return (
334
- other.name == self.name and
335
- other.percentage == self.percentage
336
- )
337
-
338
- class FillRectX(PercentageRectWidth):
339
- def __init__(self):
340
- super().__init__(1)
341
- self.name = "fill_rect_x"
342
- self.affects_size = True
343
-
344
-
345
- class FillRectY(PercentageRectHeight):
346
- def __init__(self):
347
- super().__init__(1)
348
- self.name = "fill_rect_y"
349
- self.affects_size = True
350
-
351
-
352
- class AspectRatio(Constraint):
353
- def __init__(
354
- self,
355
- ratio: int | float | pygame.rect.FRectType = 1,
356
- reference_axis: bf.axis = bf.axis.HORIZONTAL,
357
- ):
358
- super().__init__()
359
- self.ref_axis: bf.axis = reference_axis
360
- self.affects_size = True
361
-
362
- if isinstance(ratio, float | int):
363
- self.ratio = ratio
364
- elif isinstance(ratio, pygame.rect.FRect):
365
- self.ratio = (
366
- round(ratio.w / ratio.h,2)
367
- if reference_axis == bf.axis.HORIZONTAL
368
- else round(ratio.h / ratio.w,2)
369
- )
370
- else:
371
- raise TypeError(f"Ratio must be float or FRect")
372
-
373
-
374
-
375
- def evaluate(self, parent_widget, child_widget):
376
- if self.ref_axis == bf.axis.HORIZONTAL:
377
- return self.ratio == round(child_widget.rect.h / child_widget.rect.w,2)
378
- if self.ref_axis == bf.axis.VERTICAL:
379
- return self.ratio == round(child_widget.rect.w / child_widget.rect.h,2)
380
-
381
-
382
- def apply_constraint(self, parent_widget, child_widget):
383
-
384
- if self.ref_axis == bf.axis.VERTICAL:
385
- if child_widget.autoresize_w:
386
- child_widget.set_autoresize_w(False)
387
- child_widget.set_size((child_widget.rect.h * self.ratio, None))
388
-
389
- if self.ref_axis == bf.axis.HORIZONTAL:
390
- if child_widget.autoresize_h:
391
- child_widget.set_autoresize_h(False)
392
-
393
- child_widget.set_size((None, child_widget.rect.w * self.ratio))
394
-
395
- def __str__(self) -> str:
396
- return f"{self.name.upper()}[ratio = {self.ratio}, ref = {'Vertical' if self.ref_axis == bf.axis.VERTICAL else 'Horizontal'}]"
397
-
398
-
399
- def __eq__(self,other:"Constraint")->bool:
400
- if not isinstance(other,self.__class__):
401
- return False
402
- return (
403
- other.name == self.name and
404
- other.ratio == self.ratio and
405
- other.ref_axis == self.ref_axis
406
- )
407
-
408
- class AnchorBottom(Constraint):
409
- def __init__(self):
410
- super().__init__()
411
- self.affects_position = True
412
-
413
- def evaluate(self, parent_widget, child_widget):
414
- return (
415
- child_widget.rect.bottom
416
- == parent_widget.get_inner_bottom()
417
- )
418
-
419
- def apply_constraint(self, parent_widget, child_widget):
420
- child_widget.set_position(
421
- child_widget.rect.x, parent_widget.get_inner_bottom() - child_widget.rect.h
422
- )
423
-
424
- class AnchorTop(Constraint):
425
- def __init__(self):
426
- super().__init__()
427
- self.affects_position = True
428
-
429
- def evaluate(self, parent_widget, child_widget):
430
- return (child_widget.rect.top == parent_widget.get_inner_top())
431
-
432
- def apply_constraint(self, parent_widget, child_widget):
433
- child_widget.set_position(child_widget.rect.x, parent_widget.get_inner_top())
434
-
435
-
436
- class AnchorTopRight(Constraint):
437
- def __init__(self):
438
- super().__init__()
439
- self.affects_position = True
440
-
441
- def evaluate(self, parent_widget, child_widget):
442
- return child_widget.rect.topright == parent_widget.get_inner_rect().topright
443
-
444
- def apply_constraint(self, parent_widget, child_widget):
445
- # print("before",child_widget.rect.topright, parent_widget.get_inner_rect().topright)
446
- topright = parent_widget.get_inner_rect().topright
447
- child_widget.set_position(topright[0] - child_widget.rect.w,topright[1])
448
- # print("after",child_widget.rect.topright, parent_widget.get_inner_rect().topright)
449
-
450
- class AnchorTopLeft(Constraint):
451
- def __init__(self):
452
- super().__init__()
453
- self.affects_position = True
454
-
455
- def evaluate(self, parent_widget, child_widget):
456
- return child_widget.rect.topleft == parent_widget.get_inner_rect().topleft
457
-
458
- def apply_constraint(self, parent_widget, child_widget):
459
- child_widget.set_position(*parent_widget.get_inner_rect().topleft)
460
-
461
-
462
- class AnchorBottomRight(Constraint):
463
- def __init__(self):
464
- super().__init__()
465
- self.affects_position = True
466
-
467
- def evaluate(self, parent_widget, child_widget):
468
- return (
469
- child_widget.rect.bottomright == parent_widget.get_inner_rect().bottomright
470
- )
471
-
472
- def apply_constraint(self, parent_widget, child_widget):
473
- bottomright = parent_widget.get_inner_rect().bottomright
474
-
475
- child_widget.set_position(
476
- bottomright[0] - child_widget.rect.w,
477
- bottomright[1] - child_widget.rect.h,
478
- )
479
-
480
-
481
- class AnchorRight(Constraint):
482
- def __init__(self):
483
- super().__init__()
484
- self.affects_position = True
485
-
486
- def evaluate(self, parent_widget, child_widget):
487
- return child_widget.rect.right == parent_widget.get_inner_right()
488
-
489
- def apply_constraint(self, parent_widget, child_widget):
490
- child_widget.set_position(
491
- parent_widget.get_inner_right() - child_widget.rect.w,
492
- None,
493
- )
494
-
495
-
496
- class AnchorLeft(Constraint):
497
- def __init__(self):
498
- super().__init__()
499
- self.affects_position = True
500
-
501
- def evaluate(self, parent_widget, child_widget):
502
- return child_widget.rect.left == parent_widget.get_inner_left()
503
-
504
- def apply_constraint(self, parent_widget, child_widget):
505
- child_widget.set_position(
506
- parent_widget.get_inner_left(), None
507
- )
508
-
509
-
510
- class MarginBottom(Constraint):
511
- def __init__(self, margin: float):
512
- super().__init__()
513
- self.margin = margin
514
- self.affects_position = True
515
-
516
- def evaluate(self, parent_widget, child_widget):
517
- return (
518
- child_widget.rect.bottom == parent_widget.get_inner_bottom() - self.margin
519
- )
520
-
521
- def apply_constraint(self, parent_widget, child_widget):
522
- child_widget.set_position(
523
- child_widget.rect.x,
524
- parent_widget.get_inner_bottom() - child_widget.rect.h - self.margin,
525
- )
526
-
527
- def __eq__(self,other:"Constraint")->bool:
528
- if not isinstance(other,self.__class__):
529
- return False
530
- return (
531
- other.name == self.name and
532
- other.margin == self.margin
533
- )
534
-
535
- class MarginTop(Constraint):
536
- def __init__(self, margin: float):
537
- super().__init__()
538
- self.margin = margin
539
- self.affects_position = True
540
-
541
- def evaluate(self, parent_widget, child_widget):
542
- return child_widget.rect.top == parent_widget.get_inner_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_inner_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
- self.affects_position = True
562
-
563
- def evaluate(self, parent_widget, child_widget):
564
- return child_widget.rect.left == parent_widget.get_inner_left() + self.margin
565
-
566
- def apply_constraint(self, parent_widget, child_widget):
567
- if not self.evaluate(parent_widget, child_widget):
568
- child_widget.set_position(
569
- parent_widget.get_inner_left() + self.margin, child_widget.rect.y
570
- )
571
-
572
- def __eq__(self,other:"Constraint")->bool:
573
- if not isinstance(other,self.__class__):
574
- return False
575
- return (
576
- other.name == self.name and
577
- other.margin == self.margin
578
- )
579
-
580
- class MarginRight(Constraint):
581
- def __init__(self, margin: float):
582
- super().__init__()
583
- self.margin = margin
584
- self.affects_position = True
585
-
586
- def evaluate(self, parent_widget, child_widget):
587
- return child_widget.rect.right == parent_widget.get_inner_right() - self.margin
588
-
589
- def apply_constraint(self, parent_widget, child_widget):
590
- child_widget.set_position(
591
- parent_widget.get_inner_right() - child_widget.rect.w - self.margin,
592
- child_widget.rect.y,
593
- )
594
-
595
- def __eq__(self,other:"Constraint")->bool:
596
- if not isinstance(other,self.__class__):
597
- return False
598
- return (
599
- other.name == self.name and
600
- other.margin == self.margin
601
- )
602
-
603
- class RectMarginBottom(Constraint):
604
- def __init__(self, margin: float):
605
- super().__init__()
606
- self.margin = margin
607
- self.affects_position = True
608
-
609
- def evaluate(self, parent_widget, child_widget):
610
- return (
611
- child_widget.rect.bottom == parent_widget.rect.bottom - self.margin
612
- )
613
-
614
- def apply_constraint(self, parent_widget, child_widget):
615
- child_widget.set_position(
616
- child_widget.rect.x,
617
- parent_widget.rect.bottom- child_widget.rect.h - self.margin,
618
- )
619
-
620
- def __eq__(self,other:"Constraint")->bool:
621
- if not isinstance(other,self.__class__):
622
- return False
623
- return (
624
- other.name == self.name and
625
- other.margin == self.margin
626
- )
627
-
628
- class RectMarginTop(Constraint):
629
- def __init__(self, margin: float):
630
- super().__init__()
631
- self.margin = margin
632
- self.affects_position = True
633
-
634
- def evaluate(self, parent_widget, child_widget):
635
- return child_widget.rect.top == parent_widget.rect.top + self.margin
636
-
637
- def apply_constraint(self, parent_widget, child_widget):
638
- child_widget.set_position(
639
- child_widget.rect.x, parent_widget.rect.top + self.margin
640
- )
641
-
642
- def __eq__(self,other:"Constraint")->bool:
643
- if not isinstance(other,self.__class__):
644
- return False
645
- return (
646
- other.name == self.name and
647
- other.margin == self.margin
648
- )
649
-
650
- class RectMarginLeft(Constraint):
651
- def __init__(self, margin: float):
652
- super().__init__()
653
- self.margin = margin
654
- self.affects_position = True
655
-
656
- def evaluate(self, parent_widget, child_widget):
657
- return child_widget.rect.left == parent_widget.rect.left + self.margin
658
-
659
- def apply_constraint(self, parent_widget, child_widget):
660
- if not self.evaluate(parent_widget, child_widget):
661
- child_widget.set_position(
662
- parent_widget.rect.left + self.margin, child_widget.rect.y
663
- )
664
-
665
- def __eq__(self,other:"Constraint")->bool:
666
- if not isinstance(other,self.__class__):
667
- return False
668
- return (
669
- other.name == self.name and
670
- other.margin == self.margin
671
- )
672
-
673
- class RectMarginRight(Constraint):
674
- def __init__(self, margin: float):
675
- super().__init__()
676
- self.margin = margin
677
- self.affects_position = True
678
-
679
- def evaluate(self, parent_widget, child_widget):
680
- return child_widget.rect.right == parent_widget.rect.right - self.margin
681
-
682
- def apply_constraint(self, parent_widget, child_widget):
683
- child_widget.set_position(
684
- parent_widget.rect.right - child_widget.rect.w - self.margin,
685
- child_widget.rect.y,
686
- )
687
-
688
- def __eq__(self,other:"Constraint")->bool:
689
- if not isinstance(other,self.__class__):
690
- return False
691
- return (
692
- other.name == self.name and
693
- other.margin == self.margin
694
- )
695
-
696
- class PercentageMarginBottom(Constraint):
697
- def __init__(self, margin: float):
698
- super().__init__()
699
- self.margin = margin
700
- self.affects_position = True
701
-
702
- def evaluate(self, parent_widget, child_widget):
703
- return abs(
704
- child_widget.rect.bottom
705
- - (
706
- parent_widget.get_inner_bottom()-
707
- parent_widget.get_inner_height() * self.margin)
708
- ) < 0.01
709
-
710
- def apply_constraint(self, parent_widget, child_widget):
711
- child_widget.set_position(
712
- child_widget.rect.x,
713
- parent_widget.get_inner_bottom()
714
- - child_widget.rect.h
715
- - parent_widget.get_inner_height() * self.margin,
716
- )
717
-
718
- def __eq__(self,other:"Constraint")->bool:
719
- if not isinstance(other,self.__class__):
720
- return False
721
- return (
722
- other.name == self.name and
723
- other.margin == self.margin
724
- )
725
-
726
- class PercentageMarginTop(Constraint):
727
- def __init__(self, margin: float):
728
- super().__init__()
729
- self.margin = margin
730
- self.affects_position = True
731
-
732
- def evaluate(self, parent_widget, child_widget):
733
- return abs(
734
- child_widget.rect.top
735
- - (
736
- parent_widget.get_inner_top()+
737
- parent_widget.get_inner_height() * self.margin)
738
- ) < 0.01
739
-
740
- def apply_constraint(self, parent_widget, child_widget):
741
- child_widget.set_position(
742
- child_widget.rect.x,
743
- parent_widget.get_inner_top()
744
- + parent_widget.get_inner_height() * self.margin,
745
- )
746
-
747
- def __eq__(self,other:"Constraint")->bool:
748
- if not isinstance(other,self.__class__):
749
- return False
750
- return (
751
- other.name == self.name and
752
- other.margin == self.margin
753
- )
754
-
755
- class PercentageMarginLeft(Constraint):
756
- def __init__(self, margin: float):
757
- super().__init__()
758
- self.margin = margin
759
- self.affects_position = True
760
-
761
- def evaluate(self, parent_widget, child_widget):
762
- return (
763
- child_widget.rect.left
764
- == parent_widget.get_inner_left()
765
- + parent_widget.get_inner_width() * self.margin
766
- )
767
-
768
- def apply_constraint(self, parent_widget, child_widget):
769
- if not self.evaluate(parent_widget, child_widget):
770
- child_widget.set_position(
771
- parent_widget.get_inner_left()
772
- + parent_widget.get_inner_width() * self.margin,
773
- child_widget.rect.y,
774
- )
775
-
776
- def __eq__(self,other:"Constraint")->bool:
777
- if not isinstance(other,self.__class__):
778
- return False
779
- return (
780
- other.name == self.name and
781
- other.margin == self.margin
782
- )
783
-
784
- class PercentageMarginRight(Constraint):
785
- def __init__(self, margin: float):
786
- super().__init__()
787
- self.margin = margin
788
- self.affects_position = True
789
-
790
- def evaluate(self, parent_widget, child_widget):
791
- return (
792
- child_widget.rect.right
793
- == parent_widget.get_inner_right()
794
- - parent_widget.get_inner_width() * self.margin
795
- )
796
-
797
- def apply_constraint(self, parent_widget, child_widget):
798
- child_widget.set_position(
799
- parent_widget.get_inner_right()
800
- - child_widget.rect.w
801
- - parent_widget.get_inner_width() * self.margin,
802
- child_widget.rect.y,
803
- )
804
-
805
- def __eq__(self,other:"Constraint")->bool:
806
- if not isinstance(other,self.__class__):
807
- return False
808
- return (
809
- other.name == self.name and
810
- other.margin == self.margin
811
- )
812
-
813
- class PercentageRectMarginBottom(Constraint):
814
- def __init__(self, margin: float):
815
- super().__init__()
816
- self.margin = margin
817
- self.affects_position = True
818
-
819
- def evaluate(self, parent_widget, child_widget):
820
- return (
821
- child_widget.rect.bottom
822
- == parent_widget.rect.top + parent_widget.rect.height * self.margin
823
- )
824
-
825
- def apply_constraint(self, parent_widget, child_widget):
826
- child_widget.set_position(
827
- child_widget.rect.x,
828
- parent_widget.rect.bottom
829
- - child_widget.rect.height
830
- - parent_widget.rect.height * self.margin,
831
- )
832
-
833
- def __eq__(self,other:"Constraint")->bool:
834
- if not isinstance(other,self.__class__):
835
- return False
836
- return (
837
- other.name == self.name and
838
- other.margin == self.margin
839
- )
840
-
841
- class PercentageRectMarginTop(Constraint):
842
- def __init__(self, margin: float):
843
- super().__init__()
844
- self.margin = margin
845
- self.affects_position = True
846
-
847
- def evaluate(self, parent_widget, child_widget):
848
- return (
849
- child_widget.rect.top
850
- == parent_widget.rect.top + parent_widget.rect.height * self.margin
851
- )
852
-
853
- def apply_constraint(self, parent_widget, child_widget):
854
- child_widget.set_position(
855
- child_widget.rect.x,
856
- parent_widget.rect.top + parent_widget.rect.height * self.margin,
857
- )
858
-
859
- def __eq__(self,other:"Constraint")->bool:
860
- if not isinstance(other,self.__class__):
861
- return False
862
- return (
863
- other.name == self.name and
864
- other.margin == self.margin
865
- )
866
-
867
- class PercentageRectMarginLeft(Constraint):
868
- def __init__(self, margin: float):
869
- super().__init__()
870
- self.margin = margin
871
- self.affects_position = True
872
-
873
- def evaluate(self, parent_widget, child_widget):
874
- return (
875
- child_widget.rect.left
876
- == parent_widget.rect.left + parent_widget.rect.width * self.margin
877
- )
878
-
879
- def apply_constraint(self, parent_widget, child_widget):
880
- if not self.evaluate(parent_widget, child_widget):
881
- child_widget.set_position(
882
- parent_widget.rect.left + parent_widget.rect.width * self.margin,
883
- child_widget.rect.y,
884
- )
885
-
886
- def __eq__(self,other:"Constraint")->bool:
887
- if not isinstance(other,self.__class__):
888
- return False
889
- return (
890
- other.name == self.name and
891
- other.margin == self.margin
892
- )
893
-
894
- class PercentageRectMarginRight(Constraint):
895
- def __init__(self, margin: float):
896
- super().__init__()
897
- self.margin = margin
898
- self.affects_position = True
899
-
900
- def evaluate(self, parent_widget, child_widget):
901
- return (
902
- child_widget.rect.right
903
- == parent_widget.rect.right - parent_widget.rect.width * self.margin
904
- )
905
-
906
- def apply_constraint(self, parent_widget, child_widget):
907
- child_widget.set_position(
908
- parent_widget.rect.right
909
- - child_widget.rect.width
910
- - parent_widget.rect.width * self.margin,
911
- child_widget.rect.y,
912
- )
913
-
914
- def __eq__(self,other:"Constraint")->bool:
915
- if not isinstance(other,self.__class__):
916
- return False
917
- return (
918
- other.name == self.name and
919
- other.margin == self.margin
920
- )
921
-
922
-
923
-
924
-
925
- class Grow(Constraint, ABC):
926
-
927
- @abstractmethod
928
- def evaluate(self, parent_widget, child_widget):
929
- pass
930
-
931
- @abstractmethod
932
- def apply_constraint(self, parent_widget, child_widget):
933
- pass
934
-
935
- def __eq__(self, other: "Constraint") -> bool:
936
- return isinstance(other, self.__class__)
937
-
938
-
939
- class GrowH(Grow):
940
- def __init__(self):
941
- super().__init__()
942
- self.affects_size = True
943
-
944
- def evaluate(self, parent_widget, child_widget):
945
- siblings = [s for s in parent_widget.children if s != child_widget]
946
- sibling_width = sum(s.rect.w for s in siblings)
947
- return abs(parent_widget.get_inner_width() - (child_widget.rect.w + sibling_width)) == 0
948
-
949
- def apply_constraint(self, parent_widget, child_widget):
950
- child_widget.set_autoresize_w(False)
951
- siblings = [s for s in parent_widget.children if s != child_widget]
952
- sibling_width = sum(s.rect.w for s in siblings)
953
- # print(parent_widget.get_inner_width() - sibling_width," is new size")
954
- if hasattr(parent_widget,"layout"):
955
- w = parent_widget.layout.get_free_space()[0]
956
- else:
957
- w = parent_widget.get_inner_width()
958
- child_widget.set_size((w - sibling_width, None))
959
-
960
-
961
- class GrowV(Grow):
962
- def __init__(self):
963
- super().__init__()
964
- self.affects_size = True
965
-
966
- def evaluate(self, parent_widget, child_widget):
967
- siblings = [s for s in parent_widget.children if s != child_widget]
968
- sibling_height = sum(s.rect.h for s in siblings)
969
- return abs(parent_widget.get_inner_height() - (child_widget.rect.h + sibling_height)) == 0
970
-
971
- def apply_constraint(self, parent_widget, child_widget):
972
- child_widget.set_autoresize_h(False)
973
- siblings = [s for s in parent_widget.children if s != child_widget]
974
- sibling_height = sum(s.rect.h for s in siblings)
975
- if hasattr(parent_widget,"layou"):
976
- h = parent_widget.layout.get_free_space()[1]
977
- else:
978
- h = parent_widget.get_inner_height()
979
-
980
- child_widget.set_size((None, h- sibling_height))