コード例 #1
0
    def testBasic(self):
        self.machine = QStateMachine()
        s1 = QState()
        s2 = QState()
        s3 = QFinalState()

        QObject.connect(self.machine, SIGNAL("started()"), self.cb)

        self.anim = QParallelAnimationGroup()

        self.machine.addState(s1)
        self.machine.addState(s2)
        self.machine.addState(s3)
        self.machine.setInitialState(s1)
        self.machine.addDefaultAnimation(self.anim)
        self.machine.start()

        QTimer.singleShot(100, self.app.quit)
        self.app.exec_()
コード例 #2
0
    def testCase(self):
        check = QCheckBox()
        check.setTristate(True)

        s1 = QState()
        s2 = QState()

        t1 = CheckedTransition(check)
        t1.setTargetState(s2)
        s1.addTransition(t1)

        machine = QStateMachine()
        machine.addState(s1)
        machine.addState(s2)
        machine.setInitialState(s1)
        machine.start()

        check.stateChanged[int].emit(1)
        check.show()
        self.app.exec_()
        self.assert_(t1.eventTested)
コード例 #3
0
ファイル: bug_416.py プロジェクト: Hasimir/PySide
    def testCase(self):
        check = QCheckBox()
        check.setTristate(True)

        s1 = QState()
        s2 = QState()

        t1 = CheckedTransition(check)
        t1.setTargetState(s2)
        s1.addTransition(t1)

        machine = QStateMachine()
        machine.addState(s1)
        machine.addState(s2)
        machine.setInitialState(s1)
        machine.start()

        check.stateChanged[int].emit(1)
        check.show()
        self.app.exec_()
        self.assert_(t1.eventTested)
コード例 #4
0
    def testBasic(self):
        '''QStateMachine.configuration converting QSet to python set'''
        machine = QStateMachine()
        s1 = QState()
        machine.addState(s1)
        machine.setInitialState(s1)
        machine.start()

        QTimer.singleShot(100, self.app.quit)
        self.app.exec_()

        configuration = machine.configuration()

        self.assert_(isinstance(configuration, set))
        self.assert_(s1 in configuration)
コード例 #5
0
    def _make_states(self, conn, button, action, label):
        """
        Creates the four states for the simple state machine.
        Adds the needed properties for the passed controls.

        :param conn: the connection instance that defines this machine.
        :type conn: AbstractLEAPConnection

        :param button: the switch button.
        :type button: QPushButton

        :param action: the actionh that controls connection switch in a menu.
        :type action: QAction

        :param label: the label that displays the connection state
        :type label: QLabel

        :returns: a dict of states
        :rtype: dict
        """
        states = {}

        # TODO add tooltip

        # OFF State ----------------------
        off = QState()
        off_label = _tr("Turn {0}").format(
            conn.Connected.short_label)
        if button:
            off.assignProperty(
                button, 'text', off_label)
            off.assignProperty(
                button, 'enabled', True)
        if action:
            off.assignProperty(
                action, 'text', off_label)
        off.setObjectName(_OFF)
        states[_OFF] = off

        # CONNECTING State ----------------
        connecting = SignallingState(
            conn.qtsigs.connecting_signal,
            name=conn.name)
        on_label = _tr("Turn {0}").format(
            conn.Disconnected.short_label)
        if button:
            connecting.assignProperty(
                button, 'text', on_label)
            connecting.assignProperty(
                button, 'enabled', False)
        if action:
            connecting.assignProperty(
                action, 'text', on_label)
            connecting.assignProperty(
                action, 'enabled', False)
        connecting.setObjectName(_CON)
        states[_CON] = connecting

        # ON State ------------------------
        on = QState()
        if button:
            on.assignProperty(
                button, 'text', on_label)
            on.assignProperty(
                button, 'enabled', True)
        if action:
            on.assignProperty(
                action, 'text', on_label)
            on.assignProperty(
                action, 'enabled', True)
        # TODO set label for ON state
        on.setObjectName(_ON)
        states[_ON] = on

        # DISCONNECTING State -------------
        disconnecting = SignallingState(
            conn.qtsigs.disconnecting_signal,
            name=conn.name)
        if button:
            disconnecting.assignProperty(
                button, 'enabled', False)
        # XXX complete disconnecting
        # TODO disable button
        disconnecting.setObjectName(_DIS)
        states[_DIS] = disconnecting

        return states
コード例 #6
0
ファイル: bug_1031.py プロジェクト: zkactivity/PySide
from PySide.QtCore import QStateMachine, QState

mach = QStateMachine()
state = QState(mach)
print(state.machine())
コード例 #7
0
ファイル: main.py プロジェクト: Ingener74/Steamy-Serpent
    def __init__(self, parent=None):
        QWidget.__init__(self, parent)
        self.setupUi(self)

        machine = QStateMachine(self)

        s11 = QState()
        s11.setObjectName('s11')
        s11.assignProperty(self.lineEdit, 'text', u'Состояние 1')

        s12 = QState()
        s12.setObjectName('s12')
        s12.assignProperty(self.lineEdit, 'text', u'Состояние 2')

        s13 = QState()
        s13.setObjectName('s13')
        s13.assignProperty(self.lineEdit, 'text', u'Состояние 3')

        # s11.entered.connect(self.s11entered)

        s11.addTransition(self.ChangeState.clicked, s12)
        s12.addTransition(self.ChangeState.clicked, s13)
        s13.addTransition(self.ChangeState.clicked, s11)

        machine.addState(s11)
        machine.addState(s12)
        machine.addState(s13)

        machine.setInitialState(s11)

        machine.start()
コード例 #8
0
ファイル: first.py プロジェクト: satishgoda/learningqt
from PySide.QtGui import QPushButton, QLabel
from PySide.QtCore import QStateMachine, QState

switch = QPushButton("Switch")
notification = QLabel("Flip the switch")

onState = QState()
offState = QState()

offState.addTransition(switch, "clicked()", onState)
onState.addTransition(switch, "clicked()", offState)

offState.assignProperty(notification, "text", "Off")
onState.assignProperty(notification, "text", "On")

machine = QStateMachine()

machine.addState(onState)
machine.addState(offState)

machine.setInitialState(offState)

machine.start()

switch.show()
notification.show()