Skip to content
Permalink
Browse files

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

…xists

- minor fixes and cleanup
  • Loading branch information
slarosa committed May 15, 2013
1 parent 02ab027 commit 0175a8053dae7dd3b22d0d9f52d48a870cbaf05f
@@ -90,6 +90,8 @@ def __init__(self, parent=None):
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 @@ def __init__(self, parent=None):
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 @@ def __init__(self, parent=None):
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 @@ def uncommentCode(self):
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 @@ def openScriptFile(self):
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,33 +680,27 @@ def callWidgetMessageBarEditor(self, text, level, timed):
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':
if script not in self.tabListScript:
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)
@@ -266,20 +266,13 @@ def contextMenuEvent(self, e):
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")
iconFind = QgsApplication.getThemeIcon("console/iconSearchEditorConsole.png")
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 @@ def contextMenuEvent(self, e):
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 @@ def keyPressEvent(self, e):
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 @@ def __init__(self, parent, parentConsole, filename, readOnly):
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 @@ def save(self, fileName=None):
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 @@ def save(self, fileName=None):
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 @@ def closeCurrentWidget(self):
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 @@ def restoreTabs(self):
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()
@@ -181,7 +181,7 @@ def restoreSettings(self):
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)
@@ -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">

0 comments on commit 0175a80

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