[PyQt] Newbe: ui files and resources

James A. Benson jbenson at sextans.lowell.edu
Wed Dec 12 00:23:43 GMT 2007


On Tue, 11 Dec 2007, Oleg Klimov wrote:

>> I also created a .qrc file for the "open" icon.
>> I then run pyuic4 and pyrcc4 and they create the ui_ and qrc_
>> files. The last line of the qrc_ files contains the

->correction...should have read: The last line of the ui_ file
contains the<-

>> line:
>>
>> import nrpapp_rc
>>
>> My app is called nrpapp. When i run my app, it complains because
>> there is no nrpapp_rc. There is of course the qrc_nrpapp.py.
>> If i get rid of the nrpapp_rc line in the ui_ file then it works
>> fine (of course i include a line: import qrc_nrpapp in my nrpapp.py).
>
> This should work just fine by default.
>
> a.ui -> a_ui.py
> a.qrc -> a_rc.py
>
> a_ui.py expects a_rc.py (import a_rc), if you included .qrc in the designer.
>
> I'd suggest you check the tools you're using to run pyuic4/pyrcc4.
> These tools probably run 'pyuic4 a.ui -o wrong_output.py'. Try running
> by hand from command line.
>
>
> Oleg
>

Thank you for your suggestion. I used that today, and of course
that works fine. I am however surprised that the pyuic4 is
putting in an import assumed_rc_filename as its last line.
It is the:

  <resources>
   <include location="nrpapp.qrc" />
  </resources>

in my designer .ui file that causes pyuic4 to add
the "import assumed_rc_filename".

pyuic4 -o ui_nrpapp.py nrpapp.ui

the last line in the ui_nrpapp.py file is:

import nrpapp_rc

So as long as i use you suggestion in pyrcc4 and do:

pyrcc4 -o nrpapp_rc.py nrpapp.qrc

and then i import nrpapp_rc in my nrpapp.py file,
then things do work.

   It seems to me that a better behavior for
pyuic4 would be for it to _not_ include that
"import assumed_rc_filename" in the output file. Then it
would be entirely up to the use to
import user_choosen_rc_filename
in their app. The user_choosen_rc_filename.py would of course
be created by:

pqrcc4 -o user_choosen_rc_filename.py file.qrc

  This makes be think, that i'm probably doing something
wrong when i'm using designer to create the .ui file.
Until/if i find what i'm doing wrong in designer, your suggestion
works fine.

Thanks!

Jim


More information about the PyQt mailing list