[new] log widget for PyLoT

This commit is contained in:
Marcel Paffrath 2022-03-08 16:27:36 +01:00
parent dd02527c1d
commit 9036a9054e
2 changed files with 57 additions and 2 deletions

View File

@ -86,7 +86,7 @@ from pylot.core.io.location import create_creation_info, create_event
from pylot.core.util.widgets import FilterOptionsDialog, NewEventDlg, \ from pylot.core.util.widgets import FilterOptionsDialog, NewEventDlg, \
PylotCanvas, WaveformWidgetPG, PropertiesDlg, HelpForm, createAction, PickDlg, \ PylotCanvas, WaveformWidgetPG, PropertiesDlg, HelpForm, createAction, PickDlg, \
ComparisonWidget, TuneAutopicker, PylotParaBox, AutoPickDlg, CanvasWidget, AutoPickWidget, \ ComparisonWidget, TuneAutopicker, PylotParaBox, AutoPickDlg, CanvasWidget, AutoPickWidget, \
CompareEventsWidget, ProgressBarWidget, AddMetadataWidget, SingleTextLineDialog CompareEventsWidget, ProgressBarWidget, AddMetadataWidget, SingleTextLineDialog, LogWidget
from pylot.core.util.array_map import Array_map from pylot.core.util.array_map import Array_map
from pylot.core.util.structure import DATASTRUCTURE from pylot.core.util.structure import DATASTRUCTURE
from pylot.core.util.thread import Thread, Worker from pylot.core.util.thread import Thread, Worker
@ -731,6 +731,11 @@ class MainWindow(QMainWindow):
_widget.setLayout(self._main_layout) _widget.setLayout(self._main_layout)
_widget.showFullScreen() _widget.showFullScreen()
self.logwidget = LogWidget(parent=None)
self.logwidget.show()
sys.stdout = self.logwidget.stdout
sys.stderr = self.logwidget.stderr
self.setCentralWidget(_widget) self.setCentralWidget(_widget)
def init_wfWidget(self): def init_wfWidget(self):
@ -778,7 +783,6 @@ class MainWindow(QMainWindow):
if event.key() == QtCore.Qt.Key.Key_R: if event.key() == QtCore.Qt.Key.Key_R:
self.reset_gain() self.reset_gain()
def keyReleaseEvent(self, event): def keyReleaseEvent(self, event):
if event.key() == QtCore.Qt.Key.Key_Control: if event.key() == QtCore.Qt.Key.Key_Control:
self._ctrl = False self._ctrl = False

View File

@ -82,6 +82,57 @@ class QDoubleSpinBox(QtWidgets.QDoubleSpinBox):
event.ignore() event.ignore()
class TextLogWidget(QtWidgets.QTextEdit):
highlight = Signal()
def __init__(self, parent, highlight_input=False):
super(TextLogWidget, self).__init__(parent)
self.highlight_input = highlight_input
def write(self, text):
self.append(text)
if self.highlight_input:
self.highlight.emit()
class LogWidget(QtWidgets.QWidget):
def __init__(self, parent):
super(LogWidget, self).__init__(parent, Qt.Window)
self.current_active_error = False
self.qmb = None
self.setWindowTitle('PyLoT Log')
self.setMinimumWidth(800)
self.setMinimumHeight(600)
self.stdout = TextLogWidget(self)
self.stderr = TextLogWidget(self, highlight_input=True)
self.stderr.highlight.connect(self.active_error)
self.tabs = QTabWidget()
self.tabs.addTab(self.stdout, 'Log')
self.tabs.addTab(self.stderr, 'Errors')
self.layout = QtWidgets.QVBoxLayout()
self.textfield = QtWidgets.QTextEdit()
self.setLayout(self.layout)
self.layout.addWidget(self.tabs)
def active_error(self):
if self.current_active_error == False:
self.current_active_error = True
self.show()
self.activateWindow()
self.tabs.setCurrentWidget(self.stderr)
self.qmb = QtWidgets.QMessageBox(QtWidgets.QMessageBox.Icon.Warning,
'Error', 'Error occurred. Please check log!')
self.qmb.buttonClicked.connect(self.reset_error)
self.qmb.show()
def reset_error(self):
# used to make sure that write errors is finished before raising new Message box etc.
self.current_active_error = False
def getDataType(parent): def getDataType(parent):
type = QInputDialog().getItem(parent, "Select phases type", "Type:", type = QInputDialog().getItem(parent, "Select phases type", "Type:",
["manual", "automatic"]) ["manual", "automatic"])