2014-11-12 11:42:29 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
"""
|
|
|
|
***************************************************************************
|
|
|
|
AlgorithmDialog.py
|
|
|
|
---------------------
|
|
|
|
Date : August 2012
|
|
|
|
Copyright : (C) 2012 by Victor Olaya
|
|
|
|
Email : volayaf at gmail dot com
|
|
|
|
***************************************************************************
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
***************************************************************************
|
|
|
|
"""
|
|
|
|
|
|
|
|
__author__ = 'Victor Olaya'
|
|
|
|
__date__ = 'August 2012'
|
|
|
|
__copyright__ = '(C) 2012, Victor Olaya'
|
|
|
|
|
2019-02-22 20:24:56 +01:00
|
|
|
import os
|
2017-06-11 19:35:43 +10:00
|
|
|
from pprint import pformat
|
|
|
|
import time
|
|
|
|
|
2017-12-05 14:37:42 +10:00
|
|
|
from qgis.PyQt.QtCore import QCoreApplication, Qt
|
2017-08-05 22:58:16 +02:00
|
|
|
from qgis.PyQt.QtWidgets import QMessageBox, QPushButton, QSizePolicy, QDialogButtonBox
|
|
|
|
from qgis.PyQt.QtGui import QColor, QPalette
|
2014-11-12 11:42:29 +02:00
|
|
|
|
2018-02-05 22:11:34 -04:00
|
|
|
from qgis.core import (Qgis,
|
|
|
|
QgsProject,
|
2017-06-30 13:09:44 +10:00
|
|
|
QgsApplication,
|
2017-05-15 16:16:32 +10:00
|
|
|
QgsProcessingUtils,
|
2017-05-15 19:01:15 +10:00
|
|
|
QgsProcessingParameterDefinition,
|
2017-06-30 13:09:44 +10:00
|
|
|
QgsProcessingAlgRunnerTask,
|
2017-06-27 12:41:43 +10:00
|
|
|
QgsProcessingOutputHtml,
|
2017-07-08 15:25:45 +10:00
|
|
|
QgsProcessingParameterVectorDestination,
|
2017-06-06 13:43:49 +10:00
|
|
|
QgsProcessingOutputLayerDefinition,
|
2017-06-06 11:40:33 +10:00
|
|
|
QgsProcessingParameterFeatureSink,
|
2017-07-08 15:25:45 +10:00
|
|
|
QgsProcessingParameterRasterDestination,
|
2018-08-08 17:08:10 +07:00
|
|
|
QgsProcessingAlgorithm,
|
2019-02-22 20:24:56 +01:00
|
|
|
QgsProcessingParameters,
|
2018-08-08 17:08:10 +07:00
|
|
|
QgsProxyProgressTask,
|
|
|
|
QgsTaskManager)
|
2018-07-04 16:38:46 +10:00
|
|
|
from qgis.gui import (QgsGui,
|
|
|
|
QgsMessageBar,
|
2017-11-29 14:38:08 +10:00
|
|
|
QgsProcessingAlgorithmDialogBase)
|
2016-10-18 20:57:34 +03:00
|
|
|
from qgis.utils import iface
|
2016-01-18 14:16:31 +01:00
|
|
|
|
2014-11-12 11:42:29 +02:00
|
|
|
from processing.core.ProcessingLog import ProcessingLog
|
|
|
|
from processing.core.ProcessingConfig import ProcessingConfig
|
2017-06-27 12:41:43 +10:00
|
|
|
from processing.core.ProcessingResults import resultsList
|
2017-05-15 13:13:11 +10:00
|
|
|
from processing.gui.ParametersPanel import ParametersPanel
|
2015-09-24 12:07:46 +02:00
|
|
|
from processing.gui.BatchAlgorithmDialog import BatchAlgorithmDialog
|
2014-11-12 11:42:29 +02:00
|
|
|
from processing.gui.AlgorithmDialogBase import AlgorithmDialogBase
|
2018-07-23 13:58:11 +10:00
|
|
|
from processing.gui.AlgorithmExecutor import executeIterating, execute, execute_in_place
|
2014-11-12 11:42:29 +02:00
|
|
|
from processing.gui.Postprocessing import handleAlgorithmResults
|
2018-09-03 10:16:51 +10:00
|
|
|
from processing.gui.wrappers import WidgetWrapper
|
2014-11-12 11:42:29 +02:00
|
|
|
|
2017-04-25 20:03:39 +10:00
|
|
|
from processing.tools import dataobjects
|
2016-10-13 13:40:47 +02:00
|
|
|
|
|
|
|
|
2017-11-29 14:38:08 +10:00
|
|
|
class AlgorithmDialog(QgsProcessingAlgorithmDialogBase):
|
2014-11-12 11:42:29 +02:00
|
|
|
|
2018-09-25 21:37:41 +10:00
|
|
|
def __init__(self, alg, in_place=False, parent=None):
|
|
|
|
super().__init__(parent)
|
|
|
|
|
2018-01-10 08:33:36 +10:00
|
|
|
self.feedback_dialog = None
|
2018-07-23 13:58:11 +10:00
|
|
|
self.in_place = in_place
|
2018-10-05 11:03:49 +02:00
|
|
|
self.active_layer = None
|
2014-11-12 11:42:29 +02:00
|
|
|
|
2018-11-19 14:14:24 +10:00
|
|
|
self.context = None
|
|
|
|
self.feedback = None
|
|
|
|
|
2017-11-29 14:38:08 +10:00
|
|
|
self.setAlgorithm(alg)
|
2017-05-15 13:13:11 +10:00
|
|
|
self.setMainWidget(self.getParametersPanel(alg, self))
|
2014-11-12 11:42:29 +02:00
|
|
|
|
2018-07-23 13:58:11 +10:00
|
|
|
if not self.in_place:
|
|
|
|
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
|
|
|
|
else:
|
2018-10-05 11:03:49 +02:00
|
|
|
self.active_layer = iface.activeLayer()
|
2018-07-23 13:58:11 +10:00
|
|
|
self.runAsBatchButton = None
|
2018-10-05 10:10:20 +02:00
|
|
|
has_selection = self.active_layer and (self.active_layer.selectedFeatureCount() > 0)
|
2018-10-05 09:21:28 +02:00
|
|
|
self.buttonBox().button(QDialogButtonBox.Ok).setText(QCoreApplication.translate("AlgorithmDialog", "Modify Selected Features")
|
|
|
|
if has_selection else QCoreApplication.translate("AlgorithmDialog", "Modify All Features"))
|
|
|
|
self.buttonBox().button(QDialogButtonBox.Close).setText(QCoreApplication.translate("AlgorithmDialog", "Cancel"))
|
2018-10-05 10:10:20 +02:00
|
|
|
self.setWindowTitle(self.windowTitle() + ' | ' + self.active_layer.name())
|
2015-09-24 12:07:46 +02:00
|
|
|
|
2017-05-15 13:13:11 +10:00
|
|
|
def getParametersPanel(self, alg, parent):
|
2018-07-23 13:58:11 +10:00
|
|
|
return ParametersPanel(parent, alg, self.in_place)
|
2017-05-15 13:13:11 +10:00
|
|
|
|
2015-09-24 12:07:46 +02:00
|
|
|
def runAsBatch(self):
|
2016-08-23 14:41:07 +02:00
|
|
|
self.close()
|
2018-11-29 09:28:04 +10:00
|
|
|
dlg = BatchAlgorithmDialog(self.algorithm().create(), parent=iface.mainWindow())
|
2016-08-23 14:41:07 +02:00
|
|
|
dlg.show()
|
2015-09-24 12:07:46 +02:00
|
|
|
dlg.exec_()
|
|
|
|
|
2017-12-21 10:22:19 +10:00
|
|
|
def setParameters(self, parameters):
|
|
|
|
self.mainWidget().setParameters(parameters)
|
|
|
|
|
2017-11-29 15:09:19 +10:00
|
|
|
def getParameterValues(self):
|
2017-05-15 16:16:32 +10:00
|
|
|
parameters = {}
|
2014-11-12 11:42:29 +02:00
|
|
|
|
2017-11-29 14:38:08 +10:00
|
|
|
if self.mainWidget() is None:
|
2017-08-14 05:19:29 +10:00
|
|
|
return parameters
|
|
|
|
|
2017-11-29 14:38:08 +10:00
|
|
|
for param in self.algorithm().parameterDefinitions():
|
2017-05-15 16:16:32 +10:00
|
|
|
if param.flags() & QgsProcessingParameterDefinition.FlagHidden:
|
2014-11-12 11:42:29 +02:00
|
|
|
continue
|
2017-05-15 16:16:32 +10:00
|
|
|
if not param.isDestination():
|
2018-09-10 18:14:03 +02:00
|
|
|
|
|
|
|
if self.in_place and param.name() == 'INPUT':
|
2018-10-05 10:10:20 +02:00
|
|
|
parameters[param.name()] = self.active_layer
|
2018-09-10 18:14:03 +02:00
|
|
|
continue
|
|
|
|
|
2018-08-14 16:41:11 +10:00
|
|
|
try:
|
|
|
|
wrapper = self.mainWidget().wrappers[param.name()]
|
|
|
|
except KeyError:
|
|
|
|
continue
|
|
|
|
|
2018-09-04 15:25:07 +10:00
|
|
|
# For compatibility with 3.x API, we need to check whether the wrapper is
|
|
|
|
# the deprecated WidgetWrapper class. If not, it's the newer
|
|
|
|
# QgsAbstractProcessingParameterWidgetWrapper class
|
|
|
|
# TODO QGIS 4.0 - remove
|
2018-09-03 10:16:51 +10:00
|
|
|
if issubclass(wrapper.__class__, WidgetWrapper):
|
2018-08-14 16:41:11 +10:00
|
|
|
widget = wrapper.widget
|
2018-09-03 10:16:51 +10:00
|
|
|
else:
|
|
|
|
widget = wrapper.wrappedWidget()
|
|
|
|
|
2018-08-14 16:41:11 +10:00
|
|
|
if widget is None:
|
|
|
|
continue
|
|
|
|
|
2018-08-31 16:36:18 +10:00
|
|
|
value = wrapper.parameterValue()
|
2018-08-14 16:41:11 +10:00
|
|
|
parameters[param.name()] = value
|
2018-07-23 13:58:11 +10:00
|
|
|
|
2018-08-14 16:41:11 +10:00
|
|
|
if not param.checkValueIsAcceptable(value):
|
|
|
|
raise AlgorithmDialogBase.InvalidParameterValue(param, widget)
|
2017-05-15 16:16:32 +10:00
|
|
|
else:
|
2018-07-23 13:58:11 +10:00
|
|
|
if self.in_place and param.name() == 'OUTPUT':
|
|
|
|
parameters[param.name()] = 'memory:'
|
|
|
|
continue
|
|
|
|
|
2017-06-06 08:40:23 +10:00
|
|
|
dest_project = None
|
2017-06-05 21:14:44 +10:00
|
|
|
if not param.flags() & QgsProcessingParameterDefinition.FlagHidden and \
|
2018-05-11 14:34:02 +02:00
|
|
|
isinstance(param, (QgsProcessingParameterRasterDestination,
|
|
|
|
QgsProcessingParameterFeatureSink,
|
|
|
|
QgsProcessingParameterVectorDestination)):
|
2017-11-29 14:38:08 +10:00
|
|
|
if self.mainWidget().checkBoxes[param.name()].isChecked():
|
2017-06-06 08:40:23 +10:00
|
|
|
dest_project = QgsProject.instance()
|
2014-11-12 11:42:29 +02:00
|
|
|
|
2019-02-22 20:24:56 +01:00
|
|
|
widget = self.mainWidget().outputWidgets[param.name()]
|
|
|
|
value = widget.getValue()
|
|
|
|
|
2017-06-22 18:21:51 +10:00
|
|
|
if value and isinstance(value, QgsProcessingOutputLayerDefinition):
|
2017-06-07 08:04:26 +10:00
|
|
|
value.destinationProject = dest_project
|
2017-06-22 18:21:51 +10:00
|
|
|
if value:
|
2017-06-07 08:04:26 +10:00
|
|
|
parameters[param.name()] = value
|
2019-02-22 20:24:56 +01:00
|
|
|
if param.isDestination():
|
|
|
|
context = dataobjects.createContext()
|
|
|
|
ok, error = self.algorithm().provider().isSupportedOutputValue(value, param, context)
|
|
|
|
if not ok:
|
2019-03-19 10:12:10 +01:00
|
|
|
raise AlgorithmDialogBase.InvalidOutputExtension(widget, error)
|
2017-05-15 19:01:15 +10:00
|
|
|
|
2018-03-21 19:22:14 +10:00
|
|
|
return self.algorithm().preprocessParameters(parameters)
|
2017-05-15 19:01:15 +10:00
|
|
|
|
2018-11-17 14:51:31 +10:00
|
|
|
def runAlgorithm(self):
|
2018-11-19 14:14:24 +10:00
|
|
|
self.feedback = self.createFeedback()
|
|
|
|
self.context = dataobjects.createContext(self.feedback)
|
2017-04-29 12:14:53 +02:00
|
|
|
|
fix python pep8 warnings and fix some revealed errors
pep8 --ignore=E111,E128,E201,E202,E203,E211,E221,E222,E225,E226,E227,E231,E241,E261,E265,E272,E302,E303,E501,E701 \
--exclude="ui_*.py,debian/*,python/ext-libs/*" \
.
2015-02-01 14:15:42 +01:00
|
|
|
checkCRS = ProcessingConfig.getSetting(ProcessingConfig.WARN_UNMATCHING_CRS)
|
2014-11-12 11:42:29 +02:00
|
|
|
try:
|
2017-11-29 15:09:19 +10:00
|
|
|
parameters = self.getParameterValues()
|
2017-05-15 16:19:46 +10:00
|
|
|
|
2018-11-19 14:14:24 +10:00
|
|
|
if checkCRS and not self.algorithm().validateInputCrs(parameters, self.context):
|
2014-11-12 11:42:29 +02:00
|
|
|
reply = QMessageBox.question(self, self.tr("Unmatching CRS's"),
|
2018-05-01 15:33:26 +10:00
|
|
|
self.tr('Parameters do not all use the same CRS. This can '
|
2015-08-22 14:29:41 +02:00
|
|
|
'cause unexpected results.\nDo you want to '
|
|
|
|
'continue?'),
|
|
|
|
QMessageBox.Yes | QMessageBox.No,
|
|
|
|
QMessageBox.No)
|
2014-11-12 11:42:29 +02:00
|
|
|
if reply == QMessageBox.No:
|
|
|
|
return
|
2018-11-19 14:14:24 +10:00
|
|
|
ok, msg = self.algorithm().checkParameterValues(parameters, self.context)
|
2018-05-28 14:29:42 +10:00
|
|
|
if not ok:
|
2014-11-12 11:42:29 +02:00
|
|
|
QMessageBox.warning(
|
|
|
|
self, self.tr('Unable to execute algorithm'), msg)
|
|
|
|
return
|
2017-11-29 14:38:08 +10:00
|
|
|
self.runButton().setEnabled(False)
|
|
|
|
self.cancelButton().setEnabled(False)
|
|
|
|
buttons = self.mainWidget().iterateButtons
|
2014-11-12 11:42:29 +02:00
|
|
|
self.iterateParam = None
|
|
|
|
|
2016-09-21 18:24:26 +02:00
|
|
|
for i in range(len(list(buttons.values()))):
|
|
|
|
button = list(buttons.values())[i]
|
2014-11-12 11:42:29 +02:00
|
|
|
if button.isChecked():
|
2016-09-21 18:24:26 +02:00
|
|
|
self.iterateParam = list(buttons.keys())[i]
|
2014-11-12 11:42:29 +02:00
|
|
|
break
|
|
|
|
|
2017-11-29 14:38:08 +10:00
|
|
|
self.clearProgress()
|
2019-04-08 10:25:26 +10:00
|
|
|
self.feedback.pushVersionInfo(self.algorithm().provider())
|
2018-02-15 22:30:52 +01:00
|
|
|
self.setProgressText(QCoreApplication.translate('AlgorithmDialog', 'Processing algorithm…'))
|
2014-11-12 11:42:29 +02:00
|
|
|
|
|
|
|
self.setInfo(
|
2018-04-19 11:41:18 +10:00
|
|
|
QCoreApplication.translate('AlgorithmDialog', '<b>Algorithm \'{0}\' starting…</b>').format(self.algorithm().displayName()), escapeHtml=False)
|
2014-11-12 11:42:29 +02:00
|
|
|
|
2018-11-19 14:14:24 +10:00
|
|
|
self.feedback.pushInfo(self.tr('Input parameters:'))
|
2017-09-15 08:34:13 +10:00
|
|
|
display_params = []
|
|
|
|
for k, v in parameters.items():
|
2018-11-19 14:14:24 +10:00
|
|
|
display_params.append("'" + k + "' : " + self.algorithm().parameterDefinition(k).valueAsPythonString(v, self.context))
|
|
|
|
self.feedback.pushCommandInfo('{ ' + ', '.join(display_params) + ' }')
|
|
|
|
self.feedback.pushInfo('')
|
2017-06-11 19:35:43 +10:00
|
|
|
start_time = time.time()
|
|
|
|
|
2014-11-12 11:42:29 +02:00
|
|
|
if self.iterateParam:
|
2018-01-10 08:33:36 +10:00
|
|
|
# Make sure the Log tab is visible before executing the algorithm
|
|
|
|
try:
|
|
|
|
self.showLog()
|
|
|
|
self.repaint()
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2017-11-29 14:38:08 +10:00
|
|
|
self.cancelButton().setEnabled(self.algorithm().flags() & QgsProcessingAlgorithm.FlagCanCancel)
|
2018-11-19 14:14:24 +10:00
|
|
|
if executeIterating(self.algorithm(), parameters, self.iterateParam, self.context, self.feedback):
|
|
|
|
self.feedback.pushInfo(
|
2018-03-09 08:26:43 +02:00
|
|
|
self.tr('Execution completed in {0:0.2f} seconds').format(time.time() - start_time))
|
2017-11-29 14:38:08 +10:00
|
|
|
self.cancelButton().setEnabled(False)
|
2018-11-19 14:14:24 +10:00
|
|
|
self.finish(True, parameters, self.context, self.feedback)
|
2014-11-12 11:42:29 +02:00
|
|
|
else:
|
2017-11-29 14:38:08 +10:00
|
|
|
self.cancelButton().setEnabled(False)
|
|
|
|
self.resetGui()
|
2014-11-12 11:42:29 +02:00
|
|
|
else:
|
2018-11-19 14:14:24 +10:00
|
|
|
command = self.algorithm().asPythonCommand(parameters, self.context)
|
2017-06-12 15:59:56 +10:00
|
|
|
if command:
|
|
|
|
ProcessingLog.addToLog(command)
|
2018-07-04 16:38:46 +10:00
|
|
|
QgsGui.instance().processingRecentAlgorithmLog().push(self.algorithm().id())
|
2017-11-29 14:38:08 +10:00
|
|
|
self.cancelButton().setEnabled(self.algorithm().flags() & QgsProcessingAlgorithm.FlagCanCancel)
|
2017-06-11 19:35:43 +10:00
|
|
|
|
2017-06-30 13:09:44 +10:00
|
|
|
def on_complete(ok, results):
|
|
|
|
if ok:
|
2018-11-19 14:14:24 +10:00
|
|
|
self.feedback.pushInfo(self.tr('Execution completed in {0:0.2f} seconds').format(time.time() - start_time))
|
|
|
|
self.feedback.pushInfo(self.tr('Results:'))
|
|
|
|
self.feedback.pushCommandInfo(pformat(results))
|
2017-06-30 13:09:44 +10:00
|
|
|
else:
|
2018-11-19 14:14:24 +10:00
|
|
|
self.feedback.reportError(
|
2018-03-09 08:26:43 +02:00
|
|
|
self.tr('Execution failed after {0:0.2f} seconds').format(time.time() - start_time))
|
2018-11-19 14:14:24 +10:00
|
|
|
self.feedback.pushInfo('')
|
2017-06-30 13:09:44 +10:00
|
|
|
|
2018-01-10 08:33:36 +10:00
|
|
|
if self.feedback_dialog is not None:
|
|
|
|
self.feedback_dialog.close()
|
|
|
|
self.feedback_dialog.deleteLater()
|
|
|
|
self.feedback_dialog = None
|
|
|
|
|
2017-11-29 14:38:08 +10:00
|
|
|
self.cancelButton().setEnabled(False)
|
2017-12-05 14:37:42 +10:00
|
|
|
|
2018-07-23 13:58:11 +10:00
|
|
|
if not self.in_place:
|
2018-11-19 14:14:24 +10:00
|
|
|
self.finish(ok, results, self.context, self.feedback)
|
2018-07-23 13:58:11 +10:00
|
|
|
elif ok:
|
|
|
|
self.close()
|
2017-06-30 13:09:44 +10:00
|
|
|
|
2018-11-19 14:14:24 +10:00
|
|
|
self.feedback = None
|
|
|
|
self.context = None
|
|
|
|
|
2018-07-23 13:58:11 +10:00
|
|
|
if not self.in_place and not (self.algorithm().flags() & QgsProcessingAlgorithm.FlagNoThreading):
|
2018-01-10 08:33:36 +10:00
|
|
|
# Make sure the Log tab is visible before executing the algorithm
|
|
|
|
self.showLog()
|
|
|
|
|
2018-11-19 14:14:24 +10:00
|
|
|
task = QgsProcessingAlgRunnerTask(self.algorithm(), parameters, self.context, self.feedback)
|
2019-02-20 11:53:30 +10:00
|
|
|
if task.isCanceled():
|
|
|
|
on_complete(False, {})
|
|
|
|
else:
|
|
|
|
task.executed.connect(on_complete)
|
|
|
|
self.setCurrentTask(task)
|
2017-12-05 13:42:16 +10:00
|
|
|
else:
|
2018-08-21 09:03:41 +02:00
|
|
|
self.proxy_progress = QgsProxyProgressTask(QCoreApplication.translate("AlgorithmDialog", "Executing “{}”").format(self.algorithm().displayName()))
|
2018-08-08 17:08:10 +07:00
|
|
|
QgsApplication.taskManager().addTask(self.proxy_progress)
|
2018-11-19 14:14:24 +10:00
|
|
|
self.feedback.progressChanged.connect(self.proxy_progress.setProxyProgress)
|
2018-01-10 08:33:36 +10:00
|
|
|
self.feedback_dialog = self.createProgressDialog()
|
|
|
|
self.feedback_dialog.show()
|
2018-07-23 13:58:11 +10:00
|
|
|
if self.in_place:
|
2018-11-19 14:14:24 +10:00
|
|
|
ok, results = execute_in_place(self.algorithm(), parameters, self.context, self.feedback)
|
2018-07-23 13:58:11 +10:00
|
|
|
else:
|
2018-11-19 14:14:24 +10:00
|
|
|
ok, results = execute(self.algorithm(), parameters, self.context, self.feedback)
|
|
|
|
self.feedback.progressChanged.disconnect()
|
2018-08-08 17:08:10 +07:00
|
|
|
self.proxy_progress.finalize(ok)
|
2017-12-05 13:42:16 +10:00
|
|
|
on_complete(ok, results)
|
2017-06-30 13:09:44 +10:00
|
|
|
|
2015-08-22 14:29:41 +02:00
|
|
|
except AlgorithmDialogBase.InvalidParameterValue as e:
|
2014-11-12 11:42:29 +02:00
|
|
|
try:
|
2017-11-29 14:38:08 +10:00
|
|
|
self.buttonBox().accepted.connect(lambda e=e:
|
|
|
|
e.widget.setPalette(QPalette()))
|
2014-11-12 11:42:29 +02:00
|
|
|
palette = e.widget.palette()
|
|
|
|
palette.setColor(QPalette.Base, QColor(255, 255, 0))
|
|
|
|
e.widget.setPalette(palette)
|
|
|
|
except:
|
2016-09-16 14:32:30 +02:00
|
|
|
pass
|
2017-11-29 14:38:08 +10:00
|
|
|
self.messageBar().clearWidgets()
|
|
|
|
self.messageBar().pushMessage("", self.tr("Wrong or missing parameter value: {0}").format(e.parameter.description()),
|
2018-02-05 22:11:34 -04:00
|
|
|
level=Qgis.Warning, duration=5)
|
2019-02-22 20:24:56 +01:00
|
|
|
except AlgorithmDialogBase.InvalidOutputExtension as e:
|
|
|
|
try:
|
|
|
|
self.buttonBox().accepted.connect(lambda e=e:
|
|
|
|
e.widget.setPalette(QPalette()))
|
|
|
|
palette = e.widget.palette()
|
|
|
|
palette.setColor(QPalette.Base, QColor(255, 255, 0))
|
|
|
|
e.widget.setPalette(palette)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
self.messageBar().clearWidgets()
|
|
|
|
self.messageBar().pushMessage("", e.message,
|
|
|
|
level=Qgis.Warning, duration=5)
|
2014-11-12 11:42:29 +02:00
|
|
|
|
2017-08-02 23:07:22 +10:00
|
|
|
def finish(self, successful, result, context, feedback):
|
|
|
|
keepOpen = not successful or ProcessingConfig.getSetting(ProcessingConfig.KEEP_DIALOG_OPEN)
|
2014-11-12 11:42:29 +02:00
|
|
|
|
|
|
|
if self.iterateParam is None:
|
2017-05-15 19:01:15 +10:00
|
|
|
|
2017-06-27 12:41:43 +10:00
|
|
|
# add html results to results dock
|
2017-11-29 14:38:08 +10:00
|
|
|
for out in self.algorithm().outputDefinitions():
|
2017-06-27 12:41:43 +10:00
|
|
|
if isinstance(out, QgsProcessingOutputHtml) and out.name() in result and result[out.name()]:
|
2018-02-12 12:43:02 +07:00
|
|
|
resultsList.addResult(icon=self.algorithm().icon(), name=out.description(), timestamp=time.localtime(),
|
2019-02-13 05:52:07 +10:00
|
|
|
result=result[out.name()])
|
2019-01-23 08:01:43 +01:00
|
|
|
if not handleAlgorithmResults(self.algorithm(), context, feedback, not keepOpen, result):
|
2017-11-29 14:38:08 +10:00
|
|
|
self.resetGui()
|
2015-05-20 20:21:34 +02:00
|
|
|
return
|
2014-11-12 11:42:29 +02:00
|
|
|
|
2017-11-29 14:38:08 +10:00
|
|
|
self.setExecuted(True)
|
2017-12-21 10:38:38 +10:00
|
|
|
self.setResults(result)
|
2017-11-29 14:38:08 +10:00
|
|
|
self.setInfo(self.tr('Algorithm \'{0}\' finished').format(self.algorithm().displayName()), escapeHtml=False)
|
2014-11-12 11:42:29 +02:00
|
|
|
|
|
|
|
if not keepOpen:
|
|
|
|
self.close()
|
|
|
|
else:
|
2017-11-29 14:38:08 +10:00
|
|
|
self.resetGui()
|
|
|
|
if self.algorithm().hasHtmlOutputs():
|
2014-11-12 11:42:29 +02:00
|
|
|
self.setInfo(
|
|
|
|
self.tr('HTML output has been generated by this algorithm.'
|
2017-11-29 14:38:08 +10:00
|
|
|
'\nOpen the results dialog to check it.'), escapeHtml=False)
|