Welcome to Qt Dev Helper’s documentation!

Qt Dev Helper

PyPi Version Supported Python Versions Conda Version License

Actions Status Documentation Status codecov Documentation Coverage Code style Python: black

All Contributors

Toolbox to help develop Qt applications, improving the usability of the existing tooling.

Installation

pip install qt-dev-helper

OR

conda install -c conda-forge qt-dev-helper

Features

  • Usable as Library and/or CLI tool

  • Compatible with PEP517 build system (see test case)

  • CLI auto completion

  • Project wide configuration in pyproject.toml

  • Recursive asset compiler for Qt projects (using uic and rcc):

    • *.ui -> *.py

    • *.qrc -> *.py

    • *.ui -> *.h

    • *.qrc -> *.h

    • *.scss -> *.qss

  • Support for multiple Qt tooling suppliers

    • PySide6-Essentials

    • qt6-applications

    • qt5-applications

  • Ability to open all files in a folder in QtDesigner

Planned features

  • Stand alone executable for each release (Windows)

  • File watch mode

  • qss injection into *.ui files

  • pre-commit hooks

FAQ

  • Q: Why is PyQt5 not supported?

    A: PyQt5 only ships a python specific version of uic and rcc breaking the tool API and compatibility with cpp projects. Use the matching version of qt5-applications as Qt tooling supplier.

Contributors ✨

Thanks goes out to these wonderful people (emoji key):


Sebastian Weigand

💻 🤔 🚧 📆 🚇 ⚠️ 📖

Joris Snellenburg

👀

This project follows the all-contributors specification. Contributions of any kind are welcome!

Installation

Stable release

To install Qt Dev Helper, run this command in your terminal:

$ pip install qt_dev_helper

This is the preferred method to install Qt Dev Helper, as it will always install the most recent stable release.

If you don’t have pip installed, this Python installation guide can guide you through the process.

From sources

The sources for Qt Dev Helper can be downloaded from the Github repo.

You can either clone the public repository:

$ git clone git://github.com/s-weigand/qt-dev-helper

Or download the tarball:

$ curl -OJL https://github.com/s-weigand/qt-dev-helper/tarball/main

Once you have a copy of the source, you can install it with:

$ python setup.py install

Usage

To use Qt Dev Helper in a project:

import qt_dev_helper

Command-line Interface

qt-dev-helper

Collection of CLI commands to improve workflows when developing Qt GUI Applications.

qt-dev-helper [OPTIONS] COMMAND [ARGS]...

Options

--install-completion <install_completion>

Install completion for the specified shell.

Options:

bash | zsh | fish | powershell | pwsh

--show-completion <show_completion>

Show completion for the specified shell, to copy it or customize the installation.

Options:

bash | zsh | fish | powershell | pwsh

build

Build production assets from input files.

qt-dev-helper build [OPTIONS] [BASE_PATH]

Options

-c, --config <config>

Path to a config file.

-r, --recurse-folder

Recurse directories searching for files.

Default:

False

-g, --generator <generator>

Code generator used to compile ui and resource files.

Options:

python | cpp

--flatten-folder-structure, --no-flatten-folder-structure

Whether or not to flatten the folder structure of the ui and resource files.

--ui, --no-ui

Whether or not to build ui files from ‘*.ui’ files.

Default:

True

--ui-files-folder <ui_files_folder>

Root folder containing *.ui files.

--generated-ui-code-folder <generated_ui_code_folder>

Root folder to save code generated from *.ui files to.

--uic-args <uic_args>

Additional arguments for the uic executable, as comma separated list.

--rc, --no-rc

Whether or not to build resource files from ‘*.qrc’ files.

Default:

True

--resource-folder <resource_folder>

Root folder containing *.qrc files.

--generated-rc-code-folder <generated_rc_code_folder>

Root folder to save code generated from *.qrc files to.

--form-import, --no-form-import

Python: generate imports relative to ‘.’

--rcc-args <rcc_args>

Additional arguments for the rcc executable, as comma separated list.

--qss, --no-qss

Whether or not to build qss files from ‘*.scss’ files.

Default:

True

--root-sass-file <root_sass_file>

Scss stylesheet with the style for the whole application.

--root-qss-file <root_qss_file>

Qss stylesheet with the style for the whole application, generated from ‘root_sass_file’.

Arguments

BASE_PATH

Optional argument

designer

Open *.ui files in qt-designer.

qt-dev-helper designer [OPTIONS] [FILES]...

Options

--recurse-folder, --no-recurse-folder

Whether or not to recurse directories searching for files.

Default:

True

--open-files, --no-open-files

Whether or not to open files.

Default:

True

Arguments

FILES

Optional argument(s)

Configuration

pydantic settings Config[source]

Project configuration.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

__init__ uses __pydantic_self__ instead of the more common self for the first arg to allow self as a field name.

Show JSON schema
{
   "title": "Config",
   "description": "Project configuration.",
   "type": "object",
   "properties": {
      "base_path": {
         "description": "Directory the config was loaded from, used to resolve relative paths.",
         "format": "path",
         "title": "Base Path",
         "type": "string"
      },
      "root_sass_file": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "Scss stylesheet with the style for the whole application.",
         "title": "Root Sass File"
      },
      "root_qss_file": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "Qss stylesheet with the style for the whole application, generated from 'root_sass_file'.",
         "title": "Root Qss File"
      },
      "generator": {
         "allOf": [
            {
               "$ref": "#/$defs/CodeGenerators"
            }
         ],
         "default": "python",
         "description": "Code generator used to compile ui and resource files."
      },
      "flatten_folder_structure": {
         "default": true,
         "description": "Whether to keep the original folder structure or flatten it.",
         "title": "Flatten Folder Structure",
         "type": "boolean"
      },
      "ui_files_folder": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "Root folder containing *.ui files.",
         "title": "Ui Files Folder"
      },
      "generated_ui_code_folder": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "Root folder to save code generated from *.ui files to.",
         "title": "Generated Ui Code Folder"
      },
      "uic_args": {
         "description": "Additional arguments for the uic executable.",
         "items": {
            "type": "string"
         },
         "title": "Uic Args",
         "type": "array"
      },
      "form_import": {
         "default": true,
         "description": "Python: generate imports relative to '.'",
         "title": "Form Import",
         "type": "boolean"
      },
      "resource_folder": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "Root folder containing *.qrc files.",
         "title": "Resource Folder"
      },
      "generated_rc_code_folder": {
         "anyOf": [
            {
               "type": "string"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "description": "Root folder to save code generated from *.qrc files to.",
         "title": "Generated Rc Code Folder"
      },
      "rcc_args": {
         "description": "Additional arguments for the rcc executable.",
         "items": {
            "type": "string"
         },
         "title": "Rcc Args",
         "type": "array"
      }
   },
   "$defs": {
      "CodeGenerators": {
         "description": "Valid code generator values.",
         "enum": [
            "python",
            "cpp"
         ],
         "title": "CodeGenerators",
         "type": "string"
      }
   },
   "additionalProperties": false,
   "required": [
      "base_path"
   ]
}

Fields:
Validators:
  • _validate_rc_input_path » all fields

  • _validate_rc_io » all fields

  • _validate_style_input_path » all fields

  • _validate_styles_io » all fields

  • _validate_ui_input_path » all fields

  • _validate_ui_io » all fields

field base_path: Path [Required]

Directory the config was loaded from, used to resolve relative paths.

Validated by:
  • _validate_rc_input_path

  • _validate_rc_io

  • _validate_style_input_path

  • _validate_styles_io

  • _validate_ui_input_path

  • _validate_ui_io

field flatten_folder_structure: bool = True

Whether to keep the original folder structure or flatten it.

Validated by:
  • _validate_rc_input_path

  • _validate_rc_io

  • _validate_style_input_path

  • _validate_styles_io

  • _validate_ui_input_path

  • _validate_ui_io

field form_import: bool = True

Python: generate imports relative to ‘.’

Validated by:
  • _validate_rc_input_path

  • _validate_rc_io

  • _validate_style_input_path

  • _validate_styles_io

  • _validate_ui_input_path

  • _validate_ui_io

field generated_rc_code_folder: str | None = None

Root folder to save code generated from *.qrc files to.

Validated by:
  • _validate_rc_input_path

  • _validate_rc_io

  • _validate_style_input_path

  • _validate_styles_io

  • _validate_ui_input_path

  • _validate_ui_io

field generated_ui_code_folder: str | None = None

Root folder to save code generated from *.ui files to.

Validated by:
  • _validate_rc_input_path

  • _validate_rc_io

  • _validate_style_input_path

  • _validate_styles_io

  • _validate_ui_input_path

  • _validate_ui_io

field generator: CodeGenerators = CodeGenerators.python

Code generator used to compile ui and resource files.

Validated by:
  • _validate_rc_input_path

  • _validate_rc_io

  • _validate_style_input_path

  • _validate_styles_io

  • _validate_ui_input_path

  • _validate_ui_io

field rcc_args: List[str] [Optional]

Additional arguments for the rcc executable.

Validated by:
  • _validate_rc_input_path

  • _validate_rc_io

  • _validate_style_input_path

  • _validate_styles_io

  • _validate_ui_input_path

  • _validate_ui_io

field resource_folder: str | None = None

Root folder containing *.qrc files.

Validated by:
  • _validate_rc_input_path

  • _validate_rc_io

  • _validate_style_input_path

  • _validate_styles_io

  • _validate_ui_input_path

  • _validate_ui_io

field root_qss_file: str | None = None

Qss stylesheet with the style for the whole application, generated from ‘root_sass_file’.

Validated by:
  • _validate_rc_input_path

  • _validate_rc_io

  • _validate_style_input_path

  • _validate_styles_io

  • _validate_ui_input_path

  • _validate_ui_io

field root_sass_file: str | None = None

Scss stylesheet with the style for the whole application.

Validated by:
  • _validate_rc_input_path

  • _validate_rc_io

  • _validate_style_input_path

  • _validate_styles_io

  • _validate_ui_input_path

  • _validate_ui_io

field ui_files_folder: str | None = None

Root folder containing *.ui files.

Validated by:
  • _validate_rc_input_path

  • _validate_rc_io

  • _validate_style_input_path

  • _validate_styles_io

  • _validate_ui_input_path

  • _validate_ui_io

field uic_args: List[str] [Optional]

Additional arguments for the uic executable.

Validated by:
  • _validate_rc_input_path

  • _validate_rc_io

  • _validate_style_input_path

  • _validate_styles_io

  • _validate_ui_input_path

  • _validate_ui_io

deactivate_resource_build() None[source]

Deactivate resource building with build_all_assets().

deactivate_style_build() None[source]

Deactivate style building with build_all_assets().

deactivate_ui_build() None[source]

Deactivate ui building with build_all_assets().

rc_folder_paths() Tuple[Path, Path][source]

Resolve paths to root style files.

Returns:

Paths to resource_folder and generated_rc_code_folder.

Return type:

Tuple[Path, Path]

rcc_kwargs() RccKwargs[source]

Extract keyword arguments to be used with compile_resource_file.

Returns:

Keyword arguments for compile_resource_file.

Return type:

RccKwargs

root_style_paths() Tuple[Path, Path][source]

Resolve paths to root style files.

Returns:

Paths to root_sass_file and root_qss_file.

Return type:

Tuple[Path, Path]

ui_folder_paths() Tuple[Path, Path][source]

Resolve paths to root style files.

Returns:

Paths to ui_files_folder and generated_ui_code_folder.

Return type:

Tuple[Path, Path]

uic_kwargs() UicKwargs[source]

Extract keyword arguments to be used with compile_ui_file.

Returns:

Keyword arguments for compile_ui_file.

Return type:

UicKwargs

update(update_dict: Dict[str, Any], filter_none: bool = True) None[source]

Update config values.

Parameters:
  • update_dict (Dict[str, Any]) – Dict containing updated values.

  • filter_none (bool) – Whether or not to filter None values before updating. Defaults to True

Inner workings

This is the detailed documentation of the inner workings of qt_dev_helper.

qt_dev_helper

Top-level package for Qt Dev Helper.

Contributing

Contributions are welcome, and they are greatly appreciated! Every little bit helps, and credit will always be given.

You can contribute in many ways:

Types of Contributions

Report Bugs

Report bugs at https://github.com/s-weigand/qt-dev-helper/issues.

If you are reporting a bug, please include:

  • Your operating system name and version.

  • Any details about your local setup that might be helpful in troubleshooting.

  • Detailed steps to reproduce the bug.

Fix Bugs

Look through the GitHub issues for bugs. Anything tagged with “bug” and “help wanted” is open to whoever wants to implement it.

Implement Features

Look through the GitHub issues for features. Anything tagged with “enhancement” and “help wanted” is open to whoever wants to implement it.

Write Documentation

Qt Dev Helper could always use more documentation, whether as part of the official Qt Dev Helper docs, in docstrings, or even on the web in blog posts, articles, and such.

Submit Feedback

The best way to send feedback is to file an issue at https://github.com/s-weigand/qt-dev-helper/issues.

If you are proposing a feature:

  • Explain in detail how it would work.

  • Keep the scope as narrow as possible, to make it easier to implement.

  • Remember that this is a volunteer-driven project, and that contributions are welcome :)

Get Started!

Ready to contribute? Here’s how to set up qt_dev_helper for local development.

  1. Fork the qt-dev-helper repo on GitHub.

  2. Clone your fork locally:

    $ git clone git@github.com:your_name_here/qt_dev_helper.git
    
  3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:

    $ mkvirtualenv qt_dev_helper
    $ cd qt-dev-helper/
    $ pip install -e .
    
  4. install the pre-commit and pre-push hooks:

    $ pre-commit install && pre-commit install -t pre-push
    
  5. Create a branch for local development:

    $ git checkout -b name-of-your-bugfix-or-feature
    

    Now you can make your changes locally.

  6. When you’re done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:

    $ tox
    

    To get flake8 and tox, just pip install them into your virtualenv.

  7. Commit your changes and push your branch to GitHub:

    $ git add .
    $ git commit -m "Your detailed description of your changes."
    $ git push origin name-of-your-bugfix-or-feature
    
  8. Submit a pull request through the GitHub website.

Pull Request Guidelines

Before you submit a pull request, check that it meets these guidelines:

  1. The pull request should include tests.

  2. If the pull request adds functionality, the docs should be updated. Put your new functionality into a function with a docstring, and add the feature to the list in README.md.

  3. The pull request should work for Python 3.8, 3.9 and 3.10. Check https://github.com/s-weigand/qt-dev-helper/actions and make sure that the tests pass for all supported Python versions.

Tips

To run a subset of tests:

$ pytest tests.test_qt_dev_helper

Deploying

A reminder for the maintainers on how to deploy. Make sure all your changes are committed (including an entry in HISTORY.rst). Then run:

$ bump2version patch # possible: major / minor / patch
$ git push --follow-tags

Travis will then deploy to PyPI if tests pass.

Changelog

0.0.4 (2023-07-08)

  • 📚🩹 Fix missing CLI docs on RTD by @s-weigand in (#63)

  • 🚇👌 Add py3.11 CI tests and ⬆️ autoupdate pre-commit config by @s-weigand in (#69)

  • 📚 Improve readme by @s-weigand in (#70)

  • 📦 Pin pydantic to version <2 by @s-weigand in (#115)

0.0.3 (2022-09-05)

  • 🗑️ Removed qtsass310 dependency in favor of qtsass>=0.3.1 (#54)

0.0.2 (2022-09-05)

  • 👌 Use extended path when calling Qt tools and add folder containing lib files (#52)

0.0.1 (2022-09-04)

  • 🚀 First release on PyPI.

Indices and tables