def runAlgorithm(self): _locals = {} try: exec(self.editor.text(), _locals) except Exception as e: error = QgsError(traceback.format_exc(), "Processing") QgsErrorDialog.show(error, self.tr("Execution error")) return alg = None try: alg = algfactory.instances.pop().createInstance() except IndexError: for name, attr in _locals.items(): if inspect.isclass(attr) and issubclass( attr, (QgsProcessingAlgorithm, QgsProcessingFeatureBasedAlgorithm )) and attr.__name__ not in ( "QgsProcessingAlgorithm", "QgsProcessingFeatureBasedAlgorithm"): alg = attr() break if alg is None: QMessageBox.warning( self, self.tr("No script found"), self.tr("Seems there is no valid script in the file.")) return alg.setProvider( QgsApplication.processingRegistry().providerById("script")) alg.initAlgorithm() dlg = alg.createCustomParametersWidget(iface.mainWindow()) if not dlg: dlg = AlgorithmDialog(alg, parent=iface.mainWindow()) canvas = iface.mapCanvas() prevMapTool = canvas.mapTool() dlg.show() if canvas.mapTool() != prevMapTool: try: canvas.mapTool().reset() except: pass canvas.setMapTool(prevMapTool)
def runAlgorithm(self): d = {} try: exec(self.editor.text(), d) except Exception as e: error = QgsError(traceback.format_exc(), "Processing") QgsErrorDialog.show(error, self.tr("Execution error")) return alg = None for k, v in d.items(): if inspect.isclass(v) and issubclass( v, (QgsProcessingAlgorithm, QgsProcessingFeatureBasedAlgorithm)) and v.__name__ not in ( "QgsProcessingAlgorithm", "QgsProcessingFeatureBasedAlgorithm"): alg = v() break if alg is None: QMessageBox.warning( self, self.tr("No script found"), self.tr("Seems there is no valid script in the file.")) return alg.setProvider( QgsApplication.processingRegistry().providerById("script")) alg.initAlgorithm() dlg = alg.createCustomParametersWidget(self) if not dlg: dlg = AlgorithmDialog(alg) canvas = iface.mapCanvas() prevMapTool = canvas.mapTool() dlg.show() if canvas.mapTool() != prevMapTool: try: canvas.mapTool().reset() except: pass canvas.setMapTool(prevMapTool)
def runAlgorithm(self): alg = JsAlgorithm(description_file=None, script=self.editor.text()) if alg.error is not None: error = QgsError(alg.error, "R") QgsErrorDialog.show(error, self.tr("Execution error")) return alg.setProvider(QgsApplication.processingRegistry().providerById("r")) alg.initAlgorithm() dlg = alg.createCustomParametersWidget(iface.mainWindow()) if not dlg: dlg = AlgorithmDialog(alg, parent=iface.mainWindow()) canvas = iface.mapCanvas() prevMapTool = canvas.mapTool() dlg.show() if canvas.mapTool() != prevMapTool: if canvas.mapTool(): canvas.mapTool().reset() canvas.setMapTool(prevMapTool)
def testQgsErrorRepr(self): e = QgsError('you done wrong son', 'dad') self.assertEqual(e.__repr__(), "<QgsError: dad you done wrong son>")
# coding: utf-8 from PyQt4.QtCore import Qt # http://doc.qt.io/qt-4.8/qwidget.html#windowFlags-prop from qgis.core import QgsError from qgis.gui import QgsErrorDialog from qgis.utils import iface error_dialog = QgsErrorDialog(QgsError("My error message", "My GDAL tag"), "My title", iface.mainWindow(), fl=Qt.WindowFlags()) error_dialog.show(QgsError("My error message", "My GDAL tag"), "My title", iface.mainWindow(), fl=Qt.WindowFlags())