feat: 添加配置文件的导入功能及文件路径显示
新增通过系统对话框导入配置文件的功能 在界面上显示当前打开的配置文件路径 添加对50%击穿电压的验证 优化开发模式下的文件导入备用方案
This commit is contained in:
@@ -9,6 +9,7 @@ import json
|
||||
import math
|
||||
import threading
|
||||
import queue
|
||||
import tomllib
|
||||
from pathlib import Path
|
||||
from typing import Dict, Any, List
|
||||
from datetime import datetime
|
||||
@@ -524,6 +525,46 @@ class EGMWebApp:
|
||||
"message": f"保存失败: {str(e)}"
|
||||
}
|
||||
|
||||
def import_config(self) -> Dict[str, Any]:
|
||||
"""
|
||||
导入配置从 TOML 文件,弹出打开对话框
|
||||
|
||||
Returns:
|
||||
包含解析后的参数和文件路径的字典
|
||||
"""
|
||||
try:
|
||||
# 打开文件选择对话框
|
||||
result = self.window.create_file_dialog(
|
||||
webview.OPEN_DIALOG,
|
||||
directory='',
|
||||
file_types=('TOML Files (*.toml)', 'All files (*.*)')
|
||||
)
|
||||
|
||||
if result and len(result) > 0:
|
||||
file_path = result[0]
|
||||
|
||||
# 读取并解析 TOML 文件
|
||||
with open(file_path, 'rb') as f:
|
||||
toml_data = tomllib.load(f)
|
||||
|
||||
return {
|
||||
"success": True,
|
||||
"message": f"成功导入配置",
|
||||
"file_path": file_path,
|
||||
"params": toml_data
|
||||
}
|
||||
else:
|
||||
return {
|
||||
"success": False,
|
||||
"message": "用户取消了选择"
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"导入配置失败: {str(e)}")
|
||||
return {
|
||||
"success": False,
|
||||
"message": f"导入失败: {str(e)}"
|
||||
}
|
||||
|
||||
def get_default_config(self) -> Dict[str, Any]:
|
||||
"""
|
||||
获取默认配置
|
||||
|
||||
Reference in New Issue
Block a user