Skip to content

Commit

Permalink
added remember last used dir for open tool in python console
Browse files Browse the repository at this point in the history
  • Loading branch information
slarosa committed Sep 13, 2012
1 parent 39db80a commit c0c8f81
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions python/console.py
Expand Up @@ -197,15 +197,20 @@ def iface(self):
self.edit.commandConsole('iface')

def openScriptFile(self):
settings = QSettings()
lastDirPath = settings.value("/pythonConsole/lastDirPath").toString()
scriptFile = QFileDialog.getOpenFileName(
self, "Open File", "", "Script file (*.py)")
self, "Open File", lastDirPath, "Script file (*.py)")
if scriptFile.isEmpty() == False:
oF = open(scriptFile, 'r')
listScriptFile = []
for line in oF:
if line != "\n":
listScriptFile.append(line)
self.edit.insertTextFromFile(listScriptFile)

lastDirPath = QFileInfo(scriptFile).path()
settings.setValue("/pythonConsole/lastDirPath", QVariant(scriptFile))


def saveScriptFile(self):
Expand All @@ -223,13 +228,10 @@ def saveScriptFile(self):
is_first_line = True
for s in listText:
if s[0:3] in (">>>", "..."):
s.replace(">>> ", "")
s.replace("... ", "")
s.replace(">>> ", "").replace("... ", "")
if is_first_line:
# see, no write() in this branch
is_first_line = False
else:
# we've just written a line; add a newline
sF.write('\n')
sF.write(s)
sF.close()
Expand Down

0 comments on commit c0c8f81

Please sign in to comment.