[PyQt] Problem with resource imports in pyuic generated files

Elvis Stansvik elvstone at gmail.com
Tue Feb 16 18:54:49 GMT 2016


2016-02-16 19:35 GMT+01:00 Baz Walter <bazwal at ftml.net>:
> On 16/02/16 12:25, Elvis Stansvik wrote:
>>
>> I have the following setup in my distribution (cut down to show the
>> essentials):
>>
>> orexplore.gui/
>>      orexplore/gui/ui/main_window.ui  --pyuic5-->
>> orexplore/gui/ui/main_window_ui.py
>>      resources/icons.qrc  --pyrcc5-->  orexplore/gui/resources/icons_rc.py
>>
>> That is, orexplore.gui is the top-level distribution directory. The
>> orexplore/ subdirectory is my main Python package. In resources/ I
>> keep .qrc files (kept outside the package source tree), and in
>> orexplore/gui/ui I have my .ui files (kept as part of the package
>> source tree).
>>
>> The problem is that if, in Designer, I set the icon for the main
>> window in main_window.ui to be an icon from the resources/icons.qrc
>> resource, then pyrcc5 --from-imports will generate an import statement
>>
>> from . import icons_rc
>>
>> which obviously won't be found.
>
>
> A common directory structure would be something like this:
>
> container_dir/
>
>   designer_files/
>     main_window.ui
>
>   icons/
>     app_icon.png
>   resources.qrc
>
>   python_package/
>     ui/
>       main_window.py
>       resources_rc.py
>     app_logic.py
>   main.py
>
> So the python package directory contains python modules and nothing else.
> The resource module generated by pyrcc just goes in the same directory as
> the ones generated by pyuic, which solves the import issue.

Ah yes, probably a good idea to to break the .ui files out of the
python package as well. Thanks.

For now, I'll have to keep the generated _ui.py and _rc.py in the same
package. This is okay, but I would rather have them split up (e.g. a
ui/ or perhaps forms/ package with the .ui files, and a resources/
package for the resources). So for me, something like a

  --resource-package <package>

flag to pyuic5 would be a welcome addition. When used with
--from-imports, it would result in:

  from <package> import foobar_rc

and when used without --from-imports, it would result in:

  import <package>.foobar_rc

Elvis

>
> --
> Regards
> Baz Walter
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> https://www.riverbankcomputing.com/mailman/listinfo/pyqt


More information about the PyQt mailing list