diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index 1533a0fbc..af6d842c8 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -55,9 +55,10 @@ def translate(context, text, comment=None): def get_text_file_string(text_file): """ - Open a file and return the contents of the file. If the supplied file name - is not a file then the function returns False. If there is an error - loading the file then the function will return None. + Open a file and return its content as unicode string. If the supplied file + name is not a file then the function returns False. If there is an error + loading the file or the content can't be decoded then the function will + return None. ``textfile`` The name of the file. @@ -68,8 +69,9 @@ def get_text_file_string(text_file): content_string = None try: file_handle = open(text_file, u'r') - content_string = file_handle.read() - except IOError: + content = file_handle.read() + content_string = content.decode(u'utf-8') + except (IOError, UnicodeError): log.exception(u'Failed to open text file %s' % text_file) finally: if file_handle: @@ -98,11 +100,10 @@ def build_icon(icon): The icon to build. This can be a QIcon, a resource string in the form ``:/resource/file.png``, or a file location like ``/path/to/file.png``. """ - button_icon = None + button_icon = QtGui.QIcon() if isinstance(icon, QtGui.QIcon): button_icon = icon elif isinstance(icon, basestring): - button_icon = QtGui.QIcon() if icon.startswith(u':/'): button_icon.addPixmap(QtGui.QPixmap(icon), QtGui.QIcon.Normal, QtGui.QIcon.Off) @@ -110,7 +111,6 @@ def build_icon(icon): button_icon.addPixmap(QtGui.QPixmap.fromImage(QtGui.QImage(icon)), QtGui.QIcon.Normal, QtGui.QIcon.Off) elif isinstance(icon, QtGui.QImage): - button_icon = QtGui.QIcon() button_icon.addPixmap(QtGui.QPixmap.fromImage(icon), QtGui.QIcon.Normal, QtGui.QIcon.Off) return button_icon diff --git a/openlp/core/lib/themexmlhandler.py b/openlp/core/lib/themexmlhandler.py index a6d1ec186..b2850d6ec 100644 --- a/openlp/core/lib/themexmlhandler.py +++ b/openlp/core/lib/themexmlhandler.py @@ -96,9 +96,8 @@ class ThemeXML(object): The path name to be added. """ if self.background_filename and path: - self.theme_name = self.theme_name.rstrip().lstrip() - self.background_filename = \ - self.background_filename.rstrip().lstrip() + self.theme_name = self.theme_name.strip() + self.background_filename = self.background_filename.strip() self.background_filename = os.path.join(path, self.theme_name, self.background_filename) @@ -334,13 +333,13 @@ class ThemeXML(object): Pull out the XML string. """ # Print our newly created XML - return self.theme_xml.toxml() + return self.theme_xml.toxml(u'utf-8').decode(u'utf-8') def extract_formatted_xml(self): """ Pull out the XML string formatted for human consumption """ - return self.theme_xml.toprettyxml(indent=u' ', newl=u'\n') + return self.theme_xml.toprettyxml(indent=u' ', newl=u'\n', encoding=u'utf-8') def parse(self, xml): """ @@ -365,11 +364,12 @@ class ThemeXML(object): ``xml`` The XML string to parse. """ - theme_xml = ElementTree(element=XML(xml)) + theme_xml = ElementTree(element=XML(xml.encode(u'ascii', u'xmlcharrefreplace'))) xml_iter = theme_xml.getiterator() master = u'' for element in xml_iter: - element.text = unicode(element.text).decode('unicode-escape') + if not isinstance(element.text, unicode): + element.text = unicode(str(element.text), u'utf-8') if element.getchildren(): master = element.tag + u'_' else: diff --git a/openlp/core/lib/toolbar.py b/openlp/core/lib/toolbar.py index 799852908..b2b05b8c0 100644 --- a/openlp/core/lib/toolbar.py +++ b/openlp/core/lib/toolbar.py @@ -72,9 +72,6 @@ class OpenLPToolbar(QtGui.QToolBar): ToolbarButton = None if icon: ButtonIcon = build_icon(icon) - else: - ButtonIcon = None - if ButtonIcon: if slot and not checkable: ToolbarButton = self.addAction(ButtonIcon, title, slot) else: diff --git a/openlp/core/theme/theme.py b/openlp/core/theme/theme.py index 75a2ddd85..b75b55a2e 100644 --- a/openlp/core/theme/theme.py +++ b/openlp/core/theme/theme.py @@ -175,7 +175,7 @@ class Theme(object): ``xml`` The data to apply to the theme """ - root = ElementTree(element=XML(xml)) + root = ElementTree(element=XML(xml.encode(u'ascii', u'xmlcharrefreplace'))) xml_iter = root.getiterator() for element in xml_iter: delphi_color_change = False diff --git a/openlp/core/ui/amendthemedialog.py b/openlp/core/ui/amendthemedialog.py index 142592d88..b736a740c 100644 --- a/openlp/core/ui/amendthemedialog.py +++ b/openlp/core/ui/amendthemedialog.py @@ -750,158 +750,153 @@ class Ui_AmendThemeDialog(object): def retranslateUi(self, AmendThemeDialog): AmendThemeDialog.setWindowTitle( - translate(u'AmendThemeForm', u'Theme Maintenance')) + translate('AmendThemeForm', 'Theme Maintenance')) self.ThemeNameLabel.setText( - translate(u'AmendThemeForm', u'Theme Name:')) + translate('AmendThemeForm', 'Theme Name:')) self.BackgroundLabel.setText( - translate(u'AmendThemeForm', u'Background:')) + translate('AmendThemeForm', 'Visibility:')) self.BackgroundComboBox.setItemText(0, - translate(u'AmendThemeForm', u'Opaque')) + translate('AmendThemeForm', 'Opaque')) self.BackgroundComboBox.setItemText(1, - translate(u'AmendThemeForm', u'Transparent')) + translate('AmendThemeForm', 'Transparent')) self.BackgroundTypeLabel.setText( - translate(u'AmendThemeForm', u'Background Type:')) + translate('AmendThemeForm', 'Type:')) self.BackgroundTypeComboBox.setItemText(0, - translate(u'AmendThemeForm', u'Solid Color')) + translate('AmendThemeForm', 'Solid Color')) self.BackgroundTypeComboBox.setItemText(1, - translate(u'AmendThemeForm', u'Gradient')) + translate('AmendThemeForm', 'Gradient')) self.BackgroundTypeComboBox.setItemText(2, - translate(u'AmendThemeForm', u'Image')) - self.Color1Label.setText(translate(u'AmendThemeForm', u'')) - self.Color2Label.setText(translate(u'AmendThemeForm', u'')) - self.ImageLabel.setText(translate(u'AmendThemeForm', u'Image:')) - self.GradientLabel.setText(translate(u'AmendThemeForm', u'Gradient :')) + translate('AmendThemeForm', 'Image')) + self.Color1Label.setText(u':') + self.Color2Label.setText(u':') + self.ImageLabel.setText(translate('AmendThemeForm', 'Image:')) + self.GradientLabel.setText(translate('AmendThemeForm', 'Gradient:')) self.GradientComboBox.setItemText(0, - translate(u'AmendThemeForm', u'Horizontal')) + translate('AmendThemeForm', 'Horizontal')) self.GradientComboBox.setItemText(1, - translate(u'AmendThemeForm', u'Vertical')) + translate('AmendThemeForm', 'Vertical')) self.GradientComboBox.setItemText(2, - translate(u'AmendThemeForm', u'Circular')) + translate('AmendThemeForm', 'Circular')) self.ThemeTabWidget.setTabText( self.ThemeTabWidget.indexOf(self.BackgroundTab), - translate(u'AmendThemeForm', u'Background')) + translate('AmendThemeForm', '&Background')) self.FontMainGroupBox.setTitle( - translate(u'AmendThemeForm', u'Main Font')) - self.FontMainlabel.setText(translate(u'AmendThemeForm', u'Font:')) + translate('AmendThemeForm', 'Main Font')) + self.FontMainlabel.setText(translate('AmendThemeForm', 'Font:')) self.FontMainColorLabel.setText( - translate(u'AmendThemeForm', u'Font Color:')) - self.FontMainSize.setText(translate(u'AmendThemeForm', u'Size:')) - self.FontMainSizeSpinBox.setSuffix(translate(u'AmendThemeForm', u'pt')) + translate('AmendThemeForm', 'Color:')) + self.FontMainSize.setText(translate('AmendThemeForm', 'Size:')) + self.FontMainSizeSpinBox.setSuffix(translate('AmendThemeForm', 'pt')) self.FontMainWrapIndentationLabel.setText( - translate(u'AmendThemeForm', u'Wrap Indentation')) + translate('AmendThemeForm', 'Wrap indentation:')) self.FontMainWrapLineAdjustmentLabel.setText( - translate(u'AmendThemeForm', u'Adjust Line Spacing')) + translate('AmendThemeForm', 'Adjust line spacing:')) self.FontMainWeightComboBox.setItemText(0, - translate(u'AmendThemeForm', u'Normal')) + translate('AmendThemeForm', 'Normal')) self.FontMainWeightComboBox.setItemText(1, - translate(u'AmendThemeForm', u'Bold')) + translate('AmendThemeForm', 'Bold')) self.FontMainWeightComboBox.setItemText(2, - translate(u'AmendThemeForm', u'Italics')) + translate('AmendThemeForm', 'Italics')) self.FontMainWeightComboBox.setItemText(3, - translate(u'AmendThemeForm', u'Bold/Italics')) + translate('AmendThemeForm', 'Bold/Italics')) self.FontMainWeightLabel.setText( - translate(u'AmendThemeForm', u'Font Weight:')) + translate('AmendThemeForm', 'Style:')) self.MainLocationGroupBox.setTitle( - translate(u'AmendThemeForm', u'Display Location')) + translate('AmendThemeForm', 'Display Location')) self.DefaultLocationLabel.setText( - translate(u'AmendThemeForm', u'Use Default Location:')) + translate('AmendThemeForm', 'Use default location:')) self.FontMainXLabel.setText( - translate(u'AmendThemeForm', u'X Position:')) + translate('AmendThemeForm', 'X position:')) self.FontMainYLabel.setText( - translate(u'AmendThemeForm', u'Y Position:')) + translate('AmendThemeForm', 'Y position:')) self.FontMainWidthLabel.setText( - translate(u'AmendThemeForm', u'Width:')) + translate('AmendThemeForm', 'Width:')) self.FontMainHeightLabel.setText( - translate(u'AmendThemeForm', u'Height:')) - self.FontMainXSpinBox.setSuffix(translate(u'AmendThemeForm', u'px')) - self.FontMainYSpinBox.setSuffix(translate(u'AmendThemeForm', u'px')) - self.FontMainWidthSpinBox.setSuffix(translate(u'AmendThemeForm', u'px')) - self.FontMainHeightSpinBox.setSuffix( - translate(u'AmendThemeForm', u'px')) + translate('AmendThemeForm', 'Height:')) + self.FontMainXSpinBox.setSuffix(translate('AmendThemeForm', 'px')) + self.FontMainYSpinBox.setSuffix(translate('AmendThemeForm', 'px')) + self.FontMainWidthSpinBox.setSuffix(translate('AmendThemeForm', 'px')) + self.FontMainHeightSpinBox.setSuffix(translate('AmendThemeForm', 'px')) self.ThemeTabWidget.setTabText( self.ThemeTabWidget.indexOf(self.FontMainTab), - translate(u'AmendThemeForm', u'Font Main')) + translate('AmendThemeForm', '&Main Font')) self.FooterFontGroupBox.setTitle( - translate(u'AmendThemeForm', u'Footer Font')) - self.FontFooterLabel.setText(translate(u'AmendThemeForm', u'Font:')) + translate('AmendThemeForm', 'Footer Font')) + self.FontFooterLabel.setText(translate('AmendThemeForm', 'Font:')) self.FontFooterColorLabel.setText( - translate(u'AmendThemeForm', u'Font Color:')) - self.FontFooterSizeLabel.setText(translate(u'AmendThemeForm', u'Size:')) - self.FontFooterSizeSpinBox.setSuffix( - translate(u'AmendThemeForm', u'pt')) + translate('AmendThemeForm', 'Color:')) + self.FontFooterSizeLabel.setText(translate('AmendThemeForm', 'Size:')) + self.FontFooterSizeSpinBox.setSuffix(translate('AmendThemeForm', 'pt')) self.FontFooterWeightComboBox.setItemText(0, - translate(u'AmendThemeForm', u'Normal')) + translate('AmendThemeForm', 'Normal')) self.FontFooterWeightComboBox.setItemText(1, - translate(u'AmendThemeForm', u'Bold')) + translate('AmendThemeForm', 'Bold')) self.FontFooterWeightComboBox.setItemText(2, - translate(u'AmendThemeForm', u'Italics')) + translate('AmendThemeForm', 'Italics')) self.FontFooterWeightComboBox.setItemText(3, - translate(u'AmendThemeForm', u'Bold/Italics')) + translate('AmendThemeForm', 'Bold/Italics')) self.FontFooterWeightLabel.setText( - translate(u'AmendThemeForm', u'Font Weight:')) + translate('AmendThemeForm', 'Style:')) self.LocationFooterGroupBox.setTitle( - translate(u'AmendThemeForm', u'Display Location')) + translate('AmendThemeForm', 'Display Location')) self.FontFooterDefaultLabel.setText( - translate(u'AmendThemeForm', u'Use Default Location:')) + translate('AmendThemeForm', 'Use default location:')) self.FontFooterXLabel.setText( - translate(u'AmendThemeForm', u'X Position:')) + translate('AmendThemeForm', 'X position:')) self.FontFooterYLabel.setText( - translate(u'AmendThemeForm', u'Y Position:')) + translate('AmendThemeForm', 'Y position:')) self.FontFooterWidthLabel.setText( - translate(u'AmendThemeForm', u'Width:')) + translate('AmendThemeForm', 'Width:')) self.FontFooterHeightLabel.setText( - translate(u'AmendThemeForm', u'Height:')) - self.FontFooterXSpinBox.setSuffix( - translate(u'AmendThemeForm', u'px')) - self.FontFooterYSpinBox.setSuffix( - translate(u'AmendThemeForm', u'px')) - self.FontFooterWidthSpinBox.setSuffix( - translate(u'AmendThemeForm', u'px')) + translate('AmendThemeForm', 'Height:')) + self.FontFooterXSpinBox.setSuffix(translate('AmendThemeForm', 'px')) + self.FontFooterYSpinBox.setSuffix(translate('AmendThemeForm', 'px')) + self.FontFooterWidthSpinBox.setSuffix(translate('AmendThemeForm', 'px')) self.FontFooterHeightSpinBox.setSuffix( - translate(u'AmendThemeForm', u'px')) + translate('AmendThemeForm', 'px')) self.ThemeTabWidget.setTabText( self.ThemeTabWidget.indexOf(self.FontFooterTab), - translate(u'AmendThemeForm', u'Font Footer')) - self.OutlineGroupBox.setTitle(translate(u'AmendThemeForm', u'Outline')) + translate('AmendThemeForm', '&Footer Font')) + self.OutlineGroupBox.setTitle(translate('AmendThemeForm', 'Outline')) self.OutlineSpinBoxLabel.setText( - translate(u'AmendThemeForm', u'Outline Size:')) - self.OutlineSpinBox.setSuffix(translate(u'AmendThemeForm', u'px')) + translate('AmendThemeForm', 'Outline size:')) + self.OutlineSpinBox.setSuffix(translate('AmendThemeForm', 'px')) self.OutlineColorLabel.setText( - translate(u'AmendThemeForm', u'Outline Color:')) + translate('AmendThemeForm', 'Outline color:')) self.OutlineEnabledLabel.setText( - translate(u'AmendThemeForm', u'Show Outline:')) - self.ShadowGroupBox.setTitle(translate(u'AmendThemeForm', u'Shadow')) + translate('AmendThemeForm', 'Show outline:')) + self.ShadowGroupBox.setTitle(translate('AmendThemeForm', 'Shadow')) self.ShadowSpinBoxLabel.setText( - translate(u'AmendThemeForm', u'Shadow Size:')) - self.ShadowSpinBox.setSuffix(translate(u'AmendThemeForm', u'px')) + translate('AmendThemeForm', 'Shadow size:')) + self.ShadowSpinBox.setSuffix(translate('AmendThemeForm', 'px')) self.ShadowColorLabel.setText( - translate(u'AmendThemeForm', u'Shadow Color:')) + translate('AmendThemeForm', 'Shadow color:')) self.ShadowEnabledLabel.setText( - translate(u'AmendThemeForm', u'Show Shadow:')) + translate('AmendThemeForm', 'Show shadow:')) self.AlignmentGroupBox.setTitle( - translate(u'AmendThemeForm', u'Alignment')) + translate('AmendThemeForm', 'Alignment')) self.HorizontalLabel.setText( - translate(u'AmendThemeForm', u'Horizontal Align:')) + translate('AmendThemeForm', 'Horizontal align:')) self.HorizontalComboBox.setItemText(0, - translate(u'AmendThemeForm', u'Left')) + translate('AmendThemeForm', 'Left')) self.HorizontalComboBox.setItemText(1, - translate(u'AmendThemeForm', u'Right')) + translate('AmendThemeForm', 'Right')) self.HorizontalComboBox.setItemText(2, - translate(u'AmendThemeForm', u'Center')) + translate('AmendThemeForm', 'Center')) self.VerticalLabel.setText( - translate(u'AmendThemeForm', u'Vertical Align:')) + translate('AmendThemeForm', 'Vertical align:')) self.VerticalComboBox.setItemText(0, - translate(u'AmendThemeForm', u'Top')) + translate('AmendThemeForm', 'Top')) self.VerticalComboBox.setItemText(1, - translate(u'AmendThemeForm', u'Middle')) + translate('AmendThemeForm', 'Middle')) self.VerticalComboBox.setItemText(2, - translate(u'AmendThemeForm', u'Bottom')) + translate('AmendThemeForm', 'Bottom')) self.TransitionGroupBox.setTitle( - translate(u'AmendThemeForm', u'Slide Transition')) + translate('AmendThemeForm', 'Slide Transition')) self.SlideTransitionCheckedBoxLabel.setText( - translate(u'AmendThemeForm', u'Transition Active:')) + translate('AmendThemeForm', 'Transition active:')) self.ThemeTabWidget.setTabText( self.ThemeTabWidget.indexOf(self.OtherOptionsTab), - translate(u'AmendThemeForm', u'Other Options')) - self.PreviewGroupBox.setTitle(translate(u'AmendThemeForm', u'Preview')) + translate('AmendThemeForm', '&Other Options')) + self.PreviewGroupBox.setTitle(translate('AmendThemeForm', 'Preview')) diff --git a/openlp/core/ui/amendthemeform.py b/openlp/core/ui/amendthemeform.py index 9306a931c..20664c8e0 100644 --- a/openlp/core/ui/amendthemeform.py +++ b/openlp/core/ui/amendthemeform.py @@ -138,8 +138,8 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog): def accept(self): new_theme = ThemeXML() - theme_name = unicode(self.ThemeNameEdit.displayText()) - new_theme.new_document(theme_name.encode('unicode-escape')) + theme_name = unicode(self.ThemeNameEdit.text()) + new_theme.new_document(theme_name) save_from = None save_to = None if self.theme.background_mode == u'transparent': @@ -209,8 +209,8 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog): self.previewTheme() def onImageToolButtonClicked(self): - filename = QtGui.QFileDialog.getOpenFileName( - self, translate(u'AmendThemeForm', u'Open file')) + filename = unicode(QtGui.QFileDialog.getOpenFileName( + self, translate('AmendThemeForm', 'Open File'))) if filename: self.ImageLineEdit.setText(filename) self.theme.background_filename = filename @@ -647,7 +647,7 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog): self.Color1PushButton.setStyleSheet( u'background-color: %s' % unicode(theme.background_color)) self.Color1Label.setText( - translate(u'AmendThemeForm', u'Background Color:')) + translate('AmendThemeForm', 'Color:')) self.Color1Label.setVisible(True) self.Color1PushButton.setVisible(True) self.Color2Label.setVisible(False) @@ -663,9 +663,9 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog): self.Color2PushButton.setStyleSheet(u'background-color: %s' \ % unicode(theme.background_endColor)) self.Color1Label.setText( - translate(u'AmendThemeForm', u'First Color:')) + translate('AmendThemeForm', 'First color:')) self.Color2Label.setText( - translate(u'AmendThemeForm', u'Second Color:')) + translate('AmendThemeForm', 'Second color:')) self.Color1Label.setVisible(True) self.Color1PushButton.setVisible(True) self.Color2Label.setVisible(True) @@ -734,7 +734,7 @@ class AmendThemeForm(QtGui.QDialog, Ui_AmendThemeDialog): (self.FontMainHeightSpinBox.value(), metrics.height(), page_length)) page_length_text = unicode( - translate(u'AmendThemeForm', u'Slide Height is %s rows')) + translate('AmendThemeForm', 'Slide height is %s rows.')) self.FontMainLinesPageLabel.setText(page_length_text % page_length) frame = self.thememanager.generateImage(self.theme) self.ThemePreview.setPixmap(QtGui.QPixmap.fromImage(frame)) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index d92f8d2ac..0f21b7307 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -356,8 +356,6 @@ class Ui_MainWindow(object): """ MainWindow.mainTitle = translate('MainWindow', 'OpenLP 2.0') MainWindow.language = translate('MainWindow', 'English') - MainWindow.defaultThemeText = translate('MainWindow', - 'Default Theme: ') MainWindow.setWindowTitle(MainWindow.mainTitle) self.FileMenu.setTitle(translate('MainWindow', '&File')) self.FileImportMenu.setTitle(translate('MainWindow', '&Import')) @@ -774,7 +772,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): def defaultThemeChanged(self, theme): self.DefaultThemeLabel.setText( - u'%s %s' % (self.defaultThemeText, theme)) + unicode(translate('MainWindow', 'Default Theme: %s')) % theme) def toggleMediaManager(self, visible): if self.MediaManagerDock.isVisible() != visible: diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index a5d6644de..431b1d450 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -54,25 +54,25 @@ class ThemeManager(QtGui.QWidget): self.amendThemeForm = AmendThemeForm(self) self.Toolbar = OpenLPToolbar(self) self.Toolbar.addToolbarButton( - translate(u'ThemeManager', u'New Theme'), u':/themes/theme_new.png', - translate(u'ThemeManager', u'Create a new theme'), self.onAddTheme) + translate('ThemeManager', 'New Theme'), u':/themes/theme_new.png', + translate('ThemeManager', 'Create a new theme.'), self.onAddTheme) self.Toolbar.addToolbarButton( - translate(u'ThemeManager', u'Edit Theme'), + translate('ThemeManager', 'Edit Theme'), u':/themes/theme_edit.png', - translate(u'ThemeManager', u'Edit a theme'), self.onEditTheme) + translate('ThemeManager', 'Edit a theme.'), self.onEditTheme) self.Toolbar.addToolbarButton( - translate(u'ThemeManager', u'Delete Theme'), + translate('ThemeManager', 'Delete Theme'), u':/general/general_delete.png', - translate(u'ThemeManager', u'Delete a theme'), self.onDeleteTheme) + translate('ThemeManager', 'Delete a theme.'), self.onDeleteTheme) self.Toolbar.addSeparator() self.Toolbar.addToolbarButton( - translate(u'ThemeManager', u'Import Theme'), + translate('ThemeManager', 'Import Theme'), u':/general/general_import.png', - translate(u'ThemeManager', u'Import a theme'), self.onImportTheme) + translate('ThemeManager', 'Import a theme.'), self.onImportTheme) self.Toolbar.addToolbarButton( - translate(u'ThemeManager', u'Export Theme'), + translate('ThemeManager', 'Export Theme'), u':/general/general_export.png', - translate(u'ThemeManager', u'Export a theme'), self.onExportTheme) + translate('ThemeManager', 'Export a theme.'), self.onExportTheme) self.ThemeWidget = QtGui.QWidgetAction(self.Toolbar) self.Layout.addWidget(self.Toolbar) self.ThemeListWidget = QtGui.QListWidget(self) @@ -83,23 +83,23 @@ class ThemeManager(QtGui.QWidget): self.ThemeListWidget.addAction( context_menu_action(self.ThemeListWidget, u':/themes/theme_edit.png', - translate(u'ThemeManager', u'Edit a theme'), self.onEditTheme)) + translate('ThemeManager', '&Edit Theme'), self.onEditTheme)) self.ThemeListWidget.addAction( context_menu_separator(self.ThemeListWidget)) self.ThemeListWidget.addAction( context_menu_action(self.ThemeListWidget, u':/general/general_delete.png', - translate(u'ThemeManager', u'Delete theme'), + translate('ThemeManager', '&Delete Theme'), self.onDeleteTheme)) self.ThemeListWidget.addAction( context_menu_action(self.ThemeListWidget, u':/general/general_export.png', - translate(u'ThemeManager', u'Make Global'), + translate('ThemeManager', 'Set As &Global Default'), self.changeGlobalFromScreen)) self.ThemeListWidget.addAction( context_menu_action(self.ThemeListWidget, u':/general/general_export.png', - translate(u'ThemeManager', u'Export theme'), + translate('ThemeManager', 'E&xport Theme'), self.onExportTheme)) self.ThemeListWidget.addAction( context_menu_separator(self.ThemeListWidget)) @@ -136,7 +136,7 @@ class ThemeManager(QtGui.QWidget): self.ThemeListWidget.item(count).setText(newName) #Set the new name if themeName == newName: - name = unicode(translate(u'ThemeManager', u'%s (default)')) % \ + name = unicode(translate('ThemeManager', '%s (default)')) % \ newName self.ThemeListWidget.item(count).setText(name) @@ -158,7 +158,7 @@ class ThemeManager(QtGui.QWidget): if count == selected_row: self.global_theme = unicode( self.ThemeListWidget.item(count).text()) - name = unicode(translate(u'ThemeManager', u'%s (default)')) % \ + name = unicode(translate('ThemeManager', '%s (default)')) % \ self.global_theme self.ThemeListWidget.item(count).setText(name) QtCore.QSettings().setValue( @@ -203,26 +203,26 @@ class ThemeManager(QtGui.QWidget): theme = unicode(item.text()) # should be the same unless default if theme != unicode(item.data(QtCore.Qt.UserRole).toString()): - QtGui.QMessageBox.critical( - self, translate(u'ThemeManager', u'Error'), - translate(u'ThemeManager', - u'You are unable to delete the default theme.'), + QtGui.QMessageBox.critical(self, + translate('ThemeManager', 'Error'), + translate('ThemeManager', + 'You are unable to delete the default theme.'), QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) else: for plugin in self.parent.plugin_manager.plugins: if not plugin.can_delete_theme(theme): QtGui.QMessageBox.critical(self, - translate(u'ThemeManager', u'Error'), - translate(u'ThemeManager', - u'Theme %s is use in %s plugin' % (theme, - plugin.name))) + translate('ThemeManager', 'Error'), + unicode(translate('ThemeManager', + 'Theme %s is use in %s plugin.')) % \ + (theme, plugin.name)) return if unicode(self.parent.ServiceManagerContents.ThemeComboBox \ .currentText()) == theme: QtGui.QMessageBox.critical(self, - translate(u'ThemeManager', u'Error'), - translate(u'ThemeManager', - u'Theme %s is use by Service Manager' % theme)) + translate('ThemeManager', 'Error'), + unicode(translate('ThemeManager', + 'Theme %s is use by the service manager.')) % theme) return self.themelist.remove(theme) th = theme + u'.png' @@ -249,12 +249,12 @@ class ThemeManager(QtGui.QWidget): item = self.ThemeListWidget.currentItem() if item is None: QtGui.QMessageBox.critical(self, - translate(u'ThemeManager', u'Error'), - translate(u'ThemeManager', u'You have not selected a theme.')) + translate('ThemeManager', 'Error'), + translate('ThemeManager', 'You have not selected a theme.')) return theme = unicode(item.data(QtCore.Qt.UserRole).toString()) path = QtGui.QFileDialog.getExistingDirectory(self, - unicode(translate(u'ThemeManager', u'Save Theme - (%s)')) % theme, + unicode(translate('ThemeManager', 'Save Theme - (%s)')) % theme, SettingsManager.get_last_dir(self.settingsSection, 1)) path = unicode(path) if path: @@ -270,15 +270,15 @@ class ThemeManager(QtGui.QWidget): os.path.join(source, name).encode(u'utf-8'), os.path.join(theme, name).encode(u'utf-8')) QtGui.QMessageBox.information(self, - translate(u'ThemeManager', u'Theme Exported'), - translate(u'ThemeManager', - u'Your theme has been successfully exported.')) + translate('ThemeManager', 'Theme Exported'), + translate('ThemeManager', + 'Your theme has been successfully exported.')) except (IOError, OSError): log.exception(u'Export Theme Failed') QtGui.QMessageBox.critical(self, - translate(u'ThemeManager', u'Theme Export Failed'), - translate(u'ThemeManager', - u'Your theme could not be exported due to an error.')) + translate('ThemeManager', 'Theme Export Failed'), + translate('ThemeManager', + 'Your theme could not be exported due to an error.')) finally: if zip: zip.close() @@ -289,9 +289,10 @@ class ThemeManager(QtGui.QWidget): attempting to extract OpenLP themes from those files. This process will load both OpenLP version 1 and version 2 themes. """ - files = QtGui.QFileDialog.getOpenFileNames( - self, translate(u'ThemeManager', u'Select Theme Import File'), - SettingsManager.get_last_dir(self.settingsSection), u'Theme (*.*)') + files = QtGui.QFileDialog.getOpenFileNames(self, + translate('ThemeManager', 'Select Theme Import File'), + SettingsManager.get_last_dir(self.settingsSection), + translate('ThemeManager', 'Theme (*.*)')) log.info(u'New Themes %s', unicode(files)) if files: for file in files: @@ -318,8 +319,8 @@ class ThemeManager(QtGui.QWidget): if os.path.exists(theme): textName = os.path.splitext(name)[0] if textName == self.global_theme: - name = unicode(translate(u'ThemeManager', - u'%s (default)')) % textName + name = unicode(translate('ThemeManager', + '%s (default)')) % textName else: name = textName thumb = os.path.join(self.thumbPath, u'%s.png' % textName) @@ -394,9 +395,9 @@ class ThemeManager(QtGui.QWidget): ucsfile = file.decode(u'utf-8') except UnicodeDecodeError: QtGui.QMessageBox.critical( - self, translate(u'ThemeManager', u'Error'), - translate(u'ThemeManager', u'File is not a valid ' - u'theme.\nThe content encoding is not UTF-8.')) + self, translate('ThemeManager', 'Error'), + translate('ThemeManager', 'File is not a valid theme.\n' + 'The content encoding is not UTF-8.')) log.exception(u'Filename "%s" is not valid UTF-8' % \ file.decode(u'utf-8', u'replace')) continue @@ -417,30 +418,36 @@ class ThemeManager(QtGui.QWidget): theme_dir = os.path.join(dir, names[0]) if not os.path.exists(theme_dir): os.mkdir(os.path.join(dir, names[0])) - xml_data = zip.read(file) if os.path.splitext(ucsfile)[1].lower() in [u'.xml']: + xml_data = zip.read(file) + try: + xml_data = xml_data.decode(u'utf-8') + except UnicodeDecodeError: + log.exception(u'Theme XML is not UTF-8 ' + 'encoded.') + break; if self.checkVersion1(xml_data): # upgrade theme xml filexml = self.migrateVersion122(xml_data) else: filexml = xml_data outfile = open(fullpath, u'w') - outfile.write(filexml) + outfile.write(filexml.encode(u'utf-8')) else: outfile = open(fullpath, u'wb') outfile.write(zip.read(file)) if filexml: self.generateAndSaveImage(dir, themename, filexml) else: - QtGui.QMessageBox.critical( - self, translate(u'ThemeManager', u'Error'), - translate(u'ThemeManager', u'File is not a valid theme.')) + QtGui.QMessageBox.critical(self, + translate('ThemeManager', 'Error'), + translate('ThemeManager', 'File is not a valid theme.')) log.exception(u'Theme file dosen\'t contain XML data %s' % filename) except (IOError, NameError): - QtGui.QMessageBox.critical( - self, translate(u'ThemeManager', u'Error'), - translate(u'ThemeManager', u'File is not a valid theme.')) + QtGui.QMessageBox.critical(self, + translate('ThemeManager', 'Error'), + translate('ThemeManager', 'File is not a valid theme.')) log.exception(u'Importing theme from zip file failed %s' % filename) finally: if zip: @@ -456,7 +463,7 @@ class ThemeManager(QtGui.QWidget): Theme XML to check the version of """ log.debug(u'checkVersion1 ') - theme = xmlfile + theme = xmlfile.encode(u'ascii', u'xmlcharrefreplace') tree = ElementTree(element=XML(theme)).getroot() if tree.find(u'BackgroundType') is None: return False @@ -526,11 +533,11 @@ class ThemeManager(QtGui.QWidget): result = QtGui.QMessageBox.Yes if self.saveThemeName != name: if os.path.exists(theme_file): - result = QtGui.QMessageBox.question( - self, translate(u'ThemeManager', u'Theme Exists'), - translate(u'ThemeManager', - u'A theme with this name already exists, ' - u'would you like to overwrite it?'), + result = QtGui.QMessageBox.question(self, + translate('ThemeManager', 'Theme Exists'), + translate('ThemeManager', + 'A theme with this name already exists. ' + 'Would you like to overwrite it?'), (QtGui.QMessageBox.Yes | QtGui.QMessageBox.No), QtGui.QMessageBox.No) if result == QtGui.QMessageBox.Yes: @@ -598,7 +605,7 @@ class ThemeManager(QtGui.QWidget): """ log.debug(u'base theme created') newtheme = ThemeXML() - newtheme.new_document(unicode(translate(u'ThemeManager', u'New Theme'))) + newtheme.new_document(unicode(translate('ThemeManager', 'New Theme'))) newtheme.add_background_solid(unicode(u'#000000')) newtheme.add_font(unicode(QtGui.QFont().family()), unicode(u'#FFFFFF'), unicode(30), u'False') diff --git a/openlp/core/ui/themestab.py b/openlp/core/ui/themestab.py index 5fd8d5119..73fbfeb88 100644 --- a/openlp/core/ui/themestab.py +++ b/openlp/core/ui/themestab.py @@ -37,7 +37,7 @@ class ThemesTab(SettingsTab): def setupUi(self): self.setObjectName(u'ThemesTab') - self.tabTitleVisible = translate(u'ThemesTab', u'Themes') + self.tabTitleVisible = translate('ThemesTab', 'Themes') self.ThemesTabLayout = QtGui.QHBoxLayout(self) self.ThemesTabLayout.setSpacing(8) self.ThemesTabLayout.setMargin(8) @@ -106,26 +106,26 @@ class ThemesTab(SettingsTab): QtCore.SIGNAL(u'theme_update_list'), self.updateThemeList) def retranslateUi(self): - self.GlobalGroupBox.setTitle(translate(u'ThemesTab', u'Global theme')) - self.LevelGroupBox.setTitle(translate(u'ThemesTab', u'Theme level')) + self.GlobalGroupBox.setTitle(translate('ThemesTab', 'Global Theme')) + self.LevelGroupBox.setTitle(translate('ThemesTab', 'Theme Level')) self.SongLevelRadioButton.setText( - translate(u'ThemesTab', u'Song level')) + translate('ThemesTab', 'S&ong Level')) self.SongLevelLabel.setText( - translate(u'ThemesTab', u'Use the theme from each song ' - u'in the database. If a song doesn\'t have a theme associated with ' - u'it, then use the service\'s theme. If the service doesn\'t have ' - u'a theme, then use the global theme.')) + translate('ThemesTab', 'Use the theme from each song ' + 'in the database. If a song doesn\'t have a theme associated with ' + 'it, then use the service\'s theme. If the service doesn\'t have ' + 'a theme, then use the global theme.')) self.ServiceLevelRadioButton.setText( - translate(u'ThemesTab', u'Service level')) + translate('ThemesTab', '&Service Level')) self.ServiceLevelLabel.setText( - translate(u'ThemesTab', u'Use the theme from the service, ' - u'overriding any of the individual songs\' themes. If the ' - u'service doesn\'t have a theme, then use the global theme.')) + translate('ThemesTab', 'Use the theme from the service, ' + 'overriding any of the individual songs\' themes. If the ' + 'service doesn\'t have a theme, then use the global theme.')) self.GlobalLevelRadioButton.setText( - translate(u'ThemesTab', u'Global level')) + translate('ThemesTab', '&Global Level')) self.GlobalLevelLabel.setText( - translate(u'ThemesTab', u'Use the global theme, overriding any ' - u'themes associated with either the service or the songs.')) + translate('ThemesTab', 'Use the global theme, overriding any ' + 'themes associated with either the service or the songs.')) def load(self): settings = QtCore.QSettings() diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index ae7569c10..5d8fe03a4 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -29,7 +29,7 @@ import os from PyQt4 import QtCore, QtGui from openlp.core.lib import MediaManagerItem, BaseListWithDnD, build_icon, \ - ItemCapabilities, SettingsManager, context_menu_action, Receiver, translate + ItemCapabilities, SettingsManager, translate log = logging.getLogger(__name__)