优化日志显示
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
"""配置文件 I/O(Step 4 重构)。
|
||||
"""配置文件 I/O(Step 4 重构)。
|
||||
|
||||
从 pqAutomationApp.PQAutomationApp 中搬迁。每个函数第一行 `self = app`
|
||||
以保留原有 `self.xxx` 属性访问不变。
|
||||
@@ -33,19 +33,19 @@ def get_config_path(self):
|
||||
def load_pq_config(self):
|
||||
"""加载PQ配置(兼容打包后的程序)"""
|
||||
try:
|
||||
# ✅ 使用 self.config_file(已经是动态路径)
|
||||
# 使用 self.config_file(已经是动态路径)
|
||||
if os.path.exists(self.config_file):
|
||||
with open(self.config_file, "r", encoding="utf-8") as f:
|
||||
config_dict = json.load(f)
|
||||
self.config.from_dict(config_dict)
|
||||
if hasattr(self, "log_gui"):
|
||||
self.log_gui.log("✓ 配置文件加载成功")
|
||||
self.log_gui.log("配置文件加载成功", level="success")
|
||||
else:
|
||||
if hasattr(self, "log_gui"):
|
||||
self.log_gui.log("⚠️ 配置文件不存在,使用默认配置")
|
||||
self.log_gui.log("配置文件不存在,使用默认配置", level="error")
|
||||
except Exception as e:
|
||||
if hasattr(self, "log_gui"):
|
||||
self.log_gui.log(f"⚠️ 加载配置文件失败: {str(e)},使用默认配置")
|
||||
self.log_gui.log(f"加载配置文件失败: {str(e)},使用默认配置", level="error")
|
||||
|
||||
|
||||
def save_pq_config(self):
|
||||
@@ -58,7 +58,7 @@ def save_pq_config(self):
|
||||
self.config.save_to_file(self.config_file)
|
||||
except Exception as e:
|
||||
if hasattr(self, "log_gui"):
|
||||
self.log_gui.log(f"保存配置文件失败: {str(e)}")
|
||||
self.log_gui.log(f"保存配置文件失败: {str(e)}", level="error")
|
||||
|
||||
|
||||
def clear_config_file(self):
|
||||
@@ -71,14 +71,14 @@ def clear_config_file(self):
|
||||
if os.path.exists(config_file):
|
||||
os.remove(config_file)
|
||||
self.config_cleared = True
|
||||
messagebox.showinfo("提示", "✓ 清理成功")
|
||||
self.log_gui.log("✓ 配置文件清理成功")
|
||||
messagebox.showinfo("提示", "清理成功")
|
||||
self.log_gui.log("配置文件清理成功", level="success")
|
||||
else:
|
||||
messagebox.showinfo("提示", "配置文件不存在")
|
||||
self.log_gui.log("⚠️ 配置文件不存在")
|
||||
self.log_gui.log("配置文件不存在", level="error")
|
||||
|
||||
except Exception as e:
|
||||
messagebox.showerror("错误", "❌ 清理失败")
|
||||
self.log_gui.log(f"❌ 配置文件清理失败: {str(e)}")
|
||||
messagebox.showerror("错误", "[Error] 清理失败")
|
||||
self.log_gui.log(f"[Error] 配置文件清理失败: {str(e)}", level="error")
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user