Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PyQt4 import QtCore,QtGui,uic
- import sys
- import time
- import threading
- qtCreatorFile = "Getar.ui"
- #speed = 0
- #amplitudo = 0
- Ui_MainWindow,QtBaseClass = uic.loadUiType(qtCreatorFile)
- class MyApp(QtGui.QTabWidget,Ui_MainWindow):
- speed = 0
- amplitudo = 0
- ii = 0
- threads = []
- def __init__(self):
- #global speed
- #global amplitudo
- QtGui.QTabWidget.__init__(self)
- Ui_MainWindow.__init__(self)
- self.setupUi(self)
- self.amplitudoS.setMinimum(0)
- self.amplitudoS.setMaximum(30)
- self.amplitudoS.setValue(0)
- self.amplitudoS.valueChanged.connect(self.valueAmplitudo)
- self.amplitudoS.sliderReleased.connect(self.getThread)
- self.l1.setText(str(self.amplitudoS.value()))
- self.speedS.setMinimum(0)
- self.speedS.setMaximum(30)
- self.speedS.setValue(0)
- self.speedS.valueChanged.connect(self.valueSpeed)
- self.speedS.sliderReleased.connect(self.getThread)
- self.l2.setText(str(self.speedS.value()))
- self.start.clicked.connect(self.StartThread)
- self.stop.clicked.connect(self.StopThread)
- def getThread(self):
- MyApp.ii = MyApp.ii + 1
- #global
- if self.sender() == self.amplitudoS:
- MyApp.amplitudo = int(self.amplitudoS.value())
- elif self.sender() == self.speedS:
- MyApp.speed = int(self.speedS.value())
- if MyApp.amplitudo > 0 and MyApp.speed > 0:
- thread1 = ThreadRun(MyApp.amplitudo,MyApp.speed,"amplitudo")
- thread1.setName(str(MyApp.ii))
- thread1.start()
- def valueAmplitudo(self):
- value = self.amplitudoS.value()
- self.l1.setText(str(value))
- def valueSpeed(self):
- value2 = self.speedS.value()
- self.l2.setText(str(value2))
- def StartThread(self):
- thread3 = ThreadRun(int(self.ampli2.text()),int(self.speed2.text()),"amplitudo")
- thread3.setName("manual")
- thread3.start()
- MyApp.threads.append(thread3)
- def StopThread(self):
- for t in MyApp.threads:
- t.stop()
- class ThreadRun(threading.Thread):
- def __init__(self,num,s,sub):
- threading.Thread.__init__(self)
- self.autoRun = False
- self.number = num
- self.speed = s
- self.subject = sub
- def run(self):
- print("starting " + self.subject)
- while self.autoRun == True:
- if self.speed > 0 and self.number > 0:
- print(str(self.number) + " " + self.subject)
- time.sleep(self.speed)
- else:
- self.autoRun = False
- break
- print("stoping " + self.subject)
- def start(self):
- self.autoRun = True
- super(ThreadRun,self).start()
- def stop(self):
- self.autoRun = False
- if __name__ == "__main__":
- app = QtGui.QApplication(sys.argv)
- window = MyApp()
- window.show()
- sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement