From 675ce063f0d475e70dd903b5a0a12cf96cdfd6cf Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 1 Oct 2026 22:40:20 +0300 Subject: [PATCH] =?UTF-8?q?feat(qt-ports):=20=D1=83=D0=BD=D0=B8=D1=84?= =?UTF-8?q?=D0=B8=D1=86=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20=D0=B2?= =?UTF-8?q?=D1=8B=D0=B1=D0=BE=D1=80=20=D0=BF=D0=BE=D1=81=D0=BB=D0=B5=D0=B4?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D0=BF=D0=BE=D1=80=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/set_devices/qt_ports/port_selection.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 python/set_devices/qt_ports/port_selection.py 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)