📌  相关文章
📜  \pyrcc_main.py:文件不存在'resources.qrc' - 无论代码示例

📅  最后修改于: 2022-03-11 14:56:23.943000             🧑  作者: Mango

代码示例1
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('    %s\n' % path.lstrip(':/'))

with open(os.path.join(tmpdir, 'resources.qrc'), 'w') as stream:
    stream.write('\n')
    stream.write('\n%s\n' % ''.join(files))