Skip to content

AbstractAnimationMixin

Base classes

Name Children Inherits
ObjectMixin
prettyqt.core.object

Subclasses

Class Module Description
AbstractAnimation prettyqt.core.abstractanimation
VariantAnimationMixin prettyqt.core.variantanimation
PauseAnimation prettyqt.core.pauseanimation
AnimationGroupMixin prettyqt.core.animationgroup

⋔ Inheritance diagram

graph TD
  1473299791600["core.AbstractAnimationMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473299815024 --> 1473299791600
  140713234304496 --> 1473299815024

🛈 DocStrings

Bases: ObjectMixin

The base of all animations.

Source code in prettyqt\core\abstractanimation.py
class AbstractAnimationMixin(core.ObjectMixin):
    """The base of all animations."""

    def __len__(self):
        return self.duration()

    def __and__(self, other: core.QAbstractAnimation) -> core.SequentialAnimationGroup:
        group = core.SequentialAnimationGroup()
        group.addAnimation(self)
        group.addAnimation(other)
        return group

    def __or__(self, other: core.QAbstractAnimation) -> core.ParallelAnimationGroup:
        group = core.ParallelAnimationGroup()
        group.addAnimation(self)
        group.addAnimation(other)
        return group

    def _get_map(self):
        maps = super()._get_map()
        maps |= {"direction": DIRECTION, "state": STATE}
        return maps

    def toggle_direction(self):
        Direction = AbstractAnimation.Direction
        is_forward = self.direction() == Direction.Forward
        direction = Direction.Backward if is_forward else Direction.Forward
        self.setDirection(direction)

    def set_direction(self, direction: DirectionStr | core.QAbstractAnimation.Direction):
        """Set animation direction.

        Args:
            direction: animation direction
        """
        self.setDirection(DIRECTION.get_enum_value(direction))

    def get_direction(self) -> DirectionStr:
        """Get the current animation direction.

        Returns:
            animation direction
        """
        return DIRECTION.inverse[self.direction()]

    def get_state(self) -> StateStr:
        """Get the current animation state.

        Returns:
            animation state
        """
        return STATE.inverse[self.state()]

    def start_animation(
        self,
        policy: DeletionPolicyStr | core.QAbstractAnimation.DeletionPolicy = "keep",
        interval: int = 0,
        single_shot: bool = True,
    ):
        """Start the animation.

        Args:
            policy: animation policy
            interval: time interval / delay for timer
            single_shot: whether animation gets triggered once or in intervals
        """
        if policy in DELETION_POLICY:
            policy = DELETION_POLICY[policy]
        if interval:
            fn = functools.partial(self.start, policy)
            self.start_callback_timer(fn, interval, single_shot=single_shot)
        else:
            self.start(policy)

    def restart_animation(
        self,
        policy: DeletionPolicyStr | core.QAbstractAnimation.DeletionPolicy = "keep",
    ):
        """Restart the animation.

        Args:
            policy: animation policy
        """
        self.stop()
        self.start_animation(policy)

    def run(self, delay: int = 0, single_shot: bool = True):
        self.start_callback_timer(self.start, delay, single_shot=single_shot)

get_direction() -> DirectionStr

Get the current animation direction.

Source code in prettyqt\core\abstractanimation.py
def get_direction(self) -> DirectionStr:
    """Get the current animation direction.

    Returns:
        animation direction
    """
    return DIRECTION.inverse[self.direction()]

get_state() -> StateStr

Get the current animation state.

Source code in prettyqt\core\abstractanimation.py
def get_state(self) -> StateStr:
    """Get the current animation state.

    Returns:
        animation state
    """
    return STATE.inverse[self.state()]

restart_animation(policy: DeletionPolicyStr | core.QAbstractAnimation.DeletionPolicy = 'keep')

Restart the animation.

Parameters:

Name Type Description Default
policy DeletionPolicyStr | DeletionPolicy

animation policy

'keep'
Source code in prettyqt\core\abstractanimation.py
def restart_animation(
    self,
    policy: DeletionPolicyStr | core.QAbstractAnimation.DeletionPolicy = "keep",
):
    """Restart the animation.

    Args:
        policy: animation policy
    """
    self.stop()
    self.start_animation(policy)

set_direction(direction: DirectionStr | core.QAbstractAnimation.Direction)

Set animation direction.

Parameters:

Name Type Description Default
direction DirectionStr | Direction

animation direction

required
Source code in prettyqt\core\abstractanimation.py
def set_direction(self, direction: DirectionStr | core.QAbstractAnimation.Direction):
    """Set animation direction.

    Args:
        direction: animation direction
    """
    self.setDirection(DIRECTION.get_enum_value(direction))

start_animation(policy: DeletionPolicyStr | core.QAbstractAnimation.DeletionPolicy = 'keep', interval: int = 0, single_shot: bool = True)

Start the animation.

Parameters:

Name Type Description Default
policy DeletionPolicyStr | DeletionPolicy

animation policy

'keep'
interval int

time interval / delay for timer

0
single_shot bool

whether animation gets triggered once or in intervals

True
Source code in prettyqt\core\abstractanimation.py
def start_animation(
    self,
    policy: DeletionPolicyStr | core.QAbstractAnimation.DeletionPolicy = "keep",
    interval: int = 0,
    single_shot: bool = True,
):
    """Start the animation.

    Args:
        policy: animation policy
        interval: time interval / delay for timer
        single_shot: whether animation gets triggered once or in intervals
    """
    if policy in DELETION_POLICY:
        policy = DELETION_POLICY[policy]
    if interval:
        fn = functools.partial(self.start, policy)
        self.start_callback_timer(fn, interval, single_shot=single_shot)
    else:
        self.start(policy)