def __init__(self):
        super(Demo, self).__init__()
        self.resize(600, 600)

        self.plane = QLabel(self)
        self.plane.resize(50, 50)
        self.plane.setPixmap(QPixmap('plane.gif').scaled(
            self.plane.size()))  # 1

        self.animation1 = QPropertyAnimation(self.plane, b'geometry')
        self.animation1.setDuration(2000)
        self.animation1.setStartValue(QRect(300, 500, 50, 50))
        self.animation1.setEndValue(QRect(200, 400, 50, 50))
        self.animation1.setLoopCount(1)

        self.animation2 = QPropertyAnimation(self.plane, b'geometry')
        self.animation2.setDuration(2000)
        self.animation2.setStartValue(QRect(200, 400, 50, 50))
        self.animation2.setEndValue(QRect(400, 300, 50, 50))
        self.animation2.setLoopCount(1)

        self.animation3 = QPropertyAnimation(self.plane, b'geometry')
        self.animation3.setDuration(2000)
        self.animation3.setStartValue(QRect(400, 300, 50, 50))
        self.animation3.setEndValue(QRect(200, 200, 50, 50))
        self.animation3.setLoopCount(1)

        self.animation_group = QSequentialAnimationGroup(self)  # 2
        self.animation_group.addAnimation(self.animation1)
        self.animation_group.addPause(1000)
        self.animation_group.addAnimation(self.animation2)
        self.animation_group.addAnimation(self.animation3)
        self.animation_group.start()
Ejemplo n.º 2
0
 def __init__(self, state):
     super().__init__()
     self.interactive = False
     self.figures = copy.deepcopy(state.state)
     self.rows = len(self.figures)
     self.animationGroup = QSequentialAnimationGroup(self)
     self.initState(state)
Ejemplo n.º 3
0
    def __init__(self,
                 *args,
                 pulse_unchecked_color="#44999999",
                 pulse_checked_color="#4400B0EE",
                 **kwargs):

        self._pulse_radius = 0

        super().__init__(*args, **kwargs)

        self.animation = QPropertyAnimation(self, b"handle_position", self)
        self.animation.setEasingCurve(QEasingCurve.InOutCubic)
        self.animation.setDuration(200)  # time in ms

        self.pulse_anim = QPropertyAnimation(self, b"pulse_radius", self)
        self.pulse_anim.setDuration(350)  # time in ms
        self.pulse_anim.setStartValue(10)
        self.pulse_anim.setEndValue(20)

        self.animations_group = QSequentialAnimationGroup()
        self.animations_group.addAnimation(self.animation)
        self.animations_group.addAnimation(self.pulse_anim)

        self._pulse_unchecked_animation = QBrush(QColor(pulse_unchecked_color))
        self._pulse_checked_animation = QBrush(QColor(pulse_checked_color))
Ejemplo n.º 4
0
    def __init__(self, parent=None):
        QStatusBar.__init__(self, parent)
        self.setAutoFillBackground(
            True)  # set the widget background to be filled automatically

        # Define colours to use in animations
        red = QColor(255, 0, 0)
        red_transparent = QColor(255, 0, 0, alpha=0)
        green = QColor(0, 255, 0)
        green_transparent = QColor(0, 255, 0, alpha=0)

        # Setup fade out animation for red
        fade_out = QPropertyAnimation(self, b"back_color")
        fade_out.setStartValue(red)
        fade_out.setEndValue(red_transparent)
        fade_out.setDuration(2000)

        # Setup fade in animation for red
        fade_in = QPropertyAnimation(self, b"back_color")
        fade_in.setStartValue(red_transparent)
        fade_in.setEndValue(red)
        fade_in.setDuration(2000)

        # Setup stay animation for red
        stay_red = QPropertyAnimation(self, b"back_color")
        stay_red.setStartValue(red)
        stay_red.setEndValue(red)
        stay_red.setDuration(1000)

        # Setup animation group for no connection
        self._no_conn_anim = QSequentialAnimationGroup()
        self._no_conn_anim.addAnimation(fade_out)
        self._no_conn_anim.addAnimation(fade_in)
        self._no_conn_anim.addAnimation(stay_red)
        self._no_conn_anim.setLoopCount(-1)  # loop infinitely

        # Setup fade out animation for green
        fade_out = QPropertyAnimation(self, b"back_color")
        fade_out.setStartValue(green)
        fade_out.setEndValue(green_transparent)
        fade_out.setDuration(2000)

        # Setup fade in animation for green
        fade_in = QPropertyAnimation(self, b"back_color")
        fade_in.setStartValue(green_transparent)
        fade_in.setEndValue(green)
        fade_in.setDuration(2000)

        # Setup stay animation for green
        stay_green = QPropertyAnimation(self, b"back_color")
        stay_green.setStartValue(green)
        stay_green.setEndValue(green)
        stay_green.setDuration(1000)

        # Setup animation group for a connection
        self._conn_anim = QSequentialAnimationGroup()
        self._conn_anim.addAnimation(fade_out)
        self._conn_anim.addAnimation(fade_in)
        self._conn_anim.addAnimation(stay_green)
        self._conn_anim.setLoopCount(-1)
Ejemplo n.º 5
0
    def __init__(self, scatter):
        super(ScatterDataModifier, self).__init__()

        self.m_graph = scatter
        self.m_inputHandler = CustomInputHandler()

        self.m_graph.activeTheme().setType(Q3DTheme.ThemeDigia)
        self.m_graph.setShadowQuality(QAbstract3DGraph.ShadowQualityMedium)
        self.m_graph.scene().activeCamera().setCameraPreset(
            Q3DCamera.CameraPresetFront)

        self.m_graph.setAxisX(QValue3DAxis())
        self.m_graph.setAxisY(QValue3DAxis())
        self.m_graph.setAxisZ(QValue3DAxis())

        self.m_graph.axisX().setRange(-10.0, 10.0)
        self.m_graph.axisY().setRange(-5.0, 5.0)
        self.m_graph.axisZ().setRange(-5.0, 5.0)

        series = QScatter3DSeries()
        series.setItemLabelFormat("@xLabel, @yLabel, @zLabel")
        series.setMesh(QAbstract3DSeries.MeshCube)
        series.setItemSize(0.15)
        self.m_graph.addSeries(series)

        self.m_animationCameraX = QPropertyAnimation(
            self.m_graph.scene().activeCamera(), 'xRotation')
        self.m_animationCameraX.setDuration(20000)
        self.m_animationCameraX.setStartValue(0.0)
        self.m_animationCameraX.setEndValue(360.0)
        self.m_animationCameraX.setLoopCount(-1)

        upAnimation = QPropertyAnimation(self.m_graph.scene().activeCamera(),
                                         'yRotation')
        upAnimation.setDuration(9000)
        upAnimation.setStartValue(5.0)
        upAnimation.setEndValue(45.0)

        downAnimation = QPropertyAnimation(self.m_graph.scene().activeCamera(),
                                           'yRotation')
        downAnimation.setDuration(9000)
        downAnimation.setStartValue(45.0)
        downAnimation.setEndValue(5.0)

        self.m_animationCameraY = QSequentialAnimationGroup()
        self.m_animationCameraY.setLoopCount(-1)
        self.m_animationCameraY.addAnimation(upAnimation)
        self.m_animationCameraY.addAnimation(downAnimation)

        self.m_animationCameraX.start()
        self.m_animationCameraY.start()

        self.m_graph.setActiveInputHandler(self.m_inputHandler)

        self.m_selectionTimer = QTimer()
        self.m_selectionTimer.setInterval(10)
        self.m_selectionTimer.timeout.connect(self.triggerSelection)
        self.m_selectionTimer.start()
Ejemplo n.º 6
0
 def __init__(self):
     super().__init__()
     # 记录所有模块
     self.labels = []
     self.order = [x for x in range(9)]
     self.group = QSequentialAnimationGroup()
     self.solutions = []
     self.positions = []
     # 求解器
     self.sol = solution.Solution()
     self.initUI()
Ejemplo n.º 7
0
    def __init__(self, letters, player, scene):
        super(Hand, self).__init__()

        self.player = player
        self.letters = letters  # set of letters being used
        self.scene = scene

        self.extra_tiles = []
        self.tilesinplay = []  # tiles being moved
        self.hand = []  # details of hand as (letter, tile) tuple
        self.group = QSequentialAnimationGroup()
        self.group.finished.connect(self.an_end)
 def __init__(self, *args):
     super().__init__(*args)
     self.img = None
     self.thumb = None
     self.filename = None
     self.np_array = None
     self.status = ClassifiedImageBundle.UNDECIDED
     self.color = None
     self.keep = None
     self.show_buttons = False
     self._animation_progress = 1.0
     self.ani = QSequentialAnimationGroup()
     self.init_animation()
Ejemplo n.º 9
0
class AnimatedLabel(QLabel):
    """Class that extends the default functionality of the QLabel adding an animation to it"""

    SLOW_DURATION = 1500
    MID_DURATION = 1000
    FAST_DURATION = 500

    def __init__(self, parent=None, color='yellow'):
        """Constructor of the class

        Keyword Arguments:
            parent {ui.gui.views.toolbar.ToolBar} -- Parent of this widget (default: {None})
            color {str} -- Color name for the label (default: {'yellow'})
        """
        QLabel.__init__(self, parent)
        self.config_animation(self.MID_DURATION)
        self.setPixmap(QPixmap(':/assets/recording.png'))
        self.setFixedSize(40, 40)
        self.setAlignment(Qt.AlignCenter)
        self.setStyleSheet('color: ' + color)
        self.setScaledContents(True)

    def config_animation(self, duration):
        """Start a fading animation for this label

        Arguments:
            duration {int} -- Duration in milliseconds of a complete fadein-fadeout cycle
        """
        self.effect = QGraphicsOpacityEffect()
        self.setGraphicsEffect(self.effect)

        self.fadeout = QPropertyAnimation(self.effect, b"opacity")
        self.fadeout.setDuration(duration)
        self.fadeout.setStartValue(1)
        self.fadeout.setEndValue(0)

        self.fadein = QPropertyAnimation(self.effect, b"opacity")
        self.fadein.setDuration(duration)
        self.fadein.setStartValue(0)
        self.fadein.setEndValue(1)

        self.group_animation = QSequentialAnimationGroup()
        self.group_animation.addAnimation(self.fadein)
        self.group_animation.addAnimation(self.fadeout)
        self.group_animation.setLoopCount(-1)

    def start_animation(self):
        self.group_animation.start()

    def stop_animation(self):
        self.group_animation.stop()
Ejemplo n.º 10
0
    def __init__(self, view):
        self.view = view

        self.nodes = []
        self.edges = []
        self.connections = []
        self.directed_graph = Graph(directed=True)
        self.undirected_graph = Graph(directed=False)

        self.node_radius = 15
        self.node_fieldRadius = 80
        #self.graph_data = ''

        self.label_node_count = self.view.frame_graph.findChild(QLineEdit, 'lineEdit_node_count')

        self.DFS_sequential = QSequentialAnimationGroup()
        self.BFS_sequential = QSequentialAnimationGroup()
        self.DIJKSTRA_sequential = QSequentialAnimationGroup()
        self.sequential = QSequentialAnimationGroup()

        # Se atribuie cele 3 animatii ale algoritmilor animatiei de grup
        self.sequential.addAnimation(self.DFS_sequential)
        self.sequential.addAnimation(self.BFS_sequential)
        self.sequential.addAnimation(self.DIJKSTRA_sequential)

        self.gravity = True
        self.force_mode = False
        self.directed = False
Ejemplo n.º 11
0
 def __init__(self, tetris, tetritile):
     super(QTetris.QTetritile, self).__init__()
     tetritile.delegate = self
     self.color = self.colorMap[type(tetritile.tetrimino)]
     self.tetris = tetris
     self.moveAnimation = QSequentialAnimationGroup()
     self.dropAnimation = QPropertyAnimation(self, b"pos")
     self.collapseAnimation = QPropertyAnimation(self, b"pos")
     self.shiftAnimation = QPropertyAnimation(self, b"pos")
     self.collapseAnimation.finished.connect(
         lambda tetritile=tetritile: self.tetris.disappearEvent(
             tetritile))
     self.tetris.scene.addItem(self)
     self.setPos(QPointF(0, 4))
     self.moveEvent(tetritile)
Ejemplo n.º 12
0
    def start(self):
        height = self.height()
        width = self.width()
        for i in range(self._ball_numbers):
            self._seq_animations.append(QSequentialAnimationGroup(self))
            # 增加间隔
            self._seq_animations[i].addPause(self.duration_pause * i)
            # 第一段
            par_animation1 = QParallelAnimationGroup(self)
            ra = RoundAnimation(self._balls[i], b'pos', self)
            ra.setEasingCurve(self.ec)
            ra.setDuration(self.duration)
            ra.setStartValue(QPoint(2 * self.ball_radius, 2 * self.ball_radius))
            ra.setEndValue(QPoint(width - 2 * self.ball_radius, height - 2 * self.ball_radius))
            par_animation1.addAnimation(ra)
            pa = QPropertyAnimation(self._balls[i], b'_style', self)
            pa.setEasingCurve(self.ec)
            pa.setDuration(self.duration)
            pa.setStartValue(0)
            pa.setKeyValueAt(0.5, 255)
            pa.setEndValue(0)
            par_animation1.addAnimation(pa)
            self._seq_animations[i].addAnimation(par_animation1)
            # 增加间隔
            self._seq_animations[i].addPause(self.duration_pause * (self._ball_numbers - i - 1))

        for seq in self._seq_animations:
            seq.setLoopCount(-1)
            seq.start(QAbstractAnimation.DeleteWhenStopped)
Ejemplo n.º 13
0
 def __init__(self, parent=None, f=Qt.ToolTip | Qt.FramelessWindowHint):
     super(Notification, self).__init__(parent, f)
     self.parent = parent
     self.theme = self.parent.theme
     self.setObjectName('notification')
     self.setWindowModality(Qt.NonModal)
     self.setMinimumWidth(450)
     self._title, self._message = '', ''
     self._icons = dict()
     self.buttons = list()
     self.msgLabel = QLabel(self)
     self.msgLabel.setWordWrap(True)
     logo = QPixmap(82, 82)
     logo.load(':/images/vidcutter-small.png', 'PNG')
     logo_label = QLabel(self)
     logo_label.setPixmap(logo)
     self.left_layout = QVBoxLayout()
     self.left_layout.addWidget(logo_label)
     self.right_layout = QVBoxLayout()
     self.right_layout.addWidget(self.msgLabel)
     if sys.platform != 'win32':
         effect = QGraphicsOpacityEffect()
         effect.setOpacity(1)
         self.window().setGraphicsEffect(effect)
         self.animations = QSequentialAnimationGroup(self)
         self.pauseAnimation = self.animations.addPause(
             int(self.duration / 2 * 1000))
         opacityAnimation = QPropertyAnimation(effect, b'opacity',
                                               self.animations)
         opacityAnimation.setDuration(2000)
         opacityAnimation.setStartValue(1.0)
         opacityAnimation.setEndValue(0.0)
         opacityAnimation.setEasingCurve(QEasingCurve.InOutQuad)
         self.animations.addAnimation(opacityAnimation)
         self.animations.finished.connect(self.close)
         self.shown.connect(self.fadeOut)
     else:
         self.shown.connect(
             lambda: QTimer.singleShot(self.duration * 1000, self.fadeOut))
     layout = QHBoxLayout()
     layout.addStretch(1)
     layout.addLayout(self.left_layout)
     layout.addSpacing(10)
     layout.addLayout(self.right_layout)
     layout.addStretch(1)
     self.setLayout(layout)
Ejemplo n.º 14
0
    def __init__(self,
                 parent=None,
                 bar_color=Qt.gray,
                 checked_color="#00B0FF",
                 handle_color=Qt.white,
                 pulse_unchecked_color="#44999999",
                 pulse_checked_color="#4400B0EE"
                 ):
        super().__init__(parent)

        # Save our properties on the object via self, so we can access them later
        # in the paintEvent.
        self._bar_brush = QBrush(bar_color)
        self._bar_checked_brush = QBrush(QColor(checked_color).lighter())

        self._handle_brush = QBrush(handle_color)
        self._handle_checked_brush = QBrush(QColor(checked_color))

        self._pulse_unchecked_animation = QBrush(QColor(pulse_unchecked_color))
        self._pulse_checked_animation = QBrush(QColor(pulse_checked_color))

        # Setup the rest of the widget.
        self.setContentsMargins(8, 0, 8, 0)
        self._handle_position = 0

        self._pulse_radius = 0

        self.animation = QPropertyAnimation(self, b"handle_position", self)
        self.animation.setEasingCurve(QEasingCurve.InOutCubic)
        self.animation.setDuration(200)  # time in ms

        self.pulse_anim = QPropertyAnimation(self, b"pulse_radius", self)
        self.pulse_anim.setDuration(350)  # time in ms
        self.pulse_anim.setStartValue(10)
        self.pulse_anim.setEndValue(20)

        self.animations_group = QSequentialAnimationGroup()
        self.animations_group.addAnimation(self.animation)
        self.animations_group.addAnimation(self.pulse_anim)

        self.stateChanged.connect(self.setup_animation)
Ejemplo n.º 15
0
    def show_hide_menu(self, checked):
        animation_group = QSequentialAnimationGroup(self)
        for idx, target in enumerate(self.animation_target):
            animation = QPropertyAnimation()
            animation.setTargetObject(target)
            animation.setPropertyName(b"pos")
            animation.setEndValue(self.pushButton.pos())
            animation.setStartValue(self.animation_target_pos[idx])
            animation.setDuration(200)
            animation.setEasingCurve(QEasingCurve.InOutBounce)
            animation_group.addAnimation(animation)

        animation_group.setDirection(not checked)
        animation_group.start(QAbstractAnimation.DeleteWhenStopped)
Ejemplo n.º 16
0
    def start(self):
        bh = self.height() / 2 - self._ball_radius
        width = self.width()
        for i in range(self._ball_numbers):
            self._seq_animations.append(QSequentialAnimationGroup(self))
            # 增加间隔
            self._seq_animations[i].addPause(self.duration_pause * i)
            # 第一段
            par_animation1 = QParallelAnimationGroup(self)
            pa = QPropertyAnimation(self._balls[i], b'pos', self)
            pa.setEasingCurve(self._ec1)
            pa.setDuration(self.duration * self._first_flag)
            pa.setStartValue(QPoint(0, bh))
            pa.setEndValue(QPoint(width * 0.4, bh))
            par_animation1.addAnimation(pa)
            pa = QPropertyAnimation(self._balls[i], b'_style', self)
            pa.setEasingCurve(self._ec1)
            pa.setDuration(self.duration * self._first_flag)
            pa.setStartValue(0)
            pa.setEndValue(255)
            par_animation1.addAnimation(pa)
            self._seq_animations[i].addAnimation(par_animation1)
            # 第二段
            pa = QPropertyAnimation(self._balls[i], b'pos', self)
            pa.setDuration(self.duration * self._second_flag)
            pa.setStartValue(QPoint(width * 0.4, bh))
            pa.setEndValue(QPoint(width * 0.6, bh))
            self._seq_animations[i].addAnimation(pa)
            # 第三段
            par_animation2 = QParallelAnimationGroup(self)
            pa = QPropertyAnimation(self._balls[i], b'pos', self)
            pa.setEasingCurve(self._ec2)
            pa.setDuration(self.duration * self._three_flag)
            pa.setStartValue(QPoint(width * 0.6, bh))
            pa.setEndValue(QPoint(width, bh))
            par_animation2.addAnimation(pa)
            pa = QPropertyAnimation(self._balls[i], b'_style', self)
            pa.setEasingCurve(self._ec2)
            pa.setDuration(self.duration * self._three_flag)
            pa.setStartValue(255)
            pa.setEndValue(0)
            par_animation2.addAnimation(pa)
            self._seq_animations[i].addAnimation(par_animation2)
            # 增加间隔
            self._seq_animations[i].addPause(self.duration_pause *
                                             (self._ball_numbers - i - 1))

        for seq in self._seq_animations:
            seq.setLoopCount(-1)
            seq.start(QAbstractAnimation.DeleteWhenStopped)
Ejemplo n.º 17
0
    def config_animation(self, duration):
        """Start a fading animation for this label

        Arguments:
            duration {int} -- Duration in milliseconds of a complete fadein-fadeout cycle
        """
        self.effect = QGraphicsOpacityEffect()
        self.setGraphicsEffect(self.effect)

        self.fadeout = QPropertyAnimation(self.effect, b"opacity")
        self.fadeout.setDuration(duration)
        self.fadeout.setStartValue(1)
        self.fadeout.setEndValue(0)

        self.fadein = QPropertyAnimation(self.effect, b"opacity")
        self.fadein.setDuration(duration)
        self.fadein.setStartValue(0)
        self.fadein.setEndValue(1)

        self.group_animation = QSequentialAnimationGroup()
        self.group_animation.addAnimation(self.fadein)
        self.group_animation.addAnimation(self.fadeout)
        self.group_animation.setLoopCount(-1)
Ejemplo n.º 18
0
    def start_animation(self, duration):
        """Start the fading animation of the label

        Arguments:
            duration {int} -- Duration in milliseconds of a complete fade in-fade out cycle
        """
        self.effect = QGraphicsOpacityEffect()
        self.setGraphicsEffect(self.effect)

        self.animation1 = QPropertyAnimation(self.effect, b"opacity")
        self.animation1.setDuration(duration)
        self.animation1.setStartValue(1)
        self.animation1.setEndValue(0)

        self.animation2 = QPropertyAnimation(self.effect, b"opacity")
        self.animation2.setDuration(duration)
        self.animation2.setStartValue(0)
        self.animation2.setEndValue(1)

        self.ga = QSequentialAnimationGroup()
        self.ga.addAnimation(self.animation1)
        self.ga.addAnimation(self.animation2)
        self.ga.setLoopCount(-1)
        self.ga.start()
Ejemplo n.º 19
0
    def start_animation(self, duration):
        """Start a fadein-fadeout animation

        Arguments:
            duration {int} -- Duration of millisecondns of each fadein-fadeout cycle of the animation.
        """
        self.effect = QGraphicsOpacityEffect()
        self.setGraphicsEffect(self.effect)

        self.animation1 = QPropertyAnimation(self.effect, b"opacity")
        self.animation1.setDuration(duration)
        self.animation1.setStartValue(1)
        self.animation1.setEndValue(0)

        self.animation2 = QPropertyAnimation(self.effect, b"opacity")
        self.animation2.setDuration(duration)
        self.animation2.setStartValue(0)
        self.animation2.setEndValue(1)

        self.ga = QSequentialAnimationGroup()
        self.ga.addAnimation(self.animation1)
        self.ga.addAnimation(self.animation2)
        self.ga.setLoopCount(-1)
        self.ga.start()
Ejemplo n.º 20
0
    def menu(self):
        """
        展示动画效果
        :return:
        """

        animation_group = QSequentialAnimationGroup(self.widget)
        for idx, target in enumerate(self.animation_targets):
            animation = QPropertyAnimation()
            animation.setTargetObject(target)
            animation.setPropertyName(b"pos")
            animation.setStartValue(self.menu_btn.pos())
            animation.setEndValue(self.animation_targets_pos[idx])
            animation.setDuration(self.duration)
            animation.setEasingCurve(QEasingCurve.InOutBounce)
            animation_group.addAnimation(animation)

        animation_group.setDirection(self.checked)
        animation_group.start(QAbstractAnimation.DeleteWhenStopped)
Ejemplo n.º 21
0
    def shake_animate(self, shake_me):
        ''' Make the "shake_me" input object shake breifly '''
        start = QtCore.QPointF(shake_me.x(), shake_me.y())
        end = QtCore.QPointF(shake_me.x() + 5, shake_me.y())
        self.animation_seq = QSeqAnimate()

        for n in range(5):
            animation = QAnimate(shake_me, b'pos')
            animation.setDuration(50)
            if n % 2 == 0:
                animation.setStartValue(end)
                animation.setEndValue(start)
            else:
                animation.setStartValue(start)
                animation.setEndValue(end)
            animation.setEasingCurve(QtCore.QEasingCurve.OutQuint)
            self.animation_seq.addAnimation(animation)
        self.animation_seq.start()
Ejemplo n.º 22
0
    def set_fadeout(self, wait_for_sec=7):
        opc = QGraphicsOpacityEffect(self)
        self.opc = opc
        self.setGraphicsEffect(opc)

        cue = QSequentialAnimationGroup()
        self.cue = cue
        cue.addPause(wait_for_sec * 1000)

        # Fade-out
        anim = QPropertyAnimation(opc, b"opacity")
        self.anim = anim
        anim.setDuration(3000)
        anim.setStartValue(1)
        anim.setEndValue(0)
        anim.setEasingCurve(QEasingCurve.InExpo)

        cue.addAnimation(anim)
        cue.finished.connect(self.deleteLater)
        cue.start(QAbstractAnimation.DeleteWhenStopped)
Ejemplo n.º 23
0
class AnimatedLabel(QLabel):
    """This class extends the functionality of the default QLabel to add a fadein-fadeout animation"""

    clicked = pyqtSignal()

    in_label = False
    SLOW_DURATION = 1500
    FAST_DURATION = 500

    def __init__(self, parent=None, color='yellow'):
        """Constructor of the class

        Keyword Arguments:
            parent {ui.gui.views.title.TitleWindow} -- Parent of this widget (default: {None})
            color {str} -- Color of the start text (default: {'yellow'})
        """
        QLabel.__init__(self, parent)
        self.start_animation(self.SLOW_DURATION)
        font = QFont('Arial', 20)
        self.setFont(font)
        self.setText("Click to start")
        self.setFixedHeight(100)
        self.setAlignment(Qt.AlignCenter)
        self.setStyleSheet('color: ' + color)

    def start_animation(self, duration):
        """Function that starts the animation cycle

        Arguments:
            duration {int} -- Duration in milliseconds of a complete fadein-fadeout animation cycle.
        """
        self.effect = QGraphicsOpacityEffect()
        self.setGraphicsEffect(self.effect)

        self.animation1 = QPropertyAnimation(self.effect, b"opacity")
        self.animation1.setDuration(duration)
        self.animation1.setStartValue(1)
        self.animation1.setEndValue(0)

        self.animation2 = QPropertyAnimation(self.effect, b"opacity")
        self.animation2.setDuration(duration)
        self.animation2.setStartValue(0)
        self.animation2.setEndValue(1)

        self.ga = QSequentialAnimationGroup()
        self.ga.addAnimation(self.animation1)
        self.ga.addAnimation(self.animation2)
        self.ga.setLoopCount(-1)
        self.ga.start()
Ejemplo n.º 24
0
 def smooth_move(self, number):
     if self.is_in_base():
         deley = 500
         self.parent().anim = QPropertyAnimation(self, b"geometry")
         self.parent().anim.setDuration(deley)
         self.parent().anim.setEndValue(self.__positions[0].geometry())
         self.parent().anim.start()
     else:
         deley = 250 * number
         pic_index = [pos.geometry()
                      for pos in self.__positions].index(self.geometry())
         self.parent().anim_grp = QSequentialAnimationGroup()
         for i in range(number):
             self.parent().anim = QPropertyAnimation(self, b"geometry")
             self.parent().anim.setDuration(250)
             self.parent().anim.setStartValue(
                 self.__positions[pic_index + i].geometry())
             self.parent().anim.setEndValue(self.__positions[pic_index + i +
                                                             1].geometry())
             self.parent().anim_grp.addAnimation(self.parent().anim)
         self.parent().anim_grp.start()
     return deley + 100
Ejemplo n.º 25
0
def rain(pix, node):
    node.pix.setOriginPt()
    pos = node.pix.pos()
    sync = random.randint(17, 31) * 50

    y = int(pos.y())
    ViewH = common["ViewH"]
    bottom = y + ViewH + node.pix.height * 2
    top = y + node.pix.height * 2

    rain1 = QPropertyAnimation(node, b'pos')
    rain1.setDuration(sync)
    rain1.setStartValue(pos)
    rain1.setEndValue(pos + QPointF(0, bottom))

    opacity1 = QPropertyAnimation(node, b'opacity')
    opacity1.setDuration(sync)
    opacity1.setStartValue(node.pix.opacity())
    opacity1.setKeyValueAt(.10, .50)
    opacity1.setEndValue(0)

    par1 = QParallelAnimationGroup()
    par1.addAnimation(rain1)
    par1.addAnimation(opacity1)

    rain2 = QPropertyAnimation(node, b'pos')
    rain2.setDuration(sync)
    rain2.setStartValue(pos + QPointF(0, -top))
    rain2.setEndValue(pos)

    opacity2 = QPropertyAnimation(node, b'opacity')
    opacity2.setDuration(sync)
    opacity2.setStartValue(node.pix.opacity())
    opacity2.setEndValue(.85)

    par2 = QParallelAnimationGroup()
    par2.addAnimation(rain2)
    par2.addAnimation(opacity2)

    rain = QSequentialAnimationGroup()
    rain.addAnimation(par1)
    rain.addAnimation(par2)

    rain.setLoopCount(-1)

    return rain
Ejemplo n.º 26
0
class AnimatedLabel(QLabel):
    """This is a helper class that extends the functioality of the default QLabel with a fade in-out animation"""

    SLOW_DURATION = 1500
    FAST_DURATION = 500

    def __init__(self, parent=None, color='yellow'):
        """Constructor of the class

        Keyword Arguments:
            parent {ui.gui.views.main_view.MainView} -- parent of this widget (default: {None})
            color {str} -- Foreground color of the label (default: {'yellow'})
        """
        QLabel.__init__(self, parent)
        self.start_animation(self.SLOW_DURATION)
        font = QFont('Arial', 30)
        self.setFont(font)
        self.setText("Select your layout")
        self.setFixedHeight(100)
        self.setAlignment(Qt.AlignCenter)
        self.setStyleSheet('color: ' + color)

    def start_animation(self, duration):
        """Start the fading animation of the label

        Arguments:
            duration {int} -- Duration in milliseconds of a complete fade in-fade out cycle
        """
        self.effect = QGraphicsOpacityEffect()
        self.setGraphicsEffect(self.effect)

        self.animation1 = QPropertyAnimation(self.effect, b"opacity")
        self.animation1.setDuration(duration)
        self.animation1.setStartValue(1)
        self.animation1.setEndValue(0)

        self.animation2 = QPropertyAnimation(self.effect, b"opacity")
        self.animation2.setDuration(duration)
        self.animation2.setStartValue(0)
        self.animation2.setEndValue(1)

        self.ga = QSequentialAnimationGroup()
        self.ga.addAnimation(self.animation1)
        self.ga.addAnimation(self.animation2)
        self.ga.setLoopCount(-1)
        self.ga.start()
Ejemplo n.º 27
0
def pulse(pix):
    node = Node(pix)
    node.pix.setOriginPt()
    random.seed()
    sync = random.gauss(450, 50)

    pulse = QPropertyAnimation(node, b'scale')
    pulse.setDuration(sync)

    pulse.setStartValue(node.pix.scale * random.gauss(1.25, .25))
    pulse.setEndValue(node.pix.scale * random.gauss(1.25, .25))

    pulse.setLoopCount(-1)

    seq = QSequentialAnimationGroup()
    seq.addAnimation(pulse)
    seq.addPause(random.randint(10, 30) * 30)

    return seq
Ejemplo n.º 28
0
def stage(pix, which):
    node = Node(pix)
    pos = node.pix.pos()
    node.pix.setOriginPt()

    x = int(pos.x())
    ViewW = common["ViewW"]
    left = x + node.pix.width * 3
    right = ViewW + node.pix.width * 3

    if which.endswith('Left'):
        stage1, stage2 = stageLeft(node, pos, left, right)
    else:
        stage1, stage2 = stageRight(node, pos, left, right)

    stage = QSequentialAnimationGroup()
    stage.addAnimation(stage1)
    stage.addAnimation(stage2)

    stage.setLoopCount(-1)

    return stage
Ejemplo n.º 29
0
    def _initAnimations(self):
        for index in range(5):  # 5个小圆
            item = CircleItem(self)
            item.valueChanged.connect(self.update)
            # 串行动画组
            seqAnimation = QSequentialAnimationGroup(self)
            seqAnimation.setLoopCount(-1)
            self._items.append((item, seqAnimation))

            # 暂停延迟动画
            seqAnimation.addAnimation(QPauseAnimation(150 * index, self))

            # 加速,并行动画组1
            parAnimation1 = QParallelAnimationGroup(self)
            # 透明度
            parAnimation1.addAnimation(QPropertyAnimation(
                item, b'opacity', self, duration=400, startValue=0, endValue=1.0))
            # x坐标
            parAnimation1.addAnimation(QPropertyAnimation(
                item, b'x', self, duration=400, startValue=0, endValue=25.0))
            seqAnimation.addAnimation(parAnimation1)
            ##

            # 匀速
            seqAnimation.addAnimation(QPropertyAnimation(
                item, b'x', self, duration=2000, startValue=25.0, endValue=75.0))

            # 加速,并行动画组2
            parAnimation2 = QParallelAnimationGroup(self)
            # 透明度
            parAnimation2.addAnimation(QPropertyAnimation(
                item, b'opacity', self, duration=400, startValue=1.0, endValue=0))
            # x坐标
            parAnimation2.addAnimation(QPropertyAnimation(
                item, b'x', self, duration=400, startValue=75.0, endValue=100.0))
            seqAnimation.addAnimation(parAnimation2)
            ##

            # 暂停延迟动画
            seqAnimation.addAnimation(
                QPauseAnimation((5 - index - 1) * 150, self))

        for _, animation in self._items:
            animation.start()
Ejemplo n.º 30
0
class AnimatedToggle(QCheckBox):
    _transparent_pen = QPen(Qt.transparent)
    _light_grey_pen = QPen(Qt.lightGray)

    def __init__(self,
                 parent=None,
                 bar_color=Qt.gray,
                 checked_color="#00B0FF",
                 handle_color=Qt.white,
                 pulse_unchecked_color="#44999999",
                 pulse_checked_color="#4400B0EE"
                 ):
        super().__init__(parent)

        # Save our properties on the object via self, so we can access them later
        # in the paintEvent.
        self._bar_brush = QBrush(bar_color)
        self._bar_checked_brush = QBrush(QColor(checked_color).lighter())

        self._handle_brush = QBrush(handle_color)
        self._handle_checked_brush = QBrush(QColor(checked_color))

        self._pulse_unchecked_animation = QBrush(QColor(pulse_unchecked_color))
        self._pulse_checked_animation = QBrush(QColor(pulse_checked_color))

        # Setup the rest of the widget.
        self.setContentsMargins(8, 0, 8, 0)
        self._handle_position = 0

        self._pulse_radius = 0

        self.animation = QPropertyAnimation(self, b"handle_position", self)
        self.animation.setEasingCurve(QEasingCurve.InOutCubic)
        self.animation.setDuration(200)  # time in ms

        self.pulse_anim = QPropertyAnimation(self, b"pulse_radius", self)
        self.pulse_anim.setDuration(350)  # time in ms
        self.pulse_anim.setStartValue(10)
        self.pulse_anim.setEndValue(20)

        self.animations_group = QSequentialAnimationGroup()
        self.animations_group.addAnimation(self.animation)
        self.animations_group.addAnimation(self.pulse_anim)

        self.stateChanged.connect(self.setup_animation)

    def sizeHint(self):
        return QSize(58, 45)

    def hitButton(self, pos: QPoint):
        return self.contentsRect().contains(pos)

    @pyqtSlot(int)
    def setup_animation(self, value):
        self.animations_group.stop()
        if value:
            self.animation.setEndValue(1)
        else:
            self.animation.setEndValue(0)
        self.animations_group.start()

    def paintEvent(self, e: QPaintEvent):

        contRect = self.contentsRect()
        handleRadius = round(0.24 * contRect.height())

        p = QPainter(self)
        p.setRenderHint(QPainter.Antialiasing)

        p.setPen(self._transparent_pen)
        barRect = QRectF(
            0, 0,
            contRect.width() - handleRadius, 0.40 * contRect.height()
        )
        barRect.moveCenter(contRect.center())
        rounding = barRect.height() / 2

        # the handle will move along this line
        trailLength = contRect.width() - 2 * handleRadius

        xPos = contRect.x() + handleRadius + trailLength * self._handle_position

        if self.pulse_anim.state() == QPropertyAnimation.Running:
            p.setBrush(
                self._pulse_checked_animation if
                self.isChecked() else self._pulse_unchecked_animation)
            p.drawEllipse(QPointF(xPos, barRect.center().y()),
                          self._pulse_radius, self._pulse_radius)

        if self.isChecked():
            p.setBrush(self._bar_checked_brush)
            p.drawRoundedRect(barRect, rounding, rounding)
            p.setBrush(self._handle_checked_brush)

        else:
            p.setBrush(self._bar_brush)
            p.drawRoundedRect(barRect, rounding, rounding)
            p.setPen(self._light_grey_pen)
            p.setBrush(self._handle_brush)

        p.drawEllipse(
            QPointF(xPos, barRect.center().y()),
            handleRadius, handleRadius)

        p.end()

    @pyqtProperty(float)
    def handle_position(self):
        return self._handle_position

    @handle_position.setter
    def handle_position(self, pos):
        """change the property
        we need to trigger QWidget.update() method, either by:
            1- calling it here [ what we doing ].
            2- connecting the QPropertyAnimation.valueChanged() signal to it.
        """
        self._handle_position = pos
        self.update()

    @pyqtProperty(float)
    def pulse_radius(self):
        return self._pulse_radius

    @pulse_radius.setter
    def pulse_radius(self, pos):
        self._pulse_radius = pos
        self.update()
Ejemplo n.º 31
0
            QRect(200, 50, 50, 50), button3, QRect(50, 200, 50, 50), button4,
            QRect(200, 200, 50, 50), group)

    state7 = createGeometryState(button1, QRect(0, 0, 50, 50), button2,
            QRect(250, 0, 50, 50), button3, QRect(0, 250, 50, 50), button4,
            QRect(250, 250, 50, 50), group)

    group.setInitialState(state1)

    animationGroup = QParallelAnimationGroup()
    anim = QPropertyAnimation(button4, 'geometry')
    anim.setDuration(1000)
    anim.setEasingCurve(QEasingCurve.OutElastic)
    animationGroup.addAnimation(anim)

    subGroup = QSequentialAnimationGroup(animationGroup)
    subGroup.addPause(100)
    anim = QPropertyAnimation(button3, 'geometry')
    anim.setDuration(1000)
    anim.setEasingCurve(QEasingCurve.OutElastic)
    subGroup.addAnimation(anim)

    subGroup = QSequentialAnimationGroup(animationGroup)
    subGroup.addPause(150)
    anim = QPropertyAnimation(button2, 'geometry')
    anim.setDuration(1000)
    anim.setEasingCurve(QEasingCurve.OutElastic)
    subGroup.addAnimation(anim)

    subGroup = QSequentialAnimationGroup(animationGroup)
    subGroup.addPause(200)
Ejemplo n.º 32
0
    def __init__(self, size, parent=None):
        super(PadNavigator, self).__init__(parent)

        self.form = Ui_Form()

        splash = SplashItem()
        splash.setZValue(1)

        pad = FlippablePad(size)
        flipRotation = QGraphicsRotation(pad)
        xRotation = QGraphicsRotation(pad)
        yRotation = QGraphicsRotation(pad)
        flipRotation.setAxis(Qt.YAxis)
        xRotation.setAxis(Qt.YAxis)
        yRotation.setAxis(Qt.XAxis)
        pad.setTransformations([flipRotation, xRotation, yRotation])

        backItem = QGraphicsProxyWidget(pad)
        widget = QWidget()
        self.form.setupUi(widget)
        self.form.hostName.setFocus()
        backItem.setWidget(widget)
        backItem.setVisible(False)
        backItem.setFocus()
        backItem.setCacheMode(QGraphicsItem.ItemCoordinateCache)
        r = backItem.rect()
        backItem.setTransform(QTransform().rotate(180, Qt.YAxis).translate(-r.width()/2, -r.height()/2))

        selectionItem = RoundRectItem(QRectF(-60, -60, 120, 120),
                QColor(Qt.gray), pad)
        selectionItem.setZValue(0.5)

        smoothSplashMove = QPropertyAnimation(splash, b'y')
        smoothSplashOpacity = QPropertyAnimation(splash, b'opacity')
        smoothSplashMove.setEasingCurve(QEasingCurve.InQuad)
        smoothSplashMove.setDuration(250)
        smoothSplashOpacity.setDuration(250)

        smoothXSelection = QPropertyAnimation(selectionItem, b'x')
        smoothYSelection = QPropertyAnimation(selectionItem, b'y')
        smoothXRotation = QPropertyAnimation(xRotation, b'angle')
        smoothYRotation = QPropertyAnimation(yRotation, b'angle')
        smoothXSelection.setDuration(125)
        smoothYSelection.setDuration(125)
        smoothXRotation.setDuration(125)
        smoothYRotation.setDuration(125)
        smoothXSelection.setEasingCurve(QEasingCurve.InOutQuad)
        smoothYSelection.setEasingCurve(QEasingCurve.InOutQuad)
        smoothXRotation.setEasingCurve(QEasingCurve.InOutQuad)
        smoothYRotation.setEasingCurve(QEasingCurve.InOutQuad)

        smoothFlipRotation = QPropertyAnimation(flipRotation, b'angle')
        smoothFlipScale = QPropertyAnimation(pad, b'scale')
        smoothFlipXRotation = QPropertyAnimation(xRotation, b'angle')
        smoothFlipYRotation = QPropertyAnimation(yRotation, b'angle')
        flipAnimation = QParallelAnimationGroup(self)
        smoothFlipScale.setDuration(500)
        smoothFlipRotation.setDuration(500)
        smoothFlipXRotation.setDuration(500)
        smoothFlipYRotation.setDuration(500)
        smoothFlipScale.setEasingCurve(QEasingCurve.InOutQuad)
        smoothFlipRotation.setEasingCurve(QEasingCurve.InOutQuad)
        smoothFlipXRotation.setEasingCurve(QEasingCurve.InOutQuad)
        smoothFlipYRotation.setEasingCurve(QEasingCurve.InOutQuad)
        smoothFlipScale.setKeyValueAt(0, 1.0)
        smoothFlipScale.setKeyValueAt(0.5, 0.7)
        smoothFlipScale.setKeyValueAt(1, 1.0)
        flipAnimation.addAnimation(smoothFlipRotation)
        flipAnimation.addAnimation(smoothFlipScale)
        flipAnimation.addAnimation(smoothFlipXRotation)
        flipAnimation.addAnimation(smoothFlipYRotation)

        setVariablesSequence = QSequentialAnimationGroup()
        setFillAnimation = QPropertyAnimation(pad, b'fill')
        setBackItemVisibleAnimation = QPropertyAnimation(backItem, b'visible')
        setSelectionItemVisibleAnimation = QPropertyAnimation(selectionItem, b'visible')
        setFillAnimation.setDuration(0)
        setBackItemVisibleAnimation.setDuration(0)
        setSelectionItemVisibleAnimation.setDuration(0)
        setVariablesSequence.addPause(250)
        setVariablesSequence.addAnimation(setBackItemVisibleAnimation)
        setVariablesSequence.addAnimation(setSelectionItemVisibleAnimation)
        setVariablesSequence.addAnimation(setFillAnimation)
        flipAnimation.addAnimation(setVariablesSequence)

        stateMachine = QStateMachine(self)
        splashState = QState(stateMachine)
        frontState = QState(stateMachine)
        historyState = QHistoryState(frontState)
        backState = QState(stateMachine)

        frontState.assignProperty(pad, "fill", False)
        frontState.assignProperty(splash, "opacity", 0.0)
        frontState.assignProperty(backItem, "visible", False)
        frontState.assignProperty(flipRotation, "angle", 0.0)
        frontState.assignProperty(selectionItem, "visible", True)

        backState.assignProperty(pad, "fill", True)
        backState.assignProperty(backItem, "visible", True)
        backState.assignProperty(xRotation, "angle", 0.0)
        backState.assignProperty(yRotation, "angle", 0.0)
        backState.assignProperty(flipRotation, "angle", 180.0)
        backState.assignProperty(selectionItem, "visible", False)

        stateMachine.addDefaultAnimation(smoothXRotation)
        stateMachine.addDefaultAnimation(smoothYRotation)
        stateMachine.addDefaultAnimation(smoothXSelection)
        stateMachine.addDefaultAnimation(smoothYSelection)
        stateMachine.setInitialState(splashState)

        anyKeyTransition = QEventTransition(self, QEvent.KeyPress, splashState)
        anyKeyTransition.setTargetState(frontState)
        anyKeyTransition.addAnimation(smoothSplashMove)
        anyKeyTransition.addAnimation(smoothSplashOpacity)

        enterTransition = QKeyEventTransition(self, QEvent.KeyPress,
                Qt.Key_Enter, backState)
        returnTransition = QKeyEventTransition(self, QEvent.KeyPress,
                Qt.Key_Return, backState)
        backEnterTransition = QKeyEventTransition(self, QEvent.KeyPress,
                Qt.Key_Enter, frontState)
        backReturnTransition = QKeyEventTransition(self, QEvent.KeyPress,
                Qt.Key_Return, frontState)
        enterTransition.setTargetState(historyState)
        returnTransition.setTargetState(historyState)
        backEnterTransition.setTargetState(backState)
        backReturnTransition.setTargetState(backState)
        enterTransition.addAnimation(flipAnimation)
        returnTransition.addAnimation(flipAnimation)
        backEnterTransition.addAnimation(flipAnimation)
        backReturnTransition.addAnimation(flipAnimation)

        columns = size.width()
        rows = size.height()
        stateGrid = []
        for y in range(rows):
            stateGrid.append([QState(frontState) for _ in range(columns)])

        frontState.setInitialState(stateGrid[0][0])
        selectionItem.setPos(pad.iconAt(0, 0).pos())

        for y in range(rows):
            for x in range(columns):
                state = stateGrid[y][x]

                rightTransition = QKeyEventTransition(self, QEvent.KeyPress,
                        Qt.Key_Right, state)
                leftTransition = QKeyEventTransition(self, QEvent.KeyPress,
                        Qt.Key_Left, state)
                downTransition = QKeyEventTransition(self, QEvent.KeyPress,
                        Qt.Key_Down, state)
                upTransition = QKeyEventTransition(self, QEvent.KeyPress,
                        Qt.Key_Up, state)

                rightTransition.setTargetState(stateGrid[y][(x + 1) % columns])
                leftTransition.setTargetState(stateGrid[y][((x - 1) + columns) % columns])
                downTransition.setTargetState(stateGrid[(y + 1) % rows][x])
                upTransition.setTargetState(stateGrid[((y - 1) + rows) % rows][x])

                icon = pad.iconAt(x, y)
                state.assignProperty(xRotation, "angle", -icon.x() / 6.0)
                state.assignProperty(yRotation, "angle", icon.y() / 6.0)
                state.assignProperty(selectionItem, "x", icon.x())
                state.assignProperty(selectionItem, "y", icon.y())
                frontState.assignProperty(icon, "visible", True)
                backState.assignProperty(icon, "visible", False)

                setIconVisibleAnimation = QPropertyAnimation(icon, b'visible')
                setIconVisibleAnimation.setDuration(0)
                setVariablesSequence.addAnimation(setIconVisibleAnimation)

        scene = QGraphicsScene(self)
        scene.setBackgroundBrush(QBrush(QPixmap(":/images/blue_angle_swirl.jpg")))
        scene.setItemIndexMethod(QGraphicsScene.NoIndex)
        scene.addItem(pad)
        scene.setSceneRect(scene.itemsBoundingRect())
        self.setScene(scene)

        sbr = splash.boundingRect()
        splash.setPos(-sbr.width() / 2, scene.sceneRect().top() - 2)
        frontState.assignProperty(splash, "y", splash.y() - 100.0)
        scene.addItem(splash)

        self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.setMinimumSize(50, 50)
        self.setViewportUpdateMode(QGraphicsView.FullViewportUpdate)
        self.setCacheMode(QGraphicsView.CacheBackground)
        self.setRenderHints(QPainter.Antialiasing |
                QPainter.SmoothPixmapTransform | QPainter.TextAntialiasing)

        if QGLFormat.hasOpenGL():
            self.setViewport(QGLWidget(QGLFormat(QGL.SampleBuffers)))

        stateMachine.start()
Ejemplo n.º 33
0
    state3.assignProperty(p2, 'pos', QPointF(0, 5 + 64 + 5))
    state3.assignProperty(p3, 'pos', QPointF(5, 5 + (64 + 5) + 64))
    state3.assignProperty(p4, 'pos', QPointF(5 + 64 + 5, 5))
    state3.assignProperty(p5, 'pos', QPointF(5 + 64 + 5, 5 + 64 + 5))
    state3.assignProperty(p6, 'pos', QPointF(5 + 64 + 5, 5 + (64 + 5) + 64))
    state3.assignProperty(widget, 'geometry', QRectF(138, 5, 400 - 138, 200))
    state3.assignProperty(box, 'geometry', QRect(5, 205, 400, 90))
    state3.assignProperty(p1, 'opacity', 1.0)
    state3.assignProperty(p2, 'opacity', 1.0)
    state3.assignProperty(p3, 'opacity', 1.0)
    state3.assignProperty(p4, 'opacity', 1.0)
    state3.assignProperty(p5, 'opacity', 1.0)
    state3.assignProperty(p6, 'opacity', 1.0)

    t1 = state1.addTransition(button.clicked, state2)
    animation1SubGroup = QSequentialAnimationGroup()
    animation1SubGroup.addPause(250)
    animation1SubGroup.addAnimation(QPropertyAnimation(box, b'geometry', state1))
    t1.addAnimation(animation1SubGroup)
    t1.addAnimation(QPropertyAnimation(widget, b'geometry', state1))
    t1.addAnimation(QPropertyAnimation(p1, b'pos', state1))
    t1.addAnimation(QPropertyAnimation(p2, b'pos', state1))
    t1.addAnimation(QPropertyAnimation(p3, b'pos', state1))
    t1.addAnimation(QPropertyAnimation(p4, b'pos', state1))
    t1.addAnimation(QPropertyAnimation(p5, b'pos', state1))
    t1.addAnimation(QPropertyAnimation(p6, b'pos', state1))
    t1.addAnimation(QPropertyAnimation(p1, b'rotation', state1))
    t1.addAnimation(QPropertyAnimation(p2, b'rotation', state1))
    t1.addAnimation(QPropertyAnimation(p3, b'rotation', state1))
    t1.addAnimation(QPropertyAnimation(p4, b'rotation', state1))
    t1.addAnimation(QPropertyAnimation(p5, b'rotation', state1))
Ejemplo n.º 34
0
    def __init__(self, scene, x_max, y_max, back_color):

        scene = QGraphicsScene(0, 0, x_max, y_max)
        scene.setBackgroundBrush(back_color)

        color = [Qt.green, Qt.lightGray, Qt.darkYellow, QtGui.QColor.fromRgb(255, 85, 0)]
        self.anim_butt = [ QGraphicsRectWidget(color[j]) for j in range(4) ]
        for j in range(4):
            scene.addItem(self.anim_butt[j])

        self.window = QGraphicsView(scene)
        self.window.setFrameStyle(0)
        self.window.setAlignment(Qt.AlignLeft | Qt.AlignTop)
        self.window.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.window.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)

        self.machine = QStateMachine()

        self.group = QState()
        self.timer = QTimer()
        self.timer.setInterval(1250)
        self.timer.setSingleShot(True)
        self.group.entered.connect(self.timer.start)

        # set states positions
        anim_state_rects = [ [QRect(x_max*xp/6, y_max*yp/4, 8, 8) for xp in range(4)] for yp in range(4) ]
        self.states = [ self.createGeometryState(
                                self.anim_butt[0], anim_state_rects[0][j], self.anim_butt[1], anim_state_rects[1][j],
                                self.anim_butt[2], anim_state_rects[2][j], self.anim_butt[3], anim_state_rects[3][j],
                                self.group
                            ) for j in range(4) ]

        self.group.setInitialState(self.states[0])


        self.animationGroup = QParallelAnimationGroup()
        self.anim = QPropertyAnimation(self.anim_butt[3], 'geometry')
        self.anim.setDuration(1250)
        self.anim.setEasingCurve(QEasingCurve.InBack)
        self.animationGroup.addAnimation(self.anim)

        self.subGroup = QSequentialAnimationGroup(self.animationGroup)
        self.subGroup.addPause(100)
        self.anim = QPropertyAnimation(self.anim_butt[2], 'geometry')
        self.anim.setDuration(1000)
        self.anim.setEasingCurve(QEasingCurve.OutElastic)
        self.subGroup.addAnimation(self.anim)

        self.subGroup = QSequentialAnimationGroup(self.animationGroup)
        self.subGroup.addPause(500)
        self.anim = QPropertyAnimation(self.anim_butt[1], 'geometry')
        self.anim.setDuration(500)
        self.anim.setEasingCurve(QEasingCurve.OutElastic)
        self.subGroup.addAnimation(self.anim)

        self.subGroup = QSequentialAnimationGroup(self.animationGroup)
        self.subGroup.addPause(750)
        self.anim = QPropertyAnimation(self.anim_butt[0], 'geometry')
        self.anim.setDuration(250)
        self.anim.setEasingCurve(QEasingCurve.OutElastic)
        self.subGroup.addAnimation(self.anim)

        self.stateSwitcher = StateSwitcher(self.machine)
        self.group.addTransition(self.timer.timeout, self.stateSwitcher)
        for j in range(4):
            self.stateSwitcher.addState(self.states[j], self.animationGroup)

        self.machine.addState(self.group)
        self.machine.setInitialState(self.group)
        self.machine.start()