def createAlgorithmDialog(algOrName, parameters={}): """ Creates and returns an algorithm dialog for the specified algorithm, prepopulated with a given set of parameters. It is the caller's responsibility to execute and delete this dialog. :param algOrName: Either an instance of an algorithm, or an algorithm's ID :param parameters: Initial algorithm parameters dictionary :returns algorithm results as a dictionary, or None if execution failed :rtype: Union[dict, None] """ if isinstance(algOrName, QgsProcessingAlgorithm): alg = algOrName.create() else: alg = QgsApplication.processingRegistry().createAlgorithmById( algOrName) if alg is None: return False dlg = alg.createCustomParametersWidget(iface.mainWindow()) if not dlg: dlg = AlgorithmDialog(alg, parent=iface.mainWindow()) dlg.setParameters(parameters) return dlg
def createAlgorithmDialog(algOrName, parameters={}): """ Creates and returns an algorithm dialog for the specified algorithm, prepopulated with a given set of parameters. It is the caller's responsibility to execute and delete this dialog. :param algOrName: Either an instance of an algorithm, or an algorithm's ID :param parameters: Initial algorithm parameters dictionary :returns algorithm results as a dictionary, or None if execution failed :rtype: Union[dict, None] """ if isinstance(algOrName, QgsProcessingAlgorithm): alg = algOrName.create() else: alg = QgsApplication.processingRegistry().createAlgorithmById(algOrName) if alg is None: return False dlg = alg.createCustomParametersWidget(iface.mainWindow()) if not dlg: dlg = AlgorithmDialog(alg, parent=iface.mainWindow()) dlg.setParameters(parameters) return dlg
def runModel(self): valid, errors = self.model().validate() if not valid: message_box = QMessageBox() message_box.setWindowTitle(self.tr('Model is Invalid')) message_box.setIcon(QMessageBox.Warning) message_box.setText(self.tr('This model is not valid and contains one or more issues. Are you sure you want to run it in this state?')) message_box.setStandardButtons(QMessageBox.Yes | QMessageBox.Cancel) message_box.setDefaultButton(QMessageBox.Cancel) error_string = '' for e in errors: e = re.sub(r'<[^>]*>', '', e) error_string += '• {}\n'.format(e) message_box.setDetailedText(error_string) if message_box.exec_() == QMessageBox.Cancel: return def on_finished(successful, results): self.setLastRunChildAlgorithmResults(dlg.results().get('CHILD_RESULTS', {})) self.setLastRunChildAlgorithmInputs(dlg.results().get('CHILD_INPUTS', {})) dlg = AlgorithmDialog(self.model().create(), parent=self) dlg.setParameters(self.model().designerParameterValues()) dlg.algorithmFinished.connect(on_finished) dlg.exec_() if dlg.wasExecuted(): self.model().setDesignerParameterValues(dlg.createProcessingParameters(include_default=False))
def runModel(self): if len(self.model().childAlgorithms()) == 0: self.messageBar().pushMessage( "", self. tr("Model doesn't contain any algorithm and/or parameter and can't be executed" ), level=Qgis.Warning, duration=5) return dlg = AlgorithmDialog(self.model().create(), parent=self) dlg.setParameters(self.model().designerParameterValues()) dlg.exec_() if dlg.wasExecuted(): self.model().setDesignerParameterValues(dlg.getParameterValues())
def runModel(self): if len(self.model().childAlgorithms()) == 0: self.messageBar().pushMessage("", self.tr( "Model doesn't contain any algorithm and/or parameter and can't be executed"), level=Qgis.Warning, duration=5) return def on_finished(successful, results): self.setLastRunChildAlgorithmResults(dlg.results().get('CHILD_RESULTS', {})) self.setLastRunChildAlgorithmInputs(dlg.results().get('CHILD_INPUTS', {})) dlg = AlgorithmDialog(self.model().create(), parent=self) dlg.setParameters(self.model().designerParameterValues()) dlg.algorithmFinished.connect(on_finished) dlg.exec_() if dlg.wasExecuted(): self.model().setDesignerParameterValues(dlg.getParameterValues())
def createAlgorithmDialog(algOrName, parameters={}): """Creates and returns an algorithm dialog for the specified algorithm, prepopulated with a given set of parameters. It is the caller's responsibility to execute and delete this dialog. """ if isinstance(algOrName, QgsProcessingAlgorithm): alg = algOrName else: alg = QgsApplication.processingRegistry().createAlgorithmById(algOrName) if alg is None: return False dlg = alg.createCustomParametersWidget(iface.mainWindow()) if not dlg: dlg = AlgorithmDialog(alg) dlg.setParameters(parameters) return dlg
def createAlgorithmDialog(algOrName, parameters={}): """Creates and returns an algorithm dialog for the specified algorithm, prepopulated with a given set of parameters. It is the caller's responsibility to execute and delete this dialog. """ if isinstance(algOrName, QgsProcessingAlgorithm): alg = algOrName else: alg = QgsApplication.processingRegistry().createAlgorithmById(algOrName) if alg is None: return False dlg = alg.createCustomParametersWidget(iface.mainWindow()) if not dlg: dlg = AlgorithmDialog(alg) dlg.setParameters(parameters) return dlg