I'm writing a simple script for resizing photos. I'd like to have a widget with text-field in which messages appear after resizing each file.
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import time, sys
from PyQt5.QtCore import pyqtSignal, QThread
from PyQt5.QtWidgets import QApplication, QPushButton, QTextEdit, QWidget, QVBoxLayout
class Thread(QThread):
log = pyqtSignal(str)
def __init__(self, parent=None):
super(Thread, self).__init__(parent)
def test(self, i):
time.sleep(1)
self.log.emit(str(i))
class Widget(QWidget):
def __init__(self):
super().__init__()
self.ui()
def process(self):
self.toLog('some text...')
worker = Thread()
worker.log.connect(self.toLog)
for i in range(1, 5):
worker.test(i)
def ui(self):
self.LogOutputTxt = QTextEdit()
self.LogOutputTxt.setReadOnly(True)
startBtn = QPushButton('Start')
startBtn.clicked.connect(self.start)
layout = QVBoxLayout()
layout.addWidget(self.LogOutputTxt)
layout.addWidget(startBtn)
self.setLayout(layout)
self.resize(400, 300)
self.show()
def start(self):
self.toLog('start')
self.process()
def toLog(self, txt):
self.LogOutputTxt.append(txt)
if __name__ == '__main__':
app = QApplication(sys.argv)
ui = Widget()
sys.exit(app.exec_())
So far all the messages appear at once after all files are resized. Is there any way to do it one by one (I mean file resized, message displayed, etc.)?