Improve how manuscript dialog closing is handled
This commit is contained in:
@@ -56,7 +56,7 @@ class GuiManuscript(QDialog):
|
|||||||
def __init__(self, mainGui: GuiMain):
|
def __init__(self, mainGui: GuiMain):
|
||||||
super().__init__(parent=mainGui)
|
super().__init__(parent=mainGui)
|
||||||
|
|
||||||
logger.debug("Initialising GuiManuscript ...")
|
logger.debug("Created: GuiManuscript")
|
||||||
self.setObjectName("GuiManuscript")
|
self.setObjectName("GuiManuscript")
|
||||||
|
|
||||||
self.mainGui = mainGui
|
self.mainGui = mainGui
|
||||||
@@ -161,10 +161,14 @@ class GuiManuscript(QDialog):
|
|||||||
self.setLayout(self.outerBox)
|
self.setLayout(self.outerBox)
|
||||||
self.setSizeGripEnabled(True)
|
self.setSizeGripEnabled(True)
|
||||||
|
|
||||||
logger.debug("GuiManuscript initialisation complete")
|
logger.debug("Ready: GuiManuscript")
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
logger.debug("Deleted: GuiManuscript")
|
||||||
|
return
|
||||||
|
|
||||||
def loadContent(self):
|
def loadContent(self):
|
||||||
"""Load dialog content from project data.
|
"""Load dialog content from project data.
|
||||||
"""
|
"""
|
||||||
@@ -179,8 +183,13 @@ class GuiManuscript(QDialog):
|
|||||||
def closeEvent(self, event):
|
def closeEvent(self, event):
|
||||||
"""Capture the user closing the window so we can save settings.
|
"""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()
|
event.accept()
|
||||||
|
self.deleteLater()
|
||||||
return
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
@@ -216,7 +225,8 @@ class GuiManuscript(QDialog):
|
|||||||
|
|
||||||
@pyqtSlot()
|
@pyqtSlot()
|
||||||
def _generatePreview(self):
|
def _generatePreview(self):
|
||||||
"""
|
"""Run the document builder on the current build settings for
|
||||||
|
the preview widget.
|
||||||
"""
|
"""
|
||||||
build = self._getSelectedBuild()
|
build = self._getSelectedBuild()
|
||||||
if build is None:
|
if build is None:
|
||||||
@@ -255,7 +265,6 @@ class GuiManuscript(QDialog):
|
|||||||
def _doClose(self):
|
def _doClose(self):
|
||||||
"""The close button has been clicked.
|
"""The close button has been clicked.
|
||||||
"""
|
"""
|
||||||
self._beforeClose()
|
|
||||||
self.close()
|
self.close()
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -278,15 +287,6 @@ class GuiManuscript(QDialog):
|
|||||||
"""
|
"""
|
||||||
return
|
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):
|
def _saveSettings(self):
|
||||||
"""Save the various user settings.
|
"""Save the various user settings.
|
||||||
"""
|
"""
|
||||||
@@ -309,16 +309,15 @@ class GuiManuscript(QDialog):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def _openSettingsDialog(self, build: BuildSettings):
|
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.setModal(False)
|
||||||
dlgSettings.show()
|
dlgSettings.show()
|
||||||
dlgSettings.raise_()
|
dlgSettings.raise_()
|
||||||
qApp.processEvents()
|
qApp.processEvents()
|
||||||
dlgSettings.loadContent()
|
dlgSettings.loadContent()
|
||||||
dlgSettings.newSettingsReady.connect(self._processNewSettings)
|
dlgSettings.newSettingsReady.connect(self._processNewSettings)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def _updateBuildsList(self):
|
def _updateBuildsList(self):
|
||||||
|
|||||||
@@ -65,10 +65,10 @@ class GuiBuildSettings(QDialog):
|
|||||||
|
|
||||||
newSettingsReady = pyqtSignal(BuildSettings)
|
newSettingsReady = pyqtSignal(BuildSettings)
|
||||||
|
|
||||||
def __init__(self, mainGui: GuiMain, build: BuildSettings):
|
def __init__(self, parent: QWidget, mainGui: GuiMain, build: BuildSettings):
|
||||||
super().__init__(parent=mainGui)
|
super().__init__(parent=parent)
|
||||||
|
|
||||||
logger.debug("Initialising GuiBuildSettings ...")
|
logger.debug("Created: GuiBuildSettings")
|
||||||
self.setObjectName("GuiBuildSettings")
|
self.setObjectName("GuiBuildSettings")
|
||||||
|
|
||||||
self.mainGui = mainGui
|
self.mainGui = mainGui
|
||||||
@@ -159,10 +159,13 @@ class GuiBuildSettings(QDialog):
|
|||||||
# Set Default Tab
|
# Set Default Tab
|
||||||
self.optSideBar.setSelected(self.OPT_FILTERS)
|
self.optSideBar.setSelected(self.OPT_FILTERS)
|
||||||
|
|
||||||
logger.debug("GuiBuildSettings initialisation complete")
|
logger.debug("Ready: GuiBuildSettings")
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def __del__(self):
|
||||||
|
logger.debug("Deleted: GuiBuildSettings")
|
||||||
|
|
||||||
def loadContent(self):
|
def loadContent(self):
|
||||||
"""Populate the child widgets.
|
"""Populate the child widgets.
|
||||||
"""
|
"""
|
||||||
@@ -199,21 +202,13 @@ class GuiBuildSettings(QDialog):
|
|||||||
"""Handle button clicks from the dialog button box.
|
"""Handle button clicks from the dialog button box.
|
||||||
"""
|
"""
|
||||||
role = self.dlgButtons.buttonRole(button)
|
role = self.dlgButtons.buttonRole(button)
|
||||||
if role in (QDialogButtonBox.ApplyRole, QDialogButtonBox.AcceptRole):
|
if role == QDialogButtonBox.ApplyRole:
|
||||||
self._build.setName(self.editBuildName.text())
|
self._emitBuildData()
|
||||||
self.optTabHeadings.saveContent()
|
elif role == QDialogButtonBox.AcceptRole:
|
||||||
self.optTabContent.saveContent()
|
self._emitBuildData()
|
||||||
self.optTabFormat.saveContent()
|
self.close()
|
||||||
self.optTabOutput.saveContent()
|
|
||||||
self.newSettingsReady.emit(self._build)
|
|
||||||
|
|
||||||
self._saveSettings()
|
|
||||||
if role == QDialogButtonBox.AcceptRole:
|
|
||||||
self.accept()
|
|
||||||
elif role == QDialogButtonBox.RejectRole:
|
elif role == QDialogButtonBox.RejectRole:
|
||||||
if self._checkOkClose():
|
self.close()
|
||||||
self.reject()
|
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
@@ -223,25 +218,30 @@ class GuiBuildSettings(QDialog):
|
|||||||
def closeEvent(self, event: QEvent):
|
def closeEvent(self, event: QEvent):
|
||||||
"""Capture the user closing the window so we can save settings.
|
"""Capture the user closing the window so we can save settings.
|
||||||
"""
|
"""
|
||||||
if self._checkOkClose():
|
logger.debug("Closing: GuiBuildSettings")
|
||||||
self._saveSettings()
|
self._askToSaveBuild()
|
||||||
event.accept()
|
self._saveSettings()
|
||||||
|
event.accept()
|
||||||
|
self.deleteLater()
|
||||||
return
|
return
|
||||||
|
|
||||||
##
|
##
|
||||||
# Internal Functions
|
# Internal Functions
|
||||||
##
|
##
|
||||||
|
|
||||||
def _checkOkClose(self) -> bool:
|
def _askToSaveBuild(self):
|
||||||
"""Check if there are unsaved changes, and if there are, ask if
|
"""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:
|
if self._build.changed:
|
||||||
return self.mainGui.askQuestion(
|
doSave = self.mainGui.askQuestion(
|
||||||
self.tr("Build Settings"),
|
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):
|
def _saveSettings(self):
|
||||||
"""Save the various user settings.
|
"""Save the various user settings.
|
||||||
@@ -262,6 +262,18 @@ class GuiBuildSettings(QDialog):
|
|||||||
|
|
||||||
return
|
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
|
# END Class GuiBuildSettings
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user