Skip to content

Commit

Permalink
[pyqgis-console] fixes for the new SIP APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
slarosa committed Jun 8, 2013
1 parent c0e7102 commit 780772f
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 22 deletions.
14 changes: 8 additions & 6 deletions python/console/console.py
Expand Up @@ -52,9 +52,9 @@ def show_console():
_console.activate()
## Shows help on first launch of the console
settings = QSettings()
if settings.value('pythonConsole/contextHelpOnFirstLaunch', True).toBool():
if settings.value('pythonConsole/contextHelpOnFirstLaunch', True, type=bool):
QgsContextHelp.run( "PythonConsole" )
settings.setValue('pythonConsole/contextHelpOnFirstLaunch', QVariant(False))
settings.setValue('pythonConsole/contextHelpOnFirstLaunch', False)

_old_stdout = sys.stdout
_console_output = None
Expand Down Expand Up @@ -615,7 +615,7 @@ def uncommentCode(self):
self.tabEditorWidget.currentWidget().newEditor.commentEditorCode(False)

def openScriptFile(self):
lastDirPath = self.settings.value("pythonConsole/lastDirPath")
lastDirPath = self.settings.value("pythonConsole/lastDirPath", "")
openFileTr = QCoreApplication.translate("PythonConsole", "Open File")
fileList = QFileDialog.getOpenFileNames(
self, openFileTr, lastDirPath, "Script file (*.py)")
Expand Down Expand Up @@ -645,9 +645,9 @@ def saveScriptFile(self):
error.strerror))
self.callWidgetMessageBarEditor(msgText, 2, False)

def saveAsScriptFile(self, index=None):
def saveAsScriptFile(self, index=-1):
tabWidget = self.tabEditorWidget.currentWidget()
if index:
if index != -1:
tabWidget = self.tabEditorWidget.widget(index)
index = self.tabEditorWidget.currentIndex()
if tabWidget is None:
Expand Down Expand Up @@ -701,6 +701,8 @@ def updateTabListScript(self, script, action=None):
if action == 'remove':
self.tabListScript.remove(script)
elif action == 'append':
if not self.tabListScript:
self.tabListScript = []
if script not in self.tabListScript:
self.tabListScript.append(script)
else:
Expand All @@ -716,7 +718,7 @@ def saveSettingsConsole(self):
self.shell.writeHistoryFile(True)

def restoreSettingsConsole(self):
storedTabScripts = self.settings.value("pythonConsole/tabScripts")
storedTabScripts = self.settings.value("pythonConsole/tabScripts", [])
self.tabListScript = storedTabScripts
self.splitter.restoreState(self.settings.value("pythonConsole/splitterConsole", QByteArray()))
self.splitterEditor.restoreState(self.settings.value("pythonConsole/splitterEditor", QByteArray()))
Expand Down
10 changes: 4 additions & 6 deletions python/console/console_editor.py
Expand Up @@ -236,13 +236,13 @@ def setLexers(self):
self.lexer.setFont(font, 4)

self.api = QsciAPIs(self.lexer)
chekBoxAPI = self.settings.value("pythonConsole/preloadAPI", True)
chekBoxAPI = self.settings.value("pythonConsole/preloadAPI", True, type=bool)
if chekBoxAPI:
self.api.loadPrepared( QgsApplication.pkgDataPath() + "/python/qsci_apis/pyqgis_master.pap" )
else:
apiPath = self.settings.value("pythonConsole/userAPI")
for i in range(0, len(apiPath)):
self.api.load(QString(unicode(apiPath[i])))
self.api.load(unicode(apiPath[i]))
self.api.prepare()
self.lexer.setAPIs(self.api)

Expand Down Expand Up @@ -547,12 +547,9 @@ def _runSubProcess(self, filename, tmp=False):
sys.stderr.write(s)

def runScriptCode(self):
autoSave = self.settings.value("pythonConsole/autoSaveScript")

autoSave = self.settings.value("pythonConsole/autoSaveScript", False, type=bool)
tabWidget = self.parent.tw.currentWidget()

filename = tabWidget.path

msgEditorBlank = QCoreApplication.translate('PythonConsole',
'Hey, type something to run!')
msgEditorUnsaved = QCoreApplication.translate('PythonConsole',
Expand Down Expand Up @@ -958,6 +955,7 @@ def closeAll(self):
def saveAs(self):
idx = self.idx
self.parent.saveAsScriptFile(idx)
self.setCurrentWidget(self.widget(idx))

def enableSaveIfModified(self, tab):
tabWidget = self.widget(tab)
Expand Down
2 changes: 1 addition & 1 deletion python/console/console_sci.py
Expand Up @@ -188,7 +188,7 @@ def setLexers(self):
self.lexer.setFont(font, 4)

self.api = QsciAPIs(self.lexer)
chekBoxAPI = self.settings.value("pythonConsole/preloadAPI", True)
chekBoxAPI = self.settings.value("pythonConsole/preloadAPI", True, type=bool)
if chekBoxAPI:
self.api.loadPrepared( QgsApplication.pkgDataPath() + "/python/qsci_apis/pyqgis_master.pap" )
else:
Expand Down
19 changes: 10 additions & 9 deletions python/console/console_settings.py
Expand Up @@ -61,14 +61,14 @@ def enableDisable(self, value):

def loadAPIFile(self):
settings = QSettings()
lastDirPath = settings.value("pythonConsole/lastDirAPIPath")
lastDirPath = settings.value("pythonConsole/lastDirAPIPath", "", type=str)
fileAPI = QFileDialog.getOpenFileName(
self, "Open API File", lastDirPath, "API file (*.api)")
if fileAPI:
self.addAPI(fileAPI)

lastDirPath = QFileInfo(fileAPI).path()
settings.setValue("pythonConsole/lastDirAPIPath", QVariant(fileAPI))
settings.setValue("pythonConsole/lastDirAPIPath", fileAPI)

def accept(self):
if not self.preloadAPI.isChecked():
Expand Down Expand Up @@ -150,13 +150,14 @@ def restoreSettings(self):
"Monospace")))
self.preloadAPI.setChecked(settings.value("pythonConsole/preloadAPI", True, type=bool))
itemTable = settings.value("pythonConsole/userAPI", [])
for i in range(len(itemTable)):
self.tableWidget.insertRow(i)
self.tableWidget.setColumnCount(2)
pathSplit = itemTable[i].split("/")
apiName = pathSplit[-1][0:-4]
self.tableWidget.setItem(i, 0, QTableWidgetItem(apiName))
self.tableWidget.setItem(i, 1, QTableWidgetItem(itemTable[i]))
if itemTable:
for i in range(len(itemTable)):
self.tableWidget.insertRow(i)
self.tableWidget.setColumnCount(2)
pathSplit = itemTable[i].split("/")
apiName = pathSplit[-1][0:-4]
self.tableWidget.setItem(i, 0, QTableWidgetItem(apiName))
self.tableWidget.setItem(i, 1, QTableWidgetItem(itemTable[i]))
self.autoSaveScript.setChecked(settings.value("pythonConsole/autoSaveScript", False, type=bool))

self.autoCompThreshold.setValue(settings.value("pythonConsole/autoCompThreshold", 2, type=int))
Expand Down

0 comments on commit 780772f

Please sign in to comment.