Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
sextante file dialog now remembers last used folder
  • Loading branch information
volaya committed Jan 12, 2013
1 parent 59b1d8d commit 5b431df
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
19 changes: 17 additions & 2 deletions python/plugins/sextante/gui/FileSelectionPanel.py
Expand Up @@ -23,6 +23,7 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os
from PyQt4 import QtGui, QtCore
from sextante.core.SextanteUtils import SextanteUtils

Expand All @@ -44,14 +45,28 @@ def __init__(self, isFolder):
self.setLayout(self.horizontalLayout)

def showSelectionDialog(self):
# find the file dialog's working directory
settings = QtCore.QSettings()
text = str(self.text.text())
if os.path.isdir(text):
path = text
elif os.path.isdir( os.path.dirname(text) ):
path = os.path.dirname(text)
elif settings.contains("/SextanteQGIS/LastInputPath"):
path = str(settings.value( "/SextanteQGIS/LastInputPath",QtCore.QVariant( "" ) ).toString())
else:
path = ""

if self.isFolder:
folder = QtGui.QFileDialog.getExistingDirectory (self, "Select folder")
folder = QtGui.QFileDialog.getExistingDirectory (self, "Select folder", path)
if folder:
self.text.setText(str(folder))
settings.setValue("/SextanteQGIS/LastInputPath", os.path.dirname(str(folder)))
else:
filenames = QtGui.QFileDialog.getOpenFileNames(self, "Open file", QtCore.QString(""), "*.*")
filenames = QtGui.QFileDialog.getOpenFileNames(self, "Open file", path, "*.*")
if filenames:
self.text.setText(str(filenames.join(";")))
settings.setValue("/SextanteQGIS/LastInputPath", os.path.dirname(str(filenames[0])))

def getValue(self):
s = str(self.text.text())
Expand Down
16 changes: 15 additions & 1 deletion python/plugins/sextante/gui/InputLayerSelectorPanel.py
Expand Up @@ -23,6 +23,7 @@
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'

import os
from PyQt4 import QtGui, QtCore

class InputLayerSelectorPanel(QtGui.QWidget):
Expand All @@ -44,10 +45,23 @@ def __init__(self, options):
self.setLayout(self.horizontalLayout)

def showSelectionDialog(self):
filename = QtGui.QFileDialog.getOpenFileName(self, "All files", "", "*.*")
# find the file dialog's working directory
settings = QtCore.QSettings()
text = str(self.text.currentText())
if os.path.isdir(text):
path = text
elif os.path.isdir( os.path.dirname(text) ):
path = os.path.dirname(text)
elif settings.contains("/SextanteQGIS/LastInputPath"):
path = str(settings.value( "/SextanteQGIS/LastInputPath",QtCore.QVariant( "" ) ).toString())
else:
path = ""

filename = QtGui.QFileDialog.getOpenFileName(self, "All files", path, "*.*")
if filename:
self.text.addItem(filename, filename)
self.text.setCurrentIndex(self.text.count() - 1)
settings.setValue("/SextanteQGIS/LastInputPath", os.path.dirname(str(filename)))

def getValue(self):
return self.text.itemData(self.text.currentIndex()).toPyObject()

0 comments on commit 5b431df

Please sign in to comment.