Skip to main content

A PyQt6 toolkit for wrapping scripts in a GUI with live stdout capture

Project description

qtwrap

A PyQt6 toolkit for wrapping standard Python scripts in a GUI.

Requirements

  • Python >= 3.12

Installation

pip install qtwrap

or, to add it to a uv-managed project:

uv add qtwrap

Quick Start

A simple window allowing to capture the stdout and stderr of the given function with Exception handling.

import time
from PyQt6.QtWidgets import QApplication, QWidget, QPushButton, QTextEdit, QVBoxLayout, QComboBox
from qtwrap import LogLevel, DirectorySelector, ChoiceSelector, ScriptCaptureWindow

class MainWindow(ScriptCaptureWindow):
    def __init__(self, func):
        super().__init__(func)

        self.setWindowTitle("MainWindow")
        self.setGeometry(100, 100, 800, 600)

        widget = QWidget()
        layout = QVBoxLayout()

        self.__output = QTextEdit()
        self.__dir = DirectorySelector()
        self.__choice = ChoiceSelector("one", "two", "three")
        self.__btn = QPushButton("Start")

        layout.addWidget(self.__dir)
        layout.addWidget(self.__choice)
        layout.addWidget(self.__btn)
        layout.addWidget(self.__output)
        widget.setLayout(layout)

        self.setCentralWidget(widget)
        self.set_output_field(self.__output)
        self.__btn.clicked.connect(self.__start)

        self.show()

    def __args(self):
        return {
            "path": self.__dir.path(),
            "choices": self.__choice.choice()
        }

    def __start(self):
        if len(self.__dir.path()) == 0:
            self.status("The path must be set.", LogLevel.ERROR)
            return

        if len(self.__choice.choice()) == 0:
            self.status("Make a choice.", LogLevel.ERROR)
            return

        self._started(kwargs=self.__args())

def f(path: str, choices: list):
    for _ in range(5):
        print(f"{path=} | {choices=}")
        time.sleep(0.3)
    print(1/0)

app = QApplication([])
window = MainWindow(f)
app.exec()

Features

  • Live output capturestdout and stderr from the wrapped function are streamed into the GUI as they're produced, including output from background threading.Threads spawned inside it, not just the main call.
  • Non-blocking execution — the wrapped function runs on a separate thread, so the GUI stays responsive while it works.
  • Automatic input locking — all input widgets are disabled while the script runs and re-enabled automatically once it finishes, without any manual wiring per widget.
  • Exception handling — unhandled exceptions, including ones raised inside child threads, are caught and displayed in the output field with a full traceback instead of crashing or printing to the console.
  • Ready-made input widgetsDirectorySelector, FileSelector, and ChoiceSelector cover common script inputs out of the box.
  • Status bar & output saving — built-in status messages for validation/errors, plus a menu action to save the captured output to a file.

License

This project is licensed under the terms of the LICENSE file included in this repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

qtwrap-1.0.2.tar.gz (38.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

qtwrap-1.0.2-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file qtwrap-1.0.2.tar.gz.

File metadata

  • Download URL: qtwrap-1.0.2.tar.gz
  • Upload date:
  • Size: 38.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for qtwrap-1.0.2.tar.gz
Algorithm Hash digest
SHA256 7dd6aa3feaf6541b7c2e3bf06851ff0a9696d67e346073b497d3f38b99c1735e
MD5 c9e24bc099194cac00748489c9302747
BLAKE2b-256 42ae1365e93a6bbd06206b8f7bf9c67a5f4de7a55e8d795a646e3c16bbe3557d

See more details on using hashes here.

File details

Details for the file qtwrap-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: qtwrap-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for qtwrap-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e7d503b4d2e52645400aea4416cde3f164b38b754032a9a68139962c6ee8b848
MD5 9bc43d7b7fe5190d7fd2a0d0ba6e6e59
BLAKE2b-256 1fa46248316be7446d6808aefc08d3e91c0519a2821631fd048ca70e50cf6ff8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page