Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for generating qrc file #28

Closed
akshaybabloo opened this issue May 8, 2021 · 7 comments
Closed

Support for generating qrc file #28

akshaybabloo opened this issue May 8, 2021 · 7 comments

Comments

@akshaybabloo
Copy link

Thank you for adding the generate function in #25

Could you add a way to generate qrc file too? - https://doc.qt.io/qt-6/resources.html

@akshaybabloo
Copy link
Author

This is what I am doing so far to generate a qrc file:

import os
from pathlib import Path

from jinja2 import Environment, FileSystemLoader, select_autoescape
from qt_material import export_theme

root_path = os.path.abspath('../')

theme_path = os.path.join(root_path, "theme")
qss_path = os.path.join(root_path, "style.qss")
qrc_path = os.path.join(root_path, "style.qrc")

export_theme(theme='dark_teal.xml', qss=qss_path, output=theme_path, prefix=':theme/')

p = Path(theme_path)
files = ['/'.join(a.parts[-3:]) for a in p.glob("**/*.svg")]

env = Environment(loader=FileSystemLoader("."), autoescape=select_autoescape(['html', 'xml']))
template = env.get_template("styles.qrc")
render = template.render(files=files)

with open(qrc_path, 'w') as f:
    f.write(render)

styles.qrc

<!DOCTYPE RCC>
<RCC version="1.0">
<qresource>
    {%- for file in files %}
    <file>{{ file }}</file>{% endfor %}
</qresource>
<qresource>
    <file>style.qss</file>
</qresource>
</RCC>

@YeisonCardona
Copy link
Contributor

Hi @akshaybabloo

There is no reason to use Qt resource system, since you can handle any resource with Python techniques, even the pyrcc tool will be deprecated in PyQt6.

Embed random files into a single Python file is not the proper way to handle resources, both Python and all operating systems has package manager that handle them without problems.

I honestly don't recommend using qrc for new developments.

@akshaybabloo
Copy link
Author

I am not too sure if that can be done in C++ though?

@YeisonCardona
Copy link
Contributor

YeisonCardona commented May 9, 2021

Qt resource system is all fine and well for C++ programs where qresources get statically linked into the executable itself, reducing the number of files to be installed.

I could get back the qrc generation.

@akshaybabloo
Copy link
Author

I am not too sure how the answer in #25 is being used. Because as far as I know qrc files are embedded into the static file.

Also, mac being mac, wants to know the path where it could find the icons from. I don't see any other way. Unless I am wrong.

@YeisonCardona
Copy link
Contributor

Hi @akshaybabloo

I just add the rcc argument to the export_theme function.

export_theme(theme='dark_teal.xml', qss='dark_teal.qss', rcc='resources.rcc',
             output='theme', prefix='icon:/', invert_secondary=False, extra=extra)

The .qss will use the file:/ prefix by default .

@akshaybabloo
Copy link
Author

Awesome! Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants