下面的脚本将从
resources_rc.py
文件生成人
pyrcc
. 它将与PyQt4/5和Python 2/3一起使用。这些文件将写入与给定
资源\u rc。py公司
文件
用法:
python qrc_gen.py path/to/resources_rc.py
qrc\U gen.py
:
import sys, os, tempfile
import sip
sip.setapi('QString', 2)
from PyQt4 import QtCore
# from PyQt5 import QtCore
respath = os.path.abspath(sys.argv[1])
dirpath = os.path.dirname(respath)
sys.path.insert(0, dirpath)
import resources_rc
tmpdir = tempfile.mkdtemp(prefix='qrc_', dir=dirpath)
it = QtCore.QDirIterator(':', QtCore.QDirIterator.Subdirectories)
files = []
while it.hasNext():
uri = it.next()
path = uri.lstrip(':/')
if path.startswith('qt-project.org'):
continue
tmp = os.path.join(tmpdir, path)
if it.fileInfo().isDir():
try:
os.makedirs(tmp)
except OSError:
pass
else:
res = QtCore.QFile(uri)
res.open(QtCore.QIODevice.ReadOnly)
with open(tmp, 'wb') as stream:
stream.write(bytes(res.readAll()))
res.close()
files.append(' <file>%s</file>\n' % path.lstrip(':/'))
with open(os.path.join(tmpdir, 'resources.qrc'), 'w') as stream:
stream.write('<!DOCTYPE RCC><RCC version="1.0">\n')
stream.write('<qresource>\n%s</qresource>\n' % ''.join(files))