[PySide] Help with resource files

Algis Kabaila akabaila at pcug.org.au
Sun Apr 7 15:33:29 CEST 2013


Hi Sean,

I think that the last statement of your program is based on wrong premise 
the python print statement will print a pyside (or pyqt) object - a pyside 
file.  But python does not really directly know much about pyside objects.

I think that for the script to work you need to have something like 
textEdit and use something like textEdit.setText(<your text object>.  I 
have not used qrc resoources only for icons (images), though in M 
Summerfields "Rapid GUI Programming with Python and QT" chapter 6 pp 165 to 
203 described is an example "The Image Changer".  The code should still be 
on the web. He does use the html  files that are referred to via qrc 
resources.

To use icon images as qrc resources, you might like to take a quick look 
at simplistic  tutorial that has links to source code and other materials 
for  download: 
http://qt-project.org/wiki/PySideSimplicissimus_Module_5_Combine

In particular, combineAllIn1 module may be closer to your liking:
http://qt-project.org/wiki/PySideSimplicissimus_Module_7_CombineAllIn1

They are simple newbie examples and are well below your standards, but it 
never hurts to stoop down a bit.  These examples were written in python 
2.x and are being changed to pthon3.  Your feedback would be appreciated!

I think you will be suitably impressed how readily PySide can be used in 
Python 2.x and in Python 3.x with minimal change of code!

Al.

On Sunday 07 April 2013 16:14:52 Algis Kabaila wrote:

Hello Sean,

It is not a fault of python version.  I am on linux kubuntu 12.04 LTS OS 
with "python" pointing to python 2.7  and python3 to python 3.2.  Changed 
your script to python3 syntax and repeated the exercise with the same 
lemon result at the end:

ak at supremo:~/Documents/2013/Algis/linux$ python3 test.py
Running PySide 1.1.0 / Qt 4.8.1
PySide compiled with Qt 4.8.1
Does it exist?: True
readAll(): `'
ak at supremo:~/Documents/2013/Algis/linux$ 

"supremo" is a funny name for my old black big and clunky computer (with a 
decent PCU etc.) 

There is a small reference to accessing files in Mark Summerfields "bible" 
on PyQt.  But now I must quit this keyboard - one of our grand daughters 
is comming to watch a film on Lithuanian basketball, named "the other dream 
team".

Sorry for butting in to the list - hope to be back sometime and might try 
to concoct my own example and see if it shows where the "dog is burried".

Al.

On Sunday 07 April 2013 01:27:24 Sean Fisk wrote:

                    Hello Al,                


My bad. I'm using Python 2.7.3 64-bit on Mac OS 10.6 with PySide 1.1.2 and 
Qt 4.8.4. It's not the system Python nor one installed from the 
distributions on python.org; I compiled it myself and am using 
virtualenvwrapper to manage my virtualenvs, if any of that matters.


Thanks for the tip on Python 3. I'm using Python 2 and I believe that 
pyside-rcc defaults to Python 2. The resource module is in fact importing 
fine. There are no syntax errors or anything like that. It's weird: I tried 
importing in ipython and the import was fine. I just can't read the 
resource content as I should be able to.


Thanks,                


-- 
Sean Fisk

                                 
On Sunday, April 7, 2013 at 1:19 AM, Algis Kabaila wrote:                
                    
Hi Sean,

You do not give much away: to begin with, your OS and Python version would 
be useful.

If it is Python 3.x then a small change may help:

pyside-rcc -py3 resources.qrc -o resources.py 

Just a shot in the dark, Sean!

Al.

On Saturday 06 April 2013 17:51:28 Sean Fisk wrote:

Hello everyone, 


I want to embed some images and fonts in my PySide program using Qt's 
resource system. I've used it very successfully in C++. However, I'm 
having some trouble getting resource files to work with PySide. The 
resource files seem to compile it all right, but I can't read my files in my 
program.


I've created a minimum example to illustrate the problem:


test.py
#!/usr/bin/env python
# test.py
import PySide
from PySide import QtCore
import resources

# Versions
print 'Running PySide {0} / Qt {1}'.format(
    PySide.__version__, QtCore.__version__)
print 'PySide compiled with Qt {0}'.format(QtCore.qVersion())

# Read resource
test_txt = QtCore.QFile(':/test.txt')
print 'Does it exist?: {0}'.format(test_txt.exists())
print "readAll(): `{0}'".format(test_txt.readAll())
resources.qrc
<RCC>
  <qresource prefix="/">
    <file>test.txt</file>
  </qresource>
</RCC>
test.txt
This is just a test.
Instructions
Compile the resource file and then run:
$ pyside-rcc resources.qrc -o resources.py
$ python test.py
Running PySide 1.1.2 / Qt 4.8.4
PySide compiled with Qt 4.8.4
Does it exist?: True
readAll(): `'
Interestingly, if I change the readAll() call to readLine(), the program 
segfaults. Anyone have any suggestions? I'd be open to other ways to 
distribute fonts and images with my program as well.


Sincerely,


-- 
Sean Fisk




                                                                                                                     
                    
                            





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


More information about the PySide mailing list