Skip to content
Permalink
Browse files

When processing tasks are clicked in task manager, reopen the

algorithm dialog
  • Loading branch information
nyalldawson committed Jan 9, 2018
1 parent 7603487 commit b8defc113cdd72f4d79a5571b011d02d7330175e
@@ -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)
@@ -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:'))
@@ -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()
@@ -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)

@@ -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()
@@ -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)
@@ -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.
You can’t perform that action at this time.