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

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

@@ -25,6 +25,7 @@ from typing import TYPE_CHECKING
from app.ucd_domain import ConnectionChanged, UcdError
from drivers.caSerail import CASerail
from drivers.ucd_driver import DeviceInfo
from app.views.modern_styles import get_theme_palette
from typing import TYPE_CHECKING
@@ -189,8 +190,7 @@ class ConnectionController:
self.disconnect_ucd()
self.disconnect_ca()
self._enable_widgets()
self._app.ucd_status_indicator.config(bg="gray")
self._app.ca_status_indicator.config(bg="gray")
self._app.refresh_connection_indicators()
self._app.status_var.set("串口连接已断开")
except Exception as exc: # noqa: BLE001
self._log(f"断开连接时发生错误: {exc}", level="info")
@@ -212,10 +212,7 @@ class ConnectionController:
)
app.ca_com_combo.config(values=com_ports)
if hasattr(app, "ucd_status_indicator"):
app.ucd_status_indicator.config(bg="gray")
if hasattr(app, "ca_status_indicator"):
app.ca_status_indicator.config(bg="gray")
app.refresh_connection_indicators()
app.update_config()
@@ -254,7 +251,45 @@ def check_com_connections(self: "PQAutomationApp"):
def update_connection_indicator(self: "PQAutomationApp", indicator, connected):
indicator.config(bg="green" if connected else "red")
_draw_connection_indicator(indicator, "green" if connected else "red")
def refresh_connection_indicators(self: "PQAutomationApp"):
"""根据当前设备状态重画 UCD / CA 指示灯。"""
if hasattr(self, "ucd_status_indicator"):
ucd_connected = bool(getattr(self.ucd, "status", False))
_draw_connection_indicator(
self.ucd_status_indicator,
"green" if ucd_connected else "gray",
)
if hasattr(self, "ca_status_indicator"):
ca_connected = getattr(self, "ca", None) is not None
_draw_connection_indicator(
self.ca_status_indicator,
"green" if ca_connected else "gray",
)
def _draw_connection_indicator(canvas, state: str) -> None:
palette = get_theme_palette()
color_map = {
"green": "#2ECC71",
"red": "#E74C3C",
"gray": "#9AA3AD",
}
fill = color_map.get(state, state)
border = palette["border"]
bg = palette["card_bg"]
try:
canvas.configure(bg=bg, highlightbackground=border, highlightcolor=border)
canvas.delete("all")
# 保持原有视觉:方形状态灯(红/绿/灰)
canvas.create_rectangle(0, 0, 15, 15, fill=fill, outline=border, width=1)
except Exception:
try:
canvas.config(bg=fill)
except Exception:
pass
def check_port_connection(self: "PQAutomationApp", is_ucd=True):
@@ -323,6 +358,7 @@ __all__ = [
"refresh_com_ports",
"check_com_connections",
"update_connection_indicator",
"refresh_connection_indicators",
"check_port_connection",
"enable_com_widgets",
"disconnect_com_connections",
@@ -338,6 +374,7 @@ class DeviceConnectionMixin:
refresh_com_ports = refresh_com_ports
check_com_connections = check_com_connections
update_connection_indicator = update_connection_indicator
refresh_connection_indicators = refresh_connection_indicators
check_port_connection = check_port_connection
enable_com_widgets = enable_com_widgets
disconnect_com_connections = disconnect_com_connections