Skip to main content

Turn click CLI's into QT applications

Project description

clickqt

License: MIT GitHub Workflow Status PyPI version

clickqt generates Qt GUIs from click commands. Your click CLI remains the single source of truth, your users get the benefit from a GUI.

Feature List

  • Build a GUI automatically from click CLIs
  • Launch GUIs for already installed CLIs (or from a Python file) via clickqtfy.
  • Ship a GUI for your Python package with three lines of code
  • Map common click types to Qt widgets, including bool, int, float, str, Choice, DateTime, Path, File, tuple, nargs, and multiple.
  • Support for hierarchically nested click.Groups
  • Carry over defaults, required flags, callbacks, and envvar-based initialization.
  • Execute your command from the GUI and stream stdout/stderr to an in-app terminal panel.
  • Export the current GUI state as a shell command and import command lines from the clipboard.
  • Support option grouping headers from click-option-group.

Installation instructions

clickqt requires Python >=3.10.

Install from PyPI:

python -m pip install clickqt

Install from conda-forge:

conda install -c conda-forge clickqt

Install for local development:

python -m pip install --editable .[tests]
pre-commit install

Usage for end users (via clickqtfy)

Generate a GUI from an installed entry point:

clickqtfy ENTRYPOINT

Generate a GUI from a Python file and a click command object name:

clickqtfy path/to/module.py COMMAND_FUNCTION

In the generated GUI:

  • Run executes the current command.
  • Stop requests interruption of a running command.
  • Copy-To-Clipboard exports the current command line.
  • Import-From-Clipboard parses a command line and updates widgets.

Usage for library maintainers

Expose a GUI to your users via the qtgui_from_click function:

import click
from clickqt import qtgui_from_click


@click.command()
@click.option("--count", default=1, type=int)
@click.argument("name")
def greet(count: int, name: str) -> None:
    for _ in range(count):
        click.echo(f"Hello {name}")


greet_gui = qtgui_from_click(
    greet,
    application_name="Greeter",
    invocation_command="greet",
)

Publish CLI and GUI entry points in pyproject.toml:

[project.scripts]
greet = "yourpkg.cli:greet"

[project.gui-scripts]
greet_gui = "yourpkg.cli:greet_gui"

For custom click.ParamType, provide a widget/getter/setter mapping:

from PySide6.QtWidgets import QLineEdit

custom_mapping = {
    MyParamType: (
        QLineEdit,
        lambda w: w.widget.text(),
        lambda w, v: w.widget.setText(str(v)),
    )
}
gui = qtgui_from_click(cmd, custom_mapping=custom_mapping)

Constraints

  • Unknown custom click.ParamType falls back to a text field unless you provide custom_mapping.
  • click-option-group is displayed visually, but group relationship rules are not enforced by clickqt.
  • Parameters with hidden=True are currently still rendered in the GUI.
  • clickqt executes command callbacks directly; advanced custom click.Command/click.Context behavior may differ from CLI invocation.
  • Multi-value envvar handling can differ from Click's type-specific envvar splitting behavior.

Licensing

MIT License. See LICENSE.md.

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

clickqt-1.0.0.tar.gz (98.3 kB view details)

Uploaded Source

File details

Details for the file clickqt-1.0.0.tar.gz.

File metadata

  • Download URL: clickqt-1.0.0.tar.gz
  • Upload date:
  • Size: 98.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for clickqt-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5ec4d6a10e8ce1a3200f63b464c0c579c1ed59cfb88a19cc2ade3aecd7a53b47
MD5 2070392627bc56a0d9511993c4d6a54b
BLAKE2b-256 5fb2d43be606aa9ec22c86c7747f1339c89637d3917dfd684432c0d78ac52fd7

See more details on using hashes here.

Provenance

The following attestation bundles were made for clickqt-1.0.0.tar.gz:

Publisher: pypi.yml on ssciwr/clickqt

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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