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.1.tar.gz (9.2 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.1-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: qtwrap-1.0.1.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for qtwrap-1.0.1.tar.gz
Algorithm Hash digest
SHA256 92d0eb25e6220ddc353efccb122824821626a46ce88577e4618b9ae26712cdc5
MD5 3bf41b1b97e59d40cdff6b1c25f399bf
BLAKE2b-256 3b00709fc2594e1987c60893796c830d04594f26c70a4332aeff6c2eeff86492

See more details on using hashes here.

File details

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

File metadata

  • Download URL: qtwrap-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for qtwrap-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 be4942e57e4e4479d9479dd4a99cdc52608752aa7e808481ca7acb911f2ea38a
MD5 e24d331192ab119a595a84edbc85b07f
BLAKE2b-256 f4e3067e7c5f0935c7cd1f009acda88fcccf1f4925b9917a0e65eb65ee19f4ec

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