Advertisement
cendolinside

GUI

Mar 20th, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.16 KB | None | 0 0
  1. from PyQt4 import QtCore,QtGui,uic
  2. import sys
  3. import time
  4. import threading
  5.  
  6.  
  7. qtCreatorFile = "Getar.ui"
  8.  
  9. #speed = 0
  10. #amplitudo = 0
  11.  
  12. Ui_MainWindow,QtBaseClass = uic.loadUiType(qtCreatorFile)
  13.  
  14. class MyApp(QtGui.QTabWidget,Ui_MainWindow):
  15.     speed = 0
  16.     amplitudo = 0
  17.     ii = 0
  18.     threads = []
  19.     def __init__(self):
  20.         #global speed
  21.         #global amplitudo
  22.         QtGui.QTabWidget.__init__(self)
  23.         Ui_MainWindow.__init__(self)
  24.         self.setupUi(self)
  25.  
  26.        
  27.        
  28.  
  29.         self.amplitudoS.setMinimum(0)
  30.         self.amplitudoS.setMaximum(30)
  31.         self.amplitudoS.setValue(0)
  32.         self.amplitudoS.valueChanged.connect(self.valueAmplitudo)
  33.         self.amplitudoS.sliderReleased.connect(self.getThread)
  34.  
  35.         self.l1.setText(str(self.amplitudoS.value()))
  36.  
  37.         self.speedS.setMinimum(0)
  38.         self.speedS.setMaximum(30)
  39.         self.speedS.setValue(0)
  40.         self.speedS.valueChanged.connect(self.valueSpeed)
  41.         self.speedS.sliderReleased.connect(self.getThread)
  42.  
  43.         self.l2.setText(str(self.speedS.value()))
  44.        
  45.  
  46.  
  47.  
  48.         self.start.clicked.connect(self.StartThread)
  49.         self.stop.clicked.connect(self.StopThread)
  50.        
  51.     def getThread(self):
  52.         MyApp.ii = MyApp.ii + 1
  53.         #global
  54.         if self.sender() == self.amplitudoS:
  55.             MyApp.amplitudo = int(self.amplitudoS.value())
  56.         elif self.sender() == self.speedS:
  57.             MyApp.speed = int(self.speedS.value())
  58.  
  59.         if MyApp.amplitudo > 0 and MyApp.speed > 0:
  60.            
  61.             thread1 = ThreadRun(MyApp.amplitudo,MyApp.speed,"amplitudo")
  62.             thread1.setName(str(MyApp.ii))
  63.  
  64.             thread1.start()
  65.  
  66.     def valueAmplitudo(self):
  67.         value = self.amplitudoS.value()
  68.         self.l1.setText(str(value))
  69.        
  70.  
  71.     def valueSpeed(self):
  72.         value2 = self.speedS.value()
  73.         self.l2.setText(str(value2))
  74.        
  75.        
  76.     def StartThread(self):
  77.         thread3 = ThreadRun(int(self.ampli2.text()),int(self.speed2.text()),"amplitudo")
  78.         thread3.setName("manual")
  79.         thread3.start()
  80.         MyApp.threads.append(thread3)
  81.        
  82.     def StopThread(self):
  83.        
  84.         for t in MyApp.threads:
  85.             t.stop()
  86.      
  87.                
  88. class ThreadRun(threading.Thread):
  89.     def __init__(self,num,s,sub):
  90.         threading.Thread.__init__(self)
  91.         self.autoRun = False
  92.         self.number = num
  93.         self.speed = s
  94.         self.subject = sub
  95.        
  96.     def run(self):
  97.        
  98.         print("starting " + self.subject)
  99.  
  100.         while self.autoRun == True:
  101.             if self.speed > 0 and self.number > 0:
  102.                 print(str(self.number) + " " + self.subject)
  103.                 time.sleep(self.speed)
  104.             else:
  105.                 self.autoRun = False
  106.                 break
  107.         print("stoping " + self.subject)
  108.        
  109.     def start(self):
  110.         self.autoRun = True
  111.         super(ThreadRun,self).start()
  112.  
  113.     def stop(self):
  114.         self.autoRun = False
  115.        
  116.  
  117. if __name__ == "__main__":
  118.     app = QtGui.QApplication(sys.argv)
  119.     window = MyApp()
  120.     window.show()
  121.     sys.exit(app.exec_())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement