当前位置: 动力学知识库 > 问答 > 编程问答 >

pyqt - 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?

网友答案:

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).

分享给朋友:
您可能感兴趣的文章:
随机阅读: