<div dir="ltr">Do not overwrite important methods with names that don't really match what they're doing. Also, your implementation will cause recursion, which is clearly not good.<div>Just change the function name with something more appropriate, like "stop" or "stop and wait" and *then* call self.wait() there.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Il giorno ven 2 lug 2021 alle ore 07:40 Demosthenes Koptsis <<a href="mailto:demosthenesk@gmail.com">demosthenesk@gmail.com</a>> ha scritto:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">What do you think of this implementation ?<br>
<br>
<br>
Thread.py<br>
<br>
---------------------------<br>
<br>
from PyQt5.QtWidgets import *<br>
from PyQt5.QtCore import *<br>
from MainWindow import *<br>
import sys<br>
import time<br>
<br>
<br>
class RunThread(QtCore.QThread):<br>
     counter_value = QtCore.pyqtSignal(int)  # define new Signal<br>
<br>
     def __init__(self, parent=None, counter_start=0):<br>
         super(RunThread, self).__init__(parent)<br>
         self.counter = counter_start<br>
         self.is_running = True<br>
<br>
     def run(self):<br>
         self.is_running = True<br>
         while self.counter < 100 and self.is_running is True:<br>
             time.sleep(0.5)<br>
             self.counter += 1<br>
             self.counter_value.emit(self.counter)  # emit new Signal <br>
with value<br>
<br>
     def stop(self):<br>
         try:<br>
             self.is_running = False<br>
             self.terminate()<br>
         except:<br>
             pass<br>
<br>
     def wait(self):<br>
         try:<br>
             self.is_running = False<br>
             self.wait()<br>
         except:<br>
             pass<br>
<br>
class MainWindow(QWidget):<br>
     def __init__(self, parent=None):<br>
         super(MainWindow, self).__init__(parent)<br>
         self.ui = Ui_Form()<br>
         self.ui.setupUi(self)<br>
         self.center()<br>
         #Init progressBar<br>
         self.ui.progressBar.setValue(0)<br>
         #Buttons<br>
         self.ui.btnRun.clicked.connect(self.StartThread)<br>
         self.ui.btnStop.clicked.connect(self.WaitThread)<br>
         self.ui.dial.sliderMoved.connect(self.SetLCD)<br>
         #Init Thread<br>
         self.MyThread = RunThread(parent=None, counter_start=0)<br>
<br>
     def SetLCD(self):<br>
         self.ui.lcdNumber.display(self.ui.dial.value())<br>
<br>
     def WaitThread(self):<br>
         self.MyThread.wait()<br>
<br>
     def StartThread(self):<br>
         self.MyThread.start()<br>
self.MyThread.counter_value.connect(self.SetProgressBarValue)<br>
<br>
     def SetProgressBarValue(self):<br>
         self.ui.progressBar.setValue(self.MyThread.counter)<br>
<br>
     def center(self):<br>
         # geometry of the main window<br>
         qr = self.frameGeometry()<br>
<br>
         # center point of screen<br>
         cp = QDesktopWidget().availableGeometry().center()<br>
<br>
         # move rectangle's center point to screen's center point<br>
         qr.moveCenter(cp)<br>
<br>
         # top left of rectangle becomes top left of window centering it<br>
         self.move(qr.topLeft())<br>
<br>
if __name__ == '__main__':<br>
     app = QApplication(sys.argv)<br>
     w = MainWindow()<br>
     #   Disable maximize window button<br>
     w.setWindowFlags(Qt.WindowCloseButtonHint | <br>
Qt.WindowMinimizeButtonHint)<br>
     w.show()<br>
     sys.exit(app.exec_())<br>
<br>
</blockquote></div><br clear="all"><div><br></div>-- <br><div dir="ltr" class="gmail_signature">È difficile avere una convinzione precisa quando si parla delle ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi<br><a href="http://www.jidesk.net" target="_blank">http://www.jidesk.net</a></div>