Skip to content
Permalink
Browse files

[console] Better handling of default paths for open/save dialogs

  • Loading branch information
nyalldawson committed Aug 18, 2015
1 parent 15e452e commit 46da64a88eade97adf3c4b9ccfa0f287f9393c3d
Showing with 9 additions and 5 deletions.
  1. +5 −3 python/console/console.py
  2. +4 −2 python/console/console_editor.py
@@ -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
@@ -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)")
@@ -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
@@ -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,
@@ -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)
@@ -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):

0 comments on commit 46da64a

Please sign in to comment.
You can’t perform that action at this time.