I’m working on a Python application with pyQt5, more specific with QThread, QObject, QMainWindow.
I have a main class (QMainWindow) with 2 functions (I run the functions here because I need to use/call QLabels, QLineEdit.text (), etc.) The function called “initialDF” downloads a data frame from the web and “plays” with it, finally the function gets a variable called "Test " and a final dataframe called “Data”. The funtion called “bucleDF” turn “Data”.
I need to use "Test " as While validator in another class (QObject) that runs my QThread and i need to call “Data” in While-loop for “update” the validator calling “Test”.
class Worker (QObject):
finished = pyqtSignal()
stage1 = pyqtSignal()
stage2 = pyqtSignal()
def __init__(self) -> None:
super().__init__(parent=None)
def bucleRelleno(self):
self.stage1.emit()
while test <= '17:00':
self.stage2.emit()
lasttime = pd.to_datetime(max(data.index))
lasttime = lasttime + datetime.timedelta(minutes=60)
nexttime = lasttime + datetime.timedelta(minutes=2)
test = "{:d}:{:02d}".format(nexttime.hour, nexttime.minute)
t.sleep(1)
self.finished.emit()
class MainWindow (QMainWindow):
global data
def __init__(self, parent=None):
super(MainWindow, self).__init__()
uic.loadUi('xxxx', self)
self.run.clicked.connect(self.runLongTask)
def runLongTask(self):
self.thread = QThread()
self.worker = Worker()
self.worker.moveToThread(self.thread)
self.thread.started.connect(self.worker.bucleRelleno)
self.worker.finished.connect(self.thread.quit)
self.worker.finished.connect(self.worker.deleteLater)
self.thread.finished.connect(self.thread.deleteLater)
self.worker.stage1.connect(self.initialDF)
self.worker.stage2.connect(self.bucleDF)
self.thread.start()
def initialDF(self):
data = pandas.DataFrame()
lasttime = pd.to_datetime(max(data.index))
lasttime = lasttime + datetime.timedelta(minutes=60)
nexttime = lasttime + datetime.timedelta(minutes=2)
test = "{:d}:{:02d}".format(nexttime.hour, nexttime.minute)
return data, test
def bucleDF(self):
data2 = pandas.DataFrame()
data = pd.concat([data, data2])
return data