Skip to content
Permalink
Browse files

Start sipapi update

  • Loading branch information
NathanW2 committed May 29, 2013
1 parent 23782b7 commit 17d424340e8a16eff227cb3992cb7b7da360a375
@@ -243,7 +243,7 @@ def __init__(self, parent=None):
self.objectListButton = QAction(self)
self.objectListButton.setCheckable(True)
self.objectListButton.setEnabled(self.settings.value("pythonConsole/enableObjectInsp",
False).toBool())
False, type=bool))
self.objectListButton.setIcon(QgsApplication.getThemeIcon("console/iconClassBrowserConsole.png"))
self.objectListButton.setMenuRole(QAction.PreferencesRole)
self.objectListButton.setIconVisibleInMenu(True)
@@ -548,7 +548,7 @@ def _findPrev(self):
self.tabEditorWidget.currentWidget().newEditor.findText(False)

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

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

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

def restoreSettingsConsole(self):
storedTabScripts = self.settings.value("pythonConsole/tabScripts")
self.tabListScript = storedTabScripts.toList()
self.splitter.restoreState(self.settings.value("pythonConsole/splitterConsole").toByteArray())
self.splitterEditor.restoreState(self.settings.value("pythonConsole/splitterEditor").toByteArray())
self.splitterObj.restoreState(self.settings.value("pythonConsole/splitterObj").toByteArray())
self.tabListScript = storedTabScripts
self.splitter.restoreState(self.settings.value("pythonConsole/splitterConsole"))
self.splitterEditor.restoreState(self.settings.value("pythonConsole/splitterEditor"))
self.splitterObj.restoreState(self.settings.value("pythonConsole/splitterObj"))

if __name__ == '__main__':
a = QApplication(sys.argv)
@@ -183,9 +183,9 @@ def __init__(self, parent=None):
def settingsEditor(self):
# Set Python lexer
self.setLexers()
threshold = self.settings.value("pythonConsole/autoCompThresholdEditor", 2).toInt()[0]
radioButtonSource = self.settings.value("pythonConsole/autoCompleteSourceEditor", 'fromAPI').toString()
autoCompEnabled = self.settings.value("pythonConsole/autoCompleteEnabledEditor", True).toBool()
threshold = self.settings.value("pythonConsole/autoCompThresholdEditor", 2)
radioButtonSource = self.settings.value("pythonConsole/autoCompleteSourceEditor", 'fromAPI')
autoCompEnabled = self.settings.value("pythonConsole/autoCompleteEnabledEditor", True)
self.setAutoCompletionThreshold(threshold)
if autoCompEnabled:
if radioButtonSource == 'fromDoc':
@@ -198,8 +198,8 @@ def settingsEditor(self):
self.setAutoCompletionSource(self.AcsNone)

def autoCompleteKeyBinding(self):
radioButtonSource = self.settings.value("pythonConsole/autoCompleteSourceEditor").toString()
autoCompEnabled = self.settings.value("pythonConsole/autoCompleteEnabledEditor").toBool()
radioButtonSource = self.settings.value("pythonConsole/autoCompleteSourceEditor")
autoCompEnabled = self.settings.value("pythonConsole/autoCompleteEnabledEditor")
if autoCompEnabled:
if radioButtonSource == 'fromDoc':
self.autoCompleteFromDocument()
@@ -216,8 +216,8 @@ def setLexers(self):
self.lexer.setFoldComments(True)
self.lexer.setFoldQuotes(True)

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

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

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

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

@@ -385,7 +385,7 @@ def findText(self, forward):
cs = self.parent.pc.caseSensitive.isChecked()
wo = self.parent.pc.wholeWord.isChecked()
notFound = False
if not text.isEmpty():
if not text:
if not forward:
line = lineFrom
index = indexFrom
@@ -397,7 +397,7 @@ def findText(self, forward):
styleError = 'QLineEdit {background-color: #d65253; \
color: #ffffff;}'
msgText = QCoreApplication.translate('PythonConsole',
'<b>"%1"</b> was not found.').arg(text)
'<b>"{}"</b> was not found.'.format(text))
self.parent.pc.callWidgetMessageBarEditor(msgText, 0, True)
else:
styleError = ''
@@ -519,17 +519,17 @@ def _runSubProcess(self, filename, tmp=False):
else:
raise e
if tmp:
tmpFileTr = QCoreApplication.translate('PythonConsole', ' [Temporary file saved in %1]').arg(dir)
tmpFileTr = QCoreApplication.translate('PythonConsole', ' [Temporary file saved in {}]'.format(dir))
file = file + tmpFileTr
if _traceback:
msgTraceTr = QCoreApplication.translate('PythonConsole', '## Script error: %1').arg(file)
msgTraceTr = QCoreApplication.translate('PythonConsole', '## Script error: {}'.format(file))
print "## %s" % datetime.datetime.now()
print unicode(msgTraceTr)
sys.stderr.write(_traceback)
p.stderr.close()
else:
msgSuccessTr = QCoreApplication.translate('PythonConsole',
'## Script executed successfully: %1').arg(file)
'## Script executed successfully: {}'.format(file))
print "## %s" % datetime.datetime.now()
print unicode(msgSuccessTr)
sys.stdout.write(out)
@@ -539,16 +539,15 @@ def _runSubProcess(self, filename, tmp=False):
os.remove(filename)
except IOError, error:
IOErrorTr = QCoreApplication.translate('PythonConsole',
'Cannot execute file %1. Error: %2\n') \
.arg(unicode(filename)).arg(error.strerror)
'Cannot execute file {}. Error: {}\n'.format(unicode(filename), error.strerror))
print '## Error: ' + IOErrorTr
except:
s = traceback.format_exc()
print '## Error: '
sys.stderr.write(s)

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

tabWidget = self.parent.tw.currentWidget()

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

def keyPressEvent(self, e):
if self.settings.value("pythonConsole/autoCloseBracketEditor", True).toBool():
if self.settings.value("pythonConsole/autoCloseBracketEditor", True):
t = unicode(e.text())
## Close bracket automatically
if t in self.opening:
@@ -664,8 +663,7 @@ def focusInEvent(self, e):
if 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))
'The file <b>"{}"</b> has been deleted or is not accessible'.format(unicode(pathfile)))
self.parent.pc.callWidgetMessageBarEditor(msgText, 2, False)
return
if pathfile and self.lastModified != QFileInfo(pathfile).lastModified():
@@ -686,16 +684,14 @@ def focusInEvent(self, e):
self.parent.tw.listObject(self.parent.tw.currentWidget())
self.lastModified = QFileInfo(pathfile).lastModified()
msgText = QCoreApplication.translate('PythonConsole',
'The file <b>"%1"</b> has been changed and reloaded') \
.arg(unicode(pathfile))
'The file <b>"{}"</b> has been changed and reloaded'.format(unicode(pathfile)))
self.parent.pc.callWidgetMessageBarEditor(msgText, 1, False)
QsciScintilla.focusInEvent(self, e)

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

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

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

def _currentWidgetChanged(self, tab):
if self.settings.value("pythonConsole/enableObjectInsp",
False).toBool():
False):
self.listObject(tab)
self.changeLastDirPath(tab)
self.enableSaveIfModified(tab)
@@ -988,15 +984,14 @@ def newTabEditor(self, tabName=None, filename=None):
fn.close()
except IOError, error:
IOErrorTr = QCoreApplication.translate('PythonConsole',
'The file %1 could not be opened. Error: %2\n') \
.arg(unicode(filename)).arg(error.strerror)
'The file {} could not be opened. Error: {}\n'.format(unicode(filename), error.strerror))
print '## Error: '
sys.stderr.write(IOErrorTr)
return

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

def restoreTabs(self):
for script in self.restoreTabList:
pathFile = unicode(script.toString())
pathFile = unicode(script)
if QFileInfo(pathFile).exists():
tabName = pathFile.split('/')[-1]
self.newTabEditor(tabName, pathFile)
else:
errOnRestore = QCoreApplication.translate("PythonConsole",
"Unable to restore the file: \n%1\n") \
.arg(unicode(pathFile))
"Unable to restore the file: \n{}\n".format(unicode(pathFile)))
print '## Error: '
s = errOnRestore
sys.stderr.write(s)
@@ -1193,7 +1186,7 @@ def refreshSettingsEditor(self):
self.widget(i).newEditor.settingsEditor()

objInspectorEnabled = self.settings.value("pythonConsole/enableObjectInsp",
False).toBool()
False)
listObj = self.parent.objectListButton
if self.parent.listClassMethod.isVisible():
listObj.setChecked(objInspectorEnabled)
@@ -63,7 +63,7 @@ def move_cursor_to_end(self):
def get_end_pos(self):
"""Return (line, index) position of the last character"""
line = self.sO.lines() - 1
return (line, self.sO.text(line).length())
return (line, len(self.sO.text(line)))

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

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

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

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

0 comments on commit 17d4243

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