|
16 | 16 |
|
17 | 17 | from collections.abc import Iterable, Sequence
|
18 | 18 | from copy import deepcopy
|
| 19 | +from functools import partialmethod |
19 | 20 | from typing import TYPE_CHECKING, Callable
|
20 | 21 |
|
21 | 22 | from typing_extensions import Self
|
@@ -479,6 +480,52 @@ def is_introducer(self) -> bool:
|
479 | 480 | """
|
480 | 481 | return self.introducer
|
481 | 482 |
|
| 483 | + @classmethod |
| 484 | + def __init_subclass__(cls, **kwargs) -> None: |
| 485 | + super().__init_subclass__(**kwargs) |
| 486 | + |
| 487 | + cls._original__init__ = cls.__init__ |
| 488 | + |
| 489 | + @classmethod |
| 490 | + def set_default(cls, **kwargs) -> None: |
| 491 | + """Sets the default values of keyword arguments. |
| 492 | +
|
| 493 | + If this method is called without any additional keyword |
| 494 | + arguments, the original default values of the initialization |
| 495 | + method of this class are restored. |
| 496 | +
|
| 497 | + Parameters |
| 498 | + ---------- |
| 499 | +
|
| 500 | + kwargs |
| 501 | + Passing any keyword argument will update the default |
| 502 | + values of the keyword arguments of the initialization |
| 503 | + function of this class. |
| 504 | +
|
| 505 | + Examples |
| 506 | + -------- |
| 507 | +
|
| 508 | + .. manim:: ChangeDefaultAnimation |
| 509 | +
|
| 510 | + class ChangeDefaultAnimation(Scene): |
| 511 | + def construct(self): |
| 512 | + Rotate.set_default(run_time=2, rate_func=rate_functions.linear) |
| 513 | + Indicate.set_default(color=None) |
| 514 | +
|
| 515 | + S = Square(color=BLUE, fill_color=BLUE, fill_opacity=0.25) |
| 516 | + self.add(S) |
| 517 | + self.play(Rotate(S, PI)) |
| 518 | + self.play(Indicate(S)) |
| 519 | +
|
| 520 | + Rotate.set_default() |
| 521 | + Indicate.set_default() |
| 522 | +
|
| 523 | + """ |
| 524 | + if kwargs: |
| 525 | + cls.__init__ = partialmethod(cls.__init__, **kwargs) |
| 526 | + else: |
| 527 | + cls.__init__ = cls._original__init__ |
| 528 | + |
482 | 529 |
|
483 | 530 | def prepare_animation(
|
484 | 531 | anim: Animation | mobject._AnimationBuilder,
|
|
0 commit comments