Skip to content

Commit 46da64a

Browse files
committed
[console] Better handling of default paths for open/save dialogs
1 parent 15e452e commit 46da64a

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

python/console/console.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"""
2121
import os
2222

23-
from PyQt4.QtCore import Qt, QTimer, QSettings, QCoreApplication, QSize, QByteArray, QFileInfo, SIGNAL, QUrl
23+
from PyQt4.QtCore import Qt, QTimer, QSettings, QCoreApplication, QSize, QByteArray, QFileInfo, SIGNAL, QUrl, QDir
2424
from PyQt4.QtGui import QDockWidget, QToolBar, QToolButton, QWidget,\
2525
QSplitter, QTreeWidget, QAction, QFileDialog, QCheckBox, QSizePolicy, QMenu, QGridLayout, QApplication, \
2626
QDesktopServices
@@ -627,7 +627,7 @@ def openScriptFileExtEditor(self):
627627
QDesktopServices.openUrl(QUrl.fromLocalFile(path))
628628

629629
def openScriptFile(self):
630-
lastDirPath = self.settings.value("pythonConsole/lastDirPath", "")
630+
lastDirPath = self.settings.value("pythonConsole/lastDirPath", QDir.home())
631631
openFileTr = QCoreApplication.translate("PythonConsole", "Open File")
632632
fileList = QFileDialog.getOpenFileNames(
633633
self, openFileTr, lastDirPath, "Script file (*.py)")
@@ -661,7 +661,9 @@ def saveAsScriptFile(self, index=None):
661661
if not index:
662662
index = self.tabEditorWidget.currentIndex()
663663
if not tabWidget.path:
664-
pathFileName = self.tabEditorWidget.tabText(index) + '.py'
664+
fileName = self.tabEditorWidget.tabText(index) + '.py'
665+
folder = self.settings.value("pythonConsole/lastDirPath", QDir.home())
666+
pathFileName = os.path.join(folder,fileName)
665667
fileNone = True
666668
else:
667669
pathFileName = tabWidget.path

python/console/console_editor.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
Some portions of code were taken from https://code.google.com/p/pydee/
2020
"""
2121

22-
from PyQt4.QtCore import Qt, QObject, QEvent, QSettings, QCoreApplication, QFileInfo, QSize, SIGNAL
22+
from PyQt4.QtCore import Qt, QObject, QEvent, QSettings, QCoreApplication, QFileInfo, QSize, QDir, SIGNAL
2323
from PyQt4.QtGui import QFont, QFontMetrics, QColor, QShortcut, QKeySequence, QMenu, QApplication, QCursor, QWidget, QGridLayout, QSpacerItem, QSizePolicy, QFileDialog, QTabWidget, QTreeWidgetItem, QFrame, QLabel, QToolButton, QMessageBox
2424
from PyQt4.Qsci import (QsciScintilla,
2525
QsciLexerPython,
@@ -828,6 +828,8 @@ def save(self, fileName=None):
828828
self.newEditor.lastModified = QFileInfo(path).lastModified()
829829
self.pc.updateTabListScript(path, action='append')
830830
self.tw.listObject(self)
831+
lastDirPath = QFileInfo(path).path()
832+
self.pc.settings.setValue("pythonConsole/lastDirPath", lastDirPath)
831833

832834
def modified(self, modified):
833835
self.tw.tabModified(self, modified)
@@ -1250,7 +1252,7 @@ def refreshSettingsEditor(self):
12501252

12511253
def changeLastDirPath(self, tab):
12521254
tabWidget = self.widget(tab)
1253-
if tabWidget:
1255+
if tabWidget and tabWidget.path:
12541256
self.settings.setValue("pythonConsole/lastDirPath", tabWidget.path)
12551257

12561258
def widgetMessageBar(self, iface, text, level, timed=True):

0 commit comments

Comments
 (0)