forked from openlp/openlp
Merged in Michael's changes from the AST module and resolved some conflicts.
This commit is contained in:
commit
420b0ef68d
@ -549,6 +549,7 @@ class Renderer(object):
|
|||||||
# setup defaults
|
# setup defaults
|
||||||
painter = QtGui.QPainter()
|
painter = QtGui.QPainter()
|
||||||
painter.begin(self._frame)
|
painter.begin(self._frame)
|
||||||
|
painter.setRenderHint(QtGui.QPainter.Antialiasing);
|
||||||
if footer :
|
if footer :
|
||||||
font = self.footerFont
|
font = self.footerFont
|
||||||
else:
|
else:
|
||||||
|
@ -193,7 +193,7 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog):
|
|||||||
|
|
||||||
def onImageToolButtonClicked(self):
|
def onImageToolButtonClicked(self):
|
||||||
filename = QtGui.QFileDialog.getOpenFileName(
|
filename = QtGui.QFileDialog.getOpenFileName(
|
||||||
self, self.trUtf8('Open file'))
|
self, self.trUtf8(u'Open file'))
|
||||||
if filename:
|
if filename:
|
||||||
self.ImageLineEdit.setText(filename)
|
self.ImageLineEdit.setText(filename)
|
||||||
self.theme.background_filename = filename
|
self.theme.background_filename = filename
|
||||||
|
@ -556,7 +556,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||||||
here. Currently it is set to default to monitor 0 if the saved
|
here. Currently it is set to default to monitor 0 if the saved
|
||||||
monitor number does not exist.
|
monitor number does not exist.
|
||||||
"""
|
"""
|
||||||
screen_number = int(self.generalConfig.get_config(u'Monitor', 0))
|
screen_number = int(self.generalConfig.get_config(u'monitor', 0))
|
||||||
monitor_exists = False
|
monitor_exists = False
|
||||||
for screen in self.screenList:
|
for screen in self.screenList:
|
||||||
if screen[u'number'] == screen_number:
|
if screen[u'number'] == screen_number:
|
||||||
@ -575,16 +575,16 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||||||
if self.mainDisplay.isVisible():
|
if self.mainDisplay.isVisible():
|
||||||
self.mainDisplay.setFocus()
|
self.mainDisplay.setFocus()
|
||||||
self.activateWindow()
|
self.activateWindow()
|
||||||
if str_to_bool(self.generalConfig.get_config(u'Auto Open', False)):
|
if str_to_bool(self.generalConfig.get_config(u'auto open', False)):
|
||||||
self.ServiceManagerContents.onLoadService(True)
|
self.ServiceManagerContents.onLoadService(True)
|
||||||
if str_to_bool(self.generalConfig.get_config(u'Screen Blank', False)) \
|
if str_to_bool(self.generalConfig.get_config(u'screen blank', False)) \
|
||||||
and str_to_bool(self.generalConfig.get_config(u'Blank Warning', False)):
|
and str_to_bool(self.generalConfig.get_config(u'blank warning', False)):
|
||||||
QtGui.QMessageBox.question(None,
|
QtGui.QMessageBox.question(None,
|
||||||
self.trUtf8('OpenLP Main Display Blanked'),
|
self.trUtf8('OpenLP Main Display Blanked'),
|
||||||
self.trUtf8('The Main Display has been blanked out'),
|
self.trUtf8('The Main Display has been blanked out'),
|
||||||
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok),
|
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok),
|
||||||
QtGui.QMessageBox.Ok)
|
QtGui.QMessageBox.Ok)
|
||||||
#self.LiveController.blackPushButton.setChecked(True)
|
self.LiveController.blankButton.setChecked(True)
|
||||||
|
|
||||||
def onHelpAboutItemClicked(self):
|
def onHelpAboutItemClicked(self):
|
||||||
"""
|
"""
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import re
|
from ast import parse, NodeVisitor, Str
|
||||||
|
|
||||||
ts_file = u"""<?xml version="1.0" encoding="utf-8"?>
|
ts_file = u"""<?xml version="1.0" encoding="utf-8"?>
|
||||||
<!DOCTYPE TS>
|
<!DOCTYPE TS>
|
||||||
@ -42,27 +42,37 @@ ts_message = u""" <message>
|
|||||||
<translation type="unfinished"></translation>
|
<translation type="unfinished"></translation>
|
||||||
</message>
|
</message>
|
||||||
"""
|
"""
|
||||||
find_trUtf8 = re.compile(r"trUtf8\(u?(['\"])([^\1]+)\1\)", re.UNICODE)
|
|
||||||
strings = {}
|
|
||||||
|
|
||||||
def parse_file(filename):
|
class StringExtractor(NodeVisitor):
|
||||||
global strings
|
|
||||||
|
def __init__(self, strings, filename):
|
||||||
|
self.filename = filename
|
||||||
|
self.strings = strings
|
||||||
|
self.classname = 'unknown'
|
||||||
|
|
||||||
|
def visit_ClassDef(self, node):
|
||||||
|
self.classname = node.name
|
||||||
|
self.generic_visit(node)
|
||||||
|
|
||||||
|
def visit_Call(self, node):
|
||||||
|
if hasattr(node.func, 'attr') and node.func.attr == 'trUtf8' and isinstance(node.args[0], Str):
|
||||||
|
string = node.args[0].s
|
||||||
|
key = '%s-%s' % (self.classname, string)
|
||||||
|
self.strings[key] = [self.classname, self.filename, node.lineno, string]
|
||||||
|
self.generic_visit(node)
|
||||||
|
|
||||||
|
def parse_file(filename, strings):
|
||||||
file = open(filename, u'r')
|
file = open(filename, u'r')
|
||||||
class_name = u''
|
try:
|
||||||
line_number = 0
|
ast = parse(file.read())
|
||||||
for line in file:
|
except SyntaxError, e:
|
||||||
line_number += 1
|
print "Unable to parse %s: %s" % (filename, e)
|
||||||
if line[:5] == u'class':
|
return
|
||||||
class_name = line[6:line.find(u'(')]
|
|
||||||
continue
|
|
||||||
for match in find_trUtf8.finditer(line):
|
|
||||||
key = u'%s-%s' % (class_name, match.group(2))
|
|
||||||
if not key in strings:
|
|
||||||
strings[key] = [class_name, filename, line_number, match.group(2)]
|
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
def write_file(filename):
|
StringExtractor(strings, filename).visit(ast)
|
||||||
global strings
|
|
||||||
|
def write_file(filename, strings):
|
||||||
translation_file = u''
|
translation_file = u''
|
||||||
translation_contexts = []
|
translation_contexts = []
|
||||||
translation_messages = []
|
translation_messages = []
|
||||||
@ -79,18 +89,19 @@ def write_file(filename):
|
|||||||
translation_contexts.append(current_context)
|
translation_contexts.append(current_context)
|
||||||
translation_file = ts_file % (u''.join(translation_contexts))
|
translation_file = ts_file % (u''.join(translation_contexts))
|
||||||
file = open(filename, u'w')
|
file = open(filename, u'w')
|
||||||
file.write(translation_file)
|
file.write(translation_file.encode('utf8'))
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
strings = {}
|
||||||
start_dir = os.path.abspath(u'.')
|
start_dir = os.path.abspath(u'.')
|
||||||
for root, dirs, files in os.walk(start_dir):
|
for root, dirs, files in os.walk(start_dir):
|
||||||
for file in files:
|
for file in files:
|
||||||
if file.endswith(u'.py'):
|
if file.endswith(u'.py'):
|
||||||
print u'Parsing "%s"' % file
|
print u'Parsing "%s"' % file
|
||||||
parse_file(os.path.join(root, file))
|
parse_file(os.path.join(root, file), strings)
|
||||||
print u'Generating TS file...',
|
print u'Generating TS file...',
|
||||||
write_file(os.path.join(start_dir, u'..', u'resources', u'i18n', u'openlp_en.ts'))
|
write_file(os.path.join(start_dir, u'i18n', u'openlp_en.ts'), strings)
|
||||||
print u'done.'
|
print u'done.'
|
||||||
|
|
||||||
if __name__ == u'__main__':
|
if __name__ == u'__main__':
|
Loading…
Reference in New Issue
Block a user