43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
生成界面代码的脚本
|
|
运行此脚本来从 .ui 文件生成 Python 界面代码
|
|
"""
|
|
|
|
import subprocess
|
|
import sys
|
|
import os
|
|
|
|
def generate_ui_code():
|
|
"""从 .ui 文件生成 Python 代码"""
|
|
ui_file = "ibook_export_app.ui"
|
|
py_file = "ui_ibook_export_app.py"
|
|
|
|
if not os.path.exists(ui_file):
|
|
print(f"错误: 找不到 {ui_file} 文件")
|
|
return False
|
|
|
|
try:
|
|
# 使用 pyuic6 生成界面代码
|
|
result = subprocess.run([
|
|
"pyuic6",
|
|
"-o", py_file,
|
|
ui_file
|
|
], check=True, capture_output=True, text=True)
|
|
|
|
print(f"成功生成界面代码: {py_file}")
|
|
return True
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"生成界面代码失败: {e}")
|
|
print(f"错误输出: {e.stderr}")
|
|
return False
|
|
except FileNotFoundError:
|
|
print("错误: 找不到 pyuic6 命令")
|
|
print("请确保已安装 PyQt6-tools:")
|
|
print("pip install PyQt6-tools")
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
generate_ui_code()
|