diff --git a/python/set_devices/qt_ports/port_selection.py b/python/set_devices/qt_ports/port_selection.py new file mode 100644 index 0000000..e8516c0 --- /dev/null +++ b/python/set_devices/qt_ports/port_selection.py @@ -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)