Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Only use a temporary feedback object when running algorithms
Otherwise canceling a run causes all future runs to be canceled
  • Loading branch information
nyalldawson committed Jun 11, 2017
1 parent 2d2c229 commit aa544a1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
14 changes: 8 additions & 6 deletions python/plugins/processing/gui/AlgorithmDialog.py
Expand Up @@ -164,6 +164,8 @@ def accept(self):

checkCRS = ProcessingConfig.getSetting(ProcessingConfig.WARN_UNMATCHING_CRS)
try:
feedback = self.createFeedback()

parameters = self.getParamValues()

QgsMessageLog.logMessage(str(parameters), 'Processing', QgsMessageLog.CRITICAL)
Expand Down Expand Up @@ -220,8 +222,8 @@ def accept(self):
self.tr('<b>Algorithm {0} starting...</b>').format(self.alg.displayName()))

if self.iterateParam:
if executeIterating(self.alg, parameters, self.iterateParam, context, self.feedback):
self.finish(parameters, context)
if executeIterating(self.alg, parameters, self.iterateParam, context, feedback):
self.finish(parameters, context, feedback)
else:
QApplication.restoreOverrideCursor()
self.resetGUI()
Expand All @@ -231,9 +233,9 @@ def accept(self):
#if command:
# ProcessingLog.addToLog(command)
self.buttonCancel.setEnabled(self.alg.flags() & QgsProcessingAlgorithm.FlagCanCancel)
result = executeAlgorithm(self.alg, parameters, context, self.feedback)
result = executeAlgorithm(self.alg, parameters, context, feedback)
self.buttonCancel.setEnabled(False)
self.finish(result, context)
self.finish(result, context, feedback)
#TODO
#else:
# QApplication.restoreOverrideCursor()
Expand All @@ -251,12 +253,12 @@ def accept(self):
self.bar.pushMessage("", self.tr("Wrong or missing parameter value: {0}").format(e.parameter.description()),
level=QgsMessageBar.WARNING, duration=5)

def finish(self, result, context):
def finish(self, result, context, feedback):
keepOpen = ProcessingConfig.getSetting(ProcessingConfig.KEEP_DIALOG_OPEN)

if self.iterateParam is None:

if not handleAlgorithmResults(self.alg, context, self.feedback, not keepOpen):
if not handleAlgorithmResults(self.alg, context, feedback, not keepOpen):
self.resetGUI()
return

Expand Down
12 changes: 7 additions & 5 deletions python/plugins/processing/gui/AlgorithmDialogBase.py
Expand Up @@ -95,10 +95,6 @@ def __init__(self, alg):
handleLayout.addStretch()
splitterHandle.setLayout(handleLayout)

self.feedback = AlgorithmDialogFeedback(self)
self.feedback.progressChanged.connect(self.setPercentage)
self.buttonCancel.clicked.connect(self.feedback.cancel)

self.settings = QgsSettings()
self.splitter.restoreState(self.settings.value("/Processing/dialogBaseSplitter", QByteArray()))
self.restoreGeometry(self.settings.value("/Processing/dialogBase", QByteArray()))
Expand Down Expand Up @@ -147,6 +143,12 @@ def linkClicked(url):
self.showDebug = ProcessingConfig.getSetting(
ProcessingConfig.SHOW_DEBUG_IN_DIALOG)

def createFeedback(self):
feedback = AlgorithmDialogFeedback(self)
feedback.progressChanged.connect(self.setPercentage)
self.buttonCancel.clicked.connect(feedback.cancel)
return feedback

def formatHelp(self, alg):
text = alg.shortHelpString()
if not text:
Expand Down Expand Up @@ -223,7 +225,7 @@ def reject(self):
self._saveGeometry()
super(AlgorithmDialogBase, self).reject()

def finish(self, context):
def finish(self, context, feedback):
pass

def toggleCollapsed(self):
Expand Down
1 change: 0 additions & 1 deletion python/plugins/processing/gui/Postprocessing.py
Expand Up @@ -56,7 +56,6 @@ def handleAlgorithmResults(alg, context, feedback=None, showResults=True):
feedback.setProgressText(QCoreApplication.translate('Postprocessing', 'Loading resulting layers'))
i = 0
for l, details in context.layersToLoadOnCompletion().items():
feedback.setProgress(100 * i / float(len(context.layersToLoadOnCompletion())))
try:
layer = QgsProcessingUtils.mapLayerFromString(l, context)
if layer is not None:
Expand Down

0 comments on commit aa544a1

Please sign in to comment.