From b8defc113cdd72f4d79a5571b011d02d7330175e Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 9 Jan 2018 14:43:51 +1000 Subject: [PATCH] When processing tasks are clicked in task manager, reopen the algorithm dialog --- python/plugins/processing/gui/AlgorithmDialog.py | 16 +++++++++++++--- .../processing/gui/AlgorithmLocatorFilter.py | 3 --- .../plugins/processing/gui/ProcessingToolbox.py | 2 +- python/plugins/processing/tools/general.py | 3 --- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/python/plugins/processing/gui/AlgorithmDialog.py b/python/plugins/processing/gui/AlgorithmDialog.py index 54bfea91ed5..68fb07008b5 100644 --- a/python/plugins/processing/gui/AlgorithmDialog.py +++ b/python/plugins/processing/gui/AlgorithmDialog.py @@ -64,6 +64,7 @@ class AlgorithmDialog(QgsProcessingAlgorithmDialogBase): def __init__(self, alg): super().__init__() self.feedback_dialog = None + self.task = None self.setAlgorithm(alg) self.setMainWidget(self.getParametersPanel(alg, self)) @@ -71,6 +72,7 @@ class AlgorithmDialog(QgsProcessingAlgorithmDialogBase): self.runAsBatchButton = QPushButton(QCoreApplication.translate("AlgorithmDialog", "Run as Batch Process…")) self.runAsBatchButton.clicked.connect(self.runAsBatch) self.buttonBox().addButton(self.runAsBatchButton, QDialogButtonBox.ResetRole) # reset role to ensure left alignment + QgsApplication.taskManager().triggered.connect(self.taskTriggered) def getParametersPanel(self, alg, parent): return ParametersPanel(parent, alg) @@ -233,6 +235,7 @@ class AlgorithmDialog(QgsProcessingAlgorithmDialogBase): self.cancelButton().setEnabled(self.algorithm().flags() & QgsProcessingAlgorithm.FlagCanCancel) def on_complete(ok, results): + self.task = None if ok: feedback.pushInfo(self.tr('Execution completed in {0:0.2f} seconds'.format(time.time() - start_time))) feedback.pushInfo(self.tr('Results:')) @@ -255,9 +258,9 @@ class AlgorithmDialog(QgsProcessingAlgorithmDialogBase): # Make sure the Log tab is visible before executing the algorithm self.showLog() - task = QgsProcessingAlgRunnerTask(self.algorithm(), parameters, context, feedback) - task.executed.connect(on_complete) - QgsApplication.taskManager().addTask(task) + self.task = QgsProcessingAlgRunnerTask(self.algorithm(), parameters, context, feedback) + self.task.executed.connect(on_complete) + QgsApplication.taskManager().addTask(self.task) else: self.feedback_dialog = self.createProgressDialog() self.feedback_dialog.show() @@ -277,6 +280,13 @@ class AlgorithmDialog(QgsProcessingAlgorithmDialogBase): self.messageBar().pushMessage("", self.tr("Wrong or missing parameter value: {0}").format(e.parameter.description()), level=QgsMessageBar.WARNING, duration=5) + def taskTriggered(self, task): + if task == self.task: + self.show() + self.raise_() + self.setWindowState(self.windowState() & ~Qt.WindowMinimized | Qt.WindowActive) + self.activateWindow() + def finish(self, successful, result, context, feedback): keepOpen = not successful or ProcessingConfig.getSetting(ProcessingConfig.KEEP_DIALOG_OPEN) diff --git a/python/plugins/processing/gui/AlgorithmLocatorFilter.py b/python/plugins/processing/gui/AlgorithmLocatorFilter.py index 01ce8c972d0..a474f2b7082 100644 --- a/python/plugins/processing/gui/AlgorithmLocatorFilter.py +++ b/python/plugins/processing/gui/AlgorithmLocatorFilter.py @@ -88,9 +88,6 @@ class AlgorithmLocatorFilter(QgsLocatorFilter): prevMapTool = canvas.mapTool() dlg.show() dlg.exec_() - # have to manually delete the dialog - otherwise it's owned by the - # iface mainWindow and never deleted - dlg.deleteLater() if canvas.mapTool() != prevMapTool: try: canvas.mapTool().reset() diff --git a/python/plugins/processing/gui/ProcessingToolbox.py b/python/plugins/processing/gui/ProcessingToolbox.py index 5f21cb54355..46788626c0f 100755 --- a/python/plugins/processing/gui/ProcessingToolbox.py +++ b/python/plugins/processing/gui/ProcessingToolbox.py @@ -300,7 +300,7 @@ class ProcessingToolbox(BASE, WIDGET): self.addRecentAlgorithms(True) # have to manually delete the dialog - otherwise it's owned by the # iface mainWindow and never deleted - dlg.deleteLater() + # dlg.deleteLater() else: feedback = MessageBarProgress() context = dataobjects.createContext(feedback) diff --git a/python/plugins/processing/tools/general.py b/python/plugins/processing/tools/general.py index 366ccadd230..699c2981fa7 100644 --- a/python/plugins/processing/tools/general.py +++ b/python/plugins/processing/tools/general.py @@ -154,7 +154,4 @@ def execAlgorithmDialog(algOrName, parameters={}): canvas.setMapTool(prevMapTool) results = dlg.results() - # have to manually delete the dialog - otherwise it's owned by the - # iface mainWindow and never deleted - dlg.deleteLater() return results