pop-up error messages

This commit is contained in:
Dominik Demuth 2024-02-27 15:18:52 +01:00
parent e0ba48f900
commit ccf75891fb
3 changed files with 30 additions and 33 deletions

View File

@ -1,5 +1,8 @@
import logging
from pathlib import Path from pathlib import Path
from PyQt5 import QtWidgets
from .codeeditor import _make_textformats from .codeeditor import _make_textformats
from ..Qt import QtWidgets, QtCore, QtGui from ..Qt import QtWidgets, QtCore, QtGui
from nmreval.configs import config_paths from nmreval.configs import config_paths
@ -113,3 +116,27 @@ class QLog(QtWidgets.QDialog):
for lines in text[-100:]: for lines in text[-100:]:
self.plainTextEdit.appendPlainText(lines[:-1]) 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()

View File

@ -1,32 +1,3 @@
import logging
from gui_qt.Qt import QtWidgets
from gui_qt.lib.codeeditor import EditorWidget
class ConsoleDock(QtWidgets.QDockWidget):
def __init__(self, parent=None):
super().__init__(parent=parent)
self.code = EditorWidget(self)
self.code.editor.setReadOnly(True)
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)
if __name__ == "__main__":
app = QtWidgets.QApplication([])
w = ConsoleDock()
w.show()
app.exec()

View File

@ -12,7 +12,7 @@ from nmreval.lib.logger import logger
from nmreval.io.sessionwriter import NMRWriter from nmreval.io.sessionwriter import NMRWriter
from .management import UpperManagement from .management import UpperManagement
from .console import ConsoleDock, QTextHandler from ..lib.logger import ConsoleDock, QTextHandler
from ..Qt import QtGui, QtPrintSupport from ..Qt import QtGui, QtPrintSupport
from ..data.shift_graphs import QShift from ..data.shift_graphs import QShift
from ..data.signaledit import QPreviewDialog, QBaselineDialog from ..data.signaledit import QPreviewDialog, QBaselineDialog
@ -62,10 +62,11 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
self.fitresult_dialog = None self.fitresult_dialog = None
self.eval = None self.eval = None
self.editor = None self.editor = None
self.logtext = QTextHandler(self) self.logtext = QTextHandler(self)
logger.addHandler(self.logtext) logger.addHandler(self.logtext)
self.addDockWidget(QtCore.Qt.DockWidgetArea.BottomDockWidgetArea, self.logtext.console) self.addDockWidget(QtCore.Qt.DockWidgetArea.BottomDockWidgetArea, self.logtext.console)
self.logtext.console.hide()
self.movedialog = QMover(self) self.movedialog = QMover(self)
@ -251,8 +252,6 @@ class NMRMainWindow(QtWidgets.QMainWindow, Ui_BaseWindow):
filedialog.set_graphs(self.management.graphs.list()) filedialog.set_graphs(self.management.graphs.list())
raise ValueError('Test')
accepted = filedialog.exec() accepted = filedialog.exec()
if accepted: if accepted:
fname = filedialog.selectedFiles() fname = filedialog.selectedFiles()