继续优化UI加载速度

This commit is contained in:
xinzhu.yin
2026-06-22 10:52:51 +08:00
parent 92cba114a9
commit 2d8d4119e3
7 changed files with 307 additions and 72 deletions

View File

@@ -869,9 +869,113 @@ def _refresh_theme_toggle_label(self: "PQAutomationApp") -> None:
self.theme_toggle_btn.configure(text="切换深色模式")
def _replot_charts_for_current_theme(self: "PQAutomationApp") -> None:
"""刷新结果区图表配色(仅同步绘制当前可见 Tab"""
if hasattr(self, "refresh_result_charts_theme"):
try:
self.refresh_result_charts_theme(sync_draw=True, visible_only=True)
return
except Exception:
pass
test_type = None
if hasattr(self, "config"):
test_type = getattr(self.config, "current_test_type", None)
snapshots = {}
if test_type and hasattr(self, "_chart_snapshots"):
snapshots = self._chart_snapshots.get(test_type) or {}
if not snapshots:
if hasattr(self, "apply_result_chart_theme"):
self.apply_result_chart_theme(sync_draw=True)
return
for chart_name, args in snapshots.items():
plot_fn = getattr(self, f"plot_{chart_name}", None)
if plot_fn:
try:
plot_fn(*args)
except Exception:
pass
def _cancel_pending_ui_jobs(self: "PQAutomationApp") -> None:
"""取消可能在主题切换后继续触发的延迟 UI 任务。"""
for attr in ("_calman_matrix_col_job", "_chart_restore_job"):
job = getattr(self, attr, None)
if job is None:
continue
try:
self.root.after_cancel(job)
except Exception:
pass
setattr(self, attr, None)
def _refresh_all_theme_widgets(self: "PQAutomationApp") -> None:
"""同步刷新主题相关控件:优先处理可见区域,隐藏面板延后。"""
_refresh_theme_toggle_label(self)
# 侧栏 / 连接指示 / 选中态 —— 始终可见,必须立即更新
for method_name in (
"refresh_tool_panel_sidebar_theme",
"refresh_connection_indicators",
):
method = getattr(self, method_name, None)
if method is not None:
try:
method()
except Exception:
pass
current_panel = getattr(self, "current_panel", None)
if current_panel == "ai_image" and hasattr(self, "refresh_ai_image_theme"):
try:
self.refresh_ai_image_theme()
except Exception:
pass
else:
self._ai_image_theme_dirty = True
if current_panel == "single_step" and hasattr(self, "refresh_single_step_theme"):
try:
self.refresh_single_step_theme()
except Exception:
pass
if current_panel == "log" and hasattr(self, "log_gui") and hasattr(
self.log_gui, "refresh_log_theme"
):
try:
self.log_gui.refresh_log_theme()
except Exception:
pass
if hasattr(self, "refresh_custom_template_theme"):
try:
self.refresh_custom_template_theme()
except Exception:
pass
if hasattr(self, "refresh_calman_theme"):
try:
self.refresh_calman_theme()
except Exception:
pass
if hasattr(self, "update_sidebar_selection"):
try:
self.update_sidebar_selection()
except Exception:
pass
_replot_charts_for_current_theme(self)
def _on_toggle_theme(self: "PQAutomationApp") -> None:
"""切换主题:重新应用 ttk 样式并刷新所有自定义样式相关的标签"""
# 在测试进行时禁止切换主题,避免影响测量稳定性
"""切换主题:保持窗口可见,同步批量刷新避免卡顿与分批变色"""
if getattr(self, "testing", False):
try:
if hasattr(self, "log_gui"):
@@ -881,67 +985,14 @@ def _on_toggle_theme(self: "PQAutomationApp") -> None:
return
from app.views.theme_manager import toggle_theme
toggle_theme()
# apply_modern_styles()
_refresh_theme_toggle_label(self)
if hasattr(self, "refresh_tool_panel_sidebar_theme"):
try:
self.refresh_tool_panel_sidebar_theme()
except Exception:
pass
if hasattr(self, "refresh_connection_indicators"):
try:
self.refresh_connection_indicators()
except Exception:
pass
if hasattr(self, "apply_result_chart_theme"):
try:
self.apply_result_chart_theme()
except Exception:
pass
if hasattr(self, "log_gui") and hasattr(self.log_gui, "refresh_log_theme"):
try:
self.log_gui.refresh_log_theme()
except Exception:
pass
if hasattr(self, "refresh_ai_image_theme"):
try:
self.refresh_ai_image_theme()
except Exception:
pass
if hasattr(self, "refresh_single_step_theme"):
try:
self.refresh_single_step_theme()
except Exception:
pass
if hasattr(self, "refresh_custom_template_theme"):
try:
self.refresh_custom_template_theme()
except Exception:
pass
if hasattr(self, "refresh_calman_theme"):
try:
self.refresh_calman_theme()
except Exception:
pass
# 同步刷新侧栏选中态(高亮样式跟随新色板)
if hasattr(self, "update_sidebar_selection"):
try:
self.update_sidebar_selection()
except Exception:
pass
# 以新的 dark_mode 值重绘当前测试类型的所有图表
if hasattr(self, "_chart_snapshots") and hasattr(self, "config"):
test_type = getattr(self.config, "current_test_type", None)
if test_type:
snapshots = self._chart_snapshots.get(test_type, {})
for chart_name, args in snapshots.items():
plot_fn = getattr(self, f"plot_{chart_name}", None)
if plot_fn:
try:
plot_fn(*args)
except Exception:
pass
_cancel_pending_ui_jobs(self)
self._theme_transition = True
try:
toggle_theme()
_refresh_all_theme_widgets(self)
finally:
self._theme_transition = False
def update_config_info_display(self: "PQAutomationApp"):