def __init__(self, resourceType): super(GetScriptsAndModelsDialog, self).__init__(iface.mainWindow()) self.setupUi(self) self.manager = QgsNetworkAccessManager.instance() self.resourceType = resourceType if self.resourceType == self.MODELS: self.folder = ModelerUtils.defaultModelsFolder() self.urlBase = 'https://raw.githubusercontent.com/qgis/QGIS-Processing/master/models/' self.icon = QIcon(os.path.join(pluginPath, 'images', 'model.png')) elif self.resourceType == self.SCRIPTS: self.folder = ScriptUtils.defaultScriptsFolder() self.urlBase = 'https://raw.githubusercontent.com/qgis/QGIS-Processing/master/scripts/' self.icon = QIcon(os.path.join(pluginPath, 'images', 'script.png')) else: self.folder = RUtils.defaultRScriptsFolder() self.urlBase = 'https://raw.githubusercontent.com/qgis/QGIS-Processing/master/rscripts/' self.icon = QIcon(os.path.join(pluginPath, 'images', 'r.svg')) self.lastSelectedItem = None self.updateProvider = False self.populateTree() self.buttonBox.accepted.connect(self.okPressed) self.buttonBox.rejected.connect(self.cancelPressed) self.tree.currentItemChanged.connect(self.currentItemChanged)
def openModel(self): filename = unicode( QFileDialog.getOpenFileName( self, self.tr('Open Model'), ModelerUtils.defaultModelsFolder(), 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 initializeSettings(self): AlgorithmProvider.initializeSettings(self) ProcessingConfig.addSetting( Setting(self.getDescription(), ModelerUtils.MODELS_FOLDER, self.tr('Models folder', 'ModelerAlgorithmProvider'), ModelerUtils.defaultModelsFolder(), valuetype=Setting.MULTIPLE_FOLDERS))
def load(self): ProcessingConfig.settingIcons[self.name()] = self.icon() ProcessingConfig.addSetting(Setting(self.name(), ModelerUtils.MODELS_FOLDER, self.tr('Models folder', 'ModelerAlgorithmProvider'), ModelerUtils.defaultModelsFolder(), valuetype=Setting.MULTIPLE_FOLDERS)) ProviderActions.registerProviderActions(self, self.actions) ProviderContextMenuActions.registerProviderContextMenuActions(self.contextMenuActions) ProcessingConfig.readSettings() self.refreshAlgorithms() return True
def initializeSettings(self): AlgorithmProvider.initializeSettings(self) ProcessingConfig.addSetting( Setting( self.getDescription(), ModelerUtils.MODELS_FOLDER, self.tr("Models folder", "ModelerAlgorithmProvider"), ModelerUtils.defaultModelsFolder(), valuetype=Setting.MULTIPLE_FOLDERS, ) )
def saveModel(self, saveAs): if unicode(self.textGroup.text()).strip() == "" or unicode(self.textName.text()).strip() == "": QMessageBox.warning(self, self.tr("Warning"), self.tr("Please enter group and model names before saving")) return self.alg.name = unicode(self.textName.text()) self.alg.group = unicode(self.textGroup.text()) if self.alg.descriptionFile is not None and not saveAs: filename = self.alg.descriptionFile else: filename = unicode( QFileDialog.getSaveFileName( self, self.tr("Save Model"), ModelerUtils.defaultModelsFolder(), self.tr("Processing models (*.model)"), ) ) if filename: if not filename.endswith(".model"): filename += ".model" self.alg.descriptionFile = filename if filename: text = self.alg.toJson() try: fout = codecs.open(filename, "w", encoding="utf-8") except: if saveAs: QMessageBox.warning( self, self.tr("I/O error"), self.tr("Unable to save edits. Reason:\n %s") % unicode(sys.exc_info()[1]), ) else: QMessageBox.warning( self, self.tr("Can't save model"), self.tr( "This model can't be saved in its " "original location (probably you do not " "have permission to do it). Please, use " "the 'Save as...' option." ), ) return fout.write(text) fout.close() self.update = True QMessageBox.information(self, self.tr("Model saved"), self.tr("Model was correctly saved.")) self.hasChanged = False
def saveModel(self, saveAs): if unicode(self.textGroup.text()).strip() == '' \ or unicode(self.textName.text()).strip() == '': QMessageBox.warning( self, self.tr('Warning'), self.tr('Please enter group and model names before saving')) return self.alg.name = unicode(self.textName.text()) self.alg.group = unicode(self.textGroup.text()) if self.alg.descriptionFile is not None and not saveAs: filename = self.alg.descriptionFile else: filename = unicode( QFileDialog.getSaveFileName( self, self.tr('Save Model'), ModelerUtils.defaultModelsFolder(), self.tr('Processing models (*.model)'))) if filename: if not filename.endswith('.model'): filename += '.model' self.alg.descriptionFile = filename if filename: text = self.alg.toJson() try: fout = codecs.open(filename, 'w', encoding='utf-8') except: if saveAs: QMessageBox.warning( self, self.tr('I/O error'), self.tr('Unable to save edits. Reason:\n %s') % unicode(sys.exc_info()[1])) else: QMessageBox.warning( self, self.tr("Can't save model"), self.tr("This model can't be saved in its " "original location (probably you do not " "have permission to do it). Please, use " "the 'Save as...' option.")) return fout.write(text) fout.close() self.update = True QMessageBox.information(self, self.tr('Model saved'), self.tr('Model was correctly saved.')) self.hasChanged = False
def openModel(self): filename = unicode( QFileDialog.getOpenFileName( self, self.tr("Open Model"), ModelerUtils.defaultModelsFolder(), 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 initializeSettings(self): AlgorithmProvider.initializeSettings(self) ProcessingConfig.addSetting(Setting(self.name(), ModelerUtils.MODELS_FOLDER, self.tr('Models folder', 'ModelerAlgorithmProvider'), ModelerUtils.defaultModelsFolder(), valuetype=Setting.MULTIPLE_FOLDERS))