-
-
Notifications
You must be signed in to change notification settings - Fork 215
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
Why not use pkgutil for resource loading? #269
Comments
Hello @D0m0, thanks for trying pygubu. I'm glad that it is useful to you. I will investigate pkgutil and find a solution for this case. Regards |
Hello @D0m0, can you provide a little example application so I can see how do you setup PROJECT_MODULE and PROJECT_UI variables? Regards |
Hi! Here's my sample project:
main.py
|
When I launch main.py, it works as expected, printing these values:
When I run dist/gubu.pyz, it works too (but without images), printing these values:
gubu.pyz is a .zip file with a shebang header like this: #!/usr/bin/env python3 My theory is that using pkgutil.get_data() can extract resources in any case, maybe even when using PyInstaller etc. But I could be wrong, and I didn't test that. Tell me if you need help testing this. |
Thanks. One more question, which python version are You using? |
I'm using versions 3.6.2, 3.7.5, 3.9. I don't mind if you ditch the oldest versions! |
Hello @D0m0. It seems that the recommended approach is to use the importlib.resources module. I have been working with that in mind. I have created an example of use here. If you can, test it with your projects installing pygubu from the github repositories with:
If you have any suggestions let me know. Regards |
Pygubu is an ingenious tool that I discovered only now, although I use tkinter for at least 2 years! It's a professionally developed solid piece of code. I tried it and it works as intended out of the box!
I often put my project in a zip file, rename it to .pyz, and it becomes a single-file cross-platform app (which often only needs python3 installed). To load resources in such an app I use pkgutil.get_data(), which is nice because it works both ways: from a pyz-file and from the original unpacked app while I debug it. And pkgutil is a standard library.
So, when I use Pygubu I can load .ui files using builder.add_from_string(pkgutil.get_data(PROJECT_MODULE, PROJECT_UI)), but if I use images inside the .ui file, they are not being loaded.
I understand that Pygubu is adapted for use with PyInstaller and several other packagers, but maybe using pkgutil.get_data() will simplify all this resource-loading? Or maybe I'm doing something wrong?
Thanks!
The text was updated successfully, but these errors were encountered: