Skip to content
Permalink
Browse files

[processing] always use user-defined default folder for scripts/models

(cherry picked from commit 48cca3b)

Conflicts:
	python/plugins/processing/modeler/AddModelFromFileAction.py
	python/plugins/processing/script/AddScriptFromFileAction.py
  • Loading branch information
alexbruy committed Aug 4, 2016
1 parent 982eaa5 commit 5dba2e6d9c2cdfe7cccf559b37c2b267d8e1e45d
@@ -129,15 +129,15 @@ def __init__(self, resourceType):

self.resourceType = resourceType
if self.resourceType == self.MODELS:
self.folder = ModelerUtils.defaultModelsFolder()
self.folder = ModelerUtils.modelsFolders()[0]
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.folder = ScriptUtils.scriptsFolders()[0]
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.folder = RUtils.RScriptsFolders()[0]
self.urlBase = 'https://raw.githubusercontent.com/qgis/QGIS-Processing/master/rscripts/'
self.icon = QIcon(os.path.join(pluginPath, 'images', 'r.svg'))

@@ -193,10 +193,10 @@ def openScript(self):
return

if self.algType == self.SCRIPT_PYTHON:
scriptDir = ScriptUtils.defaultScriptsFolder()
scriptDir = ScriptUtils.scriptsFolders()[0]
filterName = self.tr('Python scripts (*.py)')
elif self.algType == self.SCRIPT_R:
scriptDir = RUtils.defaultRScriptsFolder()
scriptDir = RUtils.RScriptsFolders()[0]
filterName = self.tr('Processing R script (*.rsx)')

self.filename = QFileDialog.getOpenFileName(
@@ -224,10 +224,10 @@ def saveAs(self):
def saveScript(self, saveAs):
if self.filename is None or saveAs:
if self.algType == self.SCRIPT_PYTHON:
scriptDir = ScriptUtils.defaultScriptsFolder()
scriptDir = ScriptUtils.scriptsFolders()[0]
filterName = self.tr('Python scripts (*.py)')
elif self.algType == self.SCRIPT_R:
scriptDir = RUtils.defaultRScriptsFolder()
scriptDir = RUtils.RScriptsFolders()[0]
filterName = self.tr('Processing R script (*.rsx)')

self.filename = unicode(QFileDialog.getSaveFileName(self,
@@ -71,6 +71,6 @@ def execute(self):
self.tr('Error reading model', 'AddModelFromFileAction'),
self.tr('Cannot read file', 'AddModelFromFileAction'))
return
destFilename = os.path.join(ModelerUtils.modelsFolder(), os.path.basename(filename))
destFilename = os.path.join(ModelerUtils.modelsFolders()[0], os.path.basename(filename))
shutil.copyfile(filename, destFilename)
algList.reloadProvider('model')
@@ -310,7 +310,7 @@ def saveModel(self, saveAs):
else:
filename = unicode(QFileDialog.getSaveFileName(self,
self.tr('Save Model'),
ModelerUtils.defaultModelsFolder(),
ModelerUtils.modelsFolders()[0],
self.tr('Processing models (*.model)')))
if filename:
if not filename.endswith('.model'):
@@ -341,7 +341,7 @@ def saveModel(self, saveAs):

def openModel(self):
filename = unicode(QFileDialog.getOpenFileName(self,
self.tr('Open Model'), ModelerUtils.defaultModelsFolder(),
self.tr('Open Model'), ModelerUtils.modelsFolders()[0],
self.tr('Processing models (*.model *.MODEL)')))
if filename:
try:
@@ -65,7 +65,7 @@ def execute(self):
self.tr('Error reading script', 'AddScriptFromFileAction'),
self.tr('The selected file does not contain a valid script', 'AddScriptFromFileAction'))
return
destFilename = os.path.join(ScriptUtils.scriptsFolder(), os.path.basename(filename))
destFilename = os.path.join(ScriptUtils.scriptsFolders()[0], os.path.basename(filename))
with open(destFilename, 'w') as f:
f.write(script.script)
algList.reloadProvider('script')

0 comments on commit 5dba2e6

Please sign in to comment.
You can’t perform that action at this time.