11import sys
22from qtpy .QtWidgets import (
33 QTextEdit ,
4+ QPlainTextEdit ,
45 QVBoxLayout ,
56 QWidget ,
67 QTableWidget ,
910 QAbstractScrollArea ,
1011)
1112from qtpy .QtCore import QTimer , Qt
12- from qtpy .QtGui import QTextOption
13+ from qtpy .QtGui import QTextOption , QTextCursor , QFont , QFontDatabase
1314import csv
1415from pathlib import Path
1516
@@ -41,10 +42,14 @@ def __init__(self, log_file, max_height=500, parent=None):
4142 self .auto_scroll = True # Auto-scroll is enabled by default
4243
4344 def initUI (self , max_height ):
44- self .text_edit = QTextEdit (self )
45+ self .text_edit = QPlainTextEdit (self )
4546 self .text_edit .setReadOnly (True )
4647 self .text_edit .setWordWrapMode (QTextOption .NoWrap )
4748
49+ fixed = QFontDatabase .systemFont (QFontDatabase .FixedFont )
50+ fixed .setStyleHint (QFont .Monospace )
51+ self .text_edit .setFont (fixed )
52+
4853 layout = QVBoxLayout (self )
4954 layout .addWidget (self .text_edit )
5055 self .setLayout (layout )
@@ -71,15 +76,17 @@ def update_log(self):
7176 f .seek (self .last_position )
7277 new_lines = f .readlines ()
7378 self .last_position = f .tell ()
74-
79+ new_lines = [ ln for ln in new_lines if ln . strip ()]
7580 if new_lines :
76- # self.text_edit.append("".join(new_lines))
77- cursor = self .text_edit .textCursor ()
78- cursor .movePosition (cursor .End ) # Move cursor to the end
79- cursor .insertText ("" .join (new_lines )) # Insert text directly
80- if self .auto_scroll :
81- self .text_edit .moveCursor (QTextEdit ().textCursor ().End )
82-
81+ self .add_lines (new_lines )
82+
83+ def add_lines (self , text ):
84+ cursor = self .text_edit .textCursor ()
85+ cursor .movePosition (cursor .End ) # Move cursor to the end
86+ cursor .insertText ("" .join (text )) # Insert text directly
87+ if self .auto_scroll :
88+ self .text_edit .moveCursor (QTextCursor .End )
89+
8390
8491class CSVTableWidget (QTableWidget ):
8592 def __init__ (self , parent = None , file_path = None ):
0 commit comments