Fix crash if log window is open when entering mission.

Use signal to append text to LogWindow to avoid crash from crossing thread boundaries.
Change modal flag to enable interacting with LogWindow while the mission is running

Fixes https://github.com/dcs-liberation/dcs_liberation/issues/1493
This commit is contained in:
Johan Aberg
2021-10-20 13:04:16 +13:00
committed by GitHub
parent 551ea728fc
commit 17011820de
4 changed files with 26 additions and 9 deletions

View File

@@ -1,18 +1,21 @@
import logging
import typing
from PySide2.QtCore import Signal
from PySide2.QtWidgets import (
QDialog,
QPlainTextEdit,
QVBoxLayout,
QPushButton,
)
from PySide2.QtGui import QTextCursor
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
@@ -24,6 +27,7 @@ class QLogsWindow(QDialog):
self.setWindowTitle("Logs")
self.setMinimumSize(400, 100)
self.resize(1000, 450)
self.setWindowIcon(QIcon("./resources/icon.png"))
self.vbox = QVBoxLayout()
self.setLayout(self.vbox)
@@ -44,6 +48,8 @@ class QLogsWindow(QDialog):
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:
@@ -53,7 +59,10 @@ class QLogsWindow(QDialog):
if self._logging_handler is not None:
self.textbox.setPlainText(self._logging_handler.log)
self.textbox.moveCursor(QTextCursor.End)
self._logging_handler.setHook(self.appendLog)
# 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!")