Skip to content

Commit

Permalink
When processing tasks are clicked in task manager, reopen the
Browse files Browse the repository at this point in the history
algorithm dialog
  • Loading branch information
nyalldawson committed Jan 16, 2018
1 parent 7603487 commit b8defc1
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
16 changes: 13 additions & 3 deletions python/plugins/processing/gui/AlgorithmDialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,15 @@ 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))

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)
Expand Down Expand Up @@ -233,6 +235,7 @@ def accept(self):
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:'))
Expand All @@ -255,9 +258,9 @@ def on_complete(ok, results):
# 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()
Expand All @@ -277,6 +280,13 @@ def on_complete(ok, results):
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)

Expand Down
3 changes: 0 additions & 3 deletions python/plugins/processing/gui/AlgorithmLocatorFilter.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,6 @@ def triggerResult(self, result):
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()
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/gui/ProcessingToolbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def executeAlgorithm(self):
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)
Expand Down
3 changes: 0 additions & 3 deletions python/plugins/processing/tools/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit b8defc1

Please sign in to comment.