diff --git a/nw/config.py b/nw/config.py index 6e0a34b3..5138a677 100644 --- a/nw/config.py +++ b/nw/config.py @@ -54,9 +54,11 @@ class Config: # Set Application Variables self.appName = "novelWriter" self.appHandle = self.appName.lower() + self.cmdOpen = None + + # Debug Settings self.showGUI = True self.debugInfo = False - self.cmdOpen = None # Config Error Handling self.hasError = False diff --git a/nw/error.py b/nw/error.py index f5f54744..d7e191bb 100644 --- a/nw/error.py +++ b/nw/error.py @@ -138,6 +138,7 @@ class NWErrorMessage(QDialog): def exceptionHandler(exType, exValue, exTrace): """Function to catch unhandled global exceptions. """ + import nw import logging from traceback import print_tb from PyQt5.QtWidgets import qApp @@ -158,9 +159,9 @@ def exceptionHandler(exType, exValue, exTrace): return errMsg = NWErrorMessage(nwGUI) - nwGUI.activeDialog = errMsg errMsg.setMessage(exType, exValue, exTrace) - errMsg.exec_() + if nw.CONFIG.showGUI: + errMsg.exec_() try: # Try a controlled shudown diff --git a/tests/test_dialogs.py b/tests/test_dialogs.py index b41cb9cd..53e36c6b 100644 --- a/tests/test_dialogs.py +++ b/tests/test_dialogs.py @@ -17,9 +17,7 @@ from nw.gui import ( GuiDocMerge, GuiDocSplit, GuiWritingStats, GuiProjectWizard, GuiProjectLoad ) -from nw.constants import ( - nwItemType, nwItemLayout, nwItemClass -) +from nw.constants import nwItemType, nwItemLayout, nwItemClass keyDelay = 2 stepDelay = 20 diff --git a/tests/test_error.py b/tests/test_error.py index 2306d72a..4b0172a7 100644 --- a/tests/test_error.py +++ b/tests/test_error.py @@ -6,21 +6,20 @@ import nw import sys import pytest -from nwtools import getGuiItem +from PyQt5.QtWidgets import qApp -from PyQt5.QtCore import Qt, QTimer -from PyQt5.QtWidgets import qApp, QDialogButtonBox - -from nw.error import NWErrorMessage, exceptionHandler +from nw.error import NWErrorMessage @pytest.mark.error def testErrorDialog(qtbot, nwFuncTemp, nwTemp): + qApp.closeAllWindows() nwGUI = nw.main(["--testmode", "--config=%s" % nwFuncTemp, "--data=%s" % nwTemp]) qtbot.addWidget(nwGUI) nwGUI.show() qtbot.waitForWindowShown(nwGUI) nwErr = NWErrorMessage(nwGUI) + qtbot.addWidget(nwErr) nwErr.show() # Invalid Error @@ -35,23 +34,6 @@ def testErrorDialog(qtbot, nwFuncTemp, nwTemp): assert "Exception" in theMessage nwErr._doClose() nwErr.close() - del nwErr - - # Exception Handler - def handleDialog(): - while not isinstance(nwGUI.activeDialog, NWErrorMessage): - qApp.processEvents() - - nwErr = nwGUI.activeDialog - theMessage = nwErr.msgBody.toPlainText() - assert theMessage - assert "Second Error" in theMessage - assert "Exception" in theMessage - btnClose = nwErr.btnBox.button(QDialogButtonBox.Close) - qtbot.mouseClick(btnClose, Qt.LeftButton, delay=1) - - QTimer.singleShot(0, handleDialog) - exceptionHandler(Exception, "Second Error", sys.last_traceback) nwGUI.closeMain()