Пример #1
0
    def __init__(self, image):
        self.isRunning = True
        self.image = image
        self.frame = QPixmap(image.rect().size() + QSize(0, 20))
        self.frame.fill(Qt.transparent)
        QSplashScreen.__init__(self, self.frame,
                               QtCore.Qt.WindowStaysOnTopHint)

        # COMPARISON BETWEEN EASING CURVES
        easingCurve = QEasingCurve()
        easingCurve.setCustomType(self.funkyEasingFunc)
        self.anim = LoadingDotsWidget(None,
                                      ypos=110,
                                      xsize=self.image.rect().size().width() +
                                      10,
                                      sep=40,
                                      offsetx=0,
                                      speed=100,
                                      easingcurve=easingCurve,
                                      amount=3,
                                      loopingOn=3)
        self.anim.s_externalRepaint.connect(self.update)
        self.frameSize = self.rect().size() + QSize(0, 20)
Пример #2
0
class PaintWidget(QtWidgets.QWidget):
    def __init__(self):
        super(PaintWidget, self).__init__()

        self.isLooping = True
        self.yPosition = 100

        self.dotsRadius = 8
        self.dotsColor = QtGui.QColor(255, 0, 15)
        self.dotsAmount = 3
        self.dotsSpeed = 500
        self.dotsSeparation = 70

        # ANIMATION PARAMETERS
        self.customEasing = QEasingCurve()
        self.customEasing.setCustomType(self.customEasingFunc)
        self.animationSize = 500

        self.dotsPosition = []
        self.dotsAnimations = []

        self.createPosition()
        self.createAnimation()

    @staticmethod
    def customEasingFunc(x):
        return 3.3 * (x - 0.51) ** 3 + 0.2 * (x - 7.9) + 2

    def startMoving(self):
        print(self.dotsAnimations)
        separationTime = (self.dotsSeparation / self.dotsSpeed) * 1000
        for i, animation in enumerate(self.dotsAnimations):
            QtCore.QTimer.singleShot(i * separationTime, animation.start)

    def createPosition(self):
        for i in range(self.dotsAmount):
            self.dotsPosition.append(QtCore.QPoint(0, self.yPosition))


    def createAnimation(self):
        duration = (self.animationSize / self.dotsSpeed)*1000

        for i, _ in enumerate(self.dotsPosition):
            anim = QtCore.QVariantAnimation(self, startValue=0, endValue=self.animationSize,
                                            duration=duration, easingCurve=self.customEasing)
            wrapper = partial(self.updatePosition, i)
            anim.valueChanged.connect(wrapper)

            if self.isLooping:
                anim.finished.connect(anim.start)

            self.dotsAnimations.append(anim)

    @QtCore.pyqtSlot(int, QtCore.QVariant)
    def updatePosition(self, i, position):
        self.dotsPosition[i] = QtCore.QPoint(position, self.yPosition)
        self.update()

    def paintEvent(self, event):
        painter = QtGui.QPainter(self)
        painter.fillRect(self.rect(), QtCore.Qt.transparent)
        painter.setRenderHint(QtGui.QPainter.Antialiasing, True)
        painter.setPen(QtCore.Qt.NoPen)

        for position in self.dotsPosition:
            painter.setBrush(
                QtGui.QBrush(self.dotsColor, QtCore.Qt.SolidPattern)
            )
            painter.drawEllipse(position, self.dotsRadius, self.dotsRadius)