Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[console] Better handling of default paths for open/save dialogs
  • Loading branch information
nyalldawson committed Aug 18, 2015
1 parent 15e452e commit 46da64a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 5 additions & 3 deletions python/console/console.py
Expand Up @@ -20,7 +20,7 @@
"""
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
Expand Down Expand Up @@ -627,7 +627,7 @@ def openScriptFileExtEditor(self):
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)")
Expand Down Expand Up @@ -661,7 +661,9 @@ def saveAsScriptFile(self, index=None):
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
Expand Down
6 changes: 4 additions & 2 deletions python/console/console_editor.py
Expand Up @@ -19,7 +19,7 @@
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,
Expand Down Expand Up @@ -828,6 +828,8 @@ def save(self, fileName=None):
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)
Expand Down Expand Up @@ -1250,7 +1252,7 @@ def refreshSettingsEditor(self):

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):
Expand Down

0 comments on commit 46da64a

Please sign in to comment.