Skip to content

Commit 8fa0733

Browse files
author
Mehmet Aksoy
committed
Improves serial port information display
Enhances the serial port connection process by displaying more detailed information about the selected port upon connection. Additionally, refactors the serial data display to handle different color schemes for day and night modes, ensuring better readability. Also, ensures proper thread termination on application close to prevent resource leaks.
1 parent 1107948 commit 8fa0733

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/ui_main.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,18 @@ def on_start_button_clicked(self):
378378
return
379379
is_serial_port_established = True
380380
# change start_button to stop button
381-
self.ui.options_textEdit.setText('Disconnected!')
381+
# Get more info about the selected port
382+
port_info = None
383+
selected_port = self.ui.port_comboBox.currentText()
384+
for p in serial.tools.list_ports.comports():
385+
if p.device == selected_port:
386+
port_info = p
387+
break
388+
if port_info:
389+
info_text = f"RX/TX Connected to: {port_info.device}\nDescription: {port_info.description}\nManufacturer: {getattr(port_info, 'manufacturer', 'N/A')}\nHWID: {port_info.hwid}"
390+
else:
391+
info_text = f"RX/TX Connected to: {selected_port}"
392+
self.ui.options_textEdit.setText(info_text)
382393
self.ui.start_button.setText("STOP")
383394
self.ui.start_button.setStyleSheet('color: red;')
384395

@@ -398,7 +409,7 @@ def on_start_button_clicked(self):
398409
self.thread.finished.connect(self.thread.deleteLater)
399410

400411
self.enable_configuration(False)
401-
self.ui.options_textEdit.setText('RX/TX Connected!')
412+
self.ui.options_textEdit.setText('RX/TX Connected to the: ' + str(SERIAL_DEVICE.portstr))
402413
self.ui.status_label.setText("CONNECTED!")
403414
self.ui.status_label.setStyleSheet('color: green')
404415
# start the thread
@@ -449,8 +460,14 @@ def read_data_from_thread(self, serial_data):
449460
" Possibly it is not connected or the port is not available!")
450461
self.on_stop_button_clicked()
451462
else:
452-
# Replace CRLF and LF with <br> for HTML display
453463
html_data = ansi_to_html(serial_data.replace('\r\n', '<br>').replace('\n', '<br>'))
464+
# Adjust text color for day/night mode
465+
if hasattr(self, 'night_mode_enabled') and self.night_mode_enabled:
466+
# Night mode: convert black text to white
467+
html_data = html_data.replace('color:black;', 'color:white;')
468+
else:
469+
# Day mode: convert white text to black
470+
html_data = html_data.replace('color:white;', 'color:black;')
454471
self.ui.data_textEdit.insertHtml(html_data)
455472
self.ui.data_textEdit.verticalScrollBar().setValue(
456473
self.ui.data_textEdit.verticalScrollBar().maximum())
@@ -498,6 +515,10 @@ def enable_night_mode(self):
498515
def closeEvent(self, event):
499516
# Properly stop the worker and thread before closing
500517
self.stop_worker_thread()
518+
if hasattr(self, 'thread') and self.thread is not None:
519+
if self.thread.isRunning():
520+
self.thread.quit()
521+
self.thread.wait(2000) # Wait up to 2 seconds for thread to finish
501522
event.accept()
502523

503524
def start_ui_design():

0 commit comments

Comments
 (0)