修改部分UI、修改module中心点设定、添加单独连接

This commit is contained in:
xinzhu.yin
2026-06-08 11:03:10 +08:00
parent e9a591bf6e
commit febbb28a4c
8 changed files with 201 additions and 24 deletions

View File

@@ -160,8 +160,7 @@ class ConnectionController:
def check_all_async(self) -> None:
"""异步并联检测 UCD + CA通过 ``_dispatch_ui`` 回主线程更新 UI。"""
app = self._app
app.check_button.configure(state="disabled")
app.refresh_button.configure(state="disabled")
self._set_connect_widgets_state("disabled")
app.status_var.set("正在检测连接...")
app.root.update()
@@ -185,6 +184,58 @@ class ConnectionController:
threading.Thread(target=worker, daemon=True).start()
def check_ucd_async(self) -> None:
"""仅异步连接 UCD323。"""
app = self._app
self._set_connect_widgets_state("disabled")
app.status_var.set("正在连接 UCD323...")
app.root.update()
def worker():
try:
ucd_ok = self.connect_ucd(app.ucd_list_var.get())
app._dispatch_ui(
app.update_connection_indicator,
app.ucd_status_indicator,
ucd_ok,
)
app._dispatch_ui(
app.status_var.set,
"UCD323 连接成功" if ucd_ok else "UCD323 连接失败",
)
app._dispatch_ui(self._enable_widgets)
except Exception as exc: # noqa: BLE001
app._dispatch_ui(app.log_gui.log, f"UCD323 连接出错: {exc}")
app._dispatch_ui(self._enable_widgets)
threading.Thread(target=worker, daemon=True).start()
def check_ca_async(self) -> None:
"""仅异步连接 CA410。"""
app = self._app
self._set_connect_widgets_state("disabled")
app.status_var.set("正在连接 CA410...")
app.root.update()
def worker():
try:
ca_ok = self.connect_ca()
app._dispatch_ui(
app.update_connection_indicator,
app.ca_status_indicator,
ca_ok,
)
app._dispatch_ui(
app.status_var.set,
"CA410 连接成功" if ca_ok else "CA410 连接失败",
)
app._dispatch_ui(self._enable_widgets)
except Exception as exc: # noqa: BLE001
app._dispatch_ui(app.log_gui.log, f"CA410 连接出错: {exc}")
app._dispatch_ui(self._enable_widgets)
threading.Thread(target=worker, daemon=True).start()
def disconnect_all(self) -> None:
try:
self.disconnect_ucd()
@@ -196,6 +247,24 @@ class ConnectionController:
self._log(f"断开连接时发生错误: {exc}", level="info")
messagebox.showerror("错误", f"断开连接失败: {exc}")
def disconnect_ucd_only(self) -> None:
try:
self.disconnect_ucd()
self._app.refresh_connection_indicators()
self._app.status_var.set("UCD323 已断开")
except Exception as exc: # noqa: BLE001
self._log(f"断开 UCD323 时发生错误: {exc}", level="info")
messagebox.showerror("错误", f"断开 UCD323 失败: {exc}")
def disconnect_ca_only(self) -> None:
try:
self.disconnect_ca()
self._app.refresh_connection_indicators()
self._app.status_var.set("CA410 已断开")
except Exception as exc: # noqa: BLE001
self._log(f"断开 CA410 时发生错误: {exc}", level="info")
messagebox.showerror("错误", f"断开 CA410 失败: {exc}")
def refresh_ports(self) -> None:
"""刷新 UCD + COM 端口下拉框;指示器复位。"""
app = self._app
@@ -219,8 +288,21 @@ class ConnectionController:
# -- 内部 ----------------------------------------------------
def _enable_widgets(self) -> None:
self._app.check_button.configure(state="normal")
self._app.refresh_button.configure(state="normal")
self._set_connect_widgets_state("normal")
def _set_connect_widgets_state(self, state: str) -> None:
for attr in (
"check_button",
"ucd_connect_button",
"ca_connect_button",
"refresh_button",
):
widget = getattr(self._app, attr, None)
if widget is not None:
try:
widget.configure(state=state)
except Exception: # noqa: BLE001
pass
def _log(self, msg: str, *, level: str = "info") -> None:
log_gui = getattr(self._app, "log_gui", None)
@@ -250,6 +332,14 @@ def check_com_connections(self: "PQAutomationApp"):
self.connection.check_all_async()
def check_ucd_connection(self: "PQAutomationApp"):
self.connection.check_ucd_async()
def check_ca_connection(self: "PQAutomationApp"):
self.connection.check_ca_async()
def update_connection_indicator(self: "PQAutomationApp", indicator, connected):
_draw_connection_indicator(indicator, "green" if connected else "red")
@@ -307,6 +397,14 @@ def disconnect_com_connections(self: "PQAutomationApp"):
self.connection.disconnect_all()
def disconnect_ucd_connection(self: "PQAutomationApp"):
self.connection.disconnect_ucd_only()
def disconnect_ca_connection(self: "PQAutomationApp"):
self.connection.disconnect_ca_only()
def _get_ca_measure_lock(self: "PQAutomationApp"):
lock = getattr(self, "_ca_measure_lock", None)
if lock is None:
@@ -357,11 +455,15 @@ __all__ = [
"get_available_com_ports",
"refresh_com_ports",
"check_com_connections",
"check_ucd_connection",
"check_ca_connection",
"update_connection_indicator",
"refresh_connection_indicators",
"check_port_connection",
"enable_com_widgets",
"disconnect_com_connections",
"disconnect_ucd_connection",
"disconnect_ca_connection",
]
@@ -373,11 +475,15 @@ class DeviceConnectionMixin:
get_available_com_ports = get_available_com_ports
refresh_com_ports = refresh_com_ports
check_com_connections = check_com_connections
check_ucd_connection = check_ucd_connection
check_ca_connection = check_ca_connection
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
disconnect_ucd_connection = disconnect_ucd_connection
disconnect_ca_connection = disconnect_ca_connection
_get_ca_measure_lock = _get_ca_measure_lock
_read_ca_display = _read_ca_display
read_ca_xyLv = read_ca_xyLv