Skip to content

Commit

Permalink
[processing] allow selecting multiple file in ‘add script from file’
Browse files Browse the repository at this point in the history
  • Loading branch information
volaya committed Dec 1, 2016
1 parent 91d0f1e commit 2c4eb3c
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions python/plugins/processing/script/AddScriptFromFileAction.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,28 @@ def getIcon(self):
def execute(self):
settings = QSettings()
lastDir = settings.value('Processing/lastScriptsDir', '')
filename, selected_filter = QFileDialog.getOpenFileName(self.toolbox,
filenames, selected_filter = QFileDialog.getOpenFileNames(self.toolbox,
self.tr('Script files', 'AddScriptFromFileAction'), lastDir,
self.tr('Script files (*.py *.PY)', 'AddScriptFromFileAction'))
if filename:
try:
settings.setValue('Processing/lastScriptsDir',
QFileInfo(filename).absoluteDir().absolutePath())
script = ScriptAlgorithm(filename)
except WrongScriptException:
if filenames:
validAlgs = 0
wrongAlgs = []
for filename in filenames:
try:
settings.setValue('Processing/lastScriptsDir',
QFileInfo(filename).absoluteDir().absolutePath())
script = ScriptAlgorithm(filename)
destFilename = os.path.join(ScriptUtils.scriptsFolders()[0], os.path.basename(filename))
with open(destFilename, 'w') as f:
f.write(script.script)
validAlgs += 1
except WrongScriptException:
wrongAlgs.append(os.path.basename(filename))
if validAlgs:
algList.reloadProvider('script')
if wrongAlgs:
QMessageBox.warning(self.toolbox,
self.tr('Error reading script', 'AddScriptFromFileAction'),
self.tr('The selected file does not contain a valid script', 'AddScriptFromFileAction'))
return
destFilename = os.path.join(ScriptUtils.scriptsFolders()[0], os.path.basename(filename))
with open(destFilename, 'w') as f:
f.write(script.script)
algList.reloadProvider('script')
self.tr('Error reading scripts', 'AddScriptFromFileAction'),
self.tr('The following files do not contain a valid script:\n-', 'AddScriptFromFileAction')
+ "\n-".join(wrongAlgs))

0 comments on commit 2c4eb3c

Please sign in to comment.