From 5d2acd779f66def7582a963fef5a9da8ceabf2cb Mon Sep 17 00:00:00 2001 From: rozyczko Date: Fri, 26 Mar 2021 16:36:29 +0100 Subject: [PATCH 1/5] Initial implementation of thread stopping. Stops work as expected but restarted jobs are wonky. Needs careful fixing. --- easyDiffractionApp/Logic/Fitter.py | 4 ++++ easyDiffractionApp/Logic/PyQmlProxy.py | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/easyDiffractionApp/Logic/Fitter.py b/easyDiffractionApp/Logic/Fitter.py index 63cc5df2..597d0697 100644 --- a/easyDiffractionApp/Logic/Fitter.py +++ b/easyDiffractionApp/Logic/Fitter.py @@ -26,3 +26,7 @@ def run(self): return str(ex) self.finished.emit(res) return res + + def stop(self): + self.terminate() + self.wait() # to assure proper termination diff --git a/easyDiffractionApp/Logic/PyQmlProxy.py b/easyDiffractionApp/Logic/PyQmlProxy.py index a3ec86d3..ac34ac4c 100644 --- a/easyDiffractionApp/Logic/PyQmlProxy.py +++ b/easyDiffractionApp/Logic/PyQmlProxy.py @@ -1282,6 +1282,11 @@ def _onCurrentCalculatorChanged(self): @Slot() def fit(self): + # if running, stop the thread + if not self.isFitFinished: + self.stop_fit() + self._setFitResultsFailed("Fitting stopped") + return self.isFitFinished = False exp_data = self._data.experiments[0] @@ -1295,11 +1300,15 @@ def fit(self): self._fitter_thread = ThreadedFitter(self.fitter, 'fit', *args, **kwargs) self._fitter_thread.finished.connect(self._setFitResults) self._fitter_thread.failed.connect(self._setFitResultsFailed) + self._fitter_thread.setTerminationEnabled(True) self._fitter_thread.start() # self._setFitResults(res) # self.fitFinished.emit() + def stop_fit(self): + self._fitter_thread.stop() + @Property('QVariant', notify=fitResultsChanged) def fitResults(self): return self._fit_results From d684bcdfbb4a61e3f3291c33e7e6b9e9c37d88ac Mon Sep 17 00:00:00 2001 From: rozyczko Date: Tue, 30 Mar 2021 09:28:47 +0200 Subject: [PATCH 2/5] Added confirmation/save state dialog on app exit. --- .../Gui/Components/ApplicationWindow.qml | 10 ++++ .../Gui/Components/CloseDialog.qml | 51 +++++++++++++++++++ easyDiffractionApp/Gui/Components/qmldir | 2 + easyDiffractionApp/main.py | 9 ++-- 4 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 easyDiffractionApp/Gui/Components/CloseDialog.qml diff --git a/easyDiffractionApp/Gui/Components/ApplicationWindow.qml b/easyDiffractionApp/Gui/Components/ApplicationWindow.qml index a64b69f8..81765239 100644 --- a/easyDiffractionApp/Gui/Components/ApplicationWindow.qml +++ b/easyDiffractionApp/Gui/Components/ApplicationWindow.qml @@ -9,6 +9,7 @@ import easyAppGui.Elements 1.0 as EaElements import easyAppGui.Components 1.0 as EaComponents import Gui.Globals 1.0 as ExGlobals +import Gui.Components 1.0 as ExComponents import Gui.Pages.Home 1.0 as ExHomePage import Gui.Pages.Project 1.0 as ExProjectPage import Gui.Pages.Sample 1.0 as ExSamplePage @@ -323,6 +324,11 @@ EaComponents.ApplicationWindow { } } + onClosing: { + closeDialogue.visible = ExGlobals.Constants.proxy.stateHasChanged + close.accepted = !ExGlobals.Constants.proxy.stateHasChanged + } + /////////////// // Init dialogs /////////////// @@ -335,4 +341,8 @@ EaComponents.ApplicationWindow { } } + ExComponents.CloseDialog { + id: closeDialogue + visible: false + } } diff --git a/easyDiffractionApp/Gui/Components/CloseDialog.qml b/easyDiffractionApp/Gui/Components/CloseDialog.qml new file mode 100644 index 00000000..ea8aa8dd --- /dev/null +++ b/easyDiffractionApp/Gui/Components/CloseDialog.qml @@ -0,0 +1,51 @@ +import QtQuick 2.14 +import QtQuick.Controls 2.14 + +import easyAppGui.Style 1.0 as EaStyle +import easyAppGui.Elements 1.0 as EaElements + +import Gui.Globals 1.0 as ExGlobals + +EaElements.Dialog { + id: dialog + title: "Save Changes" + parent: Overlay.overlay + + x: (parent.width - width) * 0.5 + y: (parent.height - height) * 0.5 + + modal: true + + Column { + spacing: 2 * EaStyle.Sizes.fontPixelSize + EaElements.Label { + anchors.horizontalCenter: parent.horizontalCenter + text: "The project has not been saved. Do you want to exit?" + } + + Row { + spacing: 2 * EaStyle.Sizes.fontPixelSize + anchors.horizontalCenter: parent.horizontalCenter + + EaElements.TabButton { + fontIcon: "\uf0c7" + text: "Save and exit" + onClicked: { + ExGlobals.Constants.proxy.saveProject() + Qt.quit() + dialog.close() + } + } + + EaElements.TabButton { + fontIcon: "\uf057" + text: "Exit without saving" + onClicked: { + dialog.close() + Qt.quit() + } + } + } + } +} + diff --git a/easyDiffractionApp/Gui/Components/qmldir b/easyDiffractionApp/Gui/Components/qmldir index b1dc6990..8654d990 100644 --- a/easyDiffractionApp/Gui/Components/qmldir +++ b/easyDiffractionApp/Gui/Components/qmldir @@ -13,6 +13,8 @@ ExperimentDataChartQtCharts 1.0 ExperimentDataChartQtCharts.qml AnalysisDataChartQtCharts 1.0 AnalysisDataChartQtCharts.qml AnalysisDataChartBokeh 1.0 AnalysisDataChartBokeh.qml +CloseDialog 1.0 CloseDialog.qml + # Sidebar components SamplePhasesExplorer 1.0 SamplePhasesExplorer.qml diff --git a/easyDiffractionApp/main.py b/easyDiffractionApp/main.py index 23e5eb30..c47683b9 100644 --- a/easyDiffractionApp/main.py +++ b/easyDiffractionApp/main.py @@ -88,13 +88,16 @@ def main(): # Load the root QML file engine.load(main_qml_path) - # Root application window - root_window = engine.rootObjects()[0] - # Customize app window titlebar if platform.system() == "Darwin": import ctypes, objc, Cocoa + # Root application window + root_obj = engine.rootObjects() + if not root_obj: + sys.exit(-1) + root_window = root_obj[0] + ptr = int(root_window.winId()) view = objc.objc_object(c_void_p=ctypes.c_void_p(ptr)) window = view._.window From d44bae3ef6a6d8aae210a65c40ec851cbd4ef1ce Mon Sep 17 00:00:00 2001 From: rozyczko Date: Tue, 30 Mar 2021 09:38:42 +0200 Subject: [PATCH 3/5] Remove changes belonging to unrelated branch/functionality --- easyDiffractionApp/Logic/Fitter.py | 4 ---- easyDiffractionApp/Logic/PyQmlProxy.py | 9 --------- 2 files changed, 13 deletions(-) diff --git a/easyDiffractionApp/Logic/Fitter.py b/easyDiffractionApp/Logic/Fitter.py index 597d0697..63cc5df2 100644 --- a/easyDiffractionApp/Logic/Fitter.py +++ b/easyDiffractionApp/Logic/Fitter.py @@ -26,7 +26,3 @@ def run(self): return str(ex) self.finished.emit(res) return res - - def stop(self): - self.terminate() - self.wait() # to assure proper termination diff --git a/easyDiffractionApp/Logic/PyQmlProxy.py b/easyDiffractionApp/Logic/PyQmlProxy.py index ac34ac4c..a3ec86d3 100644 --- a/easyDiffractionApp/Logic/PyQmlProxy.py +++ b/easyDiffractionApp/Logic/PyQmlProxy.py @@ -1282,11 +1282,6 @@ def _onCurrentCalculatorChanged(self): @Slot() def fit(self): - # if running, stop the thread - if not self.isFitFinished: - self.stop_fit() - self._setFitResultsFailed("Fitting stopped") - return self.isFitFinished = False exp_data = self._data.experiments[0] @@ -1300,15 +1295,11 @@ def fit(self): self._fitter_thread = ThreadedFitter(self.fitter, 'fit', *args, **kwargs) self._fitter_thread.finished.connect(self._setFitResults) self._fitter_thread.failed.connect(self._setFitResultsFailed) - self._fitter_thread.setTerminationEnabled(True) self._fitter_thread.start() # self._setFitResults(res) # self.fitFinished.emit() - def stop_fit(self): - self._fitter_thread.stop() - @Property('QVariant', notify=fitResultsChanged) def fitResults(self): return self._fit_results From fc0a71c8a443e3ea5209604c875915ef3df12289 Mon Sep 17 00:00:00 2001 From: rozyczko Date: Fri, 2 Apr 2021 12:36:04 +0200 Subject: [PATCH 4/5] Code review changes --- .../Gui/Components/ApplicationWindow.qml | 4 +- .../Gui/Components/CloseDialog.qml | 48 ++++++++----------- 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/easyDiffractionApp/Gui/Components/ApplicationWindow.qml b/easyDiffractionApp/Gui/Components/ApplicationWindow.qml index 81765239..3ffcea37 100644 --- a/easyDiffractionApp/Gui/Components/ApplicationWindow.qml +++ b/easyDiffractionApp/Gui/Components/ApplicationWindow.qml @@ -325,7 +325,7 @@ EaComponents.ApplicationWindow { } onClosing: { - closeDialogue.visible = ExGlobals.Constants.proxy.stateHasChanged + closeDialog.visible = ExGlobals.Constants.proxy.stateHasChanged close.accepted = !ExGlobals.Constants.proxy.stateHasChanged } @@ -342,7 +342,7 @@ EaComponents.ApplicationWindow { } ExComponents.CloseDialog { - id: closeDialogue + id: closeDialog visible: false } } diff --git a/easyDiffractionApp/Gui/Components/CloseDialog.qml b/easyDiffractionApp/Gui/Components/CloseDialog.qml index ea8aa8dd..a379dbde 100644 --- a/easyDiffractionApp/Gui/Components/CloseDialog.qml +++ b/easyDiffractionApp/Gui/Components/CloseDialog.qml @@ -8,42 +8,32 @@ import Gui.Globals 1.0 as ExGlobals EaElements.Dialog { id: dialog - title: "Save Changes" + title: qsTr("Save Changes") parent: Overlay.overlay x: (parent.width - width) * 0.5 y: (parent.height - height) * 0.5 - modal: true - - Column { + spacing: 2 * EaStyle.Sizes.fontPixelSize + EaElements.Label { + anchors.horizontalCenter: parent.horizontalCenter + text: qsTr("The project has not been saved. Do you want to exit?") + } + footer: EaElements.DialogButtonBox { spacing: 2 * EaStyle.Sizes.fontPixelSize - EaElements.Label { - anchors.horizontalCenter: parent.horizontalCenter - text: "The project has not been saved. Do you want to exit?" - } - - Row { - spacing: 2 * EaStyle.Sizes.fontPixelSize - anchors.horizontalCenter: parent.horizontalCenter - - EaElements.TabButton { - fontIcon: "\uf0c7" - text: "Save and exit" - onClicked: { - ExGlobals.Constants.proxy.saveProject() - Qt.quit() - dialog.close() - } + bottomPadding: EaStyle.Sizes.fontPixelSize * 1.2 + rightPadding: EaStyle.Sizes.fontPixelSize * 1.2 + EaElements.Button { + text: qsTr("Save and exit") + onClicked: { + ExGlobals.Constants.proxy.saveProject() + Qt.quit() } - - EaElements.TabButton { - fontIcon: "\uf057" - text: "Exit without saving" - onClicked: { - dialog.close() - Qt.quit() - } + } + EaElements.Button { + text: qsTr("Exit without saving") + onClicked: { + Qt.quit() } } } From 725fbe2aa35a93588208b025673db5c463bb2855 Mon Sep 17 00:00:00 2001 From: Andrew Sazonov Date: Wed, 7 Apr 2021 14:48:40 +0200 Subject: [PATCH 5/5] Refactor app dialogs --- .../Gui/Components/CloseDialog.qml | 16 +++------------- .../Gui/Components/ResultsDialog.qml | 6 ------ .../Gui/Pages/Summary/MainContentReport.qml | 6 ------ 3 files changed, 3 insertions(+), 25 deletions(-) diff --git a/easyDiffractionApp/Gui/Components/CloseDialog.qml b/easyDiffractionApp/Gui/Components/CloseDialog.qml index a379dbde..f806295d 100644 --- a/easyDiffractionApp/Gui/Components/CloseDialog.qml +++ b/easyDiffractionApp/Gui/Components/CloseDialog.qml @@ -1,28 +1,19 @@ import QtQuick 2.14 import QtQuick.Controls 2.14 -import easyAppGui.Style 1.0 as EaStyle import easyAppGui.Elements 1.0 as EaElements import Gui.Globals 1.0 as ExGlobals EaElements.Dialog { - id: dialog title: qsTr("Save Changes") - parent: Overlay.overlay - x: (parent.width - width) * 0.5 - y: (parent.height - height) * 0.5 - - spacing: 2 * EaStyle.Sizes.fontPixelSize EaElements.Label { anchors.horizontalCenter: parent.horizontalCenter text: qsTr("The project has not been saved. Do you want to exit?") } + footer: EaElements.DialogButtonBox { - spacing: 2 * EaStyle.Sizes.fontPixelSize - bottomPadding: EaStyle.Sizes.fontPixelSize * 1.2 - rightPadding: EaStyle.Sizes.fontPixelSize * 1.2 EaElements.Button { text: qsTr("Save and exit") onClicked: { @@ -30,11 +21,10 @@ EaElements.Dialog { Qt.quit() } } + EaElements.Button { text: qsTr("Exit without saving") - onClicked: { - Qt.quit() - } + onClicked: Qt.quit() } } } diff --git a/easyDiffractionApp/Gui/Components/ResultsDialog.qml b/easyDiffractionApp/Gui/Components/ResultsDialog.qml index 4a184bc5..38ef1189 100644 --- a/easyDiffractionApp/Gui/Components/ResultsDialog.qml +++ b/easyDiffractionApp/Gui/Components/ResultsDialog.qml @@ -13,12 +13,6 @@ EaElements.Dialog { title: qsTr("Refinement Results") - parent: Overlay.overlay - - x: (parent.width - width) * 0.5 - y: (parent.height - height) * 0.5 - - modal: true standardButtons: Dialog.Ok Column { diff --git a/easyDiffractionApp/Gui/Pages/Summary/MainContentReport.qml b/easyDiffractionApp/Gui/Pages/Summary/MainContentReport.qml index 96878016..0c5b9208 100644 --- a/easyDiffractionApp/Gui/Pages/Summary/MainContentReport.qml +++ b/easyDiffractionApp/Gui/Pages/Summary/MainContentReport.qml @@ -94,12 +94,6 @@ Item { visible: false title: qsTr("Save confirmation") - parent: Overlay.overlay - - x: (parent.width - width) * 0.5 - y: (parent.height - height) * 0.5 - - modal: true standardButtons: Dialog.Ok Row {