Skip to content

Commit 17d4243

Browse files
committedMay 29, 2013
Start sipapi update
1 parent 23782b7 commit 17d4243

File tree

7 files changed

+106
-100
lines changed

7 files changed

+106
-100
lines changed
 

‎python/console/console.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ def __init__(self, parent=None):
243243
self.objectListButton = QAction(self)
244244
self.objectListButton.setCheckable(True)
245245
self.objectListButton.setEnabled(self.settings.value("pythonConsole/enableObjectInsp",
246-
False).toBool())
246+
False, type=bool))
247247
self.objectListButton.setIcon(QgsApplication.getThemeIcon("console/iconClassBrowserConsole.png"))
248248
self.objectListButton.setMenuRole(QAction.PreferencesRole)
249249
self.objectListButton.setIconVisibleInMenu(True)
@@ -548,7 +548,7 @@ def _findPrev(self):
548548
self.tabEditorWidget.currentWidget().newEditor.findText(False)
549549

550550
def _textFindChanged(self):
551-
if not self.lineEditFind.text().isEmpty():
551+
if not self.lineEditFind.text():
552552
self.findNextButton.setEnabled(True)
553553
self.findPrevButton.setEnabled(True)
554554
else:
@@ -610,11 +610,11 @@ def uncommentCode(self):
610610
self.tabEditorWidget.currentWidget().newEditor.commentEditorCode(False)
611611

612612
def openScriptFile(self):
613-
lastDirPath = self.settings.value("pythonConsole/lastDirPath").toString()
613+
lastDirPath = self.settings.value("pythonConsole/lastDirPath")
614614
openFileTr = QCoreApplication.translate("PythonConsole", "Open File")
615615
fileList = QFileDialog.getOpenFileNames(
616616
self, openFileTr, lastDirPath, "Script file (*.py)")
617-
if not fileList.isEmpty():
617+
if not fileList:
618618
for pyFile in fileList:
619619
for i in range(self.tabEditorWidget.count()):
620620
tabWidget = self.tabEditorWidget.widget(i)
@@ -636,8 +636,8 @@ def saveScriptFile(self):
636636
except (IOError, OSError), error:
637637
errTr = QCoreApplication.translate("PythonConsole", "Save Error")
638638
msgText = QCoreApplication.translate('PythonConsole',
639-
'The file <b>%1</b> could not be saved. Error: %2') \
640-
.arg(unicode(tabWidget.path)).arg(error.strerror)
639+
'The file <b>{}</b> could not be saved. Error: {}'.format(unicode(tabWidget.path),
640+
error.strerror))
641641
self.callWidgetMessageBarEditor(msgText, 2, False)
642642

643643
def saveAsScriptFile(self, index=None):
@@ -657,14 +657,14 @@ def saveAsScriptFile(self, index=None):
657657
filename = QFileDialog.getSaveFileName(self,
658658
saveAsFileTr,
659659
pathFileName, "Script file (*.py)")
660-
if not filename.isEmpty():
660+
if not filename:
661661
try:
662662
tabWidget.save(filename)
663663
except (IOError, OSError), error:
664664
errTr = QCoreApplication.translate("PythonConsole", "Save Error")
665665
msgText = QCoreApplication.translate('PythonConsole',
666-
'The file <b>%1</b> could not be saved. Error: %2') \
667-
.arg(unicode(tabWidget.path)).arg(error.strerror)
666+
'The file <b>{}</b> could not be saved. Error: {}'.format(unicode(tabWidget.path),
667+
error.strerror))
668668
self.callWidgetMessageBarEditor(msgText, 2, False)
669669
if fileNone:
670670
tabWidget.path = None
@@ -712,10 +712,10 @@ def saveSettingsConsole(self):
712712

713713
def restoreSettingsConsole(self):
714714
storedTabScripts = self.settings.value("pythonConsole/tabScripts")
715-
self.tabListScript = storedTabScripts.toList()
716-
self.splitter.restoreState(self.settings.value("pythonConsole/splitterConsole").toByteArray())
717-
self.splitterEditor.restoreState(self.settings.value("pythonConsole/splitterEditor").toByteArray())
718-
self.splitterObj.restoreState(self.settings.value("pythonConsole/splitterObj").toByteArray())
715+
self.tabListScript = storedTabScripts
716+
self.splitter.restoreState(self.settings.value("pythonConsole/splitterConsole"))
717+
self.splitterEditor.restoreState(self.settings.value("pythonConsole/splitterEditor"))
718+
self.splitterObj.restoreState(self.settings.value("pythonConsole/splitterObj"))
719719

720720
if __name__ == '__main__':
721721
a = QApplication(sys.argv)

‎python/console/console_editor.py

Lines changed: 31 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,9 @@ def __init__(self, parent=None):
183183
def settingsEditor(self):
184184
# Set Python lexer
185185
self.setLexers()
186-
threshold = self.settings.value("pythonConsole/autoCompThresholdEditor", 2).toInt()[0]
187-
radioButtonSource = self.settings.value("pythonConsole/autoCompleteSourceEditor", 'fromAPI').toString()
188-
autoCompEnabled = self.settings.value("pythonConsole/autoCompleteEnabledEditor", True).toBool()
186+
threshold = self.settings.value("pythonConsole/autoCompThresholdEditor", 2)
187+
radioButtonSource = self.settings.value("pythonConsole/autoCompleteSourceEditor", 'fromAPI')
188+
autoCompEnabled = self.settings.value("pythonConsole/autoCompleteEnabledEditor", True)
189189
self.setAutoCompletionThreshold(threshold)
190190
if autoCompEnabled:
191191
if radioButtonSource == 'fromDoc':
@@ -198,8 +198,8 @@ def settingsEditor(self):
198198
self.setAutoCompletionSource(self.AcsNone)
199199

200200
def autoCompleteKeyBinding(self):
201-
radioButtonSource = self.settings.value("pythonConsole/autoCompleteSourceEditor").toString()
202-
autoCompEnabled = self.settings.value("pythonConsole/autoCompleteEnabledEditor").toBool()
201+
radioButtonSource = self.settings.value("pythonConsole/autoCompleteSourceEditor")
202+
autoCompEnabled = self.settings.value("pythonConsole/autoCompleteEnabledEditor")
203203
if autoCompEnabled:
204204
if radioButtonSource == 'fromDoc':
205205
self.autoCompleteFromDocument()
@@ -216,8 +216,8 @@ def setLexers(self):
216216
self.lexer.setFoldComments(True)
217217
self.lexer.setFoldQuotes(True)
218218

219-
loadFont = self.settings.value("pythonConsole/fontfamilytextEditor", "Monospace").toString()
220-
fontSize = self.settings.value("pythonConsole/fontsizeEditor", 10).toInt()[0]
219+
loadFont = self.settings.value("pythonConsole/fontfamilytextEditor", "Monospace")
220+
fontSize = self.settings.value("pythonConsole/fontsizeEditor", 10)
221221

222222
font = QFont(loadFont)
223223
font.setFixedPitch(True)
@@ -236,11 +236,11 @@ def setLexers(self):
236236
self.lexer.setFont(font, 4)
237237

238238
self.api = QsciAPIs(self.lexer)
239-
chekBoxAPI = self.settings.value("pythonConsole/preloadAPI", True).toBool()
239+
chekBoxAPI = self.settings.value("pythonConsole/preloadAPI", True)
240240
if chekBoxAPI:
241241
self.api.loadPrepared( QgsApplication.pkgDataPath() + "/python/qsci_apis/pyqgis_master.pap" )
242242
else:
243-
apiPath = self.settings.value("pythonConsole/userAPI").toStringList()
243+
apiPath = self.settings.value("pythonConsole/userAPI")
244244
for i in range(0, len(apiPath)):
245245
self.api.load(QString(unicode(apiPath[i])))
246246
self.api.prepare()
@@ -258,7 +258,7 @@ def move_cursor_to_end(self):
258258
def get_end_pos(self):
259259
"""Return (line, index) position of the last character"""
260260
line = self.lines() - 1
261-
return (line, self.text(line).length())
261+
return (line, len(self.text(line)))
262262

263263
def contextMenuEvent(self, e):
264264
menu = QMenu(self)
@@ -372,7 +372,7 @@ def contextMenuEvent(self, e):
372372
if QApplication.clipboard().text():
373373
pasteAction.setEnabled(True)
374374
if self.settings.value("pythonConsole/enableObjectInsp",
375-
False).toBool():
375+
False):
376376
showCodeInspection.setEnabled(True)
377377
action = menu.exec_(self.mapToGlobal(e.pos()))
378378

@@ -385,7 +385,7 @@ def findText(self, forward):
385385
cs = self.parent.pc.caseSensitive.isChecked()
386386
wo = self.parent.pc.wholeWord.isChecked()
387387
notFound = False
388-
if not text.isEmpty():
388+
if not text:
389389
if not forward:
390390
line = lineFrom
391391
index = indexFrom
@@ -397,7 +397,7 @@ def findText(self, forward):
397397
styleError = 'QLineEdit {background-color: #d65253; \
398398
color: #ffffff;}'
399399
msgText = QCoreApplication.translate('PythonConsole',
400-
'<b>"%1"</b> was not found.').arg(text)
400+
'<b>"{}"</b> was not found.'.format(text))
401401
self.parent.pc.callWidgetMessageBarEditor(msgText, 0, True)
402402
else:
403403
styleError = ''
@@ -519,17 +519,17 @@ def _runSubProcess(self, filename, tmp=False):
519519
else:
520520
raise e
521521
if tmp:
522-
tmpFileTr = QCoreApplication.translate('PythonConsole', ' [Temporary file saved in %1]').arg(dir)
522+
tmpFileTr = QCoreApplication.translate('PythonConsole', ' [Temporary file saved in {}]'.format(dir))
523523
file = file + tmpFileTr
524524
if _traceback:
525-
msgTraceTr = QCoreApplication.translate('PythonConsole', '## Script error: %1').arg(file)
525+
msgTraceTr = QCoreApplication.translate('PythonConsole', '## Script error: {}'.format(file))
526526
print "## %s" % datetime.datetime.now()
527527
print unicode(msgTraceTr)
528528
sys.stderr.write(_traceback)
529529
p.stderr.close()
530530
else:
531531
msgSuccessTr = QCoreApplication.translate('PythonConsole',
532-
'## Script executed successfully: %1').arg(file)
532+
'## Script executed successfully: {}'.format(file))
533533
print "## %s" % datetime.datetime.now()
534534
print unicode(msgSuccessTr)
535535
sys.stdout.write(out)
@@ -539,16 +539,15 @@ def _runSubProcess(self, filename, tmp=False):
539539
os.remove(filename)
540540
except IOError, error:
541541
IOErrorTr = QCoreApplication.translate('PythonConsole',
542-
'Cannot execute file %1. Error: %2\n') \
543-
.arg(unicode(filename)).arg(error.strerror)
542+
'Cannot execute file {}. Error: {}\n'.format(unicode(filename), error.strerror))
544543
print '## Error: ' + IOErrorTr
545544
except:
546545
s = traceback.format_exc()
547546
print '## Error: '
548547
sys.stderr.write(s)
549548

550549
def runScriptCode(self):
551-
autoSave = self.settings.value("pythonConsole/autoSaveScript").toBool()
550+
autoSave = self.settings.value("pythonConsole/autoSaveScript")
552551

553552
tabWidget = self.parent.tw.currentWidget()
554553

@@ -630,7 +629,7 @@ def syntaxCheck(self, filename=None, fromContextMenu=True):
630629
self.bufferMarkerLine.append(eline)
631630
self.markerAdd(eline, self.MARKER_NUM)
632631
loadFont = self.settings.value("pythonConsole/fontfamilytextEditor",
633-
"Monospace").toString()
632+
"Monospace")
634633
styleAnn = QsciStyle(-1,"Annotation",
635634
QColor(255,0,0),
636635
QColor(255,200,0),
@@ -651,7 +650,7 @@ def syntaxCheck(self, filename=None, fromContextMenu=True):
651650
return True
652651

653652
def keyPressEvent(self, e):
654-
if self.settings.value("pythonConsole/autoCloseBracketEditor", True).toBool():
653+
if self.settings.value("pythonConsole/autoCloseBracketEditor", True):
655654
t = unicode(e.text())
656655
## Close bracket automatically
657656
if t in self.opening:
@@ -664,8 +663,7 @@ def focusInEvent(self, e):
664663
if pathfile:
665664
if not QFileInfo(pathfile).exists():
666665
msgText = QCoreApplication.translate('PythonConsole',
667-
'The file <b>"%1"</b> has been deleted or is not accessible') \
668-
.arg(unicode(pathfile))
666+
'The file <b>"{}"</b> has been deleted or is not accessible'.format(unicode(pathfile)))
669667
self.parent.pc.callWidgetMessageBarEditor(msgText, 2, False)
670668
return
671669
if pathfile and self.lastModified != QFileInfo(pathfile).lastModified():
@@ -686,16 +684,14 @@ def focusInEvent(self, e):
686684
self.parent.tw.listObject(self.parent.tw.currentWidget())
687685
self.lastModified = QFileInfo(pathfile).lastModified()
688686
msgText = QCoreApplication.translate('PythonConsole',
689-
'The file <b>"%1"</b> has been changed and reloaded') \
690-
.arg(unicode(pathfile))
687+
'The file <b>"{}"</b> has been changed and reloaded'.format(unicode(pathfile)))
691688
self.parent.pc.callWidgetMessageBarEditor(msgText, 1, False)
692689
QsciScintilla.focusInEvent(self, e)
693690

694691
def fileReadOnly(self):
695692
tabWidget = self.parent.tw.currentWidget()
696693
msgText = QCoreApplication.translate('PythonConsole',
697-
'The file <b>"%1"</b> is read only, please save to different file first.') \
698-
.arg(unicode(tabWidget.path))
694+
'The file <b>"{}"</b> is read only, please save to different file first.'.format(unicode(tabWidget.path)))
699695
self.parent.pc.callWidgetMessageBarEditor(msgText, 1, False)
700696

701697
class EditorTab(QWidget):
@@ -865,7 +861,7 @@ def __init__(self, parent):
865861
# Restore script of the previuos session
866862
self.settings = QSettings()
867863
tabScripts = self.settings.value("pythonConsole/tabScripts")
868-
self.restoreTabList = tabScripts.toList()
864+
self.restoreTabList = tabScripts
869865

870866
if self.restoreTabList:
871867
self.topFrame.show()
@@ -912,7 +908,7 @@ def __init__(self, parent):
912908

913909
def _currentWidgetChanged(self, tab):
914910
if self.settings.value("pythonConsole/enableObjectInsp",
915-
False).toBool():
911+
False):
916912
self.listObject(tab)
917913
self.changeLastDirPath(tab)
918914
self.enableSaveIfModified(tab)
@@ -988,15 +984,14 @@ def newTabEditor(self, tabName=None, filename=None):
988984
fn.close()
989985
except IOError, error:
990986
IOErrorTr = QCoreApplication.translate('PythonConsole',
991-
'The file %1 could not be opened. Error: %2\n') \
992-
.arg(unicode(filename)).arg(error.strerror)
987+
'The file {} could not be opened. Error: {}\n'.format(unicode(filename), error.strerror))
993988
print '## Error: '
994989
sys.stderr.write(IOErrorTr)
995990
return
996991

997992
nr = self.count()
998993
if not tabName:
999-
tabName = QCoreApplication.translate('PythonConsole', 'Untitled-%1').arg(nr)
994+
tabName = QCoreApplication.translate('PythonConsole', 'Untitled-{}'.format(nr))
1000995
self.tab = EditorTab(self, self.parent, filename, readOnly)
1001996
self.iconTab = QgsApplication.getThemeIcon('console/iconTabEditorConsole.png')
1002997
self.addTab(self.tab, self.iconTab, tabName + ' (ro)' if readOnly else tabName)
@@ -1031,8 +1026,7 @@ def _removeTab(self, tab, tab2index=False):
10311026
txtSaveOnRemove = QCoreApplication.translate("PythonConsole",
10321027
"Python Console: Save File")
10331028
txtMsgSaveOnRemove = QCoreApplication.translate("PythonConsole",
1034-
"The file <b>'%1'</b> has been modified, save changes?") \
1035-
.arg(self.tabText(tab))
1029+
"The file <b>'{}'</b> has been modified, save changes?".format(self.tabText(tab)))
10361030
res = QMessageBox.question( self, txtSaveOnRemove,
10371031
txtMsgSaveOnRemove,
10381032
QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel )
@@ -1070,14 +1064,13 @@ def closeCurrentWidget(self):
10701064

10711065
def restoreTabs(self):
10721066
for script in self.restoreTabList:
1073-
pathFile = unicode(script.toString())
1067+
pathFile = unicode(script)
10741068
if QFileInfo(pathFile).exists():
10751069
tabName = pathFile.split('/')[-1]
10761070
self.newTabEditor(tabName, pathFile)
10771071
else:
10781072
errOnRestore = QCoreApplication.translate("PythonConsole",
1079-
"Unable to restore the file: \n%1\n") \
1080-
.arg(unicode(pathFile))
1073+
"Unable to restore the file: \n{}\n".format(unicode(pathFile)))
10811074
print '## Error: '
10821075
s = errOnRestore
10831076
sys.stderr.write(s)
@@ -1193,7 +1186,7 @@ def refreshSettingsEditor(self):
11931186
self.widget(i).newEditor.settingsEditor()
11941187

11951188
objInspectorEnabled = self.settings.value("pythonConsole/enableObjectInsp",
1196-
False).toBool()
1189+
False)
11971190
listObj = self.parent.objectListButton
11981191
if self.parent.listClassMethod.isVisible():
11991192
listObj.setChecked(objInspectorEnabled)

‎python/console/console_output.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def move_cursor_to_end(self):
6363
def get_end_pos(self):
6464
"""Return (line, index) position of the last character"""
6565
line = self.sO.lines() - 1
66-
return (line, self.sO.text(line).length())
66+
return (line, len(self.sO.text(line)))
6767

6868
def flush(self):
6969
pass
@@ -133,8 +133,8 @@ def __init__(self, parent=None):
133133

134134
def insertInitText(self):
135135
txtInit = QCoreApplication.translate("PythonConsole",
136-
"Python %1 on %2\n"
137-
"## Type help(iface) for more info and list of methods.\n").arg(sys.version, socket.gethostname())
136+
"Python {} on {}\n"
137+
"## Type help(iface) for more info and list of methods.\n".format(sys.version, socket.gethostname()))
138138
initText = self.setText(txtInit)
139139

140140
def refreshLexerProperties(self):
@@ -143,8 +143,8 @@ def refreshLexerProperties(self):
143143
def setLexers(self):
144144
self.lexer = QsciLexerPython()
145145

146-
loadFont = self.settings.value("pythonConsole/fontfamilytext", "Monospace").toString()
147-
fontSize = self.settings.value("pythonConsole/fontsize", 10).toInt()[0]
146+
loadFont = self.settings.value("pythonConsole/fontfamilytext", "Monospace")
147+
fontSize = self.settings.value("pythonConsole/fontsize", 10)
148148
font = QFont(loadFont)
149149
font.setFixedPitch(True)
150150
font.setPointSize(fontSize)
@@ -252,7 +252,7 @@ def enteredSelected(self):
252252
def keyPressEvent(self, e):
253253
# empty text indicates possible shortcut key sequence so stay in output
254254
txt = e.text()
255-
if txt.length() and txt >= " ":
255+
if len(txt) and txt >= " ":
256256
self.shell.append(txt)
257257
self.shell.move_cursor_to_end()
258258
self.shell.setFocus()

‎python/console/console_sci.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def __init__(self, parent=None):
6565
for line in _init_commands:
6666
self.runsource(line)
6767

68-
self.history = QStringList()
68+
self.history = []
6969
self.historyIndex = 0
7070
# Read history command file
7171
self.readHistoryFile()
@@ -114,10 +114,10 @@ def __init__(self, parent=None):
114114
def settingsShell(self):
115115
# Set Python lexer
116116
self.setLexers()
117-
threshold = self.settings.value("pythonConsole/autoCompThreshold", 2).toInt()[0]
117+
threshold = self.settings.value("pythonConsole/autoCompThreshold", 2)
118118
self.setAutoCompletionThreshold(threshold)
119-
radioButtonSource = self.settings.value("pythonConsole/autoCompleteSource", 'fromAPI').toString()
120-
autoCompEnabled = self.settings.value("pythonConsole/autoCompleteEnabled", True).toBool()
119+
radioButtonSource = self.settings.value("pythonConsole/autoCompleteSource", 'fromAPI')
120+
autoCompEnabled = self.settings.value("pythonConsole/autoCompleteEnabled", True)
121121
if autoCompEnabled:
122122
if radioButtonSource == 'fromDoc':
123123
self.setAutoCompletionSource(self.AcsDocument)
@@ -135,8 +135,8 @@ def showHistory(self):
135135
self.historyDlg.activateWindow()
136136

137137
def autoCompleteKeyBinding(self):
138-
radioButtonSource = self.settings.value("pythonConsole/autoCompleteSource").toString()
139-
autoCompEnabled = self.settings.value("pythonConsole/autoCompleteEnabled").toBool()
138+
radioButtonSource = self.settings.value("pythonConsole/autoCompleteSource")
139+
autoCompEnabled = self.settings.value("pythonConsole/autoCompleteEnabled")
140140
if autoCompEnabled:
141141
if radioButtonSource == 'fromDoc':
142142
self.autoCompleteFromDocument()
@@ -149,7 +149,7 @@ def commandConsole(self, command):
149149
if not self.is_cursor_on_last_line():
150150
self.move_cursor_to_end()
151151
line, pos = self.getCursorPosition()
152-
selCmdLenght = self.text(line).length()
152+
selCmdLenght = len(self.text(line))
153153
self.setSelection(line, 4, line, selCmdLenght)
154154
self.removeSelectedText()
155155
if command == "sextante":
@@ -168,8 +168,8 @@ def commandConsole(self, command):
168168
def setLexers(self):
169169
self.lexer = QsciLexerPython()
170170

171-
loadFont = self.settings.value("pythonConsole/fontfamilytext", "Monospace").toString()
172-
fontSize = self.settings.value("pythonConsole/fontsize", 10).toInt()[0]
171+
loadFont = self.settings.value("pythonConsole/fontfamilytext", "Monospace")
172+
fontSize = self.settings.value("pythonConsole/fontsize", 10)
173173

174174
font = QFont(loadFont)
175175
font.setFixedPitch(True)
@@ -188,11 +188,11 @@ def setLexers(self):
188188
self.lexer.setFont(font, 4)
189189

190190
self.api = QsciAPIs(self.lexer)
191-
chekBoxAPI = self.settings.value("pythonConsole/preloadAPI", True).toBool()
191+
chekBoxAPI = self.settings.value("pythonConsole/preloadAPI", True)
192192
if chekBoxAPI:
193193
self.api.loadPrepared( QgsApplication.pkgDataPath() + "/python/qsci_apis/pyqgis_master.pap" )
194194
else:
195-
apiPath = self.settings.value("pythonConsole/userAPI").toStringList()
195+
apiPath = self.settings.value("pythonConsole/userAPI")
196196
for i in range(0, len(apiPath)):
197197
self.api.load(QString(unicode(apiPath[i])))
198198
self.api.prepare()
@@ -223,7 +223,7 @@ def getTextLength(self):
223223
def get_end_pos(self):
224224
"""Return (line, index) position of the last character"""
225225
line = self.lines() - 1
226-
return (line, self.text(line).length())
226+
return (line, len(self.text(line)))
227227

228228
def is_cursor_at_end(self):
229229
"""Return True if cursor is at the end of text"""
@@ -262,7 +262,7 @@ def displayPrompt(self, more=False):
262262
self.move_cursor_to_end()
263263

264264
def updateHistory(self, command):
265-
if isinstance(command, QStringList):
265+
if isinstance(command, list):
266266
for line in command:
267267
self.history.append(line)
268268
elif not command == "":
@@ -320,9 +320,9 @@ def clearHistorySession(self):
320320
self.clearHistory(True)
321321

322322
def showPrevious(self):
323-
if self.historyIndex < len(self.history) and not self.history.isEmpty():
323+
if self.historyIndex < len(self.history) and not self.history:
324324
line, pos = self.getCursorPosition()
325-
selCmdLenght = self.text(line).length()
325+
selCmdLenght = len(self.text(line))
326326
self.setSelection(line, 4, line, selCmdLenght)
327327
self.removeSelectedText()
328328
self.historyIndex += 1
@@ -335,9 +335,9 @@ def showPrevious(self):
335335
#self.SendScintilla(QsciScintilla.SCI_DELETEBACK)
336336

337337
def showNext(self):
338-
if self.historyIndex > 0 and not self.history.isEmpty():
338+
if self.historyIndex > 0 and not self.history:
339339
line, pos = self.getCursorPosition()
340-
selCmdLenght = self.text(line).length()
340+
selCmdLenght = len(self.text(line))
341341
self.setSelection(line, 4, line, selCmdLenght)
342342
self.removeSelectedText()
343343
self.historyIndex -= 1
@@ -406,7 +406,7 @@ def keyPressEvent(self, e):
406406
self.showNext()
407407
## TODO: press event for auto-completion file directory
408408
else:
409-
if self.settings.value("pythonConsole/autoCloseBracket", True).toBool():
409+
if self.settings.value("pythonConsole/autoCloseBracket", True):
410410
t = unicode(e.text())
411411
## Close bracket automatically
412412
if t in self.opening:
@@ -521,9 +521,9 @@ def entered(self):
521521

522522
def currentCommand(self):
523523
linenr, index = self.getCursorPosition()
524-
txtLength = self.text(linenr).length()
524+
txtLength = len(self.text(linenr))
525525
string = self.text()
526-
cmdLine = string.right(txtLength - 4)
526+
cmdLine = string[4:]
527527
cmd = unicode(cmdLine)
528528
return cmd
529529

@@ -578,7 +578,7 @@ def __init__(self, parent):
578578
self.reloadHistory.clicked.connect(self._reloadHistory)
579579

580580
def _runHistory(self, item):
581-
cmd = item.data(Qt.DisplayRole).toString()
581+
cmd = item.data(Qt.DisplayRole)
582582
self.parent.runCommand(unicode(cmd))
583583

584584
def _reloadHistory(self):

‎python/console/console_settings.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def enableDisable(self, value):
6161

6262
def loadAPIFile(self):
6363
settings = QSettings()
64-
lastDirPath = settings.value("pythonConsole/lastDirAPIPath").toString()
64+
lastDirPath = settings.value("pythonConsole/lastDirAPIPath")
6565
fileAPI = QFileDialog.getOpenFileName(
6666
self, "Open API File", lastDirPath, "API file (*.api)")
6767
if fileAPI:
@@ -142,29 +142,29 @@ def saveSettings(self):
142142

143143
def restoreSettings(self):
144144
settings = QSettings()
145-
self.spinBox.setValue(settings.value("pythonConsole/fontsize", 10).toInt()[0])
146-
self.spinBoxEditor.setValue(settings.value("pythonConsole/fontsizeEditor", 10).toInt()[0])
145+
self.spinBox.setValue(settings.value("pythonConsole/fontsize", 10))
146+
self.spinBoxEditor.setValue(settings.value("pythonConsole/fontsizeEditor", 10))
147147
self.fontComboBox.setCurrentFont(QFont(settings.value("pythonConsole/fontfamilytext",
148-
"Monospace").toString()))
148+
"Monospace")))
149149
self.fontComboBoxEditor.setCurrentFont(QFont(settings.value("pythonConsole/fontfamilytextEditor",
150-
"Monospace").toString()))
151-
self.preloadAPI.setChecked(settings.value("pythonConsole/preloadAPI", True).toBool())
152-
itemTable = settings.value("pythonConsole/userAPI").toStringList()
150+
"Monospace")))
151+
self.preloadAPI.setChecked(settings.value("pythonConsole/preloadAPI", True, type=bool))
152+
itemTable = settings.value("pythonConsole/userAPI")
153153
for i in range(len(itemTable)):
154154
self.tableWidget.insertRow(i)
155155
self.tableWidget.setColumnCount(2)
156156
pathSplit = itemTable[i].split("/")
157157
apiName = pathSplit[-1][0:-4]
158158
self.tableWidget.setItem(i, 0, QTableWidgetItem(apiName))
159159
self.tableWidget.setItem(i, 1, QTableWidgetItem(itemTable[i]))
160-
self.autoSaveScript.setChecked(settings.value("pythonConsole/autoSaveScript", False).toBool())
160+
self.autoSaveScript.setChecked(settings.value("pythonConsole/autoSaveScript", False, type=bool))
161161

162-
self.autoCompThreshold.setValue(settings.value("pythonConsole/autoCompThreshold", 2).toInt()[0])
163-
self.autoCompThresholdEditor.setValue(settings.value("pythonConsole/autoCompThresholdEditor", 2).toInt()[0])
162+
self.autoCompThreshold.setValue(settings.value("pythonConsole/autoCompThreshold", 2))
163+
self.autoCompThresholdEditor.setValue(settings.value("pythonConsole/autoCompThresholdEditor", 2))
164164

165-
self.enableObjectInspector.setChecked(settings.value("pythonConsole/enableObjectInsp", False).toBool())
166-
self.autoCloseBracketEditor.setChecked(settings.value("pythonConsole/autoCloseBracketEditor", True).toBool())
167-
self.autoCloseBracket.setChecked(settings.value("pythonConsole/autoCloseBracket", True).toBool())
165+
self.enableObjectInspector.setChecked(settings.value("pythonConsole/enableObjectInsp", False, type=bool))
166+
self.autoCloseBracketEditor.setChecked(settings.value("pythonConsole/autoCloseBracketEditor", True, type=bool))
167+
self.autoCloseBracket.setChecked(settings.value("pythonConsole/autoCloseBracket", True, type=bool))
168168

169169
if settings.value("pythonConsole/autoCompleteSource") == 'fromDoc':
170170
self.autoCompFromDoc.setChecked(True)

‎python/utils.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
2929
"""
3030

31-
from PyQt4.QtCore import QCoreApplication, QLocale, QString
31+
from PyQt4.QtCore import QCoreApplication, QLocale
3232
from qgis.core import QGis, QgsExpression, QgsMessageLog
3333
from string import Template
3434
import sys
@@ -182,8 +182,8 @@ def loadPlugin(packageName):
182182
__import__(packageName)
183183
return True
184184
except:
185-
msgTemplate = QCoreApplication.translate("Python", "Couldn't load plugin '%1' from ['%2']")
186-
msg = msgTemplate.arg(packageName).arg("', '".join(sys.path))
185+
msgTemplate = QCoreApplication.translate("Python", "Couldn't load plugin '%s' from ['%s']")
186+
msg = msgTemplate % (packageName, "', '".join(sys.path))
187187
showException(sys.exc_type, sys.exc_value, sys.exc_traceback, msg)
188188
return False
189189

@@ -196,14 +196,14 @@ def startPlugin(packageName):
196196

197197
package = sys.modules[packageName]
198198

199-
errMsg = QCoreApplication.translate("Python", "Couldn't load plugin %1" ).arg(packageName)
199+
errMsg = QCoreApplication.translate("Python", "Couldn't load plugin %s" ) % packageName
200200

201201
# create an instance of the plugin
202202
try:
203203
plugins[packageName] = package.classFactory(iface)
204204
except:
205205
_unloadPluginModules(packageName)
206-
msg = QCoreApplication.translate("Python", "%1 due an error when calling its classFactory() method").arg(errMsg)
206+
msg = QCoreApplication.translate("Python", "%s due an error when calling its classFactory() method") % errMsg
207207
showException(sys.exc_type, sys.exc_value, sys.exc_traceback, msg)
208208
return False
209209

@@ -213,7 +213,7 @@ def startPlugin(packageName):
213213
except:
214214
del plugins[packageName]
215215
_unloadPluginModules(packageName)
216-
msg = QCoreApplication.translate("Python", "%1 due an error when calling its initGui() method" ).arg( errMsg )
216+
msg = QCoreApplication.translate("Python", "%s due an error when calling its initGui() method" ) % errMsg
217217
showException(sys.exc_type, sys.exc_value, sys.exc_traceback, msg)
218218
return False
219219

@@ -255,7 +255,7 @@ def unloadPlugin(packageName):
255255
_unloadPluginModules(packageName)
256256
return True
257257
except Exception, e:
258-
msg = QCoreApplication.translate("Python", "Error while unloading plugin %1").arg(packageName)
258+
msg = QCoreApplication.translate("Python", "Error while unloading plugin %s") % packageName
259259
showException(sys.exc_type, sys.exc_value, sys.exc_traceback, msg)
260260
return False
261261

@@ -418,7 +418,7 @@ def add(values, *args):
418418
helptemplate = Template("""<h3>$name function</h3><br>$doc""")
419419
class QgsExpressionFunction(QgsExpression.Function):
420420
def __init__(self, name, args, group, helptext=''):
421-
QgsExpression.Function.__init__(self, name, args, group, QString(helptext))
421+
QgsExpression.Function.__init__(self, name, args, group, helptext)
422422

423423
def func(self, values, feature, parent):
424424
pass

‎src/python/qgspythonutilsimpl.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,26 @@ void QgsPythonUtilsImpl::initPython( QgisInterface* interface )
8888
runString( "sys.path = [" + newpaths.join( "," ) + "] + sys.path" );
8989

9090
// import SIP
91-
if ( !runString( "from sip import wrapinstance, unwrapinstance",
91+
if ( !runString( "import sip",
9292
QObject::tr( "Couldn't load SIP module." ) + "\n" + QObject::tr( "Python support will be disabled." ) ) )
9393
{
9494
exitPython();
9595
return;
9696
}
9797

98+
// set PyQt4 api versions
99+
QStringList apiV2classes;
100+
apiV2classes << "QDate" << "QDateTime" << "QString" << "QTextStream" << "QTime" << "QUrl" << "QVariant";
101+
foreach ( const QString& clsName, apiV2classes )
102+
{
103+
if ( !runString( QString( "sip.setapi('%1', 2)" ).arg( clsName ),
104+
QObject::tr( "Couldn't set SIP API versions.") + "\n" + QObject::tr( "Python support will be disabled." ) ) )
105+
{
106+
exitPython();
107+
return;
108+
}
109+
}
110+
98111
// import Qt bindings
99112
if ( !runString( "from PyQt4 import QtCore, QtGui",
100113
QObject::tr( "Couldn't load PyQt4." ) + "\n" + QObject::tr( "Python support will be disabled." ) ) )

0 commit comments

Comments
 (0)
Please sign in to comment.