def makeState(self, parentState, animationFileName):
        topLevel = QtCore.QState(parentState)

        animation = Animation()

        file = QtCore.QFile(animationFileName)
        if file.open(QtCore.QIODevice.ReadOnly):
            animation.load(file)

        frameCount = animation.totalFrames()
        previousState = None
        for i in range(frameCount):
            animation.setCurrentFrame(i)

            frameState = QtCore.QState(topLevel)
            nodeCount = animation.nodeCount()
            for j in range(nodeCount):
                frameState.assignProperty(self.m_stickMan.node(j), 'pos',
                                          animation.nodePos(j))

            frameState.setObjectName('frame %d' % i)

            if previousState is None:
                topLevel.setInitialState(frameState)
            else:
                previousState.addTransition(previousState.propertiesAssigned,
                                            frameState)

            previousState = frameState

        previousState.addTransition(previousState.propertiesAssigned,
                                    topLevel.initialState())

        return topLevel
    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)
Beispiel #3
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()
Beispiel #4
0
def createGeometryState(w1, rect1, w2, rect2, w3, rect3, w4, rect4, parent):
    result = QtCore.QState(parent)

    result.assignProperty(w1, 'geometry', rect1)
    result.assignProperty(w2, 'geometry', rect2)
    result.assignProperty(w3, 'geometry', rect3)
    result.assignProperty(w4, 'geometry', rect4)

    return result
Beispiel #5
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()
Beispiel #6
0
    centeredButton = Button(QtGui.QPixmap(':/images/centered.png'),
                            buttonParent)

    ellipseButton.setPos(-100, -100)
    figure8Button.setPos(100, -100)
    randomButton.setPos(0, 0)
    tiledButton.setPos(-100, 100)
    centeredButton.setPos(100, 100)

    scene.addItem(buttonParent)
    buttonParent.scale(0.75, 0.75)
    buttonParent.setPos(200, 200)
    buttonParent.setZValue(65)

    # States.
    rootState = QtCore.QState()
    ellipseState = QtCore.QState(rootState)
    figure8State = QtCore.QState(rootState)
    randomState = QtCore.QState(rootState)
    tiledState = QtCore.QState(rootState)
    centeredState = QtCore.QState(rootState)

    # Values.
    for i, item in enumerate(items):
        # Ellipse.
        ellipseState.assignProperty(
            item, 'pos',
            QtCore.QPointF(
                math.cos((i / 63.0) * 6.28) * 250,
                math.sin((i / 63.0) * 6.28) * 250))
Beispiel #7
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_())
Beispiel #8
0
    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))
    state1.assignProperty(p1, 'rotation', 0.0)
Beispiel #9
0
    scene = QtGui.QGraphicsScene(0, 0, 300, 300)
    scene.setBackgroundBrush(QtCore.Qt.black)
    scene.addItem(button1)
    scene.addItem(button2)
    scene.addItem(button3)
    scene.addItem(button4)

    window = QtGui.QGraphicsView(scene)
    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(100, 0, 50,
                                                       50), button2,
                                 QtCore.QRect(150, 0, 50, 50), button3,
                                 QtCore.QRect(200, 0, 50, 50), button4,
                                 QtCore.QRect(250, 0, 50, 50), group)

    state2 = createGeometryState(button1, QtCore.QRect(250, 100, 50,
                                                       50), button2,
                                 QtCore.QRect(250, 150, 50, 50), button3,
                                 QtCore.QRect(250, 200, 50, 50), button4,
Beispiel #10
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()
Beispiel #11
0
def createStates(objects, selectedRect, parent):
    for obj in objects:
        state = QtCore.QState(parent)
        state.assignProperty(obj, 'geometry', selectedRect)
        parent.addTransition(obj.clicked, state)
Beispiel #12
0
    scene.setBackgroundBrush(QtCore.Qt.white)
    scene.addItem(p1)
    scene.addItem(p2)
    scene.addItem(p3)
    scene.addItem(p4)

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

    machine = QtCore.QStateMachine()
    machine.setGlobalRestorePolicy(QtCore.QStateMachine.RestoreProperties)

    group = QtCore.QState(machine)
    selectedRect = QtCore.QRect(86, 86, 128, 128)

    idleState = QtCore.QState(group)
    group.setInitialState(idleState)

    objects = [p1, p2, p3, p4]
    createStates(objects, selectedRect, group)
    createAnimations(objects, machine)

    machine.setInitialState(group)
    machine.start()

    window.resize(300, 300)
    window.show()