Skip to content

Fx

⋔ Inheritance diagram

graph TD
  1473293675552["animations.Fx"]
  140713234304496["builtins.object"]
  140713234304496 --> 1473293675552

🛈 DocStrings

Fx delegator which allows a quick and easy way to animate widgets.

Source code in prettyqt\animations\fx.py
class Fx:
    """Fx delegator which allows a quick and easy way to animate widgets."""

    def __init__(self, widget: widgets.QWidget):
        self._widget = widget
        self._wrapper = None
        # self._meta = core.MetaObject(self._widget.metaObject())

    def __getitem__(self, value: str) -> AnimationWrapper:
        value = helpers.to_lower_camel(value)
        logger.debug(f"Building {value!r} PropertyAnimation for {self._widget!r}")
        self._wrapper = AnimationWrapper(value, self)
        return self._wrapper

    # def __getattr__(self, attr):
    #     return self.__getitem__(attr)

    def set_colorize_effect(
        self,
        color: datatypes.ColorType,
        strength: float = 0.7,
    ) -> widgets.GraphicsColorizeEffect:
        effect = widgets.GraphicsColorizeEffect(self._widget)
        effect.setColor(colors.get_color(color))
        effect.setStrength(strength)
        self._widget.setGraphicsEffect(effect)
        return effect

    def set_opacity_effect(self, opacity: float) -> widgets.GraphicsOpacityEffect:
        effect = widgets.GraphicsOpacityEffect(self._widget)
        effect.setOpacity(opacity)
        self._widget.setGraphicsEffect(effect)
        return effect

    def set_blur_effect(self, radius: int) -> widgets.GraphicsBlurEffect:
        effect = widgets.GraphicsBlurEffect(self._widget)
        effect.setBlurRadius(radius)
        self._widget.setGraphicsEffect(effect)
        return effect

    def set_drop_shadow_effect(
        self,
        radius: int = 10,
        color: datatypes.ColorType = "blue",
    ) -> widgets.GraphicsDropShadowEffect:
        effect = widgets.GraphicsDropShadowEffect(self._widget)
        effect.setBlurRadius(radius)
        effect.setColor(colors.get_color(color))
        self._widget.setGraphicsEffect(effect)
        return effect

    def fade_in(
        self,
        duration: int = 1000,
        easing: core.easingcurve.TypeStr = "in_out_sine",
        delay: int = 0,
    ) -> AnimationTimer:
        """Trigger a fade-in animation."""
        return self["windowOpacity"].transition_from(
            0.0,
            easing=easing,
            duration=duration,
            delay=delay,
        )

    def fade_out(
        self,
        duration: int = 1000,
        easing: core.easingcurve.TypeStr = "in_out_sine",
        delay: int = 0,
    ) -> AnimationTimer:
        """Trigger a fade-out animation."""
        return self["windowOpacity"].transition_to(
            0.0,
            easing=easing,
            duration=duration,
            delay=delay,
        )

    def zoom(
        self,
        duration: int = 1000,
        start: float = 1.0,
        end: float = 1.0,
        easing: core.easingcurve.TypeStr = "in_out_sine",
        anchor: str = "center",
        delay: int = 0,
    ) -> AnimationTimer:
        """Trigger a zoom animation with given anchor."""
        from prettyqt import animations

        anim = animations.ZoomAnimation(parent=self._widget, anchor=anchor)
        anim.set_easing(easing)
        anim.set_start_value(start)
        anim.set_end_value(end)
        anim.set_duration(duration)
        self.run(anim, delay)
        return anim

    def slide(
        self,
        duration: int = 1000,
        start=None,
        end=None,
        easing: core.easingcurve.TypeStr = "in_out_sine",
        delay: int = 0,
        reverse: bool = False,
        single_shot: bool = True,
    ) -> AnimationTimer:
        anim = core.PropertyAnimation(parent=self._widget)
        anim.set_easing(easing)
        pos = self._widget.geometry().topLeft()
        start_offset = core.Point(0, 0) if start is None else datatypes.to_point(start)
        end_offset = core.Point(0, 0) if end is None else datatypes.to_point(end)
        anim.set_start_value(pos + start_offset)
        anim.set_end_value(pos + end_offset)
        anim.setDuration(duration)
        anim.apply_to(self._widget.pos)
        if reverse:
            anim.append_reversed()
        return self.run(anim, delay, single_shot=single_shot)

    def bounce(
        self,
        end: datatypes.PointType,
        easing: core.easingcurve.TypeStr = "in_out_sine",
        duration: int = 1000,
        delay: int = 0,
    ) -> AnimationTimer:
        """Trigger a move animation to given offset and return to original position."""
        return self["pos"].transition_to(
            end,
            easing=easing,
            duration=duration,
            delay=delay,
            reverse=True,
        )

    def run(
        self,
        animation: core.QPropertyAnimation,
        delay: int | str = 0,
        single_shot: bool = True,
    ) -> AnimationTimer:
        """Run an animation with given delay.

        Arguments:
            animation: Animation to run
            delay: delay after which animation should start
            single_shot: whethere the animation should trigger once or repeat

        Returns:
            AnimationTimer, a core.Timer subclass with the PropertyAnimation attached.
        """
        if not animation.targetObject().isVisible():
            logger.info("Attention. Starting animation for invisible widget.")
        logger.debug(f"starting {animation!r} with {delay=}. ({single_shot=})")
        timer = AnimationTimer(
            parent=self._widget,
            single_shot=single_shot,
            interval=helpers.parse_time(delay) if isinstance(delay, str) else delay,
            animation=animation,
        )
        timer.start()
        return timer

    def highlight_widget(self, widget: widgets.QWidget):
        from prettyqt.custom_widgets.overlayborder import FocusWidget

        widget = FocusWidget(self, widget)
        widget.show()

bounce(end: datatypes.PointType, easing: core.easingcurve.TypeStr = 'in_out_sine', duration: int = 1000, delay: int = 0) -> AnimationTimer

Trigger a move animation to given offset and return to original position.

Source code in prettyqt\animations\fx.py
def bounce(
    self,
    end: datatypes.PointType,
    easing: core.easingcurve.TypeStr = "in_out_sine",
    duration: int = 1000,
    delay: int = 0,
) -> AnimationTimer:
    """Trigger a move animation to given offset and return to original position."""
    return self["pos"].transition_to(
        end,
        easing=easing,
        duration=duration,
        delay=delay,
        reverse=True,
    )

fade_in(duration: int = 1000, easing: core.easingcurve.TypeStr = 'in_out_sine', delay: int = 0) -> AnimationTimer

Trigger a fade-in animation.

Source code in prettyqt\animations\fx.py
def fade_in(
    self,
    duration: int = 1000,
    easing: core.easingcurve.TypeStr = "in_out_sine",
    delay: int = 0,
) -> AnimationTimer:
    """Trigger a fade-in animation."""
    return self["windowOpacity"].transition_from(
        0.0,
        easing=easing,
        duration=duration,
        delay=delay,
    )

fade_out(duration: int = 1000, easing: core.easingcurve.TypeStr = 'in_out_sine', delay: int = 0) -> AnimationTimer

Trigger a fade-out animation.

Source code in prettyqt\animations\fx.py
def fade_out(
    self,
    duration: int = 1000,
    easing: core.easingcurve.TypeStr = "in_out_sine",
    delay: int = 0,
) -> AnimationTimer:
    """Trigger a fade-out animation."""
    return self["windowOpacity"].transition_to(
        0.0,
        easing=easing,
        duration=duration,
        delay=delay,
    )

run(animation: core.QPropertyAnimation, delay: int | str = 0, single_shot: bool = True) -> AnimationTimer

Run an animation with given delay.

Parameters:

Name Type Description Default
animation QPropertyAnimation

Animation to run

required
delay int | str

delay after which animation should start

0
single_shot bool

whethere the animation should trigger once or repeat

True
Source code in prettyqt\animations\fx.py
def run(
    self,
    animation: core.QPropertyAnimation,
    delay: int | str = 0,
    single_shot: bool = True,
) -> AnimationTimer:
    """Run an animation with given delay.

    Arguments:
        animation: Animation to run
        delay: delay after which animation should start
        single_shot: whethere the animation should trigger once or repeat

    Returns:
        AnimationTimer, a core.Timer subclass with the PropertyAnimation attached.
    """
    if not animation.targetObject().isVisible():
        logger.info("Attention. Starting animation for invisible widget.")
    logger.debug(f"starting {animation!r} with {delay=}. ({single_shot=})")
    timer = AnimationTimer(
        parent=self._widget,
        single_shot=single_shot,
        interval=helpers.parse_time(delay) if isinstance(delay, str) else delay,
        animation=animation,
    )
    timer.start()
    return timer

zoom(duration: int = 1000, start: float = 1.0, end: float = 1.0, easing: core.easingcurve.TypeStr = 'in_out_sine', anchor: str = 'center', delay: int = 0) -> AnimationTimer

Trigger a zoom animation with given anchor.

Source code in prettyqt\animations\fx.py
def zoom(
    self,
    duration: int = 1000,
    start: float = 1.0,
    end: float = 1.0,
    easing: core.easingcurve.TypeStr = "in_out_sine",
    anchor: str = "center",
    delay: int = 0,
) -> AnimationTimer:
    """Trigger a zoom animation with given anchor."""
    from prettyqt import animations

    anim = animations.ZoomAnimation(parent=self._widget, anchor=anchor)
    anim.set_easing(easing)
    anim.set_start_value(start)
    anim.set_end_value(end)
    anim.set_duration(duration)
    self.run(anim, delay)
    return anim