diff --git a/python/console/console.py b/python/console/console.py index e7595ed601f..31e7cde563d 100644 --- a/python/console/console.py +++ b/python/console/console.py @@ -20,7 +20,7 @@ Some portions of code were taken from https://code.google.com/p/pydee/ """ import os -from PyQt4.QtCore import Qt, QTimer, QSettings, QCoreApplication, QSize, QByteArray, QFileInfo, SIGNAL, QUrl +from PyQt4.QtCore import Qt, QTimer, QSettings, QCoreApplication, QSize, QByteArray, QFileInfo, SIGNAL, QUrl, QDir from PyQt4.QtGui import QDockWidget, QToolBar, QToolButton, QWidget,\ QSplitter, QTreeWidget, QAction, QFileDialog, QCheckBox, QSizePolicy, QMenu, QGridLayout, QApplication, \ QDesktopServices @@ -627,7 +627,7 @@ class PythonConsoleWidget(QWidget): QDesktopServices.openUrl(QUrl.fromLocalFile(path)) def openScriptFile(self): - lastDirPath = self.settings.value("pythonConsole/lastDirPath", "") + lastDirPath = self.settings.value("pythonConsole/lastDirPath", QDir.home()) openFileTr = QCoreApplication.translate("PythonConsole", "Open File") fileList = QFileDialog.getOpenFileNames( self, openFileTr, lastDirPath, "Script file (*.py)") @@ -661,7 +661,9 @@ class PythonConsoleWidget(QWidget): if not index: index = self.tabEditorWidget.currentIndex() if not tabWidget.path: - pathFileName = self.tabEditorWidget.tabText(index) + '.py' + fileName = self.tabEditorWidget.tabText(index) + '.py' + folder = self.settings.value("pythonConsole/lastDirPath", QDir.home()) + pathFileName = os.path.join(folder,fileName) fileNone = True else: pathFileName = tabWidget.path diff --git a/python/console/console_editor.py b/python/console/console_editor.py index 8b990b68453..807ac7b2a82 100644 --- a/python/console/console_editor.py +++ b/python/console/console_editor.py @@ -19,7 +19,7 @@ email : lrssvtml (at) gmail (dot) com Some portions of code were taken from https://code.google.com/p/pydee/ """ -from PyQt4.QtCore import Qt, QObject, QEvent, QSettings, QCoreApplication, QFileInfo, QSize, SIGNAL +from PyQt4.QtCore import Qt, QObject, QEvent, QSettings, QCoreApplication, QFileInfo, QSize, QDir, SIGNAL from PyQt4.QtGui import QFont, QFontMetrics, QColor, QShortcut, QKeySequence, QMenu, QApplication, QCursor, QWidget, QGridLayout, QSpacerItem, QSizePolicy, QFileDialog, QTabWidget, QTreeWidgetItem, QFrame, QLabel, QToolButton, QMessageBox from PyQt4.Qsci import (QsciScintilla, QsciLexerPython, @@ -828,6 +828,8 @@ class EditorTab(QWidget): self.newEditor.lastModified = QFileInfo(path).lastModified() self.pc.updateTabListScript(path, action='append') self.tw.listObject(self) + lastDirPath = QFileInfo(path).path() + self.pc.settings.setValue("pythonConsole/lastDirPath", lastDirPath) def modified(self, modified): self.tw.tabModified(self, modified) @@ -1250,7 +1252,7 @@ class EditorTabWidget(QTabWidget): def changeLastDirPath(self, tab): tabWidget = self.widget(tab) - if tabWidget: + if tabWidget and tabWidget.path: self.settings.setValue("pythonConsole/lastDirPath", tabWidget.path) def widgetMessageBar(self, iface, text, level, timed=True):