Merge from trunk

This commit is contained in:
Raoul Snyman 2010-06-19 20:03:21 +02:00
commit 38255ffdb6
18 changed files with 195 additions and 732 deletions

View File

@ -17,7 +17,6 @@ Contents:
openlp
core/index
migration/index
plugins/index
Indices and tables

View File

@ -1,32 +0,0 @@
.. _migration-index:
:mod:`migration` Module
=======================
.. automodule:: openlp.migration
:members:
:mod:`display` Submodule
------------------------
.. automodule:: openlp.migration.display
:members:
:mod:`migratebibles` Submodule
------------------------------
.. automodule:: openlp.migration.migratebibles
:members:
:mod:`migratefiles` Submodule
-----------------------------
.. automodule:: openlp.migration.migratefiles
:members:
:mod:`migratesongs` Submodule
-----------------------------
.. automodule:: openlp.migration.migratesongs
:members:

View File

@ -52,9 +52,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.
@ -65,8 +66,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:
@ -95,11 +97,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)
@ -107,7 +108,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

View File

@ -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:

View File

@ -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:

View File

@ -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

View File

@ -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'<Color1>'))
self.Color2Label.setText(translate(u'AmendThemeForm', u'<Color2>'))
self.ImageLabel.setText(translate(u'AmendThemeForm', u'Image:'))
self.GradientLabel.setText(translate(u'AmendThemeForm', u'Gradient :'))
translate('AmendThemeForm', 'Image'))
self.Color1Label.setText(u'<Color1>:')
self.Color2Label.setText(u'<Color2>:')
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'))

View File

@ -139,8 +139,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':
@ -651,7 +651,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)
@ -667,9 +667,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)
@ -738,7 +738,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))

View File

@ -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:

View File

@ -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')

View File

@ -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()

View File

@ -1,24 +0,0 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2010 Raoul Snyman #
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
# Gorven, Scott Guerrieri, Christian Richter, Maikel Stuivenberg, Martin #
# Thompson, Jon Tibble, Carsten Tinggaard #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################

View File

@ -1,42 +0,0 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2010 Raoul Snyman #
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
# Gorven, Scott Guerrieri, Christian Richter, Maikel Stuivenberg, Martin #
# Thompson, Jon Tibble, Carsten Tinggaard #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
import logging
log = logging.getLogger(__name__)
class Display(object):
log.info(u'Display Class loaded')
@staticmethod
def output(string):
log.debug(string)
#print (string)
@staticmethod
def sub_output(string):
if not string is None:
log.debug(u' '+string)
#print (u' '+string)

View File

@ -1,198 +0,0 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2010 Raoul Snyman #
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
# Gorven, Scott Guerrieri, Christian Richter, Maikel Stuivenberg, Martin #
# Thompson, Jon Tibble, Carsten Tinggaard #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
import os
import sys
import sqlite3
from sqlalchemy.exceptions import InvalidRequestError
from sqlalchemy.orm import mapper
from openlp.core.lib import BaseModel, SettingsManager
from openlp.core.utils import AppLocation
from openlp.plugins.bibles.lib.models import *
class TBibleMeta(BaseModel):
"""
Bible Meta Data
"""
pass
class TTestament(BaseModel):
"""
Bible Testaments
"""
pass
class TBook(BaseModel):
"""
Song model
"""
pass
class TVerse(BaseModel):
"""
Topic model
"""
pass
temp_meta_table = Table(u'metadata_temp', metadata,
Column(u'key', types.Unicode(255), primary_key=True),
Column(u'value', types.Unicode(255)),
)
temp_testament_table = Table(u'testament_temp', metadata,
Column(u'id', types.Integer, primary_key=True),
Column(u'name', types.Unicode(30)),
)
temp_book_table = Table(u'book_temp', metadata,
Column(u'id', types.Integer, primary_key=True),
Column(u'testament_id', types.Integer),
Column(u'name', types.Unicode(30)),
Column(u'abbreviation', types.Unicode(5)),
)
temp_verse_table = Table(u'verse_temp', metadata,
Column(u'id', types.Integer, primary_key=True),
Column(u'book_id', types.Integer),
Column(u'chapter', types.Integer),
Column(u'verse', types.Integer),
Column(u'text', types.UnicodeText),
)
mapper(TBibleMeta, temp_meta_table)
mapper(TTestament, temp_testament_table)
mapper(TBook, temp_book_table)
mapper(TVerse, temp_verse_table)
class MigrateBibles(object):
def __init__(self, display):
self.display = display
self.data_path = AppLocation.get_section_data_path(u'bibles')
self.database_files = SettingsManager.get_files(u'bibles', u'.sqlite')
print self.database_files
def progress(self, text):
print text
self.display.output(text)
def process(self):
self.progress(u'Bibles processing started')
for db_file in self.database_files:
self.v_1_9_0(db_file)
self.progress(u'Bibles processing finished')
def v_1_9_0(self, database):
self.progress(u'Migration 1.9.0 Started for ' + database)
self._v1_9_0_old(database)
self._v1_9_0_new(database)
self._v1_9_0_cleanup(database)
self.progress(u'Migration 1.9.0 Finished for ' + database)
def _v1_9_0_old(self, database):
self.progress(u'Rename Tables ' + database)
conn = sqlite3.connect(os.path.join(self.data_path, database))
conn.execute(u'alter table book rename to book_temp;')
conn.commit()
conn.execute(u'alter table testament rename to testament_temp;')
conn.commit()
conn.execute(u'alter table verse rename to verse_temp;')
conn.commit()
conn.execute(u'alter table metadata rename to metadata_temp;')
conn.commit()
def _v1_9_0_new(self, database):
self.progress(u'Create new Tables ' + database)
self.db_url = u'sqlite:///' + self.data_path + u'/' + database
print self.db_url
self.session = init_models(self.db_url)
metadata.create_all(checkfirst=True)
self.progress(u'Create testament table')
results = self.session.query(TTestament).order_by(TTestament.id).all()
for testament_temp in results:
testament = Testament()
testament.id = testament_temp.id
testament.name = testament_temp.name
try:
self.session.add(testament)
self.session.commit()
except InvalidRequestError:
self.session.rollback()
print u'Error thrown = ', sys.exc_info()[1]
self.progress(u'Create book table')
results = self.session.query(TBook).order_by(TBook.id).all()
for book_temp in results:
book = Book()
book.id = book_temp.id
book.testament_id = book_temp.testament_id
book.name = book_temp.name
book.abbreviation = book_temp.abbreviation
try:
self.session.add(book)
self.session.commit()
except InvalidRequestError:
self.session.rollback()
print u'Error thrown = ', sys.exc_info()[1]
self.progress(u'Create verse table')
results = self.session.query(TVerse).order_by(TVerse.id).all()
for verse_temp in results:
verse = Verse()
verse.id = verse_temp.id
verse.book_id = verse_temp.book_id
verse.chapter = verse_temp.chapter
verse.verse = verse_temp.verse
verse.text = verse_temp.text
try:
self.session.add(verse)
self.session.commit()
except InvalidRequestError:
self.session.rollback()
print u'Error thrown = ', sys.exc_info()[1]
self.progress(u'Create metadata table')
results = self.session.query(TBibleMeta).order_by(TBibleMeta.key).all()
for biblemeta_temp in results:
biblemeta = BibleMeta()
biblemeta.key = biblemeta_temp.key
biblemeta.value = biblemeta_temp.value
try:
self.session.add(biblemeta)
self.session.commit()
except InvalidRequestError:
self.session.rollback()
print u'Error thrown = ', sys.exc_info()[1]
def _v1_9_0_cleanup(self, database):
self.progress(u'Update Internal Data ' + database)
conn = sqlite3.connect(os.path.join(self.data_path, database))
conn.commit()
conn.execute(u'drop table book_temp;')
conn.commit()
conn.execute(u'drop table testament_temp;')
conn.commit()
conn.execute(u'drop table verse_temp;')
conn.commit()
conn.execute(u'drop table metadata_temp;')
conn.commit()
conn.execute(u'vacuum;')
conn.commit()

View File

@ -1,54 +0,0 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2010 Raoul Snyman #
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
# Gorven, Scott Guerrieri, Christian Richter, Maikel Stuivenberg, Martin #
# Thompson, Jon Tibble, Carsten Tinggaard #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
from openlp.core.utils import AppLocation
class MigrateFiles(object):
def __init__(self, display):
self.display = display
def process(self):
self.display.output(u'Files process started')
self._initial_setup()
self.display.output(u'Files process finished')
def _initial_setup(self):
self.display.output(u'Initial Setup started')
data_path = AppLocation.get_data_path()
print data_path
self.display.sub_output(u'Config created')
bibles_path = AppLocation.get_section_data_path(u'bibles')
print bibles_path
self.display.sub_output(u'Config created')
# Media doesn't use a directory like the other plugins.
#media_path = AppLocation.get_section_data_path(u'media')
#self.display.sub_output(u'videos created')
images_path = AppLocation.get_section_data_path(u'images')
print images_path
self.display.sub_output(u'images created')
presentations_path = AppLocation.get_section_data_path(u'presentations')
print presentations_path
self.display.sub_output(u'presentations created')
self.display.output(u'Initial Setup finished')

View File

@ -1,186 +0,0 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2010 Raoul Snyman #
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
# Gorven, Scott Guerrieri, Christian Richter, Maikel Stuivenberg, Martin #
# Thompson, Jon Tibble, Carsten Tinggaard #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
import os
import sys
import sqlite3
from sqlalchemy import create_engine
from sqlalchemy.exceptions import InvalidRequestError
from sqlalchemy.orm import scoped_session, sessionmaker, mapper, relation
from openlp.core.lib import BaseModel, SettingsManager
from openlp.core.utils import AppLocation
from openlp.plugins.songs.lib.models import metadata, songs_table, Song, \
Author, Topic, Book
from openlp.plugins.songs.lib.tables import *
from openlp.plugins.songs.lib.classes import *
def init_models(url):
engine = create_engine(url)
metadata.bind = engine
session = scoped_session(
sessionmaker(autoflush=True, autocommit=False, bind=engine))
mapper(Author, authors_table)
mapper(TAuthor, temp_authors_table)
mapper(Book, song_books_table)
mapper(Song, songs_table,
properties={'authors': relation(Author, backref='songs',
secondary=authors_songs_table),
'book': relation(Book, backref='songs'),
'topics': relation(Topic, backref='songs',
secondary=songs_topics_table)})
mapper(TSong, temp_songs_table)
mapper(TSongAuthor, temp_authors_songs_table)
mapper(Topic, topics_table)
return session
temp_authors_table = Table(u'authors_temp', metadata,
Column(u'authorid', types.Integer, primary_key=True),
Column(u'authorname', String(40))
)
temp_songs_table = Table(u'songs_temp', metadata,
Column(u'songid', types.Integer, primary_key=True),
Column(u'songtitle', String(60)),
Column(u'lyrics', types.UnicodeText),
Column(u'copyrightinfo', String(255)),
Column(u'settingsid', types.Integer)
)
# Definition of the "authors_songs" table
temp_authors_songs_table = Table(u'songauthors_temp', metadata,
Column(u'authorid', types.Integer, primary_key=True),
Column(u'songid', types.Integer)
)
class TAuthor(BaseModel):
"""
Author model
"""
pass
class TSong(BaseModel):
"""
Author model
"""
pass
class TSongAuthor(BaseModel):
"""
Author model
"""
pass
class MigrateSongs(object):
def __init__(self, display):
self.display = display
self.data_path = AppLocation.get_section_data_path(u'songs')
self.database_files = SettingsManager.get_files(u'songs', u'.sqlite')
print self.database_files
def process(self):
self.display.output(u'Songs processing started')
for f in self.database_files:
self.v_1_9_0(f)
self.display.output(u'Songs processing finished')
def v_1_9_0(self, database):
self.display.output(u'Migration 1.9.0 Started for ' + database)
self._v1_9_0_old(database)
self._v1_9_0_new(database)
self._v1_9_0_cleanup(database)
self.display.output(u'Migration 1.9.0 Finished for ' + database)
def _v1_9_0_old(self, database):
self.display.sub_output(u'Rename Tables ' + database)
conn = sqlite3.connect(self.data_path + os.sep + database)
conn.execute(u'alter table authors rename to authors_temp;')
conn.commit()
conn.execute(u'alter table songs rename to songs_temp;')
conn.commit()
conn.execute(u'alter table songauthors rename to songauthors_temp;')
conn.commit()
def _v1_9_0_new(self, database):
self.display.sub_output(u'Create new Tables ' + database)
self.db_url = u'sqlite:///' + self.data_path + u'/songs.sqlite'
print self.db_url
self.session = init_models(self.db_url)
metadata.create_all(checkfirst=True)
results = self.session.query(TSong).order_by(TSong.songid).all()
for songs_temp in results:
song = Song()
song.title = songs_temp.songtitle
song.lyrics = songs_temp.lyrics.replace(u'\r\n', u'\n')
song.copyright = songs_temp.copyrightinfo
song.search_title = u''
song.search_lyrics = u''
print songs_temp.songtitle
aa = self.session.execute(
u'select * from songauthors_temp where songid =' + \
unicode(songs_temp.songid))
for row in aa:
a = row['authorid']
authors_temp = self.session.query(TAuthor).get(a)
bb = self.session.execute(
u'select * from authors where display_name = \"%s\"' % \
unicode(authors_temp.authorname)).fetchone()
if bb is None:
author = Author()
author.display_name = authors_temp.authorname
author.first_name = u''
author.last_name = u''
else:
author = self.session.query(Author).get(bb[0])
song.authors.append(author)
try:
self.session.add(song)
self.session.commit()
except InvalidRequestError:
self.session.rollback()
print u'Error thrown = ', sys.exc_info()[1]
def _v1_9_0_cleanup(self, database):
self.display.sub_output(u'Update Internal Data ' + database)
conn = sqlite3.connect(self.data_path + os.sep + database)
conn.execute("""update songs set search_title =
replace(replace(replace(replace(replace(replace(replace(replace(
replace(title, '&', 'and'), ',', ''), ';', ''), ':', ''),
'(u', ''), ')', ''), '{', ''), '}',''),'?','');""")
conn.execute("""update songs set search_lyrics =
replace(replace(replace(replace(replace(replace(replace(replace(
replace(lyrics, '&', 'and'), ',', ''), ';', ''), ':', ''),
'(u', ''), ')', ''), '{', ''), '}',''),'?','')
;""")
conn.commit()
conn.execute(u'drop table authors_temp;')
conn.commit()
conn.execute(u'drop table songs_temp;')
conn.commit()
conn.execute(u'drop table songauthors_temp;')
conn.commit()
conn.execute(u'drop table settings;')
conn.commit()

View File

@ -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__)

View File

@ -298,8 +298,10 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
last_name=text.rsplit(u' ', 1)[1], display_name=text)
self.songmanager.save_author(author)
self.song.authors.append(author)
author_item = QtGui.QListWidgetItem(unicode(author.display_name))
author_item.setData(QtCore.Qt.UserRole, QtCore.QVariant(author.id))
author_item = QtGui.QListWidgetItem(
unicode(author.display_name))
author_item.setData(QtCore.Qt.UserRole,
QtCore.QVariant(author.id))
self.AuthorsListView.addItem(author_item)
self.loadAuthors()
self.AuthorsSelectionComboItem.setCurrentIndex(0)
@ -349,7 +351,8 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self.songmanager.save_topic(topic)
self.song.topics.append(topic)
topic_item = QtGui.QListWidgetItem(unicode(topic.name))
topic_item.setData(QtCore.Qt.UserRole, QtCore.QVariant(topic.id))
topic_item.setData(QtCore.Qt.UserRole,
QtCore.QVariant(topic.id))
self.TopicsListView.addItem(topic_item)
self.loadTopics()
self.SongTopicCombo.setCurrentIndex(0)