@@ -376,6 +376,7 @@ def __init__(self):
376376 self .populate_serial_ports ()
377377
378378 self .marker_registry = {}
379+ self .log_entries = []
379380
380381 self .log_tag_colors = {
381382 "Sent" : "blue" ,
@@ -486,6 +487,25 @@ def create_tabs(self):
486487
487488 self .main_layout .addWidget (self .tabs )
488489
490+ # Filter dropdown
491+ self .filter_box = QComboBox ()
492+ self .filter_box .addItems (["All" , "Sent" , "Received" , "Modem" , "SD" ])
493+ self .filter_box .setFixedWidth (150 )
494+ self .filter_box .currentTextChanged .connect (self .filter_log_entries )
495+
496+ # Center the dropdown
497+ filter_row = QHBoxLayout ()
498+ filter_row .addStretch ()
499+ filter_row .addWidget (self .filter_box )
500+ filter_row .addStretch ()
501+ self .log_layout .addLayout (filter_row )
502+
503+ def filter_log_entries (self , selected_tag ):
504+ self .log_output .clear ()
505+ for entry in self .log_entries :
506+ if selected_tag == "All" or entry ["tag" ] == selected_tag :
507+ self .render_log_entry (entry )
508+
489509 def populate_serial_ports (self ):
490510 current_selection = self .port_combo .currentData ()
491511 self .port_combo .clear ()
@@ -526,14 +546,18 @@ def send_serial_command(self):
526546 return
527547 if self .serial_thread and self .serial_thread .isRunning ():
528548 self .serial_thread .write (text + "\n " )
529- self .command_input .clear ()
549+ #self.command_input.clear()
550+ self .command_input .setCurrentIndex (- 1 )
551+ self .command_input .setEditText ("" )
552+ self .command_input .setFocus ()
530553
531554 timestamp = datetime .now ().strftime ("[%H:%M:%S]" )
532555 log_entry = {
533556 "text" : f"{ timestamp } TX: { text } \n " ,
534557 "tag" : "Sent"
535558 }
536- self .append_to_log (log_entry )
559+ self .log_entries .append (log_entry )
560+ self .render_log_entry (log_entry )
537561 else :
538562 QMessageBox .warning (self , "Not Connected" , "No serial connection is active." )
539563
@@ -608,7 +632,8 @@ def handle_serial_data(self, line):
608632 "text" : f"{ timestamp } RX: { packet } \n " ,
609633 "tag" : tag
610634 }
611- self .append_to_log (log_entry )
635+ self .log_entries .append (log_entry )
636+ self .render_log_entry (log_entry )
612637
613638 lat = getattr (packet , "latitude" , None )
614639 lon = getattr (packet , "longitude" , None )
@@ -672,16 +697,38 @@ def handle_serial_data(self, line):
672697 "text" : f"{ timestamp } RX: { line } \n " ,
673698 "tag" : tag
674699 }
675- self .append_to_log (log_entry )
700+ self .log_entries .append (log_entry )
701+ self .render_log_entry (log_entry )
676702
677- def append_to_log (self , entry ):
703+ ''' def append_to_log(self, entry):
678704 text = entry["text"]
679705 tag = entry.get("tag", "Received") # default to Received if not specified
680706 color = self.log_tag_colors.get(tag, "black")
681707
682708 fmt = QTextCharFormat()
683709 fmt.setForeground(QColor(color))
684710
711+ cursor = self.log_output.textCursor()
712+ cursor.movePosition(QTextCursor.End)
713+ cursor.insertText(text, fmt)
714+ self.log_output.setTextCursor(cursor)
715+ self.log_output.ensureCursorVisible()'''
716+
717+ def render_log_entry (self , entry ):
718+ from PySide6 .QtGui import QTextCharFormat , QTextCursor , QColor
719+
720+ # Respect current filter
721+ selected_tag = self .filter_box .currentText ()
722+ if selected_tag != "All" and entry ["tag" ] != selected_tag :
723+ return # Don't show it
724+
725+ text = entry ["text" ]
726+ tag = entry .get ("tag" , "Received" )
727+ color = self .log_tag_colors .get (tag , "black" )
728+
729+ fmt = QTextCharFormat ()
730+ fmt .setForeground (QColor (color ))
731+
685732 cursor = self .log_output .textCursor ()
686733 cursor .movePosition (QTextCursor .End )
687734 cursor .insertText (text , fmt )
0 commit comments