dcs_liberation/qt_ui/windows/logs/QLogsWindow.py
Dan Albert 2a75d14e0e Revert upgrade to pyside6.
This appears to be incompatible with pyinstaller. I get the following
when trying to run the executable generated with pyside6:

```
Traceback (most recent call last):
  File "qt_ui\main.py", line 29, in <module>
  File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
  File "qt_ui\windows\QLiberationWindow.py", line 28, in <module>
  File "PyInstaller\loader\pyimod03_importers.py", line 476, in exec_module
  File "qt_ui\widgets\map\QLiberationMap.py", line 11, in <module>
ImportError: could not import module 'PySide6.QtPrintSupport'
```
2021-11-21 17:39:43 -08:00

77 lines
2.5 KiB
Python

import logging
import typing
from PySide2.QtCore import Signal
from PySide2.QtWidgets import (
QDialog,
QPlainTextEdit,
QVBoxLayout,
QPushButton,
)
from PySide2.QtGui import QTextCursor, QIcon
from qt_ui.logging_handler import HookableInMemoryHandler
class QLogsWindow(QDialog):
appendLogSignal = Signal(str)
vbox: QVBoxLayout
textbox: QPlainTextEdit
clear_button: QPushButton
_logging_handler: typing.Optional[HookableInMemoryHandler]
def __init__(self):
super().__init__()
self.setWindowTitle("Logs")
self.setMinimumSize(400, 100)
self.resize(1000, 450)
self.setWindowIcon(QIcon("./resources/icon.png"))
self.vbox = QVBoxLayout()
self.setLayout(self.vbox)
self.textbox = QPlainTextEdit(self)
self.textbox.setReadOnly(True)
self.textbox.setLineWrapMode(QPlainTextEdit.LineWrapMode.NoWrap)
self.textbox.move(10, 10)
self.textbox.resize(1000, 450)
self.textbox.setStyleSheet(
"font-family: 'Courier New', monospace; background: #1D2731;"
)
self.vbox.addWidget(self.textbox)
self.clear_button = QPushButton(self)
self.clear_button.setText("CLEAR")
self.clear_button.setProperty("style", "btn-primary")
self.clear_button.clicked.connect(self.clearLogs)
self.vbox.addWidget(self.clear_button)
self.appendLogSignal.connect(self.appendLog)
self._logging_handler = None
logger = logging.getLogger()
for handler in logger.handlers:
if isinstance(handler, HookableInMemoryHandler):
self._logging_handler = handler
break
if self._logging_handler is not None:
self.textbox.setPlainText(self._logging_handler.log)
self.textbox.moveCursor(QTextCursor.End)
# The Handler might be called from a different thread,
# so use signal/slot to properly handle the event in the main thread.
# https://github.com/dcs-liberation/dcs_liberation/issues/1493
self._logging_handler.setHook(self.appendLogSignal.emit)
else:
self.textbox.setPlainText("WARNING: logging not initialized!")
def clearLogs(self) -> None:
if self._logging_handler is not None:
self._logging_handler.clearLog()
self.textbox.setPlainText("")
def appendLog(self, msg: str):
self.textbox.appendPlainText(msg)
self.textbox.moveCursor(QTextCursor.End)