Beispiel #1
0
    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.'))
Beispiel #2
0
    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.modelsFolder()
            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.scriptsFolder()
            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.RScriptsFolder()
            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.updateToolbox = False
        self.populateTree()
        self.buttonBox.accepted.connect(self.okPressed)
        self.buttonBox.rejected.connect(self.cancelPressed)
        self.tree.currentItemChanged.connect(self.currentItemChanged)
    def execute(self):
        settings = QSettings()
        lastDir = settings.value('Processing/lastModelsDir', '')
        filename = QFileDialog.getOpenFileName(
            self.toolbox, self.tr('Open model', 'AddModelFromFileAction'),
            lastDir,
            self.tr('Processing model files (*.model *.MODEL)',
                    'AddModelFromFileAction'))
        if filename:
            try:
                settings.setValue(
                    'Processing/lastModelsDir',
                    QFileInfo(filename).absoluteDir().absolutePath())

                ModelerAlgorithm.fromFile(filename)
            except WrongModelException:
                QMessageBox.warning(
                    self.toolbox,
                    self.tr('Error reading model', 'AddModelFromFileAction'),
                    self.tr('The selected file does not contain a valid model',
                            'AddModelFromFileAction'))
                return
            except:
                QMessageBox.warning(
                    self.toolbox,
                    self.tr('Error reading model', 'AddModelFromFileAction'),
                    self.tr('Cannot read file', 'AddModelFromFileAction'))
                return
            destFilename = os.path.join(ModelerUtils.modelsFolder(),
                                        os.path.basename(filename))
            shutil.copyfile(filename, destFilename)
            self.toolbox.updateProvider('model')
    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.modelsFolder()
            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.scriptsFolder()
            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.RScriptsFolder()
            self.urlBase = 'https://raw.githubusercontent.com/qgis/QGIS-Processing/master/rscripts/'
            self.icon = QIcon(os.path.join(pluginPath, 'images', 'r.png'))

        self.lastSelectedItem = None
        self.updateToolbox = False
        self.populateTree()
        self.buttonBox.accepted.connect(self.okPressed)
        self.buttonBox.rejected.connect(self.cancelPressed)
        self.tree.currentItemChanged.connect(self.currentItemChanged)
Beispiel #5
0
 def execute(self):
     filename = QtGui.QFileDialog.getOpenFileName(
         self.toolbox, self.tr('Open model', 'AddModelFromFileAction'),
         None,
         self.tr('Processing model files (*.model *.MODEL)',
                 'AddModelFromFileAction'))
     if filename:
         try:
             ModelerAlgorithm.fromFile(filename)
         except WrongModelException:
             QtGui.QMessageBox.warning(
                 self.toolbox,
                 self.tr('Error reading model', 'AddModelFromFileAction'),
                 self.tr('The selected file does not contain a valid model',
                         'AddModelFromFileAction'))
             return
         except:
             QtGui.QMessageBox.warning(
                 self.toolbox,
                 self.tr('Error reading model', 'AddModelFromFileAction'),
                 self.tr('Cannot read file', 'AddModelFromFileAction'))
         destFilename = os.path.join(ModelerUtils.modelsFolder(),
                                     os.path.basename(filename))
         shutil.copyfile(filename, destFilename)
         self.toolbox.updateProvider('model')
Beispiel #6
0
    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 execute(self):
     filename = QFileDialog.getOpenFileName(
         self.toolbox,
         self.tr("Open model", "AddModelFromFileAction"),
         None,
         self.tr("Processing model files (*.model *.MODEL)", "AddModelFromFileAction"),
     )
     if filename:
         try:
             ModelerAlgorithm.fromFile(filename)
         except WrongModelException:
             QMessageBox.warning(
                 self.toolbox,
                 self.tr("Error reading model", "AddModelFromFileAction"),
                 self.tr("The selected file does not contain a valid model", "AddModelFromFileAction"),
             )
             return
         except:
             QMessageBox.warning(
                 self.toolbox,
                 self.tr("Error reading model", "AddModelFromFileAction"),
                 self.tr("Cannot read file", "AddModelFromFileAction"),
             )
         destFilename = os.path.join(ModelerUtils.modelsFolder(), os.path.basename(filename))
         shutil.copyfile(filename, destFilename)
         self.toolbox.updateProvider("model")
    def execute(self):
        settings = QSettings()
        lastDir = settings.value('Processing/lastModelsDir', '')
        filename = QFileDialog.getOpenFileName(self.toolbox,
                                               self.tr('Open model', 'AddModelFromFileAction'), lastDir,
                                               self.tr('Processing model files (*.model *.MODEL)', 'AddModelFromFileAction'))
        if filename:
            try:
                settings.setValue('Processing/lastModelsDir',
                                  QFileInfo(filename).absoluteDir().absolutePath())

                ModelerAlgorithm.fromFile(filename)
            except WrongModelException:
                QMessageBox.warning(
                    self.toolbox,
                    self.tr('Error reading model', 'AddModelFromFileAction'),
                    self.tr('The selected file does not contain a valid model', 'AddModelFromFileAction'))
                return
            except:
                QMessageBox.warning(self.toolbox,
                                    self.tr('Error reading model', 'AddModelFromFileAction'),
                                    self.tr('Cannot read file', 'AddModelFromFileAction'))
                return
            destFilename = os.path.join(ModelerUtils.modelsFolder(), os.path.basename(filename))
            shutil.copyfile(filename, destFilename)
            self.toolbox.updateProvider('model')
Beispiel #9
0
 def initializeSettings(self):
     AlgorithmProvider.initializeSettings(self)
     ProcessingConfig.addSetting(
         Setting(self.getDescription(),
                 ModelerUtils.MODELS_FOLDER,
                 self.tr('Models folder', 'ModelerAlgorithmProvider'),
                 ModelerUtils.modelsFolder(),
                 valuetype=Setting.FOLDER))
Beispiel #10
0
 def execute(self):
     filename = QtGui.QFileDialog.getOpenFileName(self.toolbox, 'model files', None,
             '*.model')
     if filename:
         try:
             model = ModelerAlgorithm()
             model.openModel(filename)
         except WrongModelException:
             QtGui.QMessageBox.warning(self.toolbox, "Error reading model", "The selected file does not contain a valid model")
             return
         destFilename = os.path.join(ModelerUtils.modelsFolder(), os.path.basename(filename))
         shutil.copyfile(filename,destFilename)
         self.toolbox.updateProvider('script')
Beispiel #11
0
 def execute(self):
     filename = QtGui.QFileDialog.getOpenFileName(self.toolbox, 'model files', None,
             '*.model')
     if filename:
         try:
             ModelerAlgorithm.fromJsonFile(filename)
         except WrongModelException:
             QtGui.QMessageBox.warning(self.toolbox, "Error reading model", "The selected file does not contain a valid model")
             return
         except:
             QtGui.QMessageBox.warning(self.toolbox, "Error reading model", "Cannot read file")
         destFilename = os.path.join(ModelerUtils.modelsFolder(), os.path.basename(filename))
         shutil.copyfile(filename,destFilename)
         self.toolbox.updateProvider('script')
Beispiel #12
0
    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.modelsFolder(),
                    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
Beispiel #13
0
 def __init__(self, resourceType):
     QDialog.__init__(self, iface.mainWindow())
     self.resourceType = resourceType
     if self.resourceType == self.MODELS:
         self.folder = ModelerUtils.modelsFolder()
         self.urlBase = "https://raw.githubusercontent.com/qgis/QGIS-Processing/master/models/"
         self.icon = QtGui.QIcon(os.path.dirname(__file__) + '/../images/model.png')
     else:
         self.folder = ScriptUtils.scriptsFolder()
         self.urlBase = "https://raw.githubusercontent.com/qgis/QGIS-Processing/master/scripts/"
         self.icon = QtGui.QIcon(os.path.dirname(__file__) + '/../images/script.png')
     self.lastSelectedItem = None
     self.setupUi(self)
     self.populateTree()
     self.updateToolbox = False
     self.buttonBox.accepted.connect(self.okPressed)
     self.buttonBox.rejected.connect(self.cancelPressed)
     self.tree.currentItemChanged .connect(self.currentItemChanged)
Beispiel #14
0
    def __init__(self):
        self.provider = PSToolsAlgorithmProvider()

        settings = QSettings()
        version_settings = settings.value("/version", '')
        current_version = version()

        if version_settings != current_version:
            settings.setValue("/version", current_version)

            models_src_path = os.path.join(cmd_folder, 'models')
            models_dst_path = ModelerUtils.modelsFolder()

            for name in os.listdir(models_src_path):
                file_src_path = os.path.join(models_src_path, name)
                file_dst_path = os.path.join(models_dst_path, name)
                if os.path.exists(file_dst_path):
                    shutil.move(file_dst_path, file_dst_path + '.old')
                shutil.copy(file_src_path, file_dst_path)
    def __init__(self):
        self.provider = PermaclimAlgorithmProvider()
        return
        settings = QSettings()
        version_settings = settings.value( "/version", '')
        current_version = version()

        if version_settings != current_version:
            settings.setValue("/version", current_version)

            models_src_path = os.path.join(cmd_folder, 'models')
            models_dst_path = ModelerUtils.modelsFolder()

            for name in os.listdir(models_src_path):
                file_src_path = os.path.join(models_src_path, name)
                file_dst_path = os.path.join(models_dst_path, name)
                if os.path.exists(file_dst_path):
                    shutil.move(file_dst_path, file_dst_path+'.old')
                shutil.copy(file_src_path, file_dst_path)
Beispiel #16
0
    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.modelsFolder(),
                                                           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
Beispiel #17
0
 def __init__(self, resourceType):
     QDialog.__init__(self, iface.mainWindow())
     self.resourceType = resourceType
     if self.resourceType == self.MODELS:
         self.folder = ModelerUtils.modelsFolder()
         self.urlBase = "https://raw.githubusercontent.com/qgis/QGIS-Processing/master/models/"
         self.icon = QtGui.QIcon(
             os.path.dirname(__file__) + '/../images/model.png')
     else:
         self.folder = ScriptUtils.scriptsFolder()
         self.urlBase = "https://raw.githubusercontent.com/qgis/QGIS-Processing/master/scripts/"
         self.icon = QtGui.QIcon(
             os.path.dirname(__file__) + '/../images/script.png')
     self.lastSelectedItem = None
     self.setupUi(self)
     self.populateTree()
     self.updateToolbox = False
     self.buttonBox.accepted.connect(self.okPressed)
     self.buttonBox.rejected.connect(self.cancelPressed)
     self.tree.currentItemChanged.connect(self.currentItemChanged)
 def initializeSettings(self):
     AlgorithmProvider.initializeSettings(self)
     ProcessingConfig.addSetting(Setting(self.getDescription(), ModelerUtils.MODELS_FOLDER, "Models folder", ModelerUtils.modelsFolder()))
 def _loadAlgorithms(self):
     folder = ModelerUtils.modelsFolder()
     self.loadFromFolder(folder)
 def modelsFolder(self):
     return ModelerUtils.modelsFolder()
 def _loadAlgorithms(self):
     folder = ModelerUtils.modelsFolder()
     self.loadFromFolder(folder)
 def modelsFolder(self):
     return ModelerUtils.modelsFolder()
 def initializeSettings(self):
     AlgorithmProvider.initializeSettings(self)
     ProcessingConfig.addSetting(Setting(self.getDescription(),
                                         ModelerUtils.MODELS_FOLDER, self.tr('Models folder', 'ModelerAlgorithmProvider'),
                                         ModelerUtils.modelsFolder(), valuetype=Setting.FOLDER))
 def _loadAlgorithms(self):
     folder = ModelerUtils.modelsFolder()
     self.loadFromFolder(folder)
     folder = os.path.join(os.path.dirname(__file__), 'models')
     self.loadFromFolder(folder)
Beispiel #25
0
 def _loadAlgorithms(self):
     folder = ModelerUtils.modelsFolder()
     self.loadFromFolder(folder)
     folder = os.path.join(os.path.dirname(__file__), 'models')
     self.loadFromFolder(folder)
 def initializeSettings(self):
     AlgorithmProvider.initializeSettings(self)
     ProcessingConfig.addSetting(
         Setting(self.getDescription(), ModelerUtils.MODELS_FOLDER,
                 "Models folder", ModelerUtils.modelsFolder()))