修改深色模式下结果图片显示异常

This commit is contained in:
xinzhu.yin
2026-06-05 16:58:46 +08:00
parent 49d82da8b9
commit e9a591bf6e
11 changed files with 385 additions and 140 deletions

View File

@@ -9,6 +9,7 @@ import ttkbootstrap as ttk
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from app.views.pq_debug_panel import PQDebugPanel
from app.views.modern_styles import get_theme_palette
from typing import TYPE_CHECKING
@@ -19,8 +20,7 @@ if TYPE_CHECKING:
def _result_bg_color() -> str:
"""根据当前主题返回结果图背景色。"""
try:
from app.views.theme_manager import is_dark
return "#1B1F24" if is_dark() else "#FFFFFF"
return get_theme_palette()["bg"]
except Exception:
return "#FFFFFF"
@@ -55,6 +55,19 @@ def apply_result_chart_theme(self: "PQAutomationApp"):
pass
def _apply_axes_theme(ax, palette, *, title=None, xlabel=None, ylabel=None):
ax.set_facecolor(palette["card_bg"])
for spine in ax.spines.values():
spine.set_color(palette["border"])
if title is not None:
ax.set_title(title, color=palette["fg"])
if xlabel is not None:
ax.set_xlabel(xlabel, color=palette["fg"])
if ylabel is not None:
ax.set_ylabel(ylabel, color=palette["fg"])
ax.tick_params(axis="both", colors=palette["fg"])
def init_gamut_chart(self: "PQAutomationApp"):
"""初始化色域图表 - 手动设置subplot位置完全避免重叠"""
container = ttk.Frame(self.gamut_chart_frame)
@@ -154,8 +167,10 @@ def init_gamma_chart(self: "PQAutomationApp"):
"""初始化Gamma曲线图表 - 左侧曲线 + 右侧表格4列 + 通用说明)"""
container = ttk.Frame(self.gamma_chart_frame)
container.pack(expand=True, fill=tk.BOTH)
palette = get_theme_palette()
self.gamma_fig = plt.Figure(figsize=(12, 6), dpi=100, constrained_layout=False)
self.gamma_fig.patch.set_facecolor(palette["bg"])
self.gamma_canvas = FigureCanvasTkAgg(self.gamma_fig, master=container)
canvas_widget = self.gamma_canvas.get_tk_widget()
@@ -163,6 +178,7 @@ def init_gamma_chart(self: "PQAutomationApp"):
# 左侧Gamma 曲线
self.gamma_ax = self.gamma_fig.add_axes([0.08, 0.12, 0.50, 0.78])
_apply_axes_theme(self.gamma_ax, palette, xlabel="灰阶 (%)", ylabel="L_bar")
self.gamma_ax.set_xlabel("灰阶 (%)", fontsize=10)
self.gamma_ax.set_ylabel("L_bar", fontsize=10)
self.gamma_ax.set_xlim(0, 105)
@@ -182,10 +198,13 @@ def init_gamma_chart(self: "PQAutomationApp"):
ha="center",
va="center",
fontsize=10,
color="gray",
color=palette["muted_fg"],
transform=self.gamma_ax.transAxes,
bbox=dict(
boxstyle="round,pad=1", facecolor="white", edgecolor="gray", alpha=0.8
boxstyle="round,pad=1",
facecolor=palette["card_bg"],
edgecolor=palette["border"],
alpha=0.95,
),
)
@@ -223,17 +242,17 @@ def init_gamma_chart(self: "PQAutomationApp"):
# 表头样式
for i in range(4):
cell = table[(0, i)]
cell.set_facecolor("#4472C4")
cell.set_text_props(weight="bold", color="white", fontsize=7)
cell.set_facecolor(palette["primary"])
cell.set_text_props(weight="bold", color=palette["select_fg"], fontsize=7)
# 数据行交替颜色
for i in range(1, len(table_data)):
for j in range(4):
cell = table[(i, j)]
if i % 2 == 0:
cell.set_facecolor("#E7E6E6")
cell.set_facecolor(palette["surface_alt_bg"])
else:
cell.set_facecolor("#FFFFFF")
cell.set_facecolor(palette["card_bg"])
# 底部说明
self.gamma_table_ax.text(
@@ -246,25 +265,27 @@ def init_gamma_chart(self: "PQAutomationApp"):
ha="center",
va="bottom",
fontsize=7,
color="gray",
color=palette["muted_fg"],
transform=self.gamma_table_ax.transAxes,
bbox=dict(
boxstyle="round,pad=0.5",
facecolor="lightyellow",
edgecolor="gray",
alpha=0.8,
facecolor=palette["surface_alt_bg"],
edgecolor=palette["border"],
alpha=0.95,
),
)
self.gamma_fig.suptitle("Gamma曲线 + 数据表格", fontsize=12, y=0.98)
self.gamma_fig.suptitle("Gamma曲线 + 数据表格", fontsize=12, y=0.98, color=palette["fg"])
self.gamma_canvas.draw()
def init_eotf_chart(self: "PQAutomationApp"):
"""初始化 EOTF 曲线图表HDR 专用)- 左侧曲线 + 右侧表格4列"""
container = ttk.Frame(self.eotf_chart_frame)
container.pack(expand=True, fill=tk.BOTH)
palette = get_theme_palette()
self.eotf_fig = plt.Figure(figsize=(12, 6), dpi=100, constrained_layout=False)
self.eotf_fig.patch.set_facecolor(palette["bg"])
self.eotf_canvas = FigureCanvasTkAgg(self.eotf_fig, master=container)
canvas_widget = self.eotf_canvas.get_tk_widget()
@@ -272,6 +293,7 @@ def init_eotf_chart(self: "PQAutomationApp"):
# 左侧EOTF 曲线
self.eotf_ax = self.eotf_fig.add_axes([0.08, 0.12, 0.50, 0.78])
_apply_axes_theme(self.eotf_ax, palette, xlabel="灰阶 (%)", ylabel="L_bar (归一化亮度)")
self.eotf_ax.set_xlabel("灰阶 (%)", fontsize=10)
self.eotf_ax.set_ylabel("L_bar (归一化亮度)", fontsize=10)
self.eotf_ax.set_xlim(0, 105)
@@ -287,10 +309,13 @@ def init_eotf_chart(self: "PQAutomationApp"):
ha="center",
va="center",
fontsize=11,
color="gray",
color=palette["muted_fg"],
transform=self.eotf_ax.transAxes,
bbox=dict(
boxstyle="round,pad=1", facecolor="white", edgecolor="gray", alpha=0.8
boxstyle="round,pad=1",
facecolor=palette["card_bg"],
edgecolor=palette["border"],
alpha=0.95,
),
)
@@ -328,17 +353,17 @@ def init_eotf_chart(self: "PQAutomationApp"):
# 表头样式
for i in range(4):
cell = table[(0, i)]
cell.set_facecolor("#4472C4")
cell.set_text_props(weight="bold", color="white", fontsize=7)
cell.set_facecolor(palette["primary"])
cell.set_text_props(weight="bold", color=palette["select_fg"], fontsize=7)
# 数据行交替颜色
for i in range(1, len(table_data)):
for j in range(4):
cell = table[(i, j)]
if i % 2 == 0:
cell.set_facecolor("#E7E6E6")
cell.set_facecolor(palette["surface_alt_bg"])
else:
cell.set_facecolor("#FFFFFF")
cell.set_facecolor(palette["card_bg"])
# 底部说明
self.eotf_table_ax.text(
@@ -351,25 +376,27 @@ def init_eotf_chart(self: "PQAutomationApp"):
ha="center",
va="bottom",
fontsize=7,
color="gray",
color=palette["muted_fg"],
transform=self.eotf_table_ax.transAxes,
bbox=dict(
boxstyle="round,pad=0.5",
facecolor="lightyellow",
edgecolor="gray",
alpha=0.8,
facecolor=palette["surface_alt_bg"],
edgecolor=palette["border"],
alpha=0.95,
),
)
self.eotf_fig.suptitle("EOTF 曲线 + 数据表格", fontsize=12, y=0.98)
self.eotf_fig.suptitle("EOTF 曲线 + 数据表格", fontsize=12, y=0.98, color=palette["fg"])
self.eotf_canvas.draw()
def init_cct_chart(self: "PQAutomationApp"):
"""初始化色度坐标图表 - 正向横坐标,标题居中最上方"""
container = ttk.Frame(self.cct_chart_frame)
container.pack(expand=True)
palette = get_theme_palette()
self.cct_fig = plt.Figure(figsize=(8, 6), dpi=100, tight_layout=False)
self.cct_fig.patch.set_facecolor(palette["bg"])
self.cct_canvas = FigureCanvasTkAgg(self.cct_fig, master=container)
canvas_widget = self.cct_canvas.get_tk_widget()
@@ -378,7 +405,9 @@ def init_cct_chart(self: "PQAutomationApp"):
canvas_widget.pack_propagate(False)
self.cct_ax1 = self.cct_fig.add_subplot(211)
self.cct_ax1.set_facecolor(palette["card_bg"])
self.cct_ax2 = self.cct_fig.add_subplot(212)
self.cct_ax2.set_facecolor(palette["card_bg"])
# 上图x coordinates
self.cct_ax1.set_xlabel("灰阶 (%)", fontsize=9)
@@ -397,7 +426,7 @@ def init_cct_chart(self: "PQAutomationApp"):
self.cct_ax2.tick_params(labelsize=8)
# 调整标题位置y=0.985(比色域/Gamma略高
self.cct_fig.suptitle("色度一致性测试", fontsize=12, y=0.985)
self.cct_fig.suptitle("色度一致性测试", fontsize=12, y=0.985, color=palette["fg"])
self.cct_fig.subplots_adjust(
left=0.12,
@@ -413,12 +442,14 @@ def init_contrast_chart(self: "PQAutomationApp"):
"""初始化对比度图表 - 固定大小,居中显示"""
container = ttk.Frame(self.contrast_chart_frame)
container.pack(expand=True)
palette = get_theme_palette()
self.contrast_fig = plt.Figure(
figsize=(6, 6),
dpi=100,
tight_layout=False,
)
self.contrast_fig.patch.set_facecolor(palette["bg"])
self.contrast_canvas = FigureCanvasTkAgg(self.contrast_fig, master=container)
canvas_widget = self.contrast_canvas.get_tk_widget()
@@ -428,12 +459,13 @@ def init_contrast_chart(self: "PQAutomationApp"):
canvas_widget.pack_propagate(False)
self.contrast_ax = self.contrast_fig.add_subplot(111)
self.contrast_ax.set_facecolor(palette["card_bg"])
self.contrast_ax.set_xlim(0, 1)
self.contrast_ax.set_ylim(0, 1)
self.contrast_ax.axis("off")
# 调整标题位置y=0.985
self.contrast_fig.suptitle("对比度测试", fontsize=12, y=0.985)
self.contrast_fig.suptitle("对比度测试", fontsize=12, y=0.985, color=palette["fg"])
self.contrast_fig.subplots_adjust(
left=0.02,
@@ -448,6 +480,7 @@ def init_accuracy_chart(self: "PQAutomationApp"):
"""初始化色准图表 - 固定大小,居中显示"""
container = ttk.Frame(self.accuracy_chart_frame)
container.pack(expand=True, fill=tk.BOTH)
palette = get_theme_palette()
container.grid_rowconfigure(0, weight=1)
container.grid_rowconfigure(1, weight=0, minsize=220)
container.grid_columnconfigure(0, weight=1)
@@ -464,18 +497,27 @@ def init_accuracy_chart(self: "PQAutomationApp"):
dpi=100,
tight_layout=False,
)
self.accuracy_fig.patch.set_facecolor(palette["bg"])
try:
self.accuracy_fig.set_layout_engine(None)
except Exception:
try:
self.accuracy_fig.set_tight_layout(False)
except Exception:
pass
self.accuracy_canvas = FigureCanvasTkAgg(self.accuracy_fig, master=plot_container)
canvas_widget = self.accuracy_canvas.get_tk_widget()
canvas_widget.pack(fill=tk.BOTH, expand=True)
self.accuracy_ax = self.accuracy_fig.add_subplot(111)
self.accuracy_ax.set_facecolor(palette["card_bg"])
self.accuracy_ax.set_xlim(0, 1)
self.accuracy_ax.set_ylim(0, 1)
self.accuracy_ax.axis("off")
# 调整标题位置
self.accuracy_fig.suptitle("色准测试", fontsize=12, y=0.985)
self.accuracy_fig.suptitle("色准测试", fontsize=12, y=0.985, color=palette["fg"])
self.accuracy_fig.subplots_adjust(
left=0.05,
@@ -616,6 +658,7 @@ def update_accuracy_result_table(self: "PQAutomationApp", accuracy_data, standar
def clear_chart(self: "PQAutomationApp"):
"""清空所有图表"""
palette = get_theme_palette()
# ========== 1. 清空色域图表 ==========
if hasattr(self, "gamut_ax_xy") and hasattr(self, "gamut_ax_uv"):
@@ -640,12 +683,17 @@ def clear_chart(self: "PQAutomationApp"):
if hasattr(self, "gamma_ax") and hasattr(self, "gamma_table_ax"):
# 清空左侧曲线
self.gamma_ax.clear()
self.gamma_fig.patch.set_facecolor(palette["bg"])
self.gamma_ax.set_facecolor(palette["card_bg"])
self.gamma_ax.set_xlim(0, 105)
self.gamma_ax.set_ylim(0, 1.1)
self.gamma_ax.set_xlabel("灰阶 (%)", fontsize=10)
self.gamma_ax.set_ylabel("L_bar", fontsize=10)
self.gamma_ax.grid(True, linestyle="--", alpha=0.3)
self.gamma_ax.tick_params(labelsize=9)
self.gamma_ax.tick_params(colors=palette["fg"])
for spine in self.gamma_ax.spines.values():
spine.set_color(palette["border"])
# 左侧提示
self.gamma_ax.text(
@@ -659,13 +707,13 @@ def clear_chart(self: "PQAutomationApp"):
ha="center",
va="center",
fontsize=10,
color="gray",
color=palette["muted_fg"],
transform=self.gamma_ax.transAxes,
bbox=dict(
boxstyle="round,pad=1",
facecolor="white",
edgecolor="gray",
alpha=0.8,
facecolor=palette["card_bg"],
edgecolor=palette["border"],
alpha=0.95,
),
)
@@ -703,17 +751,17 @@ def clear_chart(self: "PQAutomationApp"):
# 表头样式
for i in range(4):
cell = table[(0, i)]
cell.set_facecolor("#4472C4")
cell.set_text_props(weight="bold", color="white", fontsize=7)
cell.set_facecolor(palette["primary"])
cell.set_text_props(weight="bold", color=palette["select_fg"], fontsize=7)
# 数据行交替颜色
for i in range(1, len(table_data)):
for j in range(4):
cell = table[(i, j)]
if i % 2 == 0:
cell.set_facecolor("#E7E6E6")
cell.set_facecolor(palette["surface_alt_bg"])
else:
cell.set_facecolor("#FFFFFF")
cell.set_facecolor(palette["card_bg"])
# 底部说明
self.gamma_table_ax.text(
@@ -726,29 +774,34 @@ def clear_chart(self: "PQAutomationApp"):
ha="center",
va="bottom",
fontsize=7,
color="gray",
color=palette["muted_fg"],
transform=self.gamma_table_ax.transAxes,
bbox=dict(
boxstyle="round,pad=0.5",
facecolor="lightyellow",
edgecolor="gray",
alpha=0.8,
facecolor=palette["surface_alt_bg"],
edgecolor=palette["border"],
alpha=0.95,
),
)
self.gamma_fig.suptitle("Gamma曲线 + 数据表格", fontsize=12, y=0.98)
self.gamma_fig.suptitle("Gamma曲线 + 数据表格", fontsize=12, y=0.98, color=palette["fg"])
self.gamma_canvas.draw()
# ========== 3. 清空EOTF图表4列==========
if hasattr(self, "eotf_ax") and hasattr(self, "eotf_table_ax"):
# 清空左侧曲线
self.eotf_ax.clear()
self.eotf_fig.patch.set_facecolor(palette["bg"])
self.eotf_ax.set_facecolor(palette["card_bg"])
self.eotf_ax.set_xlim(0, 105)
self.eotf_ax.set_ylim(0, 1.1)
self.eotf_ax.set_xlabel("灰阶 (%)", fontsize=10)
self.eotf_ax.set_ylabel("L_bar (归一化亮度)", fontsize=10)
self.eotf_ax.grid(True, linestyle="--", alpha=0.3)
self.eotf_ax.tick_params(labelsize=9)
self.eotf_ax.tick_params(colors=palette["fg"])
for spine in self.eotf_ax.spines.values():
spine.set_color(palette["border"])
# 左侧提示
self.eotf_ax.text(
@@ -758,13 +811,13 @@ def clear_chart(self: "PQAutomationApp"):
ha="center",
va="center",
fontsize=11,
color="gray",
color=palette["muted_fg"],
transform=self.eotf_ax.transAxes,
bbox=dict(
boxstyle="round,pad=1",
facecolor="white",
edgecolor="gray",
alpha=0.8,
facecolor=palette["card_bg"],
edgecolor=palette["border"],
alpha=0.95,
),
)
@@ -802,17 +855,17 @@ def clear_chart(self: "PQAutomationApp"):
# 表头样式
for i in range(4):
cell = table[(0, i)]
cell.set_facecolor("#4472C4")
cell.set_text_props(weight="bold", color="white", fontsize=7)
cell.set_facecolor(palette["primary"])
cell.set_text_props(weight="bold", color=palette["select_fg"], fontsize=7)
# 数据行交替颜色
for i in range(1, len(table_data)):
for j in range(4):
cell = table[(i, j)]
if i % 2 == 0:
cell.set_facecolor("#E7E6E6")
cell.set_facecolor(palette["surface_alt_bg"])
else:
cell.set_facecolor("#FFFFFF")
cell.set_facecolor(palette["card_bg"])
# 底部说明
self.eotf_table_ax.text(
@@ -825,17 +878,17 @@ def clear_chart(self: "PQAutomationApp"):
ha="center",
va="bottom",
fontsize=7,
color="gray",
color=palette["muted_fg"],
transform=self.eotf_table_ax.transAxes,
bbox=dict(
boxstyle="round,pad=0.5",
facecolor="lightyellow",
edgecolor="gray",
alpha=0.8,
facecolor=palette["surface_alt_bg"],
edgecolor=palette["border"],
alpha=0.95,
),
)
self.eotf_fig.suptitle("EOTF 曲线 + 数据表格", fontsize=12, y=0.98)
self.eotf_fig.suptitle("EOTF 曲线 + 数据表格", fontsize=12, y=0.98, color=palette["fg"])
self.eotf_canvas.draw()
# ========== 4. 清空色度图表 ==========
@@ -843,8 +896,10 @@ def clear_chart(self: "PQAutomationApp"):
# 过期引用。因此清空时必须同样重建,并更新引用,否则清不干净。
if hasattr(self, "cct_fig") and hasattr(self, "cct_canvas"):
self.cct_fig.clear()
self.cct_fig.patch.set_facecolor(palette["bg"])
self.cct_ax1 = self.cct_fig.add_subplot(211)
self.cct_ax1.set_facecolor(palette["card_bg"])
self.cct_ax1.set_xlabel("灰阶 (%)", fontsize=9)
self.cct_ax1.set_ylabel("CIE x", fontsize=9)
self.cct_ax1.set_xlim(0, 105)
@@ -853,6 +908,7 @@ def clear_chart(self: "PQAutomationApp"):
self.cct_ax1.tick_params(labelsize=8)
self.cct_ax2 = self.cct_fig.add_subplot(212)
self.cct_ax2.set_facecolor(palette["card_bg"])
self.cct_ax2.set_xlabel("灰阶 (%)", fontsize=9)
self.cct_ax2.set_ylabel("CIE y", fontsize=9)
self.cct_ax2.set_xlim(0, 105)
@@ -860,7 +916,7 @@ def clear_chart(self: "PQAutomationApp"):
self.cct_ax2.grid(True, linestyle="--", alpha=0.3)
self.cct_ax2.tick_params(labelsize=8)
self.cct_fig.suptitle("色度一致性测试", fontsize=12, y=0.985)
self.cct_fig.suptitle("色度一致性测试", fontsize=12, y=0.985, color=palette["fg"])
self.cct_fig.subplots_adjust(
left=0.12,
right=0.88,
@@ -873,11 +929,13 @@ def clear_chart(self: "PQAutomationApp"):
# ========== 5. 清空对比度图表 ==========
if hasattr(self, "contrast_ax"):
self.contrast_ax.clear()
self.contrast_fig.patch.set_facecolor(palette["bg"])
self.contrast_ax.set_facecolor(palette["card_bg"])
self.contrast_ax.set_xlim(0, 1)
self.contrast_ax.set_ylim(0, 1)
self.contrast_ax.axis("off")
self.contrast_fig.suptitle("对比度测试", fontsize=12, y=0.985)
self.contrast_fig.suptitle("对比度测试", fontsize=12, y=0.985, color=palette["fg"])
# 重置布局
self.contrast_fig.subplots_adjust(
@@ -892,12 +950,14 @@ def clear_chart(self: "PQAutomationApp"):
# ========== 6. 清空色准图表 ==========
if hasattr(self, "accuracy_ax"):
self.accuracy_ax.clear()
self.accuracy_fig.patch.set_facecolor(palette["bg"])
self.accuracy_ax.set_facecolor(palette["card_bg"])
self.accuracy_ax.set_xlim(0, 1)
self.accuracy_ax.set_ylim(0, 1)
self.accuracy_ax.axis("off")
# 标题
self.accuracy_fig.suptitle("色准测试", fontsize=12, y=0.985)
self.accuracy_fig.suptitle("色准测试", fontsize=12, y=0.985, color=palette["fg"])
# 重置布局
self.accuracy_fig.subplots_adjust(

View File

@@ -600,7 +600,6 @@ def create_connection_content(self: "PQAutomationApp"):
com_frame, width=15, height=15, bg="gray", highlightthickness=0
)
self.ucd_status_indicator.grid(row=0, column=2, padx=(10, 20))
self.ucd_status_indicator.config(bg="gray")
# 添加按钮框架
button_frame = ttk.Frame(com_frame)
@@ -669,7 +668,8 @@ def create_connection_content(self: "PQAutomationApp"):
com_frame, width=15, height=15, bg="gray", highlightthickness=0
)
self.ca_status_indicator.grid(row=1, column=2, padx=(10, 20))
self.ca_status_indicator.config(bg="gray")
self.refresh_connection_indicators()
# 添加CA通道设置
ttk.Label(com_frame, text="CA通道:").grid(
@@ -808,6 +808,11 @@ def _on_toggle_theme(self: "PQAutomationApp") -> None:
toggle_theme()
# apply_modern_styles()
_refresh_theme_toggle_label(self)
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()