I don't know if it is elegant but it works
Code:
def _selectInputFile(self):
# begin by getting the directory from last time
# initial value in case the value can not be read from the config file
theInputDir = ""
# if the configuration file exists and has a directory saved
if os.path.exists(configFile):
# Initialise all the fields from the .conf file
config = ConfigParser.ConfigParser()
config.read(configFile) #(configFile is global)
# if the section "dirs" exists in the .conf file
if config.has_section("dirs"):
# if an entry exists then add the value to the form
if config.has_option("dirs", "inputdir"):
theInputDir = config.get("dirs", "inputdir")
filename=QFileDialog.getOpenFileName(theInputDir, "*.*", self, "Source File")
if filename:
self.lineEditInputFile.setText(filename)
inputDirName=os.path.dirname(filename.ascii())
self.textEditInfo.append('Input Dir: ' + inputDirName)
# write the directory to the config file for next time
config = ConfigParser.ConfigParser()
config.read(configFile)
if not config.has_section("dirs"):
config.add_section("dirs")
config.set("dirs", "inputdir", inputDirName)
fpConf=open(configFile, "w") #(configFile is global)
config.write(fpConf)
fpConf.close()
Bookmarks