feat(qt-ports): унифицировать выбор последовательного порта

This commit is contained in:
2026-10-01 22:40:20 +03:00
parent 3d9174a124
commit 675ce063f0

View File

@@ -0,0 +1,23 @@
"""Shared serial-port labels and selection for Qt project interfaces."""
def port_label(name: str, description: str = "") -> str:
"""Display the device description without changing the transport name."""
description = (description or "").strip()
return f"{name} · {description}" if description else name
def selected_port_name(combo) -> str:
"""Read item data, while allowing a manually entered port name."""
if combo.isEditable() and combo.currentText() != combo.itemText(combo.currentIndex()):
return combo.currentText().strip()
return str(combo.currentData() or combo.currentText()).strip()
def select_port_name(combo, name: str) -> None:
"""Restore by transport name; retain manually entered or absent ports."""
index = combo.findData(name)
if index >= 0:
combo.setCurrentIndex(index)
elif combo.isEditable():
combo.setEditText(name)