[PySide] Help with resource files

Sean Fisk sean at seanfisk.com
Tue Apr 9 03:48:46 CEST 2013


On Monday, April 8, 2013 at 7:55 PM, Algis Kabaila wrote:
> 
> Sean, thanks for letting me know that you actually used PySideSimplicissimus to learn PySide - makes me feel that writting it was worth while!
> 
> 
> 

It was most certainly useful. The tutorials illustrated not only how to do specific Qt things using PySide, but also a variety of things that are possible with Qt/PySide. 
> 
>  
> 
> 
> To reiterate, and hopefully making clearer, my earlier remarks in this list. Python's print command prints text string objects what your program snippet via PySide (or PyQt for that matter) returns is not a text string object. 
> 
> 
>  
> 
> 
> To make it a text object one could try to use QplainTextEdit object which may have methods to read your "texty" object and does have a method to "disgorge" a text (that can be printed with Python print() method).
> 
> 
>  
> 
> 
> I really did not see why one would want to use such inefficient way of carrying text - there is much more data in the encoded format than plain text.
> 
> 
> 

That's not necessarily true. Qt resources can be compressed in the ZIP format (http://qt-project.org/doc/qt-4.8/resources.html#compression), and text files are great candidates for compression. Of course, the byte representation (\x00), which takes 4 bytes in a Python source file, is rather inefficient. Add to that the overhead of other things in the source file.

However, the byte compiled python files are not so storage-inefficient. I downloaded a PNG of Lena and ran her through pyside-rcc, then ran python -m py_compile on the generated resource file to byte compile it. Here are the results:
$ du -h lena.png lena.py lena.pyc 464K lena.png 1.3M lena.py 464K lena.pyc
So I don't think it's all that much less efficient.

> 
> I think I now see why - you want to distribute your program as one file that can be run with 
> 
> 
> python <your program name>
> 
> 
> Is that right?
> 
> 
> And you frown upon the possibility of running it as
> 
> 
> python <your program name> <a blob of data to read>
> 
> 
>  
> 
> 
> Is that roughly the situation?
> 
> 
> 

Correct. We would like to distribute this application using py2app on Mac OS X and pyinstaller on Windows (pyinstaller and PySide/Qt do not get along very well on OS X, but py2app works well). We want to use the resource files to bundle our necessary external files with our program. At this point that includes images and fonts, but it will soon include license texts as well.

Thanks for your suggestions and help.
> 
> Al.
> 
> 
>  
> 
> 
> On Monday 08 April 2013 23:26:57 Eric Johnson wrote:
> 
> 
> > Sean Fisk <sean <at> seanfisk.com (http://seanfisk.com)> writes:
> 
> 
> > > OK, I have an interim solution. While I do believe that
> 
> 
> > > QFile.readAll() should return the file contents as a QByteArray,
> 
> 
> > > QResource.data() seems to work!
> 
> 
> > > Here is the code:
> 
> 
> > I tested it at home on OS X 10.8.2 using the builtin Python and Qt
> 
> 
> > 4.8.1, PySide 1.1.1 and it works once I opened the file with
> 
> 
> > test_txt.open(QtCore.QIODevice.ReadOnly | QtCore.QIODevice.Text)
> 
> 
> > 
> 
> 
> > Output is:
> 
> 
> > Running PySide 1.1.1 / Qt 4.8.1
> 
> 
> > PySide compiled with Qt 4.8.1
> 
> 
> > Does it exist?: True
> 
> 
> > readAll(): `This is just a test.
> 
> 
> > '
> 
> 
> > 
> 
> 
> > Is there a good reason you aren't opening the file?
> 
> 
> > 
> 
> 
> > Eric
> 
> 
> > 
> 
> 
> > 
> 
> 
> > 
> 
> 
> > 
> 
> 
> > _______________________________________________
> 
> 
> > PySide mailing list
> 
> 
> > PySide at qt-project.org (mailto:PySide at qt-project.org)
> 
> 
> > http://lists.qt-project.org/mailman/listinfo/pyside
> 
> 
> 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20130408/af880119/attachment.html>


More information about the PySide mailing list