{"id":15493515,"url":"https://github.com/addisonelliott/pyqt5ac","last_synced_at":"2025-04-22T20:12:34.787Z","repository":{"id":62582811,"uuid":"155413497","full_name":"addisonElliott/pyqt5ac","owner":"addisonElliott","description":"Python module to automatically compile UI and QRC files in PyQt5 to Python files","archived":false,"fork":false,"pushed_at":"2020-07-06T14:05:51.000Z","size":82,"stargazers_count":11,"open_issues_count":10,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-22T20:12:23.570Z","etag":null,"topics":["automatic","compiler","pyqt5","qt-gui","qt5","qt5-gui","resource","ui"],"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/addisonElliott.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-30T15:52:33.000Z","updated_at":"2024-09-08T06:03:15.000Z","dependencies_parsed_at":"2022-11-03T21:22:14.833Z","dependency_job_id":null,"html_url":"https://github.com/addisonElliott/pyqt5ac","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/addisonElliott%2Fpyqt5ac","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/addisonElliott%2Fpyqt5ac/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/addisonElliott%2Fpyqt5ac/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/addisonElliott%2Fpyqt5ac/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/addisonElliott","download_url":"https://codeload.github.com/addisonElliott/pyqt5ac/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250316057,"owners_count":21410476,"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":["automatic","compiler","pyqt5","qt-gui","qt5","qt5-gui","resource","ui"],"created_at":"2024-10-02T08:07:40.496Z","updated_at":"2025-04-22T20:12:34.763Z","avatar_url":"https://github.com/addisonElliott.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![CI](https://github.com/addisonElliott/pyqt5ac/workflows/CI/badge.svg)](https://github.com/addisonElliott/pyqt5ac/actions)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pyqt5ac.svg)](https://pypi.org/project/pyqt5ac/)\n[![PyPI](https://img.shields.io/pypi/v/pyqt5ac.svg)](https://pypi.org/project/pyqt5ac/)\n[![PyPI - License](https://img.shields.io/pypi/l/pyqt5ac.svg)](https://github.com/addisonElliott/pyqt5ac/blob/master/LICENSE)\n\n* [PyQt5 Auto Compiler (pyqt5ac)](#pyqt5-auto-compiler-pyqt5ac)\n  * [Enter \u003cstrong\u003epyqt5ac\u003c/strong\u003e!](#enter-pyqt5ac)\n* [Installing](#installing)\n* [Getting Started](#getting-started)\n  * [Running from Command Line](#running-from-command-line)\n  * [Running from Python Script](#running-from-python-script)\n* [Configuration Options](#configuration-options)\n* [Example](#example)\n  * [Option 1: YAML Config File (Recommended)](#option-1-yaml-config-file-recommended)\n  * [Option 2: JSON Config File (Deprecated)](#option-2-json-config-file-deprecated)\n  * [Option 3: Python Script](#option-3-python-script)\n  * [Option 4: Command Line](#option-4-command-line)\n  * [Resulting File Structure](#resulting-file-structure)\n* [Support](#support)\n* [License](#license)\n\nPyQt5 Auto Compiler (pyqt5ac)\n=============================\n\npyqt5ac is a Python package for automatically compiling Qt's UI and QRC files into Python files.\n\nIn PyQt5, [Qt Designer](https://www.qt.io/) is the application used to create a GUI using a drag-and-drop interface. This interface is stored in a *.ui* file and any resources such as images or icons are stored in a *.qrc* file.\n\nThese two filetypes must be compiled into Python files before they can be used in your Python program. There are a few ways to go about this currently:\n1. Manually compile the files using the command line and pyuic5 for *.ui* files and pyrcc5 for *.qrc* files.\n2. Compile the files each time the application is started up by calling pyuic5 and pyrcc5 within your Python script\n\nThe downside to the first method is that it can be a tedious endeavor to compile the files, especially when one is faced with a larger project with many of these files that need to be compiled. Although the second method eliminates the tediousness of compilation, these files are compiled **every** time you run your script, regardless of if anything has been changed. This can cause a hit in performance and take longer to startup your script.\n\n### Enter **pyqt5ac**!\n\npyqt5ac provides a command-line interface (CLI) that searches through your files and automatically compiles any *.ui* or *.qrc* files. In addition, pyqt5ac can be called from your Python script. In both instances, **ui and resource files are only compiled if they have been updated**.\n\nInstalling\n==========\n\npyqt5ac is currently available on [PyPi](https://pypi.python.org/pypi/pyqt5ac/). The simplest way to\ninstall alone is using ``pip`` at a command line\n\n    pip install pyqt5ac\n\nwhich installs the latest release.  To install the latest code from the repository (usually stable, but may have\nundocumented changes or bugs)\n\n    pip install git+https://github.com/addisonElliott/pyqt5ac.git\n\nFor developers, you can clone the pyqt5ac repository and run the ``setup.py`` file. Use the following commands to get\na copy from GitHub and install all dependencies\n\n    git clone https://github.com/addisonElliott/pyqt5ac.git\n    cd pyqt5ac\n    pip install .[dev]\n\nto install in 'develop' or 'editable' mode, where changes can be made to the local working code and Python will use\nthe updated code.\n\nGetting Started\n===============\n\nRunning from Command Line\n-------------------------\n\nIf pyqt5ac is installed via pip, the command line interface can be called like any Unix based program in the terminal\n\n    pyqt5ac [OPTIONS] [IOPATHS]...\n    \nIn the interface, the options have slightly different names so reference the help file of the interface for more information. The largest difference is that the ioPaths argument is instead a list of space delineated paths where the even items are the source file expression and the odd items are the destination file expression.\n\nThe help file of the interface can be run as\n\n    pyqt5ac --help\n\nRunning from Python Script\n--------------------------\n\nThe following snippet of code below demonstrates how to call pyqt5ac from your Python script\n\n```python\nimport pyqt5ac\n\npyqt5ac.main(rccOptions='', uicOptions='--from-imports', force=False, initPackage=True, config='',\n             ioPaths=[['gui/*.ui', 'generated/%%FILENAME%%_ui.py'],\n                     ['resources/*.qrc', 'generated/%%FILENAME%%_rc.py']])\n```\n\nConfiguration Options\n=====================\n\nAll of the options that can be specified to pyqt5ac can also be placed in a configuration file (JSON or YAML). My recommendation is to use a configuration file to allow easy compilation of your software. For testing purposes, I would use the options in the command line interface to make get everything working and then transcribe that into a configuration file for repeated use.\n\nWhether running via the command line or from a script, the arguments and options that can be given are the same. The valid options are:\n* **rccOptions** - Additional options to pass to the resource compiler. See the man page of pyrcc5 for more information on options. An example of a valid option would be \"-compress 1\". Default is to pass no options.\n* **uicOptions** - Additional options to pass to the UI compiler. See the man page of pyuic5 for more information on options. An example of a valid option would be '--from-imports'. Default is to pass no options.\n* **force** - Specifies whether to force compile all of the files found. The default is false meaning only outdated files will be compiled.\n* **config** - JSON or YAML configuration file that contains information about these parameters.\n* **ioPaths** - This is a 2D list containing information about what source files to compile and where to place the source files. The first column is the source file global expression (meaning you can use wildcards, ** for recursive folder search, ? for options, etc to match filenames) and the second column is the destination file expression. The destination file expression recognizes 'special' variables that will be replaced with information from the source filename:\n    * %%FILENAME%% - Filename of the source file without the extension\n    * %%EXT%% - Extension excluding the period of the file (e.g. ui or qrc)\n    * %%DIRNAME%% - Directory of the source file\n* **variables** - custom variables that can be used in the definition of the paths in **ioPaths**. For example, to limit the search of files to a specific directory, one can define a variable `BASEDIR` and then use it as `%%BASEDIR%%/gui/*.ui*`\n* **init_package** - If specified, an empty `__init__.py` file is also generated in every output directory if missing. Does not overwrite existing `__init__.py`. Default value is `True`.\n\nNote that all relative paths are resolved from the configuration file location, if given through a config file, or from the current working directory otherwise.\n\nExample\n=======\n\nTake the following file structure as an example project where any UI and QRC files need to be compiled. Assume that pyuic5 and pyrcc5 are located in /usr/bin and that '--from-imports' is desired for the UIC compiler.\n\n```\n|-- gui\n|   |-- mainWindow.ui\n|   |-- addDataDialog.ui\n|   `-- saveDataDialog.ui\n|-- resources\n|   |-- images\n|   |-- stylesheets\n|   |-- app.qrc\n|   `-- style.qrc\n|-- modules\n|   |-- welcome\n|   |   |-- module.ui\n|   |   `-- resources\n|   |       |-- images\n|   |       `-- module.qrc\n|   `-- dataProbe\n|       |-- module.ui\n|       `-- resources\n|           |-- images\n|           `-- module.qrc\n```\n\nThe sections below demonstrate how to setup pyqt5ac to compile the necessary files given the file structure above.\n\nOption 1: YAML Config File (Recommended)\n---------------------------------------\n\n```YAML\nioPaths:\n  -\n    - \"gui/*.ui\"\n    - \"generated/%%FILENAME%%_ui.py\"\n  -\n    - \"resources/*.qrc\"\n    - \"generated/%%FILENAME_%%%%EXT%%.py\"\n  -\n    - \"modules/*/*.ui\"\n    - \"%%DIRNAME%%/generated/%%FILENAME%%_ui.py\"\n  -\n    - \"modules/*/resources/*.qrc\"\n    - \"%%DIRNAME%%/generated/%%FILENAME%%_rc.py\"\n\nuic_options: --from-imports\ninit_package: True\nforce: False\n```\n\nNow run pyqt5ac from the command line or Python script using your config file:\n```bash\npyqt5ac --config config.yml\n```\n\nor\n```python\nimport pyqt5ac\n\npyqt5ac.main(config='config.yml')\n```\n\nOption 2: JSON Config File (Deprecated)\n---------------------------------------\n\n```JSON\n{\n  \"ioPaths\": [\n    [\"gui/*.ui\", \"generated/%%FILENAME%%_ui.py\"],\n    [\"resources/*.qrc\", \"generated/%%FILENAME%%_rc.py\"],\n    [\"modules/*/*.ui\", \"%%DIRNAME%%/generated/%%FILENAME%%_ui.py\"],\n    [\"modules/*/resources/*.qrc\", \"%%DIRNAME%%/generated/%%FILENAME%%_rc.py\"]\n  ],\n  \"rcc_options\": \"\",\n  \"uic_options\": \"--from-imports\",\n  \"init_package\": true,\n  \"force\": false\n}\n```\n\nNow run pyqt5ac from the command line or Python script using your config file:\n```bash\npyqt5ac --config config.yml\n```\n\nor\n```python\nimport pyqt5ac\n\npyqt5ac.main(config='config.yml')\n```\n\nOption 3: Python Script\n-----------------------\n\n```python\nimport pyqt5ac\n\npyqt5ac.main(uicOptions='--from-imports', force=False, initPackage=True, ioPaths=[\n        ['gui/*.ui', 'generated/%%FILENAME%%_ui.py'],\n        ['resources/*.qrc', 'generated/%%FILENAME%%_rc.py'],\n        ['modules/*/*.ui', '%%DIRNAME%%/generated/%%FILENAME%%_ui.py'],\n        ['modules/*/resources/*.qrc', '%%DIRNAME%%/generated/%%FILENAME%%_rc.py']\n    ])\n```\n\nOption 4: Command Line\n----------------------\n\n```bash\npyqt5ac --uic_options \"--from-imports\" gui/*.ui generated/%%FILENAME%%_ui.py resources/*.qrc generated/%%FILENAME%%_rc.py modules/*/*.ui %%DIRNAME%%/generated/%%FILENAME%%_ui.py modules/*/resources/*.qrc %%DIRNAME%%/generated/%%FILENAME%%_rc.py\n```\n\nResulting File Structure\n------------------------\n\n```\n|-- gui\n|   |-- mainWindow.ui\n|   |-- addDataDialog.ui\n|   `-- saveDataDialog.ui\n|-- resources\n|   |-- images\n|   |-- stylesheets\n|   |-- app.qrc\n|   `-- style.qrc\n|-- generated\n|   |-- __init__.py_\n|   |-- mainWindow_ui.py\n|   |-- addDataDialog_ui.py\n|   |-- saveDataDialog_ui.py\n|   |-- app_rc.py\n|   `-- style_rc.py\n|-- modules\n|   |-- welcome\n|   |   |-- module.ui\n|   |   |-- resources\n|   |   |   |-- images\n|   |   |   `-- module.qrc\n|   |   `-- generated\n|   |       |-- module_ui.py\n|   |       `-- module_rc.py\n|   `-- dataProbe\n|       |-- module.ui\n|       |-- resources\n|       |   |-- images\n|       |   `-- module.qrc\n|       `-- generated\n|           |-- module_ui.py\n|           `-- module_rc.py\n```\n\nSupport\n=======\n\nIssues and pull requests are encouraged!\n\nBugs can be submitted through the [issue tracker](https://github.com/addisonElliott/pyqt5ac/issues).\n\nPull requests are welcome too!\n\nLicense\n=================\n\npyqt5ac has an [MIT-based license](https://github.com/addisonElliott/pyqt5ac/blob/master/LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faddisonelliott%2Fpyqt5ac","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faddisonelliott%2Fpyqt5ac","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faddisonelliott%2Fpyqt5ac/lists"}