Skip to content
Permalink
Browse files

[pyqgis-console] fixes for the new SIP APIs

  • Loading branch information
slarosa committed Jun 8, 2013
1 parent c0e7102 commit 780772f37c74186b09edf02442de3835606fc458
@@ -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
@@ -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)")
@@ -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:
@@ -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:
@@ -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()))
@@ -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)

@@ -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',
@@ -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)
@@ -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:
@@ -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():
@@ -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))

0 comments on commit 780772f

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