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_()
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)
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)
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
from PySide.QtCore import QStateMachine, QState mach = QStateMachine() state = QState(mach) print(state.machine())
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()
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()