Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[pyqgis-console] fixes translation strings
  • Loading branch information
slarosa committed May 4, 2013
1 parent fb91f76 commit d3f9dd5
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 25 deletions.
21 changes: 12 additions & 9 deletions python/console/console.py
Expand Up @@ -464,19 +464,18 @@ def __init__(self, parent=None):
self.layoutFind = QGridLayout(self.widgetFind)
self.layoutFind.setContentsMargins(0, 0, 0, 0)
self.lineEditFind = QgsFilterLineEdit()
self.lineEditFind.setPlaceholderText('Enter text to find...')
placeHolderTxt = QCoreApplication.translate("PythonConsole", "Enter text to find...")
self.lineEditFind.setPlaceholderText(placeHolderTxt)
self.findNextButton = QToolButton()
self.findNextButton.setEnabled(False)
toolTipfindNext = QCoreApplication.translate("PythonConsole",
"Find Next")
toolTipfindNext = QCoreApplication.translate("PythonConsole", "Find Next")
self.findNextButton.setToolTip(toolTipfindNext)
self.findNextButton.setIcon(QgsApplication.getThemeIcon("console/iconSearchNextEditorConsole.png"))
self.findNextButton.setIconSize(QSize(24, 24))
self.findNextButton.setAutoRaise(True)
self.findPrevButton = QToolButton()
self.findPrevButton.setEnabled(False)
toolTipfindPrev = QCoreApplication.translate("PythonConsole",
"Find Previous")
toolTipfindPrev = QCoreApplication.translate("PythonConsole", "Find Previous")
self.findPrevButton.setToolTip(toolTipfindPrev)
self.findPrevButton.setIcon(QgsApplication.getThemeIcon("console/iconSearchPrevEditorConsole.png"))
self.findPrevButton.setIconSize(QSize(24, 24))
Expand Down Expand Up @@ -628,8 +627,9 @@ def uncommentCode(self):
def openScriptFile(self):
settings = QSettings()
lastDirPath = settings.value("pythonConsole/lastDirPath").toString()
openFileTr = QCoreApplication.translate("PythonConsole", "Open File")
filename = QFileDialog.getOpenFileName(
self, "Open File", lastDirPath, "Script file (*.py)")
self, openFileTr, lastDirPath, "Script file (*.py)")
if not filename.isEmpty():
for i in range(self.tabEditorWidget.count()):
tabWidget = self.tabEditorWidget.widget(i)
Expand All @@ -650,15 +650,18 @@ def saveScriptFile(self):
try:
tabWidget.save()
except (IOError, OSError), e:
QMessageBox.warning(self, "Save Error",
"Failed to save %s: %s" % (tabWidget.path, e))
errTr = QCoreApplication.translate("PythonConsole", "Save Error")
msgErrTr = QCoreApplication.translate("PythonConsole",
"Failed to save %1: %2").arg(tabWidget.path, e)
QMessageBox.warning(self, errTr, msgErrTr)

def saveAsScriptFile(self):
tabWidget = self.tabEditorWidget.currentWidget()
if tabWidget is None:
return
saveAsFileTr = QCoreApplication.translate("PythonConsole", "Save File As")
filename = QFileDialog.getSaveFileName(self,
"Save File As",
saveAsFileTr,
tabWidget.path, "Script file (*.py)")
if not filename.isEmpty():
#print tabWidget.path
Expand Down
60 changes: 44 additions & 16 deletions python/console/console_editor.py
Expand Up @@ -472,23 +472,30 @@ def _runSubProcess(self, filename, tmp=False):
pass
else:
raise e
tmpFileTr = QCoreApplication.translate('PythonConsole', ' [Temporary file saved in ')
if tmp:
name = name + ' [Temporary file saved in ' + dir + ']'
name = name + tmpFileTr + dir + ']'
if _traceback:
msgTraceTr = QCoreApplication.translate('PythonConsole', '## Script error: %1').arg(name)
print "## %s" % datetime.datetime.now()
print "## Script error: %s" % name
print msgTraceTr
sys.stderr.write(_traceback)
p.stderr.close()
else:
msgSuccessTr = QCoreApplication.translate('PythonConsole',
'## Script executed successfully: %1').arg(name)
print "## %s" % datetime.datetime.now()
print "## Script executed successfully: %s" % name
print msgSuccessTr
sys.stdout.write(out)
p.stdout.close()
del p
if tmp:
os.remove(filename)
except IOError, error:
print 'Cannot execute file %s. Error: %s' % (filename, error.strerror)
IOErrorTr = QCoreApplication.translate('PythonConsole',
'Cannot execute file %1. Error: %2') \
.arg(filename, error.strerror)
print IOErrorTr
except:
s = traceback.format_exc()
print '## Error: '
Expand Down Expand Up @@ -535,7 +542,8 @@ def getTextFromEditor(self):

def goToLine(self, objName, linenr):
self.SendScintilla(QsciScintilla.SCI_GOTOLINE, linenr-1)
self.SendScintilla(QsciScintilla.SCI_SETTARGETSTART, self.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS))
self.SendScintilla(QsciScintilla.SCI_SETTARGETSTART,
self.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS))
self.SendScintilla(QsciScintilla.SCI_SETTARGETEND, len(self.text()))
pos = self.SendScintilla(QsciScintilla.SCI_SEARCHINTARGET, len(objName), objName)
index = pos - self.SendScintilla(QsciScintilla.SCI_GETCURRENTPOS)
Expand All @@ -557,7 +565,10 @@ def focusInEvent(self, e):
try:
file = open(pathfile, "r").readlines()
except IOError, error:
print 'The file %s could not be opened. Error: %s' % (pathfile, error.strerror)
IOErrorTr = QCoreApplication.translate('PythonConsole',
'The file %1 could not be opened. Error: %2') \
.arg(pathfile, error.strerro)
print IOErrorTr
for line in reversed(file):
self.insert(line)
QApplication.restoreOverrideCursor()
Expand All @@ -566,7 +577,9 @@ def focusInEvent(self, e):

self.parent.tw.listObject(self.parent.tw.currentWidget())
self.mtime = os.stat(pathfile).st_mtime
msgText = QCoreApplication.translate('PythonConsole', 'The file <b>"%1"</b> has been changed and reloaded').arg(pathfile)
msgText = QCoreApplication.translate('PythonConsole',
'The file <b>"%1"</b> has been changed and reloaded') \
.arg(pathfile)
self.parent.pc.callWidgetMessageBarEditor(msgText, 1, False)

QsciScintilla.focusInEvent(self, e)
Expand Down Expand Up @@ -609,7 +622,10 @@ def loadFile(self, filename, modified):
try:
fn = open(unicode(filename), "rb")
except IOError, error:
print 'The file <b>%s</b> could not be opened. Error: %s' % (filename, error.strerror)
IOErrorTr = QCoreApplication.translate('PythonConsole',
'The file <b>%1</b> could not be opened. Error: %2') \
.arg(filename, error.strerror)
print IOErrorTr
QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
txt = fn.read()
fn.close()
Expand All @@ -621,8 +637,10 @@ def loadFile(self, filename, modified):

def save(self):
if self.path is None:
saveTr = QCoreApplication.translate('PythonConsole',
'Python Console: Save file')
self.path = str(QFileDialog().getSaveFileName(self,
"Python Console: Save file",
saveTr,
"*.py",
"Script file (*.py)"))
# If the user didn't select a file, abort the save operation
Expand Down Expand Up @@ -743,7 +761,9 @@ def __init__(self, parent):
self.connect(self.fileTabMenu, SIGNAL("triggered(QAction*)"),
self.showFileTabMenuTriggered)
self.fileTabButton = QToolButton()
self.fileTabButton.setToolTip('List all tabs')
txtToolTipMenuFile = QCoreApplication.translate("PythonConsole",
"List all tabs")
self.fileTabButton.setToolTip(txtToolTipMenuFile)
self.fileTabButton.setIcon(QgsApplication.getThemeIcon("console/iconFileTabsMenuConsole.png"))
self.fileTabButton.setIconSize(QSize(24, 24))
self.fileTabButton.setAutoRaise(True)
Expand All @@ -756,7 +776,9 @@ def __init__(self, parent):

# Open button
self.newTabButton = QToolButton()
self.newTabButton.setToolTip('New Tab')
txtToolTipNewTab = QCoreApplication.translate("PythonConsole",
"New Tab")
self.newTabButton.setToolTip(txtToolTipNewTab)
self.newTabButton.setAutoRaise(True)
self.newTabButton.setIcon(QgsApplication.getThemeIcon("console/iconNewTabEditorConsole.png"))
self.newTabButton.setIconSize(QSize(24, 24))
Expand Down Expand Up @@ -813,10 +835,13 @@ def _removeTab(self, tab, tab2index=False):
if tab2index:
tab = self.indexOf(tab)
if self.widget(tab).newEditor.isModified():
res = QMessageBox.question( self, 'Python Console: Save File',
'The file <b>"%s"</b> has been modified, save changes ?'
% self.tabText(tab),
QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel )
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))
res = QMessageBox.question( self, txtSaveOnRemove,
txtMsgSaveOnRemove,
QMessageBox.Save | QMessageBox.Discard | QMessageBox.Cancel )
if res == QMessageBox.Save:
self.widget(tab).save()
elif res == QMessageBox.Cancel:
Expand Down Expand Up @@ -856,8 +881,11 @@ def restoreTabs(self):
tabName = pathFile.split('/')[-1]
self.newTabEditor(tabName, pathFile)
else:
errOnRestore = QCoreApplication.translate("PythonConsole",
"Unable to restore the file: \n%1\n") \
.arg(pathFile)
print '## Error: '
s = 'Unable to restore the file: \n%s\n' % pathFile
s = errOnRestore
sys.stderr.write(s)
self.parent.updateTabListScript(pathFile)
if self.count() < 1:
Expand Down

0 comments on commit d3f9dd5

Please sign in to comment.