Пример #1
0
    def __init__(self, stickMan, keyReceiver):
        self.m_stickMan = stickMan
        self.m_keyReceiver = keyReceiver

        # Create animation group to be used for all transitions.
        self.m_animationGroup = QtCore.QParallelAnimationGroup()
        stickManNodeCount = self.m_stickMan.nodeCount()
        self._pas = []
        for i in range(stickManNodeCount):
            pa = QtCore.QPropertyAnimation(self.m_stickMan.node(i), 'pos')
            self._pas.append(pa)
            self.m_animationGroup.addAnimation(pa)

        # Set up intial state graph.
        self.m_machine = QtCore.QStateMachine()
        self.m_machine.addDefaultAnimation(self.m_animationGroup)

        self.m_alive = QtCore.QState(self.m_machine)
        self.m_alive.setObjectName('alive')

        # Make it blink when lightning strikes before entering dead animation.
        lightningBlink = QtCore.QState(self.m_machine)
        lightningBlink.assignProperty(self.m_stickMan.scene(),
                                      'backgroundBrush', QtCore.Qt.white)
        lightningBlink.assignProperty(self.m_stickMan, 'penColor',
                                      QtCore.Qt.black)
        lightningBlink.assignProperty(self.m_stickMan, 'fillColor',
                                      QtCore.Qt.white)
        lightningBlink.assignProperty(self.m_stickMan, 'isDead', True)

        timer = QtCore.QTimer(lightningBlink)
        timer.setSingleShot(True)
        timer.setInterval(100)
        lightningBlink.entered.connect(timer.start)
        lightningBlink.exited.connect(timer.stop)

        self.m_dead = QtCore.QState(self.m_machine)
        self.m_dead.assignProperty(self.m_stickMan.scene(), 'backgroundBrush',
                                   QtCore.Qt.black)
        self.m_dead.assignProperty(self.m_stickMan, 'penColor',
                                   QtCore.Qt.white)
        self.m_dead.assignProperty(self.m_stickMan, 'fillColor',
                                   QtCore.Qt.black)
        self.m_dead.setObjectName('dead')

        # Idle state (sets no properties).
        self.m_idle = QtCore.QState(self.m_alive)
        self.m_idle.setObjectName('idle')

        self.m_alive.setInitialState(self.m_idle)

        # Lightning strikes at random.
        self.m_alive.addTransition(LightningStrikesTransition(lightningBlink))
        lightningBlink.addTransition(timer.timeout, self.m_dead)

        self.m_machine.setInitialState(self.m_alive)
Пример #2
0
    def __init__(self, parent=None):
        super(MaterialCheckBox, self).__init__(parent)
        self._is_checked = False

        checkedIcon = MaterialIcon(
            self, os.path.join(icons_path, "baseline-check_box-24px.svg"))
        uncheckedIcon = MaterialIcon(
            self,
            os.path.join(icons_path,
                         "baseline-check_box_outline_blank-24px.svg"),
        )

        stateMachine = QtCore.QStateMachine(self)

        checkedState = QtCore.QState()
        checkedState.assignProperty(self, b"checked", True)
        checkedState.assignProperty(checkedIcon, b"opacity", 1.0)
        checkedState.assignProperty(uncheckedIcon, b"opacity", 0.0)

        uncheckedState = QtCore.QState()
        uncheckedState.assignProperty(self, b"checked", False)
        uncheckedState.assignProperty(checkedIcon, b"opacity", 0.0)
        uncheckedState.assignProperty(uncheckedIcon, b"opacity", 1.0)

        stateMachine.addState(checkedState)
        stateMachine.addState(uncheckedState)
        stateMachine.setInitialState(uncheckedState)

        duration = 2000

        transition1 = checkedState.addTransition(self.clicked, uncheckedState)
        animation1 = QtCore.QPropertyAnimation(checkedIcon,
                                               b"opacity",
                                               self,
                                               duration=duration)
        transition1.addAnimation(animation1)
        animation2 = QtCore.QPropertyAnimation(uncheckedIcon,
                                               b"opacity",
                                               self,
                                               duration=duration)
        transition1.addAnimation(animation2)

        transition2 = uncheckedState.addTransition(self.clicked, checkedState)
        animation3 = QtCore.QPropertyAnimation(checkedIcon,
                                               b"opacity",
                                               self,
                                               duration=duration)
        transition2.addAnimation(animation3)
        animation4 = QtCore.QPropertyAnimation(uncheckedIcon,
                                               b"opacity",
                                               self,
                                               duration=duration)
        transition2.addAnimation(animation4)

        stateMachine.start()
Пример #3
0
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # init buttons
        self.start = QtGui.QPushButton('')
        self.restart = QtGui.QPushButton('')
        # set icons
        self.start.setIcon(QtGui.QIcon(static_path + '/imag/play-button.png'))
        self.restart.setIcon(QtGui.QIcon(static_path + '/imag/replay.png'))
        # set size
        self.start.setMinimumHeight(30)
        self.restart.setMinimumHeight(30)
        # add events
        self.start.clicked.connect(self.start_clicked_event)
        self.restart.clicked.connect(self.restart_clicked_event)
        # properties
        self.start.setCheckable(True)
        self.restart.setEnabled(False)
        # init layer
        layer = QtGui.QHBoxLayout()
        self.setLayout(layer)
        layer.addWidget(self.start)
        layer.addWidget(self.restart)
        self.setMaximumWidth(200)
        self.setMinimumWidth(100)

        styles = [
            "background-color: #{}".format(color) for color in [
                "FFFFFF", "F8FFFB", "F2FFF8", "ECFFF4", "E6FFF1", "DFFFED",
                "D9FFEA", "D3FFE6", "CDFFE3", "C7FFE0"
            ]
        ]
        styles += styles[::-1]

        # animation doesn't work for strings but provides an appropriate delay
        animation = QtCore.QPropertyAnimation(self.start, 'styleSheet')
        animation.setDuration(40)

        states = [QtCore.QState() for style in styles]
        for j, style in enumerate(styles):
            states[j].assignProperty(self.start, 'styleSheet', style)
            states[j].addTransition(states[j].propertiesAssigned,
                                    states[(j + 1) % len(styles)])
        self.init_state = states[0]

        self.machine = QtCore.QStateMachine()
        self.machine.addDefaultAnimation(animation)
        for state in states:
            self.machine.addState(state)
        self.machine.setInitialState(states[0])
        self.machine.start()
Пример #4
0
                kineticPix.height() / 2))

        # Centered.
        centeredState.assignProperty(item, 'pos', QtCore.QPointF())

    # Ui.
    view = View(scene)
    view.setWindowTitle("Animated Tiles")
    view.setViewportUpdateMode(QtGui.QGraphicsView.BoundingRectViewportUpdate)
    view.setBackgroundBrush(QtGui.QBrush(bgPix))
    view.setCacheMode(QtGui.QGraphicsView.CacheBackground)
    view.setRenderHints(QtGui.QPainter.Antialiasing
                        | QtGui.QPainter.SmoothPixmapTransform)
    view.show()

    states = QtCore.QStateMachine()
    states.addState(rootState)
    states.setInitialState(rootState)
    rootState.setInitialState(centeredState)

    group = QtCore.QParallelAnimationGroup()
    for i, item in enumerate(items):
        anim = QtCore.QPropertyAnimation(item, 'pos')
        anim.setDuration(750 + i * 25)
        anim.setEasingCurve(QtCore.QEasingCurve.InOutBack)
        group.addAnimation(anim)

    trans = rootState.addTransition(ellipseButton.pressed, ellipseState)
    trans.addAnimation(group)

    trans = rootState.addTransition(figure8Button.pressed, figure8State)
Пример #5
0
def startanimation(parent=None):
    import sys

    app = QtGui.QApplication(sys.argv)

    button1 = QGraphicsRectWidget()
    button2 = QGraphicsRectWidget()
    button3 = QGraphicsRectWidget()
    button4 = QGraphicsRectWidget()
    button2.setZValue(1)
    button3.setZValue(2)
    button4.setZValue(3)

    scene = QtGui.QGraphicsScene(0, 0, SCREENSIZE, SCREENSIZE,parent=parent)
    scene.setBackgroundBrush(QtCore.Qt.black)
    scene.addItem(button1)
    scene.addItem(button2)
    scene.addItem(button3)
    scene.addItem(button4)

    window = QtGui.QGraphicsView(scene,parent=parent)
    window.setFrameStyle(0)
    window.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop)
    window.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
    window.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)

    machine = QtCore.QStateMachine()

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

    state1 = createGeometryState(button1, QtCore.QRect(BLOCKSIZE*2, 0, BLOCKSIZE, BLOCKSIZE),
            button2, QtCore.QRect(BLOCKSIZE*3, 0, BLOCKSIZE, BLOCKSIZE),
            button3, QtCore.QRect(SCREENSIZE-BLOCKSIZE*2, 0, BLOCKSIZE, BLOCKSIZE),
            button4, QtCore.QRect(SCREENSIZE-BLOCKSIZE, 0, BLOCKSIZE, BLOCKSIZE), group)

    state2 = createGeometryState(button1, QtCore.QRect(SCREENSIZE-BLOCKSIZE,BLOCKSIZE*2, BLOCKSIZE, BLOCKSIZE),
            button2, QtCore.QRect(SCREENSIZE-BLOCKSIZE, BLOCKSIZE*3, BLOCKSIZE, BLOCKSIZE),
            button3, QtCore.QRect(SCREENSIZE-BLOCKSIZE, SCREENSIZE-BLOCKSIZE*2, BLOCKSIZE, BLOCKSIZE),
            button4, QtCore.QRect(SCREENSIZE-BLOCKSIZE, SCREENSIZE-BLOCKSIZE, BLOCKSIZE, BLOCKSIZE), group)

    state3 = createGeometryState(button1, QtCore.QRect(BLOCKSIZE*3, SCREENSIZE-BLOCKSIZE, BLOCKSIZE, BLOCKSIZE),
            button2, QtCore.QRect(BLOCKSIZE*2, SCREENSIZE-BLOCKSIZE, BLOCKSIZE, BLOCKSIZE),
            button3, QtCore.QRect(BLOCKSIZE, SCREENSIZE-BLOCKSIZE, BLOCKSIZE, BLOCKSIZE),
            button4, QtCore.QRect(0, SCREENSIZE-BLOCKSIZE, BLOCKSIZE, BLOCKSIZE), group)

    state4 = createGeometryState(button1, QtCore.QRect(0, BLOCKSIZE*3, BLOCKSIZE, BLOCKSIZE),
            button2, QtCore.QRect(0, BLOCKSIZE*2, BLOCKSIZE, BLOCKSIZE),
            button3, QtCore.QRect(0, BLOCKSIZE, BLOCKSIZE, BLOCKSIZE),
            button4, QtCore.QRect(0, 0, BLOCKSIZE, BLOCKSIZE), group)

    state5 = createGeometryState(button1, QtCore.QRect( BLOCKSIZE*2,BLOCKSIZE*2, BLOCKSIZE, BLOCKSIZE),
            button2, QtCore.QRect(BLOCKSIZE*3, BLOCKSIZE*2, BLOCKSIZE, BLOCKSIZE),
            button3, QtCore.QRect(BLOCKSIZE*2, BLOCKSIZE*3, BLOCKSIZE, BLOCKSIZE),
            button4, QtCore.QRect(BLOCKSIZE*3, BLOCKSIZE*3, BLOCKSIZE, BLOCKSIZE), group)

    state6 = createGeometryState(button1, QtCore.QRect(BLOCKSIZE, BLOCKSIZE, BLOCKSIZE, BLOCKSIZE),
            button2, QtCore.QRect(SCREENSIZE-2*BLOCKSIZE, BLOCKSIZE, BLOCKSIZE,BLOCKSIZE),
            button3, QtCore.QRect(BLOCKSIZE, SCREENSIZE-2*BLOCKSIZE, BLOCKSIZE, BLOCKSIZE),
            button4, QtCore.QRect(SCREENSIZE-2*BLOCKSIZE, SCREENSIZE-2*BLOCKSIZE, BLOCKSIZE, BLOCKSIZE), group)

    state7 = createGeometryState(button1, QtCore.QRect(0, 0, BLOCKSIZE, BLOCKSIZE),
            button2, QtCore.QRect(SCREENSIZE-BLOCKSIZE, 0, BLOCKSIZE, BLOCKSIZE),
            button3, QtCore.QRect(0, SCREENSIZE-BLOCKSIZE, BLOCKSIZE, BLOCKSIZE),
            button4, QtCore.QRect(SCREENSIZE-BLOCKSIZE, SCREENSIZE-BLOCKSIZE, BLOCKSIZE, BLOCKSIZE), group)

    group.setInitialState(state1)

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

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

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

    subGroup = QtCore.QSequentialAnimationGroup(animationGroup)
    subGroup.addPause(200)
    anim = QtCore.QPropertyAnimation(button1, 'geometry')
    anim.setDuration(1000)
    anim.setEasingCurve(QtCore.QEasingCurve.OutElastic)
    subGroup.addAnimation(anim)

    stateSwitcher = StateSwitcher(machine)
    group.addTransition(timer.timeout, stateSwitcher)
    stateSwitcher.addState(state1, animationGroup)
    stateSwitcher.addState(state2, animationGroup)
    stateSwitcher.addState(state3, animationGroup)
    stateSwitcher.addState(state4, animationGroup)
    stateSwitcher.addState(state5, animationGroup)
    stateSwitcher.addState(state6, animationGroup)
    stateSwitcher.addState(state7, animationGroup)

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

    window.resize(SCREENSIZE, SCREENSIZE)
    window.show()

    
    sys.exit(app.exec_())
Пример #6
0
    p4 = Pixmap(QtGui.QPixmap(':/k3b.png'))
    p5 = Pixmap(QtGui.QPixmap(':/help-browser.png'))
    p6 = Pixmap(QtGui.QPixmap(':/kchart.png'))

    scene = QtGui.QGraphicsScene(0, 0, 400, 300)
    scene.setBackgroundBrush(scene.palette().window())
    scene.addItem(widget)
    scene.addItem(boxProxy)
    scene.addItem(p1)
    scene.addItem(p2)
    scene.addItem(p3)
    scene.addItem(p4)
    scene.addItem(p5)
    scene.addItem(p6)

    machine = QtCore.QStateMachine()
    state1 = QtCore.QState(machine)
    state2 = QtCore.QState(machine)
    state3 = QtCore.QState(machine)
    machine.setInitialState(state1)

    # State 1.
    state1.assignProperty(button, 'text', "Switch to state 2")
    state1.assignProperty(widget, 'geometry', QtCore.QRectF(0, 0, 400, 150))
    state1.assignProperty(box, 'geometry', QtCore.QRect(-200, 150, 200, 150))
    state1.assignProperty(p1, 'pos', QtCore.QPointF(68, 185))
    state1.assignProperty(p2, 'pos', QtCore.QPointF(168, 185))
    state1.assignProperty(p3, 'pos', QtCore.QPointF(268, 185))
    state1.assignProperty(p4, 'pos', QtCore.QPointF(68 - 150, 48 - 150))
    state1.assignProperty(p5, 'pos', QtCore.QPointF(168, 48 - 150))
    state1.assignProperty(p6, 'pos', QtCore.QPointF(268 + 150, 48 - 150))
Пример #7
0
    def __init__(self, parent=None):
        QtGui.QGraphicsScene.__init__(self, parent)
        #set the size of the scene
        self.setSceneRect(0, 0, 2000, 2000)

        button = QtGui.QPushButton('info')
        button.setMinimumSize(QtCore.QSize(50, 30))
        button.setMaximumSize(QtCore.QSize(50, 30))
        buttonProxy = QtGui.QGraphicsProxyWidget()
        buttonProxy.setWidget(button)

        box = QtGui.QGroupBox()
        box.setStyleSheet(
            "QGroupBox {background: transparent; border: 2px solid black;color: black; background-color: rgba(20%, 30%, 30%, 30%); margin: 1px; padding: 5px;} QGroupBox:Title{background:transparent; margin-top:5px; margin-left:5px;}"
        )
        box.setTitle("C'est la vie.")

        box_child = QtGui.QGroupBox(box)
        box_child.setTitle('Bonjourno')
        box_child.setObjectName('childGroupBox')
        box_child.setStyleSheet(
            "QGroupBox#childGroupBox {background: transparent; border: 2px solid black;color: black; background-color: rgba(10%, 30%, 10%, 30%); margin: 1px; padding: 5px;} QGroupBox:Title#childGroupBox{background:transparent; margin-top:5px; margin-left:5px;}"
        )

        layout2 = QtGui.QVBoxLayout()
        box.setLayout(layout2)
        layout2.addStretch()

        boxProxy = QtGui.QGraphicsProxyWidget()
        boxProxy.setWidget(box)

        # Parent widget.
        widget = QtGui.QGraphicsWidget()
        layout = QtGui.QGraphicsLinearLayout(QtCore.Qt.Vertical, widget)
        layout.addItem(buttonProxy)
        widget.setLayout(layout)

        #QGraphics Scene

        # scene = QtGui.QGraphicsScene(0, 0, 400, 300)
        # scene.setBackgroundBrush(scene.palette().window())
        # scene.addItem(widget)
        # scene.addItem(boxProxy)

        self.setBackgroundBrush(self.palette().window())
        self.addItem(widget)
        self.addItem(boxProxy)

        machine = QtCore.QStateMachine()
        state1 = QtCore.QState(machine)
        state2 = QtCore.QState(machine)
        machine.setInitialState(state1)

        # State 1.
        state1.assignProperty(widget, 'geometry',
                              QtCore.QRectF(0, 0, 400, 150))
        state1.assignProperty(box, 'geometry',
                              QtCore.QRect(-400, 50, 350, 150))
        state1.assignProperty(box_child, 'geometry',
                              QtCore.QRect(30, 300, 150, 100))
        state1.assignProperty(boxProxy, 'opacity', 1.0)

        # State 2.
        state2.assignProperty(widget, 'geometry',
                              QtCore.QRectF(0, 0, 400, 150))
        state2.assignProperty(box, 'geometry', QtCore.QRect(10, 50, 350, 150))
        state2.assignProperty(box_child, 'geometry',
                              QtCore.QRect(30, 30, 150, 100))
        state2.assignProperty(boxProxy, 'opacity', 1.0)

        t1 = state1.addTransition(button.clicked, state2)
        animation1SubGroup = QtCore.QSequentialAnimationGroup()
        animation1SubGroup.addPause(150)
        animation1SubGroup.addAnimation(
            QtCore.QPropertyAnimation(box, 'geometry', state1))

        animation1SubGroup_2 = QtCore.QSequentialAnimationGroup()
        animation1SubGroup_2.addPause(600)
        animation1SubGroup_2.addAnimation(
            QtCore.QPropertyAnimation(box_child, 'geometry', state1))

        t1.addAnimation(animation1SubGroup)
        t1.addAnimation(animation1SubGroup_2)
        t1.addAnimation(QtCore.QPropertyAnimation(widget, 'geometry', state1))

        t2 = state2.addTransition(button.clicked, state1)
        animation1SubGroup_3 = QtCore.QSequentialAnimationGroup()
        animation1SubGroup_3.addPause(300)
        animation1SubGroup_3.addAnimation(
            QtCore.QPropertyAnimation(box_child, 'geometry', state2))
        t2.addAnimation(QtCore.QPropertyAnimation(box, 'geometry', state2))
        t2.addAnimation(animation1SubGroup_3)
        t2.addAnimation(QtCore.QPropertyAnimation(widget, 'geometry', state2))

        machine.start()
Пример #8
0
 def create_machine(self):
     self.machine = QtCore.QStateMachine()
     self.create_states()
     self.create_transitions()
     self.machine.setInitialState(self.init)
     self.machine.start()