{"id":17603039,"url":"https://github.com/yjg30737/pyqt-realtime-log-widget","last_synced_at":"2025-05-07T10:20:56.376Z","repository":{"id":62242857,"uuid":"555214746","full_name":"yjg30737/pyqt-realtime-log-widget","owner":"yjg30737","description":"Display log in real time with PyQt widget","archived":false,"fork":false,"pushed_at":"2024-04-14T11:33:36.000Z","size":65,"stargazers_count":9,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T09:02:30.193Z","etag":null,"topics":["pyqt","pyqt-examples","pyqt-log","pyqt-tutorial","pyqt5","pyqt5-examples","pyqt5-tutorial","qt","qthread"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yjg30737.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-10-21T06:38:00.000Z","updated_at":"2024-07-12T01:24:23.000Z","dependencies_parsed_at":"2023-11-09T12:29:35.800Z","dependency_job_id":"e5e80d4d-d930-4c29-b39e-d44b115ce1c2","html_url":"https://github.com/yjg30737/pyqt-realtime-log-widget","commit_stats":{"total_commits":39,"total_committers":2,"mean_commits":19.5,"dds":0.02564102564102566,"last_synced_commit":"1cba78e3b712b9b5bc9b970d4938446aaa1e4e37"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yjg30737%2Fpyqt-realtime-log-widget","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yjg30737%2Fpyqt-realtime-log-widget/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yjg30737%2Fpyqt-realtime-log-widget/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yjg30737%2Fpyqt-realtime-log-widget/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yjg30737","download_url":"https://codeload.github.com/yjg30737/pyqt-realtime-log-widget/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252856818,"owners_count":21814904,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["pyqt","pyqt-examples","pyqt-log","pyqt-tutorial","pyqt5","pyqt5-examples","pyqt5-tutorial","qt","qthread"],"created_at":"2024-10-22T13:37:56.893Z","updated_at":"2025-05-07T10:20:56.345Z","avatar_url":"https://github.com/yjg30737.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pyqt-realtime-log-widget\nDisplay command log in real time with PyQt widget.\n\nThis is using subprocess and psutil to execute/manuever the process, using QThread and a variety of signals defined by me to demonstrate process' log.\n\n## Requirements\n* PyQt5\n* psutil\n\n## Install\n`python -m pip install pyqt-realtime-log-widget --upgrade`\n\nIf you want to test or modify this, clone it.\n\nIt has test code already so you can just run the logWidget.py.\n\n## Class/Method Overview\n* `LogWidget(parent=None, warn_before_close=True, show_buttons=True)`\n   * parameters\n      * `warn_before_close` - Show warning dialog before closing.\n      * `show_buttons` - Show pause and stop buttons at the bottom of the screen.\n   * function\n       * `setCommand(command: str)` - set the command that you want to see the log in real time.\n       * `started` - signal emitted after command being started.\n       * `updated(str)` - signal emitted after log being updated. updated line as an argument.\n       * `stopped` - signal emitted after log being stopped.\n       * `finished` - signal emitted after command being finished\n       * `setStartText(start_text: str)` - set the text you want to add when process begins to execute\n       * `setStopText(stop_text: str)` - set the text you want to add when process being stopped\n       * `setFinishText(finish_text: str)` - text when process being finished\n       * `getStartText`, `getStopText`, `getFinishText` are also provided.\n* `LogDialog(show_buttons=True, minimizeable=True)` - Simply put, dialog version of LogWidget.\n   * parameters\n      * `show_buttons` - Same as `LogWidget`'s.\n      * `minimizeable` - Make it able to be minimized or not  \n   * function \n      * `getLogWidget()` - I believe this is self-explanatory.\n## Feature\n* You can pause/resume/stop the command\n* Vertical scroll bar always at the bottom while log is displaying\n* Show the warning dialog when you try to close the widget, if you give the parent widget to the constructor such as `LogWidget(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.\n* You can use the signal like `started`, `updated`, `finished` as i mentioned before.\n\n## Example\n### Example 1\nYou need an example.py file. make it, write the code like below.\n\n```python\nfor i in range(1000):\n    for j in range(1000000):\n        pass\n    print(f'Log {i}')\n```\n\nAfter doing it, make main.py file or something like that and write the code below. \n\n```python\nfrom PyQt5.QtWidgets import QApplication\nfrom pyqt_realtime_log_widget import LogWidget\n\nif __name__ == '__main__':\n    import sys\n\n    app = QApplication(sys.argv)\n    window = LogWidget()\n    comm = 'python example.py'\n    window.setCommand(comm)\n    window.show()\n    sys.exit(app.exec())\n```\n\nRun it.\n\n### Result 1\n\nhttps://user-images.githubusercontent.com/55078043/197136837-97503e15-dc7b-4fa7-b892-e7c8c41d5a61.mp4\n\n### Example 2\nMake example.py file.\n```python\nfor i in range(100):\n    for j in range(1000000):\n        pass\n    print(f'Log {i}')\n```\n\nMake the Python script and write the code below\n```python\nfrom PyQt5.QtWidgets import QApplication, QPushButton, QVBoxLayout, QWidget\nfrom pyqt_realtime_log_widget import LogWidget\n\n\nclass Widget(QWidget):\n    def __init__(self):\n        super().__init__()\n        self.__initUi()\n\n    def __initUi(self):\n        self.__btn = QPushButton('Start')\n        self.__btn.clicked.connect(self.__start)\n        self.__logWidget = LogWidget(self)\n        self.__logWidget.layout().setContentsMargins(0, 0, 0, 0)\n        self.__logWidget.finished.connect(self.__finished)\n        lay = QVBoxLayout()\n        lay.addWidget(self.__btn)\n        lay.addWidget(self.__logWidget)\n        self.setLayout(lay)\n\n    def __start(self):\n        self.__btn.setEnabled(False)\n        comm = 'python example.py'\n        self.__logWidget.setCommand(comm)\n\n    def __finished(self):\n        self.__btn.setEnabled(True)\n\n\nif __name__ == '__main__':\n    import sys\n\n    app = QApplication(sys.argv)\n    widget = Widget()\n    widget.show()\n    sys.exit(app.exec())\n```\n\nRun.\n\n### Result 2\n\nhttps://user-images.githubusercontent.com/55078043/197147702-c1c86945-819d-40e6-ae4a-084146344eb9.mp4\n\n### Example 3 (LogDialog)\n```python\nfrom PyQt5.QtWidgets import QApplication\nfrom pyqt_realtime_log_widget import LogDialog\n//...\n\nif __name__ == '__main__':\n    import sys\n\n    app = QApplication(sys.argv)\n    dialog = LogDialog()\n    proc = 'python example.py'\n    dialog.setWindowTitle('Logging...')\n    logWidget = dialog.getLogWidget()\n    logWidget.setCommand(proc)\n    dialog.show()\n    sys.exit(app.exec())\n```\n\nResult? It's just a dialog version of LogWidget, so it is pointless to upload the image.\n\n## Note\nCurrently 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?\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyjg30737%2Fpyqt-realtime-log-widget","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyjg30737%2Fpyqt-realtime-log-widget","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyjg30737%2Fpyqt-realtime-log-widget/lists"}