-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add logging tab * Setup logging in GUI tab * Ruff * Rename * Adjust import * Adding overwrite to close of log_tab widget * Cosmetics * Overwrite close event of global app to close logging * Rename * Rename * remove unneccessary confirmationwq --------- Co-authored-by: Staiger, Christine <christine.staiger@wur.nl>
- Loading branch information
Showing
4 changed files
with
168 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"""Logging tab.""" | ||
|
||
import logging | ||
import sys | ||
|
||
import PyQt6 | ||
|
||
from ibridgesgui.config import CONFIG_DIR | ||
from ibridgesgui.gui_utils import UI_FILE_DIR | ||
from ibridgesgui.ui_files.tabLogging import Ui_tabLogging | ||
|
||
|
||
class QTextEditLogger(logging.Handler, PyQt6.QtCore.QObject): | ||
"""Logging in a Qt text browser.""" | ||
|
||
append_plain_text = PyQt6.QtCore.pyqtSignal(str) | ||
|
||
def __init__(self, text_browser): | ||
"""Initialise.""" | ||
super().__init__() | ||
PyQt6.QtCore.QObject.__init__(self) | ||
self.widget = text_browser | ||
self.widget.setReadOnly(True) | ||
self.append_plain_text.connect(self.widget.insertPlainText) | ||
|
||
def emit(self, record): | ||
"""Emit when new logging accurs.""" | ||
msg = self.format(record)+"\n" | ||
self.append_plain_text.emit(msg) | ||
|
||
|
||
class LogViewer(PyQt6.QtWidgets.QWidget, Ui_tabLogging): | ||
"""Set iBridges logging in GUI.""" | ||
|
||
def __init__(self, logger): | ||
"""Initialise the tab.""" | ||
super().__init__() | ||
if getattr(sys, "frozen", False): | ||
super().setupUi(self) | ||
else: | ||
PyQt6.uic.loadUi(UI_FILE_DIR / "tabLogging.ui", self) | ||
|
||
self.logger = logger | ||
self.log_label.setText(str(CONFIG_DIR)) | ||
self.log_text = QTextEditLogger(self.log_browser) | ||
self.log_text.setFormatter( | ||
logging.Formatter( | ||
'%(asctime)s %(levelname)s %(module)s %(funcName)s %(message)s')) | ||
self.logger.addHandler(self.log_text) | ||
self.logger.setLevel(logging.DEBUG) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Form implementation generated from reading ui file 'ibridgesgui/ui_files/tabLogging.ui' | ||
# | ||
# Created by: PyQt6 UI code generator 6.4.2 | ||
# | ||
# WARNING: Any manual changes made to this file will be lost when pyuic6 is | ||
# run again. Do not edit this file unless you know what you are doing. | ||
|
||
|
||
from PyQt6 import QtCore, QtGui, QtWidgets | ||
|
||
|
||
class Ui_tabLogging(object): | ||
def setupUi(self, Form): | ||
Form.setObjectName("Form") | ||
Form.resize(400, 244) | ||
Form.setStyleSheet("QWidget\n" | ||
"{\n" | ||
" background-color: rgb(211,211,211);\n" | ||
" color: rgb(88, 88, 90);\n" | ||
" selection-background-color: rgb(21, 165, 137);\n" | ||
" selection-color: rgb(245, 244, 244)\n" | ||
"}\n" | ||
"\n" | ||
"QLabel\n" | ||
"{\n" | ||
" background-color: rgb(211,211,211);\n" | ||
"}\n" | ||
"\n" | ||
"QTextBrowser\n" | ||
"{\n" | ||
" background-color: rgb(245, 244, 244)\n" | ||
"}\n" | ||
"") | ||
self.verticalLayout = QtWidgets.QVBoxLayout(Form) | ||
self.verticalLayout.setObjectName("verticalLayout") | ||
self.log_label = QtWidgets.QLabel(parent=Form) | ||
self.log_label.setObjectName("log_label") | ||
self.verticalLayout.addWidget(self.log_label) | ||
self.log_browser = QtWidgets.QTextBrowser(parent=Form) | ||
self.log_browser.setObjectName("log_browser") | ||
self.verticalLayout.addWidget(self.log_browser) | ||
|
||
self.retranslateUi(Form) | ||
QtCore.QMetaObject.connectSlotsByName(Form) | ||
|
||
def retranslateUi(self, Form): | ||
_translate = QtCore.QCoreApplication.translate | ||
Form.setWindowTitle(_translate("Form", "Form")) | ||
self.log_label.setText(_translate("Form", "Log file")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<ui version="4.0"> | ||
<class>Form</class> | ||
<widget class="QWidget" name="Form"> | ||
<property name="geometry"> | ||
<rect> | ||
<x>0</x> | ||
<y>0</y> | ||
<width>400</width> | ||
<height>244</height> | ||
</rect> | ||
</property> | ||
<property name="windowTitle"> | ||
<string>Form</string> | ||
</property> | ||
<property name="styleSheet"> | ||
<string notr="true">QWidget | ||
{ | ||
background-color: rgb(211,211,211); | ||
color: rgb(88, 88, 90); | ||
selection-background-color: rgb(21, 165, 137); | ||
selection-color: rgb(245, 244, 244) | ||
} | ||
|
||
QLabel | ||
{ | ||
background-color: rgb(211,211,211); | ||
} | ||
|
||
QTextBrowser | ||
{ | ||
background-color: rgb(245, 244, 244) | ||
} | ||
</string> | ||
</property> | ||
<layout class="QVBoxLayout" name="verticalLayout"> | ||
<item> | ||
<widget class="QLabel" name="log_label"> | ||
<property name="text"> | ||
<string>Log file</string> | ||
</property> | ||
</widget> | ||
</item> | ||
<item> | ||
<widget class="QTextBrowser" name="log_browser"/> | ||
</item> | ||
</layout> | ||
</widget> | ||
<resources/> | ||
<connections/> | ||
</ui> |