diff --git a/novelwriter/tools/manuscript.py b/novelwriter/tools/manuscript.py index 59abadbd..fe4c6693 100644 --- a/novelwriter/tools/manuscript.py +++ b/novelwriter/tools/manuscript.py @@ -56,7 +56,7 @@ class GuiManuscript(QDialog): def __init__(self, mainGui: GuiMain): super().__init__(parent=mainGui) - logger.debug("Initialising GuiManuscript ...") + logger.debug("Created: GuiManuscript") self.setObjectName("GuiManuscript") self.mainGui = mainGui @@ -161,10 +161,14 @@ class GuiManuscript(QDialog): self.setLayout(self.outerBox) self.setSizeGripEnabled(True) - logger.debug("GuiManuscript initialisation complete") + logger.debug("Ready: GuiManuscript") return + def __del__(self): + logger.debug("Deleted: GuiManuscript") + return + def loadContent(self): """Load dialog content from project data. """ @@ -179,8 +183,13 @@ class GuiManuscript(QDialog): def closeEvent(self, event): """Capture the user closing the window so we can save settings. """ - self._beforeClose() + self._saveSettings() + for obj in self.children(): + # Make sure we don't have any settings windows open + if isinstance(obj, GuiBuildSettings) and obj.isVisible(): + obj.close() event.accept() + self.deleteLater() return ## @@ -216,7 +225,8 @@ class GuiManuscript(QDialog): @pyqtSlot() def _generatePreview(self): - """ + """Run the document builder on the current build settings for + the preview widget. """ build = self._getSelectedBuild() if build is None: @@ -255,7 +265,6 @@ class GuiManuscript(QDialog): def _doClose(self): """The close button has been clicked. """ - self._beforeClose() self.close() return @@ -278,15 +287,6 @@ class GuiManuscript(QDialog): """ return - def _beforeClose(self): - """List of things to do before closing. - """ - self._saveSettings() - for qWidget in qApp.topLevelWidgets(): - if qWidget.objectName() == "GuiBuildSettings": - qWidget.close() - return - def _saveSettings(self): """Save the various user settings. """ @@ -309,16 +309,15 @@ class GuiManuscript(QDialog): return def _openSettingsDialog(self, build: BuildSettings): - """Open a new build settings dialog. + """Open the build settings dialog. """ - dlgSettings = GuiBuildSettings(self.mainGui, build) + dlgSettings = GuiBuildSettings(self, self.mainGui, build) dlgSettings.setModal(False) dlgSettings.show() dlgSettings.raise_() qApp.processEvents() dlgSettings.loadContent() dlgSettings.newSettingsReady.connect(self._processNewSettings) - return def _updateBuildsList(self): diff --git a/novelwriter/tools/manussettings.py b/novelwriter/tools/manussettings.py index c638edc9..c68eae80 100644 --- a/novelwriter/tools/manussettings.py +++ b/novelwriter/tools/manussettings.py @@ -65,10 +65,10 @@ class GuiBuildSettings(QDialog): newSettingsReady = pyqtSignal(BuildSettings) - def __init__(self, mainGui: GuiMain, build: BuildSettings): - super().__init__(parent=mainGui) + def __init__(self, parent: QWidget, mainGui: GuiMain, build: BuildSettings): + super().__init__(parent=parent) - logger.debug("Initialising GuiBuildSettings ...") + logger.debug("Created: GuiBuildSettings") self.setObjectName("GuiBuildSettings") self.mainGui = mainGui @@ -159,10 +159,13 @@ class GuiBuildSettings(QDialog): # Set Default Tab self.optSideBar.setSelected(self.OPT_FILTERS) - logger.debug("GuiBuildSettings initialisation complete") + logger.debug("Ready: GuiBuildSettings") return + def __del__(self): + logger.debug("Deleted: GuiBuildSettings") + def loadContent(self): """Populate the child widgets. """ @@ -199,21 +202,13 @@ class GuiBuildSettings(QDialog): """Handle button clicks from the dialog button box. """ role = self.dlgButtons.buttonRole(button) - if role in (QDialogButtonBox.ApplyRole, QDialogButtonBox.AcceptRole): - self._build.setName(self.editBuildName.text()) - self.optTabHeadings.saveContent() - self.optTabContent.saveContent() - self.optTabFormat.saveContent() - self.optTabOutput.saveContent() - self.newSettingsReady.emit(self._build) - - self._saveSettings() - if role == QDialogButtonBox.AcceptRole: - self.accept() + if role == QDialogButtonBox.ApplyRole: + self._emitBuildData() + elif role == QDialogButtonBox.AcceptRole: + self._emitBuildData() + self.close() elif role == QDialogButtonBox.RejectRole: - if self._checkOkClose(): - self.reject() - + self.close() return ## @@ -223,25 +218,30 @@ class GuiBuildSettings(QDialog): def closeEvent(self, event: QEvent): """Capture the user closing the window so we can save settings. """ - if self._checkOkClose(): - self._saveSettings() - event.accept() + logger.debug("Closing: GuiBuildSettings") + self._askToSaveBuild() + self._saveSettings() + event.accept() + self.deleteLater() return ## # Internal Functions ## - def _checkOkClose(self) -> bool: + def _askToSaveBuild(self): """Check if there are unsaved changes, and if there are, ask if - it';'s ok to reject them. + it's ok to reject them. """ if self._build.changed: - return self.mainGui.askQuestion( + doSave = self.mainGui.askQuestion( self.tr("Build Settings"), - self.tr("There are unsaved changes. Close anyway?") + self.tr("Do you want to save your changes?") ) - return True + if doSave: + self._emitBuildData() + self._build.resetChangedState() + return def _saveSettings(self): """Save the various user settings. @@ -262,6 +262,18 @@ class GuiBuildSettings(QDialog): return + def _emitBuildData(self): + """Assemble the build data and emit the signal. + """ + self._build.setName(self.editBuildName.text()) + self.optTabHeadings.saveContent() + self.optTabContent.saveContent() + self.optTabFormat.saveContent() + self.optTabOutput.saveContent() + self.newSettingsReady.emit(self._build) + self._build.resetChangedState() + return + # END Class GuiBuildSettings