Skip to content
Permalink
Browse files
sextante file dialog now remembers last used folder
  • Loading branch information
volaya committed Jan 12, 2013
1 parent 59b1d8d commit 5b431dfaf4838bda4388beeb575d0270c85cceeb
Showing with 32 additions and 3 deletions.
  1. +17 −2 python/plugins/sextante/gui/FileSelectionPanel.py
  2. +15 −1 python/plugins/sextante/gui/InputLayerSelectorPanel.py
@@ -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

@@ -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())
@@ -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):
@@ -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.