SHARE
TWEET

Untitled

a guest Jul 7th, 2012 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys
  2. from PyQt4 import QtCore, QtGui
  3.  
  4. class MainWindow(QtGui.QMainWindow):
  5.         def __init__(self, parent=None):
  6.                 super(MainWindow, self).__init__(parent)
  7.                 self.init_widgets()
  8.        
  9.         def init_widgets(self):
  10.                 mainLayout = QtGui.QGridLayout()
  11.                
  12.                 self.button1 = QtGui.QCommandLinkButton("Test1")
  13.                 self.button2 = QtGui.QCommandLinkButton("Test2")
  14.                 self.label = QtGui.QLabel("original value")
  15.  
  16.                 mainLayout.addWidget(self.button1, 1, 0)
  17.                 mainLayout.addWidget(self.button2, 1, 1)
  18.                 mainLayout.addWidget(self.label, 2, 0, 1, 2)
  19.                
  20.                 machine = QtCore.QStateMachine()
  21.                 s1 = QtCore.QState(machine)
  22.                 s2 = QtCore.QState(machine)
  23.                 s3 = QtCore.QState(machine)
  24.                 machine.setInitialState(s1)
  25.                
  26.                 s1.assignProperty(self.label, "text", "in state 1")
  27.                 s2.assignProperty(self.label, "text", "in state 2")
  28.                 s3.assignProperty(self.label, "text", "in state 3")
  29.                
  30.                 t1 = s1.addTransition(self.button1.clicked, s2)
  31.                 t2 = s2.addTransition(self.button1.clicked, s3)
  32.                 t3 = s3.addTransition(self.button1.clicked, s1)
  33.                
  34.                 machine.start()
  35.                
  36.                 central_widget = QtGui.QWidget()
  37.                 central_widget.setLayout(mainLayout)
  38.                 self.setCentralWidget(central_widget)
  39.  
  40. if __name__ == '__main__':
  41.         app = QtGui.QApplication(sys.argv)
  42.         MainWindow = MainWindow()
  43.         MainWindow.show()
  44.         eventLoop = app.exec_()
  45.         sys.exit(eventLoop)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top