[PySide] Fixing examples qt resource files under Python 3

Roman Lacko backup.rlacko at gmail.com
Sun Apr 20 00:05:26 CEST 2014


Hi,

Here is simple helper script to regenarate recursively all existing qt
resource files in examples folder distributed in official pyside packages
built with pyside-setup.

It will be included in next release but it could be usefull if someone has
problems running examples under Python 3, where by default the qt resource
files are generated for Python 2 only.

Just run the follwing script with Python where the PySide is installed:

$ python regenerate_examples_qt_resources.py

Regards
-Roman

====== regenerate_examples_qt_resources.py ======
import sys
import os
import subprocess
from PySide._utils import get_pyside_dir


PY_2 = sys.version_info[0] < 3


pyside_dir = get_pyside_dir()
pyside_rcc_path = os.path.join(pyside_dir, 'pyside-rcc')
pyside_rcc_options = '-py2' if PY_2 else '-py3'


def regenerate_qt_resources(src):
    names = os.listdir(src)
    for name in names:
        srcname = os.path.join(src, name)
        if os.path.isdir(srcname):
            regenerate_qt_resources(srcname)
        elif srcname.endswith('.qrc'):
            # Replace last occurence of '.qrc' in srcname
            srcname_split = srcname.rsplit('.qrc', 1)
            dstname = '_rc.py'.join(srcname_split)
            if os.path.exists(dstname):
                print('Regenerating %s from %s' % \
                    (dstname, os.path.basename(srcname)))
                subprocess.call([pyside_rcc_path,
                                 pyside_rcc_options,
                                 srcname, '-o', dstname])


if __name__ == '__main__':
    examples_dir = os.path.join(pyside_dir, 'examples')
    if os.path.exists(examples_dir):
        regenerate_qt_resources(examples_dir)
====== /regenerate_examples_qt_resources.py ======
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20140420/8d42e190/attachment.html>


More information about the PySide mailing list