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

This commit is contained in:
Nyall Dawson 2015-08-18 15:12:22 +10:00
parent 15e452e918
commit 46da64a88e
2 changed files with 9 additions and 5 deletions

View File

@ -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

View File

@ -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):