Skip to content

Commit

Permalink
Remember last used folder for processing batch save/load
Browse files Browse the repository at this point in the history
Fixes #16310
  • Loading branch information
nyalldawson committed Nov 10, 2017
1 parent 9bac962 commit 8526a2d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions python/plugins/processing/gui/BatchPanel.py
Expand Up @@ -31,8 +31,9 @@

from qgis.PyQt import uic
from qgis.PyQt.QtWidgets import QTableWidgetItem, QComboBox, QHeaderView, QFileDialog, QMessageBox

from qgis.PyQt.QtCore import QDir, QFileInfo
from qgis.core import (QgsApplication,
QgsSettings,
QgsProcessingParameterDefinition)
from qgis.gui import QgsMessageBar
from processing.gui.wrappers import WidgetWrapperFactory
Expand Down Expand Up @@ -142,10 +143,14 @@ def initWidgets(self):
self.tblParameters.horizontalHeader().setStretchLastSection(True)

def load(self):
settings = QgsSettings()
last_path = settings.value("/Processing/LastBatchPath", QDir.homePath())
filename, selected_filter = QFileDialog.getOpenFileName(self,
self.tr('Open Batch'), None,
self.tr('Open Batch'), last_path,
self.tr('JSON files (*.json)'))
if filename:
last_path = QFileInfo(filename).path()
settings.setValue('/Processing/LastBatchPath', last_path)
with open(filename) as f:
values = json.load(f)
else:
Expand Down Expand Up @@ -216,13 +221,17 @@ def save(self):
return
toSave.append({self.PARAMETERS: algParams, self.OUTPUTS: algOutputs})

settings = QgsSettings()
last_path = settings.value("/Processing/LastBatchPath", QDir.homePath())
filename, __ = QFileDialog.getSaveFileName(self,
self.tr('Save Batch'),
None,
last_path,
self.tr('JSON files (*.json)'))
if filename:
if not filename.endswith('.json'):
filename += '.json'
last_path = QFileInfo(filename).path()
settings.setValue('/Processing/LastBatchPath', last_path)
with open(filename, 'w') as f:
json.dump(toSave, f)

Expand Down

0 comments on commit 8526a2d

Please sign in to comment.