Close non-modal dialogs when project closes
This commit is contained in:
+16
-4
@@ -26,21 +26,21 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from pathlib import Path
|
||||||
from time import time
|
from time import time
|
||||||
from typing import TYPE_CHECKING, TypeVar
|
from typing import TYPE_CHECKING, TypeVar
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
from PyQt5.QtCore import QObject, QRunnable, QThreadPool, QTimer, pyqtSignal
|
from PyQt5.QtCore import QObject, QRunnable, QThreadPool, QTimer, pyqtSignal
|
||||||
from PyQt5.QtWidgets import QFileDialog, QMessageBox, QWidget
|
from PyQt5.QtWidgets import QFileDialog, QMessageBox, QWidget
|
||||||
from novelwriter.common import formatFileFilter
|
|
||||||
|
|
||||||
|
from novelwriter.common import formatFileFilter
|
||||||
from novelwriter.constants import nwFiles
|
from novelwriter.constants import nwFiles
|
||||||
from novelwriter.core.spellcheck import NWSpellEnchant
|
from novelwriter.core.spellcheck import NWSpellEnchant
|
||||||
|
|
||||||
if TYPE_CHECKING: # pragma: no cover
|
if TYPE_CHECKING: # pragma: no cover
|
||||||
from novelwriter.guimain import GuiMain
|
|
||||||
from novelwriter.gui.theme import GuiTheme
|
|
||||||
from novelwriter.core.project import NWProject
|
from novelwriter.core.project import NWProject
|
||||||
|
from novelwriter.gui.theme import GuiTheme
|
||||||
|
from novelwriter.guimain import GuiMain
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@@ -198,6 +198,7 @@ class SharedData(QObject):
|
|||||||
|
|
||||||
def closeProject(self) -> None:
|
def closeProject(self) -> None:
|
||||||
"""Close the current project."""
|
"""Close the current project."""
|
||||||
|
self._closeDialogs()
|
||||||
self.project.closeProject(self._idleTime)
|
self.project.closeProject(self._idleTime)
|
||||||
self._resetProject()
|
self._resetProject()
|
||||||
self._resetIdleTimer()
|
self._resetIdleTimer()
|
||||||
@@ -356,6 +357,17 @@ class SharedData(QObject):
|
|||||||
self._idleTime = 0.0
|
self._idleTime = 0.0
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def _closeDialogs(self) -> None:
|
||||||
|
"""Close non-modal dialogs."""
|
||||||
|
from novelwriter.tools.manuscript import GuiManuscript
|
||||||
|
from novelwriter.tools.writingstats import GuiWritingStats
|
||||||
|
|
||||||
|
for widget in self.mainGui.children():
|
||||||
|
if isinstance(widget, (GuiManuscript, GuiWritingStats)):
|
||||||
|
widget.close()
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
# END Class SharedData
|
# END Class SharedData
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -20,18 +20,18 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
"""
|
"""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import pytest
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from pytestqt.qtbot import QtBot
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
from mocked import causeOSError
|
from mocked import causeOSError
|
||||||
from tools import C, buildTestProject
|
|
||||||
|
|
||||||
from PyQt5.QtCore import pyqtSlot
|
from PyQt5.QtCore import pyqtSlot
|
||||||
from PyQt5.QtPrintSupport import QPrintPreviewDialog
|
from PyQt5.QtPrintSupport import QPrintPreviewDialog
|
||||||
from PyQt5.QtWidgets import QAction, QListWidgetItem
|
from PyQt5.QtWidgets import QAction, QListWidgetItem
|
||||||
|
from pytestqt.qtbot import QtBot
|
||||||
|
from tools import C, buildTestProject
|
||||||
|
|
||||||
from novelwriter import CONFIG, SHARED
|
from novelwriter import CONFIG, SHARED
|
||||||
from novelwriter.constants import nwHeadFmt
|
from novelwriter.constants import nwHeadFmt
|
||||||
@@ -81,7 +81,9 @@ def testManuscript_Init(monkeypatch, qtbot: QtBot, nwGUI: GuiMain, projPath: Pat
|
|||||||
manus.show()
|
manus.show()
|
||||||
manus.loadContent()
|
manus.loadContent()
|
||||||
assert manus.docPreview.toPlainText().strip() == ""
|
assert manus.docPreview.toPlainText().strip() == ""
|
||||||
manus.close()
|
|
||||||
|
nwGUI.closeProject() # This should auto-close the manuscript tool
|
||||||
|
assert manus.isHidden()
|
||||||
|
|
||||||
# qtbot.stop()
|
# qtbot.stop()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user