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): _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): 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 checkCoordsMatrix(self, coords): strResult = QgsError() for i in range(len(coords)): partNumber = str(coords[i][0]) listValues = coords[i][1] if len(listValues) == 0: strResult.append( self.translate_str("Part ") + str(partNumber) + self.translate_str(" is empty"), self.translate_str("Value error")) elif self.geometryType == QgsWkbTypes.LineGeometry and len( listValues) < 2: strResult.append( self.translate_str("Part ") + str(partNumber) + self.translate_str( " contains below 2 points." " It's not enough for creating line geometry"), self.translate_str("Value error")) elif self.geometryType == QgsWkbTypes.Polygon and len( listValues) < 3: strResult.append( self.translate_str("Part ") + str(partNumber) + self.translate_str( " contains below 3 points. It's not enough " "for creating polygon geometry"), self.translate_str("Value error")) else: for j in range(len(listValues)): currentTuple = listValues[j] for k in range(len(currentTuple)): cellStatus = self.checkValue(QVariant(currentTuple[k])) if cellStatus == CellValue.ValueNone: strResult.append( self.translate_str("Part ") + str(partNumber) + self.translate_str(" row ") + str(j + 1) + self.translate_str(" column ") + str(k + 1) + self.translate_str(" contains empty value"), self.translate_str("Value error")) elif cellStatus == CellValue.ValueNotFloat: strResult.append( self.translate_str("Part ") + str(partNumber) + self.translate_str(" row ") + str(j + 1) + self.translate_str(" column ") + str(k + 1) + self.translate_str( " contains incorrect value"), self.translate_str("Value error")) if not strResult.isEmpty(): errorDialog = QgsErrorDialog( strResult, self.translate_str('Values errors found'), self.tableViewWidget.parent()) errorDialog.showNormal() return False else: return True
def testQgsErrorRepr(self): e = QgsError('you done wrong son', 'dad') self.assertEqual(e.__repr__(), "<QgsError: dad you done wrong son>")
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())