From 9dd956bc92715f40db83e2a23e8e958fcebb1c35 Mon Sep 17 00:00:00 2001 From: "Veronica K. B. Olsen" Date: Sat, 25 May 2019 19:59:43 +0200 Subject: [PATCH] Added exit yes/no dialog --- nw/gui/mainmenu.py | 5 ++--- nw/gui/winmain.py | 20 ++++++++++++++++---- tests/test_gui.py | 3 +++ 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/nw/gui/mainmenu.py b/nw/gui/mainmenu.py index c30b6b79..91f7651f 100644 --- a/nw/gui/mainmenu.py +++ b/nw/gui/mainmenu.py @@ -13,7 +13,7 @@ import logging import nw -from PyQt5.QtWidgets import qApp, QMenuBar, QAction, QMessageBox +from PyQt5.QtWidgets import QMenuBar, QAction, QMessageBox from PyQt5.QtGui import QIcon from nw.enum import nwItemType, nwItemClass, nwDocAction @@ -91,8 +91,7 @@ class GuiMainMenu(QMenuBar): def _menuExit(self): self.theParent.closeMain() - qApp.quit() - return True + return def _toggleSpellCheck(self): self.theProject.setSpellCheck(self.toolsSpellCheck.isChecked()) diff --git a/nw/gui/winmain.py b/nw/gui/winmain.py index bfe86601..4fa127af 100644 --- a/nw/gui/winmain.py +++ b/nw/gui/winmain.py @@ -14,7 +14,7 @@ import logging import nw from os import path -from PyQt5.QtWidgets import QWidget, QMainWindow, QVBoxLayout, QFrame, QSplitter, QFileDialog, QStackedWidget, QShortcut, QMessageBox +from PyQt5.QtWidgets import qApp, QWidget, QMainWindow, QVBoxLayout, QFrame, QSplitter, QFileDialog, QStackedWidget, QShortcut, QMessageBox from PyQt5.QtGui import QIcon, QPixmap, QColor from PyQt5.QtCore import Qt, QTimer @@ -428,7 +428,17 @@ class GuiMain(QMainWindow): # Main Window Actions ## - def closeMain(self): + def closeMain(self, isYes=False): + + if not isYes: + msgBox = QMessageBox() + msgRes = msgBox.question( + self, "Exit", + "Do you want to exit %s?" % nw.__package__ + ) + if msgRes != QMessageBox.Yes: + return False + logger.info("Exiting %s" % nw.__package__) if self._takeDocumentAction(): self.saveDocument() @@ -439,7 +449,10 @@ class GuiMain(QMainWindow): self.mainConf.setMainPanePos(self.splitMain.sizes()) self.mainConf.setDocPanePos(self.splitView.sizes()) self.mainConf.saveConfig() - return + + qApp.quit() + + return True def setFocus(self, paneNo): if paneNo == 1: @@ -526,7 +539,6 @@ class GuiMain(QMainWindow): def closeEvent(self, theEvent): self.closeMain() - QMainWindow.closeEvent(self,theEvent) return ## diff --git a/tests/test_gui.py b/tests/test_gui.py index d3c6d431..94ce7eb4 100644 --- a/tests/test_gui.py +++ b/tests/test_gui.py @@ -155,6 +155,7 @@ def testMainWindows(qtbot, nwTempGUI, nwRef): sceneFile = path.join(nwTempGUI,"data_3","1489056e0916_main.nwd") assert cmpFiles(sceneFile, path.join(nwRef,"gui","1_1489056e0916_main.nwd")) + nwGUI.closeMain(True) # qtbot.stopForInteraction() @pytest.mark.gui @@ -216,6 +217,7 @@ def testProjectEditor(qtbot, nwTempGUI, nwRef): projFile = path.join(nwTempGUI,"nwProject.nwx") assert cmpFiles(projFile, path.join(nwRef,"gui","2_nwProject.nwx"), [2]) + nwGUI.closeMain(True) # qtbot.stopForInteraction() @pytest.mark.gui @@ -261,4 +263,5 @@ def testItemEditor(qtbot, nwTempGUI, nwRef): projFile = path.join(nwTempGUI,"nwProject.nwx") assert cmpFiles(projFile, path.join(nwRef,"gui","3_nwProject.nwx"), [2]) + nwGUI.closeMain(True) # qtbot.stopForInteraction()