def testDefaultScriptsFolder(self):
     """
     Tests default user scripts folder
     """
     self.assertTrue(RUtils.default_scripts_folder())
     self.assertIn('rscripts', RUtils.default_scripts_folder())
     self.assertTrue(os.path.exists(RUtils.default_scripts_folder()))
Beispiel #2
0
    def saveScript(self, saveAs):
        newPath = None
        if self.filePath is None or saveAs:
            scriptDir = RUtils.default_scripts_folder()
            newPath, _ = QFileDialog.getSaveFileName(self,
                                                     self.tr("Save script"),
                                                     scriptDir,
                                                     self.tr("R scripts (*.rsx *.RSX)"))

            if newPath:
                if not newPath.lower().endswith(".rsx"):
                    newPath += ".rsx"

                self.filePath = newPath

        if self.filePath:
            text = self.editor.text()
            try:
                with codecs.open(self.filePath, "w", encoding="utf-8") as f:
                    f.write(text)
            except IOError as e:
                QMessageBox.warning(self,
                                    self.tr("I/O error"),
                                    self.tr("Unable to save edits:\n{}").format(str(e))
                                    )
                return

            self.setHasChanged(False)

        QgsApplication.processingRegistry().providerById("r").refreshAlgorithms()
 def testScriptsFolders(self):
     """
     Test script folders
     """
     self.assertTrue(RUtils.script_folders())
     self.assertIn(RUtils.default_scripts_folder(), RUtils.script_folders())
     self.assertIn(RUtils.builtin_scripts_folder(), RUtils.script_folders())
Beispiel #4
0
    def load(self):
        """
        Called when first loading provider
        """
        ProcessingConfig.settingIcons[self.name()] = self.icon()
        ProcessingConfig.addSetting(
            Setting(self.name(),
                    RUtils.RSCRIPTS_FOLDER,
                    self.tr('R scripts folder'),
                    RUtils.default_scripts_folder(),
                    valuetype=Setting.MULTIPLE_FOLDERS))

        ProcessingConfig.addSetting(
            Setting(
                self.name(), RUtils.R_USE_USER_LIB,
                self.tr('Use user library folder instead of system libraries'),
                True))
        ProcessingConfig.addSetting(
            Setting(self.name(),
                    RUtils.R_LIBS_USER,
                    self.tr('User library folder'),
                    RUtils.r_library_folder(),
                    valuetype=Setting.FOLDER))

        ProcessingConfig.addSetting(
            Setting(self.name(),
                    RUtils.R_REPO,
                    self.tr('Package repository'),
                    "http://cran.at.r-project.org/",
                    valuetype=Setting.STRING))

        ProcessingConfig.addSetting(
            Setting(self.name(),
                    RUtils.R_FOLDER,
                    self.tr('R folder'),
                    RUtils.r_binary_folder(),
                    valuetype=Setting.FOLDER))

        if RUtils.is_windows():
            ProcessingConfig.addSetting(
                Setting(self.name(), RUtils.R_USE64,
                        self.tr('Use 64 bit version'), False))

        ProviderActions.registerProviderActions(self, self.actions)
        ProviderContextMenuActions.registerProviderContextMenuActions(
            self.contextMenuActions)
        ProcessingConfig.readSettings()
        self.refreshAlgorithms()
        self.r_version = RUtils.get_r_version()
        return True
Beispiel #5
0
    def openScript(self):
        if self.hasChanged:
            ret = QMessageBox.warning(self,
                                      self.tr("Unsaved changes"),
                                      self.tr("There are unsaved changes in the script. Continue?"),
                                      QMessageBox.Yes | QMessageBox.No, QMessageBox.No)
            if ret == QMessageBox.No:
                return

        scriptDir = RUtils.default_scripts_folder()
        fileName, _ = QFileDialog.getOpenFileName(self,
                                                  self.tr("Open script"),
                                                  scriptDir,
                                                  self.tr("R scripts (*.rsx *.RSX)"))

        if fileName == "":
            return

        with OverrideCursor(Qt.WaitCursor):
            self._loadFile(fileName)