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()
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.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()