pyqt6rc


Namepyqt6rc JSON
Version 0.7.0 PyPI version JSON
download
home_pagehttps://github.com/domarm-comat/pyqt6rc
SummaryPyQt6 UI templates resource converter
upload_time2024-11-21 15:59:52
maintainerNone
docs_urlNone
authorMartin Domaracký
requires_python<3.13,>=3.9
licenseMIT
keywords pyqt6 converter resources resource-management
VCS
bugtrack_url
requirements importlib-resources pyqt6-qt6 pyqt6-sip pyqt6 pyside6-addons pyside6-essentials pyside6 shiboken6 zipp
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pyqt6rc

![GitHub_repo](https://img.shields.io/github/license/domarm-comat/pyqt6rc?style=for-the-badge)

This library offers scripts to correct resource paths in files generated by the `pyuic6` command. 
Since PyQt6 does not include the `pyrcc6` script for converting resources, this package serves that purpose. 
In the current PyQt6 implementation, the .py files created by the pyuic6 command contain incorrect resource paths.  

**UPDATE:** As of `PyQt-6.3.1` it's possible to use `Qt’s` resource system again.
We can use `pyside6-rcc` to convert `rcc` files into `py`.  
Source for this solution can be found in [StackOverflow answer](https://stackoverflow.com/a/66104738/17872926).

Provided scripts are converting .ui files into .py files using three different ways:  

* Using `pyside6-rcc` script to convert `rcc` files into `py` and `pyuic6` to convert all `ui` files [**Use pyside6rc**]
* Native >= python3.7 solution
  using [importlib](https://docs.python.org/3/library/importlib.html#module-importlib.resources) [**Use pyqt6rc**].
* Use of [importlib_resources](https://importlib-resources.readthedocs.io/en/latest/), for compatibility with
  Python3.6+ [**Use pyqt6rc with -c option**]
* Adding resource search path using `QtCore.QDir.addSearchPath()` and modifying generated prefixes [**Use pyqt6sp**]

More on this topic can be found on [StackOverflow](https://stackoverflow.com/questions/66099225/how-can-resources-be-provided-in-pyqt6-which-has-no-pyrcc).

From version 4.0, parameter -p, --package was removed. Pyqt6rc now determines package name automatically by crawling
parent folders and looking for `\_\_init\_\_.py` file.

# Conversion #

Generated template using `pyside6rc` script:

```python
import myPackage.resources.icons  # noqa
```

Generated template using `pyuic6` script:

```python
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(":/icons/icon1.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
```

Generated template using `pyqt6rc` script:

```python
from importlib.resources import path

icon = QtGui.QIcon()
with path("myPackage.resources.icons", "icon1.png") as f_path:
    icon.addPixmap(QtGui.QPixmap(str(f_path)), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
```

Generated template using `pyqt6rc` (-c, --compatible) script:

```python
from importlib_resources import path

icon = QtGui.QIcon()
with path("myPackage.resources.icons", "icon1.png") as f_path:
    icon.addPixmap(QtGui.QPixmap(str(f_path)), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
```

Generated template using `pyqt6sp` script:

```python
import os
from os.path import dirname, normpath
from PyQt6.QtCore import QDir

prefix_resources = [('icons', '../resources/')]
for prefix, resource in prefix_resources:
    sp = QDir.searchPaths(prefix)
    QDir.setSearchPaths(prefix, set(sp + [normpath(os.path.join(dirname(__file__), resource))]))

icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("icons:icon1.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
```

# Usage examples #

Package structure example

```
myPackage
│   __init__.py    
│
└───resources
|   |   __init__.py
│   │   image1.png
│   │   image2.png
│   │   resources.qrc
|   |   ...
|   |
|   └───icons
│       │   __init__.py
│       │   icon1.png
│       │   icon2.png
│       │   ...
│   
└───templates
    │   template1.ui
    │   template2.ui
```

Batch convert all .ui files located in the templates directory using `pyside6-rcc`

```shell
pyside6rc /myPackage/templates
```

Batch convert all .ui files located in the templates directory using `pyside6-rcc`  
Without writing import line of resource package to `ui` files (`-niw`)
```shell
pyside6rc -niw /myPackage/templates
```

Batch convert all .ui files located in the templates directory using `pyside6-rcc`  
Without `ui` to `py` conversion (`-npc`)  
```shell
pyside6rc -npc /myPackage/templates
```

Batch convert all .ui files located in the templates directory using `pyside6-rcc`

```shell
pyside6-rcc /myPackage/templates
```

Batch convert all .ui files located in the templates directory

```shell
pyqt6rc /myPackage/templates
```

Convert template1.ui only

```shell
pyqt6rc /myPackage/templates/template1.ui
```

Convert template1.ui and save it in /tmp directory

```shell
pyqt6rc /myPackage/templates/template1.ui -o /tmp
```

Batch convert all .ui files located in templates directory using importlib_resources

```shell
pyqt6rc /myPackage/templates -c
```

Batch convert all .ui files located in templates directory using setSearchPaths method

```shell
pyqt6sp /myPackage/templates
```
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/domarm-comat/pyqt6rc",
    "name": "pyqt6rc",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<3.13,>=3.9",
    "maintainer_email": null,
    "keywords": "pyqt6, converter, resources, resource-management",
    "author": "Martin Domarack\u00fd",
    "author_email": "domarm@comat.sk",
    "download_url": "https://files.pythonhosted.org/packages/d9/1e/26986246c73eb379aea6e2eefb07758285a051c44465dbb9dacae6720da7/pyqt6rc-0.7.0.tar.gz",
    "platform": null,
    "description": "# pyqt6rc\n\n![GitHub_repo](https://img.shields.io/github/license/domarm-comat/pyqt6rc?style=for-the-badge)\n\nThis library offers scripts to correct resource paths in files generated by the `pyuic6` command. \nSince PyQt6 does not include the `pyrcc6` script for converting resources, this package serves that purpose. \nIn the current PyQt6 implementation, the .py files created by the pyuic6 command contain incorrect resource paths.  \n\n**UPDATE:** As of `PyQt-6.3.1` it's possible to use `Qt\u2019s` resource system again.\nWe can use `pyside6-rcc` to convert `rcc` files into `py`.  \nSource for this solution can be found in [StackOverflow answer](https://stackoverflow.com/a/66104738/17872926).\n\nProvided scripts are converting .ui files into .py files using three different ways:  \n\n* Using `pyside6-rcc` script to convert `rcc` files into `py` and `pyuic6` to convert all `ui` files [**Use pyside6rc**]\n* Native >= python3.7 solution\n  using [importlib](https://docs.python.org/3/library/importlib.html#module-importlib.resources) [**Use pyqt6rc**].\n* Use of [importlib_resources](https://importlib-resources.readthedocs.io/en/latest/), for compatibility with\n  Python3.6+ [**Use pyqt6rc with -c option**]\n* Adding resource search path using `QtCore.QDir.addSearchPath()` and modifying generated prefixes [**Use pyqt6sp**]\n\nMore on this topic can be found on [StackOverflow](https://stackoverflow.com/questions/66099225/how-can-resources-be-provided-in-pyqt6-which-has-no-pyrcc).\n\nFrom version 4.0, parameter -p, --package was removed. Pyqt6rc now determines package name automatically by crawling\nparent folders and looking for `\\_\\_init\\_\\_.py` file.\n\n# Conversion #\n\nGenerated template using `pyside6rc` script:\n\n```python\nimport myPackage.resources.icons  # noqa\n```\n\nGenerated template using `pyuic6` script:\n\n```python\nicon = QtGui.QIcon()\nicon.addPixmap(QtGui.QPixmap(\":/icons/icon1.png\"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)\n```\n\nGenerated template using `pyqt6rc` script:\n\n```python\nfrom importlib.resources import path\n\nicon = QtGui.QIcon()\nwith path(\"myPackage.resources.icons\", \"icon1.png\") as f_path:\n    icon.addPixmap(QtGui.QPixmap(str(f_path)), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)\n```\n\nGenerated template using `pyqt6rc` (-c, --compatible) script:\n\n```python\nfrom importlib_resources import path\n\nicon = QtGui.QIcon()\nwith path(\"myPackage.resources.icons\", \"icon1.png\") as f_path:\n    icon.addPixmap(QtGui.QPixmap(str(f_path)), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)\n```\n\nGenerated template using `pyqt6sp` script:\n\n```python\nimport os\nfrom os.path import dirname, normpath\nfrom PyQt6.QtCore import QDir\n\nprefix_resources = [('icons', '../resources/')]\nfor prefix, resource in prefix_resources:\n    sp = QDir.searchPaths(prefix)\n    QDir.setSearchPaths(prefix, set(sp + [normpath(os.path.join(dirname(__file__), resource))]))\n\nicon = QtGui.QIcon()\nicon.addPixmap(QtGui.QPixmap(\"icons:icon1.png\"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)\n```\n\n# Usage examples #\n\nPackage structure example\n\n```\nmyPackage\n\u2502   __init__.py    \n\u2502\n\u2514\u2500\u2500\u2500resources\n|   |   __init__.py\n\u2502   \u2502   image1.png\n\u2502   \u2502   image2.png\n\u2502   \u2502   resources.qrc\n|   |   ...\n|   |\n|   \u2514\u2500\u2500\u2500icons\n\u2502       \u2502   __init__.py\n\u2502       \u2502   icon1.png\n\u2502       \u2502   icon2.png\n\u2502       \u2502   ...\n\u2502   \n\u2514\u2500\u2500\u2500templates\n    \u2502   template1.ui\n    \u2502   template2.ui\n```\n\nBatch convert all .ui files located in the templates directory using `pyside6-rcc`\n\n```shell\npyside6rc /myPackage/templates\n```\n\nBatch convert all .ui files located in the templates directory using `pyside6-rcc`  \nWithout writing import line of resource package to `ui` files (`-niw`)\n```shell\npyside6rc -niw /myPackage/templates\n```\n\nBatch convert all .ui files located in the templates directory using `pyside6-rcc`  \nWithout `ui` to `py` conversion (`-npc`)  \n```shell\npyside6rc -npc /myPackage/templates\n```\n\nBatch convert all .ui files located in the templates directory using `pyside6-rcc`\n\n```shell\npyside6-rcc /myPackage/templates\n```\n\nBatch convert all .ui files located in the templates directory\n\n```shell\npyqt6rc /myPackage/templates\n```\n\nConvert template1.ui only\n\n```shell\npyqt6rc /myPackage/templates/template1.ui\n```\n\nConvert template1.ui and save it in /tmp directory\n\n```shell\npyqt6rc /myPackage/templates/template1.ui -o /tmp\n```\n\nBatch convert all .ui files located in templates directory using importlib_resources\n\n```shell\npyqt6rc /myPackage/templates -c\n```\n\nBatch convert all .ui files located in templates directory using setSearchPaths method\n\n```shell\npyqt6sp /myPackage/templates\n```",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "PyQt6 UI templates resource converter",
    "version": "0.7.0",
    "project_urls": {
        "Homepage": "https://github.com/domarm-comat/pyqt6rc",
        "Repository": "https://github.com/domarm-comat/pyqt6rc"
    },
    "split_keywords": [
        "pyqt6",
        " converter",
        " resources",
        " resource-management"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9dff2b827cc700f54b8055ea8694d19a48c3f1bc5b3e1da549be9c286a304ccd",
                "md5": "0cfdbbd13de473fe92cd4092e24138fc",
                "sha256": "42636335e242919056051f38d7c6031c2b1f208cd7294fde35376c4765743dda"
            },
            "downloads": -1,
            "filename": "pyqt6rc-0.7.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0cfdbbd13de473fe92cd4092e24138fc",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<3.13,>=3.9",
            "size": 35738,
            "upload_time": "2024-11-21T15:59:51",
            "upload_time_iso_8601": "2024-11-21T15:59:51.020915Z",
            "url": "https://files.pythonhosted.org/packages/9d/ff/2b827cc700f54b8055ea8694d19a48c3f1bc5b3e1da549be9c286a304ccd/pyqt6rc-0.7.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d91e26986246c73eb379aea6e2eefb07758285a051c44465dbb9dacae6720da7",
                "md5": "78077f192e6cefc17e1aae94b451c2b6",
                "sha256": "a6440923858cda57c50ae2f21e9f9d01dbb2c4bef59c579d07f9e6194763010f"
            },
            "downloads": -1,
            "filename": "pyqt6rc-0.7.0.tar.gz",
            "has_sig": false,
            "md5_digest": "78077f192e6cefc17e1aae94b451c2b6",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<3.13,>=3.9",
            "size": 15664,
            "upload_time": "2024-11-21T15:59:52",
            "upload_time_iso_8601": "2024-11-21T15:59:52.742244Z",
            "url": "https://files.pythonhosted.org/packages/d9/1e/26986246c73eb379aea6e2eefb07758285a051c44465dbb9dacae6720da7/pyqt6rc-0.7.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-21 15:59:52",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "domarm-comat",
    "github_project": "pyqt6rc",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "importlib-resources",
            "specs": [
                [
                    "==",
                    "5.13.0"
                ]
            ]
        },
        {
            "name": "pyqt6-qt6",
            "specs": [
                [
                    "==",
                    "6.7.3"
                ]
            ]
        },
        {
            "name": "pyqt6-sip",
            "specs": [
                [
                    "==",
                    "13.8.0"
                ]
            ]
        },
        {
            "name": "pyqt6",
            "specs": [
                [
                    "==",
                    "6.7.1"
                ]
            ]
        },
        {
            "name": "pyside6-addons",
            "specs": [
                [
                    "==",
                    "6.8.0.2"
                ]
            ]
        },
        {
            "name": "pyside6-essentials",
            "specs": [
                [
                    "==",
                    "6.8.0.2"
                ]
            ]
        },
        {
            "name": "pyside6",
            "specs": [
                [
                    "==",
                    "6.8.0.2"
                ]
            ]
        },
        {
            "name": "shiboken6",
            "specs": [
                [
                    "==",
                    "6.8.0.2"
                ]
            ]
        },
        {
            "name": "zipp",
            "specs": [
                [
                    "==",
                    "3.21.0"
                ]
            ]
        }
    ],
    "lcname": "pyqt6rc"
}
        
Elapsed time: 0.44629s