Exemplo n.º 1
0
def test_animationgroup():
    group = core.AnimationGroup()
    anim = core.PropertyAnimation()
    anim2 = core.PropertyAnimation()
    group += anim
    group += anim2
    assert group[0] == anim
    assert group[0:2] == [anim, anim2]
    group[1] = core.PropertyAnimation()
    assert len(group) == 2
    del group[0]
    assert len(group) == 1
Exemplo n.º 2
0
 def __init__(
     self, duration: int = 1000, easing: core.easingcurve.TypeStr = "in_out_sine"
 ):
     super().__init__()
     self.anim1 = core.PropertyAnimation()
     self.anim2 = core.PropertyAnimation()
     self.set_easing(easing)
     self.set_start_value((0, 0))
     # self.set_end_value(core.Point(0, 100))
     self.addAnimation(self.anim1)
     self.addAnimation(self.anim2)
     self.set_duration(duration)
Exemplo n.º 3
0
def test_propertyanimation():
    animation = core.PropertyAnimation()
    button = widgets.PushButton()
    animation.set_easing("in_cubic")
    assert animation.get_easing() == "in_cubic"
    animation.set_direction("forward")
    with pytest.raises(InvalidParamError):
        animation.set_direction("test")
    assert animation.get_direction() == "forward"
    assert animation.get_state() == "stopped"
    animation.setDuration(100)
    assert len(animation) == 100
    animation.apply_to(button, "geometry")
    assert animation.get_property_name() == "geometry"
    animation.setEndValue(core.Rect(20, 50, 70, 89))
    animation[0] = 1
    assert animation[0] == 1
    with pytest.raises(InvalidParamError):
        animation.start_animation("test")
    # TODO: this one breaks PySide2 test
    # animation.start_animation("keep")

    def test(val):
        return val

    animation.set_easing(test)
    # PySide2 looses custom fn here
    if prettyqt.qt.API.startswith("pyqt"):
        assert animation.get_easing() == test
    else:
        with pytest.raises(AttributeError):
            animation.get_easing()
Exemplo n.º 4
0
 def add_property_animation(
         self, obj: QtCore.QObject,
         attribute: types.ByteArrayType) -> core.PropertyAnimation:
     if isinstance(attribute, str):
         attribute = attribute.encode()
     if isinstance(attribute, bytes):
         attribute = QtCore.QByteArray(attribute)
     anim = core.PropertyAnimation(obj, attribute)
     self.addAnimation(anim)
     return anim
Exemplo n.º 5
0
    def __init__(
        self,
        message: str,
        category: CategoryStr,
        timeout=None,
        autohide: bool = False,
        buttontext: str | None = None,
        *args,
        **kwargs,
    ):
        super().__init__(*args, **kwargs)
        # Store instance variables
        self.message = message
        self.category = category
        self.timeout = timeout
        self.autohide = autohide

        # Set Object name for reference
        self.setObjectName(category)
        self.set_layout("horizontal", margin=0)

        # Create a message area
        message_area = widgets.BoxLayout("horizontal")
        message_area.set_margin(0)

        # Create the layout
        self.message_display = MessageLabel()
        self.message_display.setObjectName("message")
        self.message_display.set_size_policy("minimum", "minimum")
        self.message_display.setWordWrap(True)

        # Create a button that can close notifications
        if not buttontext:
            close_button = widgets.PushButton("\u2715")
        else:
            close_button = widgets.PushButton(buttontext)
            close_button.setStyleSheet("text-decoration: underline;")
        close_button.set_size_policy("fixed", "fixed")
        close_button.setFlat(True)
        close_button.setObjectName("closeButton")
        close_button.clicked.connect(self.close_clicked)

        # Add everything together
        message_area.addWidget(self.message_display)
        # message_area.addStretch(1)
        message_area.addWidget(close_button)
        self.layout().addLayout(message_area)

        # Initialize some variables
        # self.setStyle(category)
        self.setVisible(False)

        # Flag that is set if notification is being removed. This can be used to
        # make sure that even though the notification has not been really removed
        # yet (because it is for example in a fade out animation), it is in the
        # process of being removed
        self.is_being_removed = False
        self.is_fading_in = False
        self.opacity_effect = widgets.GraphicsOpacityEffect(self)

        # Fade in animation
        self.fade_in_anim = core.PropertyAnimation()
        self.fade_in_anim.apply_to(self.opacity_effect, "opacity")
        self.fade_in_anim.set_range(0.0, 1.0)

        # Fade out animation
        self.fade_out_anim = core.PropertyAnimation()
        self.fade_out_anim.apply_to(self.opacity_effect, "opacity")
        self.fade_in_anim.set_range(1.0, 0.0)
Exemplo n.º 6
0
        """Start the animation.

        Args:
            policy: animation policy

        Raises:
            InvalidParamError: animation policy does not exist
        """
        if policy not in DELETION_POLICY:
            raise InvalidParamError(policy, DELETION_POLICY)
        self.start(DELETION_POLICY[policy])

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

        Args:
            policy: animation policy

        Raises:
            InvalidParamError: animation policy does not exist
        """
        self.stop()
        self.start_animation(policy)


if __name__ == "__main__":
    anim1 = core.PropertyAnimation()
    anim2 = core.PropertyAnimation()
    group = anim1 | anim2
    print(type(group))