44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
import os
|
|
import argparse
|
|
import subprocess
|
|
|
|
def convert_qrc_to_py(file_path):
|
|
"""
|
|
将指定的 .qrc 文件转换为 .py 文件
|
|
:param file_path: .qrc 文件的路径
|
|
"""
|
|
# 获取文件名(不包含路径)和文件后缀
|
|
file_name, _ = os.path.splitext(os.path.basename(file_path))
|
|
output_file = os.path.join(os.path.dirname(file_path), f"{file_name}_rc.py")
|
|
|
|
# 调用 pyrcc5.bat 并传递参数
|
|
try:
|
|
subprocess.run(["pyrcc5.bat", "-o", output_file, file_path], check=True)
|
|
print(f"已成功将 {file_path} 转换为 {output_file}")
|
|
except subprocess.CalledProcessError:
|
|
print(f"转换 {file_path} 失败")
|
|
|
|
def main(recursive=False):
|
|
"""
|
|
主函数,处理当前目录下的所有 .qrc 文件
|
|
:param recursive: 是否递归处理子目录
|
|
"""
|
|
current_dir = os.getcwd()
|
|
print(f"开始在目录 {current_dir} 中查找 .qrc 文件")
|
|
|
|
for root, dirs, files in os.walk(current_dir):
|
|
# 如果不递归,限制为当前目录
|
|
if not recursive and root != current_dir:
|
|
continue
|
|
|
|
for file in files:
|
|
if file.endswith(".qrc"):
|
|
qrc_file = os.path.join(root, file)
|
|
convert_qrc_to_py(qrc_file)
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description="将当前目录下的 .qrc 文件转换为 .py 文件")
|
|
parser.add_argument("--recursive", action="store_true", help="递归处理子目录")
|
|
args = parser.parse_args()
|
|
|
|
main(recursive=args.recursive) |