Package: pyqt-realtime-log-widget
pyqt-realtime-log-widgetDisplay command log in real time with PyQt widget.This is using subprocess and psutil to execute/manuever the process, using QThread and a variety of signals defined by me to demonstrate process' log.RequirementsPyQt5psutilInstallpython -m pip install pyqt-realtime-log-widget --upgradeIf you want to test or modify this, clone it.It has test code already so you can just run the logWidget.py.Class/Method OverviewLogWidget(parent=None)setCommand(command: str)- set the command that you want to see the log in real time.started- signal emitted after command being started.updated(str)- signal emitted after log being updated. updated line as an argument.stopped- signal emitted after log being stopped.finished- signal emitted after command being finishedsetStartText(start_text: str)- set the text you want to add when process begins to executesetStopText(stop_text: str)- set the text you want to add when process being stoppedsetFinishText(finish_text: str)- text when process being finishedgetStartText,getStopText,getFinishTextare also provided.LogDialog()- Simply put, dialog version of LogWidget. Currently under development, just useLogWidget.getLogWidget()- I believe this is self-explanatory.FeatureYou can pause/resume/stop the commandVertical scroll bar always at the bottom while log is displayingShow the warning dialog when you try to close the widget, if you give the parent widget to the constructor such asLogWidget(self). Process is suspended while warning dialog is showing. If you press Yes, process will be terminated and widget will be closed. If you press no, process will be keep running until it is finished.You can use the signal likestarted,updated,finishedas i mentioned before.ExampleExample 1You need an example.py file. make it, write the code like below.foriinrange(1000):forjinrange(1000000):passprint(f'Log{i}')After doing it, make main.py file or something like that and write the code below.fromPyQt5.QtWidgetsimportQApplicationfrompyqt_realtime_log_widgetimportLogWidgetif__name__=='__main__':importsysapp=QApplication(sys.argv)window=LogWidget()comm='python example.py'window.setCommand(comm)window.show()sys.exit(app.exec())Run it.Result 1https://user-images.githubusercontent.com/55078043/197136837-97503e15-dc7b-4fa7-b892-e7c8c41d5a61.mp4Example 2Make example.py file.foriinrange(100):forjinrange(1000000):passprint(f'Log{i}')Make the Python script and write the code belowfromPyQt5.QtWidgetsimportQApplication,QPushButton,QVBoxLayout,QWidgetfrompyqt_realtime_log_widgetimportLogWidgetclassWidget(QWidget):def__init__(self):super().__init__()self.__initUi()def__initUi(self):self.__btn=QPushButton('Start')self.__btn.clicked.connect(self.__start)self.__logWidget=LogWidget(self)self.__logWidget.layout().setContentsMargins(0,0,0,0)self.__logWidget.finished.connect(self.__finished)lay=QVBoxLayout()lay.addWidget(self.__btn)lay.addWidget(self.__logWidget)self.setLayout(lay)def__start(self):self.__btn.setEnabled(False)comm='python example.py'self.__logWidget.setCommand(comm)def__finished(self):self.__btn.setEnabled(True)if__name__=='__main__':importsysapp=QApplication(sys.argv)widget=Widget()widget.show()sys.exit(app.exec())Run.Result 2https://user-images.githubusercontent.com/55078043/197147702-c1c86945-819d-40e6-ae4a-084146344eb9.mp4Example 3 (LogDialog)fromPyQt5.QtWidgetsimportQApplicationfrompyqt_realtime_log_widgetimportLogDialog//...if__name__=='__main__':importsysapp=QApplication(sys.argv)dialog=LogDialog()proc='python example.py'dialog.setWindowTitle('Logging...')logWidget=dialog.getLogWidget()logWidget.setCommand(proc)dialog.show()sys.exit(app.exec())Result? It's just a dialog version of LogWidget, so it is pointless to upload the image.NoteCurrently stop and finish signal is not well-distinguished. When process being stopped, finished event will be emitted as well, so it will be very confusing. I will fix it or how about you fix it for me?