Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customize pyuic's resource import statement?

When I use this command on windows:

python -m PyQt4.uic.pyuic user_interface.ui -o user_interface.py

After that, I add a resource:

pyrcc4.exe -py3 images.qrc -o images.py

And I end up with two beautiful files, user_interface.py, and images.py. The problem is that the user_interface.py file ends with this line of code:

... all QT stuff here.
import images_re

And because this is a module that is called from many parents, it has to be imported like this:

import myapp.gui.images_re

When I change the line of code it works perfectly, but every time I modify the user_interface.ui file and then execute the batch, it will be overwritten, and I will have to change it manually every time.

Is there any way to tell pyuic what to write in that import statement?
Or any batch code that can be executed after the pyuic and changes that line of code?
Or some tweak on the .py file that calls user_interface.py for example to change the default directory so it imports images_re from there?

like image 677
mesafria Avatar asked Nov 22 '15 22:11

mesafria


1 Answers

If you save the resource file in the same package directory as the ui file, then you can use the --from_imports option. This will add the following import line to the ui file:

    from . import resources_rc

And the command would look something like this:

    pyuic4 --from-imports --output file.py file.ui

(NB: the pyuic executable name may differ, depending on the platform).

like image 164
ekhumoro Avatar answered Nov 15 '22 12:11

ekhumoro