def createGeomColumn(self): """ first check whether everything's fine """ if self.editName.text() == "": QMessageBox.critical(self, self.tr("DB Manager"), self.tr("field name must not be empty")) return name = self.editName.text() geom_type = self.GEOM_TYPES[self.cboType.currentIndex()] dim = self.spinDim.value() try: srid = int(self.editSrid.text()) except ValueError: srid = -1 createSpatialIndex = False # now create the geometry column QApplication.setOverrideCursor(Qt.WaitCursor) try: self.table.addGeometryColumn(name, geom_type, srid, dim, createSpatialIndex) except DbError as e: DlgDbError.showError(e, self) return finally: QApplication.restoreOverrideCursor() self.accept()
def openModel(self): filename = unicode(QFileDialog.getOpenFileName(self, self.tr('Open Model'), ModelerUtils.modelsFolder(), self.tr('Processing models (*.model *.MODEL)'))) if filename: try: alg = ModelerAlgorithm.fromFile(filename) self.alg = alg self.alg.setModelerView(self) self.textGroup.setText(alg.group) self.textName.setText(alg.name) self.repaintModel() self.view.centerOn(0, 0) self.hasChanged = False except WrongModelException as e: ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, self.tr('Could not load model %s\n%s') % (filename, e.msg)) QMessageBox.critical(self, self.tr('Could not open model'), self.tr('The selected model could not be loaded.\n' 'See the log for more information.')) except Exception as e: ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, self.tr('Could not load model %s\n%s') % (filename, e.args[0])) QMessageBox.critical(self, self.tr('Could not open model'), self.tr('The selected model could not be loaded.\n' 'See the log for more information.'))
def openModel(self): filename = unicode( QFileDialog.getOpenFileName( self, self.tr('Open Model'), ModelerUtils.modelsFolder(), self.tr('Processing models (*.model *.MODEL)'))) if filename: try: alg = ModelerAlgorithm.fromFile(filename) self.alg = alg self.alg.setModelerView(self) self.textGroup.setText(alg.group) self.textName.setText(alg.name) self.repaintModel() self.view.centerOn(0, 0) self.hasChanged = False except WrongModelException as e: ProcessingLog.addToLog( ProcessingLog.LOG_ERROR, self.tr('Could not load model %s\n%s') % (filename, e.msg)) QMessageBox.critical( self, self.tr('Could not open model'), self.tr('The selected model could not be loaded.\n' 'See the log for more information.')) except Exception as e: ProcessingLog.addToLog( ProcessingLog.LOG_ERROR, self.tr('Could not load model %s\n%s') % (filename, e.args[0])) QMessageBox.critical( self, self.tr('Could not open model'), self.tr('The selected model could not be loaded.\n' 'See the log for more information.'))
def createGeomColumn(self): """ first check whether everything's fine """ if self.editName.text() == "": QMessageBox.critical(self, self.tr("DB Manager"), self.tr("field name must not be empty")) return name = self.editName.text() geom_type = self.GEOM_TYPES[self.cboType.currentIndex()] dim = self.spinDim.value() try: srid = int(self.editSrid.text()) except ValueError: srid = -1 createSpatialIndex = False # now create the geometry column QApplication.setOverrideCursor(Qt.WaitCursor) try: self.table.addGeometryColumn(name, geom_type, srid, dim, createSpatialIndex) except DbError as e: DlgDbError.showError(e, self) return finally: QApplication.restoreOverrideCursor() self.accept()
def accept(self): try: self.value = float(eval(unicode(self.leFormula.text()))) if self.isInteger: self.value = int(round(self.value)) QDialog.accept(self) except: QMessageBox.critical(self, self.tr('Wrong expression'), self.tr('The expression entered is not correct'))
def execute(self): f = os.path.join(FusionUtils.FusionPath(), 'pdq.exe') if os.path.exists(f): subprocess.Popen(f) else: QMessageBox.critical(None, self.tr('Unable to open viewer'), self.tr('The current Fusion folder does not contain the ' 'viewer executable.\nPlease check the configuration ' 'in the Processing settings dialog.'))
def accept(self): try: self.value = float(eval(unicode(self.leFormula.text()))) if self.isInteger: self.value = int(round(self.value)) QDialog.accept(self) except: QMessageBox.critical( self, self.tr('Wrong expression'), self.tr('The expression entered is not correct'))
def execute(self): f = os.path.join(FusionUtils.FusionPath(), 'pdq.exe') if os.path.exists(f): subprocess.Popen(f) else: QMessageBox.critical( None, self.tr('Unable to open viewer'), self.tr('The current Fusion folder does not contain the ' 'viewer executable.\nPlease check the configuration ' 'in the Processing settings dialog.'))
def onOK(self): """ first check whether everything's fine """ fld = self.getField(True) # don't change the original copy if fld.name == "": QMessageBox.critical(self, self.tr("DB Manager"), self.tr("field name must not be empty")) return if fld.dataType == "": QMessageBox.critical(self, self.tr("DB Manager"), self.tr("field type must not be empty")) return self.accept()
def onOK(self): """ first check whether everything's fine """ fld = self.getField(True) # don't change the original copy if fld.name == "": QMessageBox.critical(self, self.tr("DB Manager"), self.tr("field name must not be empty")) return if fld.dataType == "": QMessageBox.critical(self, self.tr("DB Manager"), self.tr("field type must not be empty")) return self.accept()
def createIndex(self): idx = self.getIndex() if idx.name == "": QMessageBox.critical(self, self.tr("Error"), self.tr("Please enter some name for the index")) return # now create the index QApplication.setOverrideCursor(Qt.WaitCursor) try: self.table.addIndex(idx) except DbError as e: DlgDbError.showError(e, self) return finally: QApplication.restoreOverrideCursor() self.accept()
def createIndex(self): idx = self.getIndex() if idx.name == "": QMessageBox.critical( self, self.tr("Error"), self.tr("Please enter some name for the index")) return # now create the index QApplication.setOverrideCursor(Qt.WaitCursor) try: self.table.addIndex(idx) except DbError as e: DlgDbError.showError(e, self) return finally: QApplication.restoreOverrideCursor() self.accept()
def load(self): filename = unicode(QFileDialog.getOpenFileName(self, self.tr('Open batch'), None, self.tr('JSON files (*.json)'))) if filename: with open(filename) as f: values = json.load(f) else: # If the user clicked on the cancel button. return self.tblParameters.setRowCount(0) try: for row, alg in enumerate(values): self.addRow() params = alg[self.PARAMETERS] outputs = alg[self.OUTPUTS] column = 0 for param in self.alg.parameters: if param.hidden: continue widget = self.tblParameters.cellWidget(row, column) if param.name in params: value = params[param.name] self.setValueInWidget(widget, value) column += 1 for out in self.alg.outputs: if out.hidden: continue widget = self.tblParameters.cellWidget(row, column) if out.name in outputs: value = outputs[out.name] self.setValueInWidget(widget, value) column += 1 except TypeError: QMessageBox.critical( self, self.tr('Error'), self.tr('An error occured while reading your file.'))
def load(self): filename = unicode( QFileDialog.getOpenFileName(self, self.tr('Open batch'), None, self.tr('JSON files (*.json)'))) if filename: with open(filename) as f: values = json.load(f) else: # If the user clicked on the cancel button. return self.tblParameters.setRowCount(0) try: for row, alg in enumerate(values): self.addRow() params = alg[self.PARAMETERS] outputs = alg[self.OUTPUTS] column = 0 for param in self.alg.parameters: if param.hidden: continue widget = self.tblParameters.cellWidget(row, column) if param.name in params: value = params[param.name] self.setValueInWidget(widget, value) column += 1 for out in self.alg.outputs: if out.hidden: continue widget = self.tblParameters.cellWidget(row, column) if out.name in outputs: value = outputs[out.name] self.setValueInWidget(widget, value) column += 1 except TypeError: QMessageBox.critical( self, self.tr('Error'), self.tr('An error occured while reading your file.'))
def getArguments(self): arguments = [] if self.targetSRSCheck.isChecked() and self.targetSRSEdit.text(): arguments.append("-a_srs") arguments.append(self.targetSRSEdit.text()) if self.creationOptionsGroupBox.isChecked(): for opt in self.creationOptionsWidget.options(): arguments.extend(["-co", opt]) if self.outsizeCheck.isChecked() and self.outsizeSpin.value() != 100: arguments.append("-outsize") arguments.append(self.outsizeSpin.text()) arguments.append(self.outsizeSpin.text()) if self.expandCheck.isChecked(): arguments.append("-expand") arguments.append(self.expand_method[self.expandCombo.currentIndex()]) if self.nodataCheck.isChecked(): arguments.append("-a_nodata") arguments.append(unicode(self.nodataSpin.value())) if self.sdsCheck.isChecked(): arguments.append("-sds") if self.srcwinCheck.isChecked() and self.srcwinEdit.text(): coordList = self.srcwinEdit.text().split() # split the string on whitespace(s) if len(coordList) == 4 and coordList[3]: try: for x in coordList: int(x) except ValueError: #print "Coordinates must be integer numbers." QMessageBox.critical(self, self.tr("Translate - srcwin"), self.tr("Image coordinates (pixels) must be integer numbers.")) else: arguments.append("-srcwin") for x in coordList: arguments.append(x) if self.prjwinCheck.isChecked() and self.prjwinEdit.text(): coordList = self.prjwinEdit.text().split() # split the string on whitespace(s) if len(coordList) == 4 and coordList[3]: try: for x in coordList: float(x) except ValueError: #print "Coordinates must be integer numbers." QMessageBox.critical(self, self.tr("Translate - prjwin"), self.tr("Image coordinates (geographic) must be numbers.")) else: arguments.append("-projwin") for x in coordList: arguments.append(x) if self.isBatchEnabled(): if self.formatCombo.currentIndex() != 0: arguments.append("-of") arguments.append(Utils.fillRasterOutputFormat(self.formatCombo.currentText())) return arguments else: return arguments outputFn = self.getOutputFileName() if outputFn: arguments.append("-of") arguments.append(self.outputFormat) arguments.append(self.getInputFileName()) arguments.append(outputFn) # set creation options filename/layer for validation if self.inSelector.layer(): self.creationOptionsWidget.setRasterLayer(self.inSelector.layer()) else: self.creationOptionsWidget.setRasterFileName(self.getInputFileName()) return arguments
def error(self, text): QMessageBox.critical(self, "Error", text) ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, text)
def error(self, text): QMessageBox.critical(self, "Error", text) ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, text)
def accept(self): self.settings.setValue("/Processing/dialogBase", self.saveGeometry()) checkCRS = ProcessingConfig.getSetting(ProcessingConfig.WARN_UNMATCHING_CRS) try: self.setParamValues() if checkCRS and not self.alg.checkInputCRS(): reply = QMessageBox.question(self, self.tr("Unmatching CRS's"), self.tr('Layers do not all use the same CRS. This can ' 'cause unexpected results.\nDo you want to ' 'continue?'), QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if reply == QMessageBox.No: return msg = self.alg._checkParameterValuesBeforeExecuting() if msg: QMessageBox.warning( self, self.tr('Unable to execute algorithm'), msg) return self.btnRun.setEnabled(False) self.btnClose.setEnabled(False) buttons = self.mainWidget.iterateButtons self.iterateParam = None for i in range(len(buttons.values())): button = buttons.values()[i] if button.isChecked(): self.iterateParam = buttons.keys()[i] break self.progressBar.setMaximum(0) self.lblProgress.setText(self.tr('Processing algorithm...')) # Make sure the Log tab is visible before executing the algorithm try: self.tabWidget.setCurrentIndex(1) self.repaint() except: pass QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) self.setInfo( self.tr('<b>Algorithm %s starting...</b>') % self.alg.name) if self.iterateParam: if runalgIterating(self.alg, self.iterateParam, self): self.finish() else: QApplication.restoreOverrideCursor() self.resetGUI() else: command = self.alg.getAsCommand() if command: ProcessingLog.addToLog( ProcessingLog.LOG_ALGORITHM, command) if runalg(self.alg, self): self.finish() else: QApplication.restoreOverrideCursor() self.resetGUI() except AlgorithmDialogBase.InvalidParameterValue as e: try: self.buttonBox.accepted.connect(lambda: e.widget.setPalette(QPalette())) palette = e.widget.palette() palette.setColor(QPalette.Base, QColor(255, 255, 0)) e.widget.setPalette(palette) self.lblProgress.setText( self.tr('<b>Missing parameter value: %s</b>') % e.parameter.description) return except: QMessageBox.critical(self, self.tr('Unable to execute algorithm'), self.tr('Wrong or missing parameter values'))