[pyqgis-console] uses QFileInfo instead of os.path to check if file exists

- minor fixes and cleanup
This commit is contained in:
Salvatore Larosa 2013-05-16 01:05:51 +02:00
parent 02ab02746a
commit 0175a8053d
4 changed files with 20 additions and 36 deletions

View File

@ -90,6 +90,8 @@ class PythonConsoleWidget(QWidget):
QWidget.__init__(self, parent)
self.setWindowTitle(QCoreApplication.translate("PythonConsole", "Python Console"))
self.settings = QSettings()
self.options = optionsDialog(self)
self.helpDlg = HelpDialog(self)
@ -242,7 +244,8 @@ class PythonConsoleWidget(QWidget):
objList = QCoreApplication.translate("PythonConsole", "Object Inspector")
self.objectListButton = QAction(self)
self.objectListButton.setCheckable(True)
self.objectListButton.setEnabled(True)
self.objectListButton.setEnabled(self.settings.value("pythonConsole/enableObjectInsp",
False).toBool())
self.objectListButton.setIcon(QgsApplication.getThemeIcon("console/iconClassBrowserConsole.png"))
self.objectListButton.setMenuRole(QAction.PreferencesRole)
self.objectListButton.setIconVisibleInMenu(True)
@ -467,7 +470,7 @@ class PythonConsoleWidget(QWidget):
self.layoutFind.setContentsMargins(0, 0, 0, 0)
self.lineEditFind = QgsFilterLineEdit()
placeHolderTxt = QCoreApplication.translate("PythonConsole", "Enter text to find...")
if pyqtconfig.Configuration().qt_version >= 0x40700:
self.lineEditFind.setPlaceholderText(placeHolderTxt)
else:
@ -596,8 +599,7 @@ class PythonConsoleWidget(QWidget):
self.tabEditorWidget.currentWidget().newEditor.commentEditorCode(False)
def openScriptFile(self):
settings = QSettings()
lastDirPath = settings.value("pythonConsole/lastDirPath").toString()
lastDirPath = self.settings.value("pythonConsole/lastDirPath").toString()
openFileTr = QCoreApplication.translate("PythonConsole", "Open File")
filename = QFileDialog.getOpenFileName(
self, openFileTr, lastDirPath, "Script file (*.py)")
@ -612,7 +614,7 @@ class PythonConsoleWidget(QWidget):
self.tabEditorWidget.newTabEditor(tabName, filename)
lastDirPath = QFileInfo(filename).path()
settings.setValue("pythonConsole/lastDirPath", QVariant(filename))
self.settings.setValue("pythonConsole/lastDirPath", QVariant(filename))
self.updateTabListScript(filename, action='append')
def saveScriptFile(self):
@ -678,7 +680,6 @@ class PythonConsoleWidget(QWidget):
self.tabEditorWidget.widgetMessageBar(iface, text, level, timed)
def updateTabListScript(self, script, action=None):
settings = QSettings()
if action == 'remove':
self.tabListScript.remove(script)
elif action == 'append':
@ -686,25 +687,20 @@ class PythonConsoleWidget(QWidget):
self.tabListScript.append(script)
else:
self.tabListScript = []
settings.setValue("pythonConsole/tabScripts",
self.settings.setValue("pythonConsole/tabScripts",
QVariant(self.tabListScript))
def saveSettingsConsole(self):
settings = QSettings()
#settings.setValue("pythonConsole/geometry", self.saveGeometry())
settings.setValue("pythonConsole/splitterObj", self.splitterObj.saveState())
settings.setValue("pythonConsole/splitterEditor", self.splitterEditor.saveState())
self.settings.setValue("pythonConsole/splitterObj", self.splitterObj.saveState())
self.settings.setValue("pythonConsole/splitterEditor", self.splitterEditor.saveState())
self.shell.writeHistoryFile()
def restoreSettingsConsole(self):
# List for tab script
settings = QSettings()
storedTabScripts = settings.value("pythonConsole/tabScripts")
storedTabScripts = self.settings.value("pythonConsole/tabScripts")
self.tabListScript = storedTabScripts.toList()
#self.restoreGeometry(settings.value("pythonConsole/geometry").toByteArray())
self.splitterEditor.restoreState(settings.value("pythonConsole/splitterEditor").toByteArray())
self.splitterObj.restoreState(settings.value("pythonConsole/splitterObj").toByteArray())
self.splitterEditor.restoreState(self.settings.value("pythonConsole/splitterEditor").toByteArray())
self.splitterObj.restoreState(self.settings.value("pythonConsole/splitterObj").toByteArray())
if __name__ == '__main__':
a = QApplication(sys.argv)

View File

@ -266,7 +266,6 @@ class Editor(QsciScintilla):
iconRun = QgsApplication.getThemeIcon("console/iconRunConsole.png")
iconRunScript = QgsApplication.getThemeIcon("console/iconRunScriptConsole.png")
iconCodePad = QgsApplication.getThemeIcon("console/iconCodepadConsole.png")
#iconNewEditor = QgsApplication.getThemeIcon("console/iconTabEditorConsole.png")
iconCommentEditor = QgsApplication.getThemeIcon("console/iconCommentEditorConsole.png")
iconUncommentEditor = QgsApplication.getThemeIcon("console/iconUncommentEditorConsole.png")
iconSettings = QgsApplication.getThemeIcon("console/iconSettingsConsole.png")
@ -274,12 +273,6 @@ class Editor(QsciScintilla):
iconSyntaxCk = QgsApplication.getThemeIcon("console/iconSyntaxErrorConsole.png")
hideEditorAction = menu.addAction("Hide Editor",
self.hideEditor)
# menu.addSeparator()
# newTabAction = menu.addAction(iconNewEditor,
# "New Tab",
# self.parent.newTab, 'Ctrl+T')
# closeTabAction = menu.addAction("Close Tab",
# self.parent.close, 'Ctrl+W')
menu.addSeparator()
syntaxCheck = menu.addAction(iconSyntaxCk, "Check Syntax",
self.syntaxCheck, 'Ctrl+4')
@ -333,11 +326,8 @@ class Editor(QsciScintilla):
runSelected.setEnabled(False)
copyAction.setEnabled(False)
selectAllAction.setEnabled(False)
# closeTabAction.setEnabled(False)
undoAction.setEnabled(False)
redoAction.setEnabled(False)
# if self.parent.tw.count() > 1:
# closeTabAction.setEnabled(True)
if self.hasSelectedText():
runSelected.setEnabled(True)
copyAction.setEnabled(True)
@ -622,7 +612,7 @@ class Editor(QsciScintilla):
def focusInEvent(self, e):
pathfile = self.parent.path
if pathfile:
if not os.path.exists(pathfile):
if not QFileInfo(pathfile).exists():
msgText = QCoreApplication.translate('PythonConsole',
'The file <b>"%1"</b> has been deleted or is not accessible') \
.arg(unicode(pathfile))
@ -672,7 +662,7 @@ class EditorTab(QWidget):
self.newEditor = Editor(self)
if filename:
self.path = filename
if os.path.exists(filename):
if QFileInfo(filename).exists():
self.loadFile(filename, False)
# Creates layout for message bar
@ -726,7 +716,7 @@ class EditorTab(QWidget):
self.pc.callWidgetMessageBarEditor(msgText, 0, True)
# Rename the original file, if it exists
path = unicode(self.path)
overwrite = os.path.exists(path)
overwrite = QFileInfo(path).exists()
if overwrite:
try:
permis = os.stat(path).st_mode
@ -736,7 +726,7 @@ class EditorTab(QWidget):
raise
temp_path = path + "~"
if os.path.exists(temp_path):
if QFileInfo(temp_path).exists():
os.remove(temp_path)
os.rename(path, temp_path)
# Save the new contents
@ -1024,10 +1014,9 @@ class EditorTabWidget(QTabWidget):
self.parent.updateTabListScript(currWidget.path, action='remove')
def restoreTabs(self):
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
for script in self.restoreTabList:
pathFile = unicode(script.toString())
if os.path.exists(pathFile):
if QFileInfo(pathFile).exists():
tabName = pathFile.split('/')[-1]
self.newTabEditor(tabName, pathFile)
else:
@ -1038,7 +1027,6 @@ class EditorTabWidget(QTabWidget):
s = errOnRestore
sys.stderr.write(s)
self.parent.updateTabListScript(pathFile, action='remove')
QApplication.restoreOverrideCursor()
if self.count() < 1:
self.newTabEditor(filename=None)
self.topFrame.close()

View File

@ -181,7 +181,7 @@ class optionsDialog(QDialog, Ui_SettingsDialogPythonConsole):
settings = QSettings()
self.spinBox.setValue(settings.value("pythonConsole/fontsize", 10).toInt()[0])
self.spinBoxEditor.setValue(settings.value("pythonConsole/fontsizeEditor", 10).toInt()[0])
self.preloadAPI.setChecked(settings.value("pythonConsole/preloadAPI").toBool())
self.preloadAPI.setChecked(settings.value("pythonConsole/preloadAPI", True).toBool())
itemTable = settings.value("pythonConsole/userAPI").toStringList()
for i in range(len(itemTable)):
self.tableWidget.insertRow(i)

View File

@ -407,7 +407,7 @@
<item row="2" column="0">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>API</string>
<string>APIs</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">