forked from openlp/openlp
openlyrics export (not finished)
This commit is contained in:
commit
6cf4e9c2d5
@ -57,4 +57,6 @@ from songbookform import SongBookForm
|
||||
from editverseform import EditVerseForm
|
||||
from editsongform import EditSongForm
|
||||
from songmaintenanceform import SongMaintenanceForm
|
||||
from songimportform import SongImportForm
|
||||
from songimportform import SongImportForm
|
||||
from songexportform import SongExportForm
|
||||
|
||||
|
233
openlp/plugins/songs/forms/songexportform.py
Normal file
233
openlp/plugins/songs/forms/songexportform.py
Normal file
@ -0,0 +1,233 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
||||
|
||||
###############################################################################
|
||||
# OpenLP - Open Source Lyrics Projection #
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Copyright (c) 2008-2011 Raoul Snyman #
|
||||
# Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael #
|
||||
# Gorven, Scott Guerrieri, Meinert Jordan, Andreas Preikschat, Christian #
|
||||
# Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon Tibble, #
|
||||
# Carsten Tinggaard, Frode Woldsund #
|
||||
# --------------------------------------------------------------------------- #
|
||||
# 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 #
|
||||
###############################################################################
|
||||
"""
|
||||
The song export function for OpenLP.
|
||||
"""
|
||||
import logging
|
||||
import os
|
||||
|
||||
from PyQt4 import QtCore, QtGui
|
||||
|
||||
from openlp.core.lib import Receiver, SettingsManager, translate
|
||||
from openlp.core.ui import criticalErrorMessageBox
|
||||
from openlp.core.ui.wizard import OpenLPWizard
|
||||
from openlp.plugins.songs.lib.db import Song
|
||||
from openlp.plugins.songs.lib.openlyricsexport import OpenLyricsExport
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class SongExportForm(OpenLPWizard):
|
||||
"""
|
||||
This is the Song Export Wizard, which allows easy exporting of Songs to
|
||||
OpenLyrics.
|
||||
"""
|
||||
log.info(u'SongExportForm loaded')
|
||||
|
||||
def __init__(self, parent, plugin):
|
||||
"""
|
||||
Instantiate the wizard, and run any extra setup we need to.
|
||||
|
||||
``parent``
|
||||
The QWidget-derived parent of the wizard.
|
||||
|
||||
``plugin``
|
||||
The songs plugin.
|
||||
"""
|
||||
self.plugin = plugin
|
||||
OpenLPWizard.__init__(self, parent, plugin, u'songExportWizard',
|
||||
u':/wizards/wizard_importsong.bmp')
|
||||
|
||||
def setupUi(self, image):
|
||||
"""
|
||||
Set up the song wizard UI.
|
||||
"""
|
||||
OpenLPWizard.setupUi(self, image)
|
||||
|
||||
def customInit(self):
|
||||
"""
|
||||
Song wizard specific initialisation.
|
||||
"""
|
||||
songs = self.plugin.manager.get_all_objects(Song)
|
||||
for song in songs:
|
||||
author_list = u''
|
||||
for author in song.authors:
|
||||
if author_list != u'':
|
||||
author_list = author_list + u', '
|
||||
author_list = author_list + author.display_name
|
||||
song_title = unicode(song.title)
|
||||
song_detail = u'%s (%s)' % (song_title, author_list)
|
||||
song_name = QtGui.QListWidgetItem(song_detail)
|
||||
song_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(song))
|
||||
self.availableListWidget.addItem(song_name)
|
||||
self.availableListWidget.selectAll()
|
||||
|
||||
def customSignals(self):
|
||||
"""
|
||||
Song wizard specific signals.
|
||||
"""
|
||||
pass
|
||||
|
||||
def addCustomPages(self):
|
||||
"""
|
||||
Add song wizard specific pages.
|
||||
"""
|
||||
# Source Page
|
||||
self.sourcePage = QtGui.QWizardPage()
|
||||
self.sourcePage.setObjectName(u'sourcePage')
|
||||
self.sourceLayout = QtGui.QHBoxLayout(self.sourcePage)
|
||||
self.sourceLayout.setObjectName(u'sourceLayout')
|
||||
self.availableGroupBox = QtGui.QGroupBox(self.sourcePage)
|
||||
self.availableGroupBox.setObjectName(u'availableGroupBox')
|
||||
self.verticalLayout = QtGui.QVBoxLayout(self.availableGroupBox)
|
||||
self.verticalLayout.setObjectName(u'verticalLayout')
|
||||
self.availableListWidget = QtGui.QListWidget(self.availableGroupBox)
|
||||
self.availableListWidget.setObjectName(u'availableListWidget')
|
||||
self.verticalLayout.addWidget(self.availableListWidget)
|
||||
self.sourceLayout.addWidget(self.availableGroupBox)
|
||||
self.selectionWidget = QtGui.QWidget(self.sourcePage)
|
||||
self.selectionWidget.setObjectName(u'selectionWidget')
|
||||
self.selectionLayout = QtGui.QVBoxLayout(self.selectionWidget)
|
||||
self.selectionLayout.setSpacing(0)
|
||||
self.selectionLayout.setMargin(0)
|
||||
self.selectionLayout.setObjectName(u'selectionLayout')
|
||||
self.addSelected = QtGui.QToolButton(self.selectionWidget)
|
||||
icon = QtGui.QIcon()
|
||||
icon.addPixmap(QtGui.QPixmap(
|
||||
u':/exports/export_move_to_list.png'),
|
||||
QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
self.addSelected.setIcon(icon)
|
||||
self.addSelected.setIconSize(QtCore.QSize(20, 20))
|
||||
self.addSelected.setObjectName(u'addSelected')
|
||||
self.selectionLayout.addWidget(self.addSelected)
|
||||
self.removeSelected = QtGui.QToolButton(self.selectionWidget)
|
||||
icon = QtGui.QIcon()
|
||||
icon.addPixmap(QtGui.QPixmap(
|
||||
u':/imports/import_remove.png'),
|
||||
QtGui.QIcon.Normal, QtGui.QIcon.Off)
|
||||
self.removeSelected.setIcon(icon)
|
||||
self.removeSelected.setIconSize(QtCore.QSize(20, 20))
|
||||
self.removeSelected.setObjectName(u'removeSelected')
|
||||
self.selectionLayout.addWidget(self.removeSelected)
|
||||
self.sourceLayout.addWidget(self.selectionWidget)
|
||||
self.selectedGroupBox = QtGui.QGroupBox(self.sourcePage)
|
||||
self.selectedGroupBox.setObjectName(u'selectedGroupBox')
|
||||
self.verticalLayout = QtGui.QVBoxLayout(self.selectedGroupBox)
|
||||
self.verticalLayout.setObjectName(u'verticalLayout')
|
||||
self.selectedListWidget = QtGui.QListWidget(self.selectedGroupBox)
|
||||
self.selectedListWidget.setObjectName(u'selectedListWidget')
|
||||
self.verticalLayout.addWidget(self.selectedListWidget)
|
||||
self.sourceLayout.addWidget(self.selectedGroupBox)
|
||||
self.addPage(self.sourcePage)
|
||||
|
||||
def retranslateUi(self):
|
||||
"""
|
||||
Song wizard localisation.
|
||||
"""
|
||||
self.setWindowTitle(
|
||||
translate('SongsPlugin.ExportWizardForm', 'Song Export Wizard'))
|
||||
self.titleLabel.setText(
|
||||
u'<span style="font-size:14pt; font-weight:600;">%s</span>' % \
|
||||
translate('SongsPlugin.ExportWizardForm',
|
||||
'Welcome to the Song Export Wizard'))
|
||||
self.informationLabel.setText(
|
||||
translate('SongsPlugin.ExportWizardForm', 'This wizard will help to '
|
||||
'export your songs to the free and open OpenLyrics worship song '
|
||||
'format. You can import these songs in all lyrics projection '
|
||||
'software, which supports OpenLyrics.'))
|
||||
self.sourcePage.setTitle(
|
||||
translate('SongsPlugin.ExportWizardForm', 'Select Emport Source'))
|
||||
self.sourcePage.setSubTitle(
|
||||
translate('SongsPlugin.ExportWizardForm',
|
||||
'Select the export format, and where to export from.'))
|
||||
|
||||
self.progressPage.setTitle(
|
||||
translate('SongsPlugin.ExportWizardForm', 'Exporting'))
|
||||
self.progressPage.setSubTitle(
|
||||
translate('SongsPlugin.ExportWizardForm',
|
||||
'Please wait while your songs are exported.'))
|
||||
self.progressLabel.setText(
|
||||
translate('SongsPlugin.ExportWizardForm', 'Ready.'))
|
||||
self.progressBar.setFormat(
|
||||
translate('SongsPlugin.ExportWizardForm', '%p%'))
|
||||
|
||||
self.availableGroupBox.setTitle(
|
||||
translate('SongsPlugin.ExportWizardForm', 'Available Songs'))
|
||||
self.addSelected.setText(
|
||||
translate('SongsPlugin.ExportWizardForm', 'Select Songs'))
|
||||
self.removeSelected.setText(
|
||||
translate('SongsPlugin.ExportWizardForm', 'Select Songs'))
|
||||
self.selectedGroupBox.setTitle(
|
||||
translate('SongsPlugin.ExportWizardForm', 'Selected Songs'))
|
||||
|
||||
def validateCurrentPage(self):
|
||||
"""
|
||||
Validate the current page before moving on to the next page.
|
||||
"""
|
||||
if self.currentPage() == self.welcomePage:
|
||||
return True
|
||||
elif self.currentPage() == self.sourcePage:
|
||||
return True
|
||||
elif self.currentPage() == self.progressPage:
|
||||
return True
|
||||
|
||||
def registerFields(self):
|
||||
"""
|
||||
Register song export wizard fields.
|
||||
"""
|
||||
pass
|
||||
|
||||
def setDefaults(self):
|
||||
"""
|
||||
Set default form values for the song export wizard.
|
||||
"""
|
||||
self.restart()
|
||||
self.finishButton.setVisible(False)
|
||||
self.cancelButton.setVisible(True)
|
||||
|
||||
def preWizard(self):
|
||||
"""
|
||||
Perform pre export tasks
|
||||
"""
|
||||
OpenLPWizard.preWizard(self)
|
||||
self.progressLabel.setText(
|
||||
translate('SongsPlugin.ExportWizardForm', 'Starting export...'))
|
||||
Receiver.send_message(u'openlp_process_events')
|
||||
|
||||
def performWizard(self):
|
||||
"""
|
||||
Perform the actual export. This method pulls in the correct exporter
|
||||
class, and then runs the ``do_export`` method of the exporter to do
|
||||
the actual exporting.
|
||||
"""
|
||||
exporter = OpenLyricsExport(self.plugin.manager,
|
||||
self.plugin.manager.get_all_objects(Song), u'/tmp/')
|
||||
if exporter.do_export():
|
||||
self.progressLabel.setText(
|
||||
translate('SongsPlugin.SongExportForm', 'Finished export.'))
|
||||
else:
|
||||
self.progressLabel.setText(
|
||||
translate('SongsPlugin.SongExportForm',
|
||||
'Your song export failed.'))
|
@ -34,7 +34,7 @@ from sqlalchemy.sql import or_
|
||||
from openlp.core.lib import MediaManagerItem, BaseListWithDnD, Receiver, \
|
||||
ItemCapabilities, translate, check_item_selected
|
||||
from openlp.plugins.songs.forms import EditSongForm, SongMaintenanceForm, \
|
||||
SongImportForm
|
||||
SongImportForm, SongExportForm
|
||||
from openlp.plugins.songs.lib import OpenLyrics, SongXML
|
||||
from openlp.plugins.songs.lib.db import Author, Song
|
||||
from openlp.core.lib.searchedit import SearchEdit
|
||||
@ -271,6 +271,12 @@ class SongMediaItem(MediaManagerItem):
|
||||
if self.import_wizard.exec_() == QtGui.QDialog.Accepted:
|
||||
Receiver.send_message(u'songs_load_list')
|
||||
|
||||
def onExportClick(self):
|
||||
if not hasattr(self, u'export_wizard'):
|
||||
self.export_wizard = SongExportForm(self, self.parent)
|
||||
if self.export_wizard.exec_() == QtGui.QDialog.Accepted:
|
||||
Receiver.send_message(u'songs_load_list')
|
||||
|
||||
def onNewClick(self):
|
||||
log.debug(u'onNewClick')
|
||||
self.edit_song_form.newSong()
|
||||
|
84
openlp/plugins/songs/lib/openlyricsexport.py
Executable file
84
openlp/plugins/songs/lib/openlyricsexport.py
Executable file
@ -0,0 +1,84 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
||||
|
||||
###############################################################################
|
||||
# OpenLP - Open Source Lyrics Projection #
|
||||
# --------------------------------------------------------------------------- #
|
||||
# Copyright (c) 2008-2011 Raoul Snyman #
|
||||
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
|
||||
# Gorven, Scott Guerrieri, Meinert Jordan, Andreas Preikschat, Christian #
|
||||
# Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon Tibble, #
|
||||
# Carsten Tinggaard, Frode Woldsund #
|
||||
# --------------------------------------------------------------------------- #
|
||||
# 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 #
|
||||
###############################################################################
|
||||
"""
|
||||
The :mod:`openlyricsexport` module provides the functionality for exporting
|
||||
songs from the database.
|
||||
"""
|
||||
import datetime
|
||||
import logging
|
||||
import os
|
||||
|
||||
from lxml import etree, objectify
|
||||
|
||||
from openlp.core.lib import translate
|
||||
from openlp.plugins.songs.lib import OpenLyrics
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class OpenLyricsExport(object):
|
||||
"""
|
||||
This provides the Openlyrics export.
|
||||
"""
|
||||
def __init__(self, master_manager, song_ids, save_path):
|
||||
"""
|
||||
Initialise the export.
|
||||
"""
|
||||
log.debug(u'initialise OpenLyricsExport')
|
||||
self.master_manager = master_manager
|
||||
self.songs = song_ids
|
||||
self.save_path = save_path
|
||||
|
||||
def do_export(self):
|
||||
"""
|
||||
Export the songs.
|
||||
"""
|
||||
openLyrics = OpenLyrics(self.master_manager)
|
||||
# self.export_wizard.exportProgressBar.setMaximum(len(songs))
|
||||
for song in self.songs:
|
||||
# if self.stop_export_flag:
|
||||
# return False
|
||||
# self.export_wizard.incrementProgressBar(unicode(translate(
|
||||
# 'SongsPlugin.OpenLyricsExport', 'Exporting %s...')) %
|
||||
# song.title)
|
||||
# Check if path exists. If not, create the directories!
|
||||
# What do we do with songs with the same title? I do not want to
|
||||
# overwrite them!
|
||||
path = os.path.join(self.save_path, song.title + u'.xml')
|
||||
# Convert the song object to an unicode string.
|
||||
xml = openLyrics.song_to_xml(song)
|
||||
song_xml = objectify.fromstring(xml)
|
||||
# Append the necessary meta data to the song.
|
||||
# (Maybe move this to the xml module?
|
||||
song_xml.set(u'version', OpenLyrics.IMPLEMENTED_VERSION)
|
||||
song_xml.set(u'createdIn', u'OpenLP 1.9.4') # Use variable
|
||||
song_xml.set(u'modifiedIn', u'OpenLP 1.9.4') # Use variable
|
||||
song_xml.set(u'modifiedDate',
|
||||
datetime.datetime.now().strftime(u'%Y-%m-%dT%H:%M:%S'))
|
||||
xml = etree.tostring(song_xml)
|
||||
tree = etree.ElementTree(etree.fromstring(xml))
|
||||
tree.write(path, encoding=u'utf-8', xml_declaration=True,
|
||||
pretty_print=True)
|
||||
return True
|
@ -212,6 +212,7 @@ class OpenLyrics(object):
|
||||
*<verseOrder>*
|
||||
OpenLP supports this property.
|
||||
"""
|
||||
IMPLEMENTED_VERSION = u'0.7'
|
||||
def __init__(self, manager):
|
||||
self.manager = manager
|
||||
|
||||
|
@ -106,8 +106,17 @@ class SongsPlugin(Plugin):
|
||||
The actual **Export** menu item, so that your actions can
|
||||
use it as their parent.
|
||||
"""
|
||||
# No menu items for now.
|
||||
pass
|
||||
# Main song import menu item - will eventually be the only one
|
||||
self.SongExportItem = QtGui.QAction(export_menu)
|
||||
self.SongExportItem.setObjectName(u'SongExportItem')
|
||||
self.SongExportItem.setText(translate(
|
||||
'SongsPlugin', '&Song'))
|
||||
self.SongExportItem.setToolTip(translate('SongsPlugin',
|
||||
'Exports songs using the export wizard.'))
|
||||
export_menu.addAction(self.SongExportItem)
|
||||
# Signals and slots
|
||||
QtCore.QObject.connect(self.SongExportItem,
|
||||
QtCore.SIGNAL(u'triggered()'), self.onSongExportItemClicked)
|
||||
|
||||
def addToolsMenuItem(self, tools_menu):
|
||||
"""
|
||||
@ -172,6 +181,10 @@ class SongsPlugin(Plugin):
|
||||
if self.mediaItem:
|
||||
self.mediaItem.onImportClick()
|
||||
|
||||
def onSongExportItemClicked(self):
|
||||
if self.mediaItem:
|
||||
self.mediaItem.onExportClick()
|
||||
|
||||
def about(self):
|
||||
about_text = translate('SongsPlugin', '<strong>Songs Plugin</strong>'
|
||||
'<br />The songs plugin provides the ability to display and '
|
||||
|
Loading…
Reference in New Issue
Block a user