From 2a6557c74b353ba066d7937f4b0cc249299b76c9 Mon Sep 17 00:00:00 2001 From: William Emfinger Date: Tue, 19 Nov 2024 09:00:31 -0600 Subject: [PATCH] feat: Allow ANSI in log files; speed up log output * Update to use `escape_ansi` when loading raw log files, which may have been copied from terminal output and therefore would contain ANSI escape sequences * Update to use QPlainTextEdit for significantly improved performance when dealing with large amounts of data (e.g. millions of points and 10s of megabytes of text --- src/main_window.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main_window.py b/src/main_window.py index ca8ceea..1ffff48 100644 --- a/src/main_window.py +++ b/src/main_window.py @@ -4,6 +4,7 @@ import re import serial import serial.tools.list_ports +from io import StringIO import threading import queue @@ -26,7 +27,7 @@ def escape_ansi(line): QDialog, QFileDialog, QSplitter, - QTextEdit, + QPlainTextEdit, QVBoxLayout, ) @@ -36,7 +37,6 @@ def escape_ansi(line): import csv from tabs import Tabs - class MainWindow(QMainWindow): from menubar import ( @@ -108,7 +108,7 @@ def __init_font__(self): def __get_editor_stylesheet__(self): return """ - QTextEdit { + QPlainTextEdit { background: rgb(27,27,28); border-color: gray; color: rgb(255, 255, 255); } QScrollBar { @@ -129,7 +129,7 @@ def __get_editor_stylesheet__(self): def __init_ui__(self): QApplication.setStyle(QStyleFactory.create("Cleanlooks")) self.__init_font__() - self.log_editor = QTextEdit() + self.log_editor = QPlainTextEdit() self.log_editor.setFont(self.font) self.log_editor.setStyleSheet(self.__get_editor_stylesheet__()) @@ -158,7 +158,7 @@ def __init_ui__(self): self.setStyleSheet("QMainWindow { background-color: rgb(27,27,28); }") - self.output_editor = QTextEdit() + self.output_editor = QPlainTextEdit() self.output_editor.setFont(self.font) self.output_editor.setStyleSheet(self.__get_editor_stylesheet__()) @@ -399,9 +399,10 @@ def __open_raw__(self): self.plot_tab.setToolTip(path) with open(path, "r") as csvfile: - self.output(csvfile.read()) - csvfile.seek(0, 0) # go back to the beginning - reader = csv.reader(csvfile) + filedata = csvfile.read() + filedata = escape_ansi(filedata) + self.output(filedata) + reader = csv.reader(StringIO(filedata)) # Clear existing plot and set new header self.__clear_plot__()