feat(qt-ports): унифицировать выбор последовательного порта
This commit is contained in:
23
python/set_devices/qt_ports/port_selection.py
Normal file
23
python/set_devices/qt_ports/port_selection.py
Normal 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)
|
||||||
Reference in New Issue
Block a user