From 24f77f753c9aa0f1bc140635cb12e1f990b992e5 Mon Sep 17 00:00:00 2001 From: Dominik Demuth Date: Tue, 27 Feb 2024 14:20:08 +0000 Subject: [PATCH] 242-uncaught-exception (#252) close issue #242 Co-authored-by: Dominik Demuth Reviewed-on: https://gitea.pkm.physik.tu-darmstadt.de/IPKM/nmreval/pulls/252 --- src/gui_qt/lib/logger.py | 27 +++++++++++++++++++++++++++ src/gui_qt/lib/utils.py | 2 +- src/gui_qt/main/console.py | 3 +++ src/gui_qt/main/mainwindow.py | 6 ++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/gui_qt/main/console.py diff --git a/src/gui_qt/lib/logger.py b/src/gui_qt/lib/logger.py index 0570d84..e1cb93c 100644 --- a/src/gui_qt/lib/logger.py +++ b/src/gui_qt/lib/logger.py @@ -1,5 +1,8 @@ +import logging from pathlib import Path +from PyQt5 import QtWidgets + from .codeeditor import _make_textformats from ..Qt import QtWidgets, QtCore, QtGui from nmreval.configs import config_paths @@ -113,3 +116,27 @@ class QLog(QtWidgets.QDialog): for lines in text[-100:]: self.plainTextEdit.appendPlainText(lines[:-1]) + + +class ConsoleDock(QtWidgets.QDockWidget): + def __init__(self, parent=None): + super().__init__(parent=parent) + + self.code = QtWidgets.QPlainTextEdit(parent) + self.code.highlight = LogHighlighter(self.code.document()) + self.code.setReadOnly(True) + self.code.setMaximumBlockCount(50) + self.setWidget(self.code) + + +class QTextHandler(logging.Handler): + def __init__(self, parent): + super().__init__() + + self.console = ConsoleDock(parent) + self.setFormatter(logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')) + + def emit(self, record): + msg = self.format(record) + self.console.code.appendPlainText(msg) + self.console.show() diff --git a/src/gui_qt/lib/utils.py b/src/gui_qt/lib/utils.py index 2f06820..5d87d1c 100644 --- a/src/gui_qt/lib/utils.py +++ b/src/gui_qt/lib/utils.py @@ -10,7 +10,7 @@ from ..Qt import QtGui, QtWidgets, QtCore @contextmanager def busy_cursor(): try: - cursor = QtGui.QCursor(QtCore.Qt.ForbiddenCursor) + cursor = QtGui.QCursor(QtCore.Qt.CursorShape.ForbiddenCursor) QtWidgets.QApplication.setOverrideCursor(cursor) yield diff --git a/src/gui_qt/main/console.py b/src/gui_qt/main/console.py new file mode 100644 index 0000000..b28b04f --- /dev/null +++ b/src/gui_qt/main/console.py @@ -0,0 +1,3 @@ + + + diff --git a/src/gui_qt/main/mainwindow.py b/src/gui_qt/main/mainwindow.py index d91b3ac..7f637d4 100644 --- a/src/gui_qt/main/mainwindow.py +++ b/src/gui_qt/main/mainwindow.py @@ -12,6 +12,7 @@ from nmreval.lib.logger import logger from nmreval.io.sessionwriter import NMRWriter from .management import UpperManagement +from ..lib.logger import ConsoleDock, QTextHandler from ..Qt import QtGui, QtPrintSupport from ..data.shift_graphs import QShift from ..data.signaledit import QPreviewDialog, QBaselineDialog @@ -62,6 +63,11 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow): self.eval = None self.editor = None + self.logtext = QTextHandler(self) + logger.addHandler(self.logtext) + self.addDockWidget(QtCore.Qt.DockWidgetArea.BottomDockWidgetArea, self.logtext.console) + self.logtext.console.hide() + self.movedialog = QMover(self) self.current_graph_widget = None