Skip to content
Permalink
Browse files

[pyqgis-console] fixes translation strings: avoids UnicodeEncode error

  • Loading branch information
slarosa committed Aug 10, 2013
1 parent 577a72b commit 2b2e452ba9c15229c1176297a9ba6acb5ff2c460
@@ -641,8 +641,8 @@ def saveScriptFile(self):
except (IOError, OSError), error:
errTr = QCoreApplication.translate("PythonConsole", "Save Error")
msgText = QCoreApplication.translate('PythonConsole',
'The file <b>{0}</b> could not be saved. Error: {1}'.format(unicode(tabWidget.path),
error.strerror))
'The file <b>{0}</b> could not be saved. Error: {1}').format(tabWidget.path,
error.strerror)
self.callWidgetMessageBarEditor(msgText, 2, False)

def saveAsScriptFile(self, index=-1):
@@ -668,8 +668,8 @@ def saveAsScriptFile(self, index=-1):
except (IOError, OSError), error:
errTr = QCoreApplication.translate("PythonConsole", "Save Error")
msgText = QCoreApplication.translate('PythonConsole',
'The file <b>{0}</b> could not be saved. Error: {1}'.format(unicode(tabWidget.path),
error.strerror))
'The file <b>{0}</b> could not be saved. Error: {1}').format(tabWidget.path,
error.strerror)
self.callWidgetMessageBarEditor(msgText, 2, False)
if fileNone:
tabWidget.path = None
@@ -66,7 +66,7 @@ def _preparationFinished(self):
rslt = self.trUtf8("Error")
if prepd:
rslt = QCoreApplication.translate("PythonConsole","Saved")
self.ui.label.setText('{0} {1}'.format(self.ui.label.text(), rslt))
self.ui.label.setText(u'{0} {1}'.format(self.ui.label.text(), rslt))
self._api = None
self.ui.progressBar.setVisible(False)
self.ui.buttonBox.button(QDialogButtonBox.Cancel).setText(
@@ -75,7 +75,7 @@ def _preparationFinished(self):

def prepareAPI(self):
# self.ui.textEdit_Qsci.setLexer(0)
exec 'self.qlexer = {0}(self.ui.textEdit_Qsci)'.format(self._api_lexer)
exec u'self.qlexer = {0}(self.ui.textEdit_Qsci)'.format(self._api_lexer)
# self.ui.textEdit_Qsci.setLexer(self.qlexer)
self._api = QsciAPIs(self.qlexer)
self._api.apiPreparationFinished.connect(self._preparationFinished)
@@ -401,7 +401,7 @@ def findText(self, forward):
styleError = 'QLineEdit {background-color: #d65253; \
color: #ffffff;}'
msgText = QCoreApplication.translate('PythonConsole',
'<b>"{0}"</b> was not found.'.format(text))
'<b>"{0}"</b> was not found.').format(text)
self.parent.pc.callWidgetMessageBarEditor(msgText, 0, True)
else:
styleError = ''
@@ -523,17 +523,17 @@ def _runSubProcess(self, filename, tmp=False):
else:
raise e
if tmp:
tmpFileTr = QCoreApplication.translate('PythonConsole', ' [Temporary file saved in {0}]'.format(dir))
tmpFileTr = QCoreApplication.translate('PythonConsole', ' [Temporary file saved in {0}]').format(dir)
file = file + tmpFileTr
if _traceback:
msgTraceTr = QCoreApplication.translate('PythonConsole', '## Script error: {0}'.format(file))
msgTraceTr = QCoreApplication.translate('PythonConsole', '## Script error: {0}').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: {0}'.format(file))
'## Script executed successfully: {0}').format(file)
print "## %s" % datetime.datetime.now()
print unicode(msgSuccessTr)
sys.stdout.write(out)
@@ -543,7 +543,8 @@ def _runSubProcess(self, filename, tmp=False):
os.remove(filename)
except IOError, error:
IOErrorTr = QCoreApplication.translate('PythonConsole',
'Cannot execute file {0}. Error: {1}\n'.format(unicode(filename), error.strerror))
'Cannot execute file {0}. Error: {1}\n').format(filename,
error.strerror)
print '## Error: ' + IOErrorTr
except:
s = traceback.format_exc()
@@ -691,7 +692,7 @@ def focusInEvent(self, e):
if pathfile:
if not QFileInfo(pathfile).exists():
msgText = QCoreApplication.translate('PythonConsole',
'The file <b>"{0}"</b> has been deleted or is not accessible'.format(unicode(pathfile)))
'The file <b>"{0}"</b> has been deleted or is not accessible').format(pathfile)
self.parent.pc.callWidgetMessageBarEditor(msgText, 2, False)
return
if pathfile and self.lastModified != QFileInfo(pathfile).lastModified():
@@ -712,14 +713,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>"{0}"</b> has been changed and reloaded'.format(unicode(pathfile)))
'The file <b>"{0}"</b> has been changed and reloaded').format(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>"{0}"</b> is read only, please save to different file first.'.format(unicode(tabWidget.path)))
'The file <b>"{0}"</b> is read only, please save to different file first.').format(tabWidget.path)
self.parent.pc.callWidgetMessageBarEditor(msgText, 1, False)

class EditorTab(QWidget):
@@ -1013,14 +1014,15 @@ def newTabEditor(self, tabName=None, filename=None):
fn.close()
except IOError, error:
IOErrorTr = QCoreApplication.translate('PythonConsole',
'The file {0} could not be opened. Error: {1}\n'.format(unicode(filename), error.strerror))
'The file {0} could not be opened. Error: {1}\n').format(filename,
error.strerror)
print '## Error: '
sys.stderr.write(IOErrorTr)
return

nr = self.count()
if not tabName:
tabName = QCoreApplication.translate('PythonConsole', 'Untitled-{0}'.format(nr))
tabName = QCoreApplication.translate('PythonConsole', 'Untitled-{0}').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)
@@ -1055,7 +1057,7 @@ def _removeTab(self, tab, tab2index=False):
txtSaveOnRemove = QCoreApplication.translate("PythonConsole",
"Python Console: Save File")
txtMsgSaveOnRemove = QCoreApplication.translate("PythonConsole",
"The file <b>'{0}'</b> has been modified, save changes?".format(self.tabText(tab)))
"The file <b>'{0}'</b> has been modified, save changes?").format(self.tabText(tab))
res = QMessageBox.question( self, txtSaveOnRemove,
txtMsgSaveOnRemove,
QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel )
@@ -1099,7 +1101,7 @@ def restoreTabs(self):
self.newTabEditor(tabName, pathFile)
else:
errOnRestore = QCoreApplication.translate("PythonConsole",
"Unable to restore the file: \n{0}\n".format(unicode(pathFile)))
"Unable to restore the file: \n{0}\n").format(pathFile)
print '## Error: '
s = errOnRestore
sys.stderr.write(s)
@@ -135,7 +135,8 @@ def __init__(self, parent=None):
def insertInitText(self):
txtInit = QCoreApplication.translate("PythonConsole",
"Python {0} on {1}\n"
"## Type help(iface) for more info and list of methods.\n".format(sys.version, socket.gethostname()))
"## Type help(iface) for more info and list of methods.\n").format(sys.version,
socket.gethostname())
initText = self.setText(txtInit)

def refreshLexerProperties(self):

0 comments on commit 2b2e452

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