Add XML Lyrics handling to Songs.

This commit is contained in:
Tim Bentley 2009-06-12 18:20:40 +01:00
parent dfb467e830
commit e8ae29e620
5 changed files with 94 additions and 60 deletions

View File

@ -102,7 +102,6 @@ class Ui_EditSongDialog(object):
self.ThemeSelectionComboItem = QtGui.QComboBox(self.ThemeGroupBox)
self.ThemeSelectionComboItem.setObjectName(u'ThemeSelectionComboItem')
self.ThemeLayout.addWidget(self.ThemeSelectionComboItem)
self.DetailsLayout.addWidget(self.ThemeGroupBox)
self.TopLayout.addWidget(self.TextWidget)
self.AdditionalWidget = QtGui.QWidget(self.TopWidget)

View File

@ -18,9 +18,10 @@ this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
"""
from PyQt4 import Qt, QtCore, QtGui
from openlp.core.lib import SongXMLBuilder, SongXMLParser
from openlp.plugins.songs.forms import AuthorsForm, TopicsForm, SongBookForm, \
EditVerseForm
from openlp.plugins.songs.lib.models import Song
from editsongdialog import Ui_EditSongDialog
@ -56,16 +57,10 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self.song_book_form = SongBookForm(self.songmanager)
self.verse_form = EditVerseForm()
self.initialise()
#self.AuthorsListView.setColumnCount(2)
#self.AuthorsListView.setColumnHidden(0, True)
#self.AuthorsListView.setColumnWidth(1, 200)
#self.AuthorsListView.setShowGrid(False)
self.AuthorsListView.setSortingEnabled(False)
self.AuthorsListView.setAlternatingRowColors(True)
#self.AuthorsListView.horizontalHeader().setVisible(False)
#self.AuthorsListView.verticalHeader().setVisible(False)
#self.savebutton = self.ButtonBox.button(QtGui.QDialogButtonBox.Save)
self.TopicsListView.setSortingEnabled(False)
self.TopicsListView.setAlternatingRowColors(True)
def initialise(self):
self.loadAuthors()
@ -90,6 +85,15 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
for book in books:
self.SongbookCombo.addItem(book.name)
def newSong(self):
self.song = Song()
self.TitleEditItem.setText(u'')
self.AlternativeEdit.setText(u'')
self.CopyrightEditItem.setText(u'')
self.VerseListWidget.clear()
self.AuthorsListView.clear()
self.TopicsListView.clear()
def loadSong(self, id):
self.song = self.songmanager.get_song(id)
self.TitleEditItem.setText(self.song.title)
@ -97,9 +101,15 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
if len(title) > 1:
self.AlternativeEdit.setText(title[1])
self.CopyrightEditItem.setText(self.song.copyright)
#self.LyricsTextEdit.setText(self.song.lyrics)
verses = self.song.lyrics.split(u'\n\n')
self.VerseListWidget.clear()
#lazy xml migration for now
if self.song.lyrics.startswith(u'<?xml version='):
songXML=SongXMLParser(self.song.lyrics)
verseList = songXML.get_verses()
for verse in verseList:
self.VerseListWidget.addItem(verse[1])
else:
verses = self.song.lyrics.split(u'\n\n')
for verse in verses:
self.VerseListWidget.addItem(verse)
# clear the results
@ -108,6 +118,12 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
author_name = QtGui.QListWidgetItem(unicode(author.display_name))
author_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(author.id))
self.AuthorsListView.addItem(author_name)
# clear the results
self.TopicsListView.clear()
for topics in self.song.topics:
author_name = QtGui.QListWidgetItem(unicode(author.display_name))
author_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(author.id))
self.AuthorsListView.addItem(author_name)
self._validate_song()
def onAddAuthorsButtonClicked(self):
@ -185,7 +201,8 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self.song.title = unicode(self.TitleEditItem.displayText())
self.song.copyright = unicode(self.CopyrightEditItem.displayText())
self.song.search_title = self.TitleEditItem.displayText() + u'@'+ self.AlternativeEdit.displayText()
self.cleanUpText()
self.processLyrics()
self.processTitle()
for i in range(0, self.AuthorsListView.count()):
print self.AuthorsListView.item(i)
@ -195,18 +212,29 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self.songmanager.save_song(self.song)
self.close()
def cleanUpText(self):
self.song.search_lyrics = self.song.lyrics.replace("'", u'')
self.song.search_lyrics = self.song.lyrics.replace(u',', u'')
self.song.search_lyrics = self.song.lyrics.replace(u';', u'')
self.song.search_lyrics = self.song.lyrics.replace(u':', u'')
self.song.search_lyrics = self.song.lyrics.replace(u'(', u'')
self.song.search_lyrics = self.song.lyrics.replace(u')', u'')
self.song.search_lyrics = self.song.lyrics.replace(u'{', u'')
self.song.search_lyrics = self.song.lyrics.replace(u'}', u'')
self.song.search_lyrics = self.song.lyrics.replace(u'?', u'')
self.song.search_lyrics = unicode(self.song.search_lyrics)
def processLyrics(self):
sxml=SongXMLBuilder()
sxml.new_document()
sxml.add_lyrics_to_song()
count = 1
text = u' '
for i in range (0, self.VerseListWidget.count()):
sxml.add_verse_to_lyrics(u'Verse', unicode(count), unicode(self.VerseListWidget.item(i).text()))
text = text + unicode(self.VerseListWidget.item(i).text()) + u' '
count += 1
text = text.replace("'", u'')
text = text.replace(u',', u'')
text = text.replace(u';', u'')
text = text.replace(u':', u'')
text = text.replace(u'(', u'')
text = text.replace(u')', u'')
text = text.replace(u'{', u'')
text = text.replace(u'}', u'')
text = text.replace(u'?', u'')
self.song.search_lyrics = unicode(text)
self.song.lyrics = unicode(sxml.extract_xml())
def processTitle(self):
self.song.search_title = self.song.search_title.replace("'", u'')
self.song.search_title = self.song.search_title.replace(u',', u'')
self.song.search_title = self.song.search_title.replace(u';', u'')

View File

@ -100,15 +100,17 @@ class SongManager():
return True
except:
log.error(u'Errow thrown %s', sys.exc_info()[1])
print u'Errow thrown ', sys.exc_info()[1]
return False
def delete_song(self, song):
def delete_song(self, songid):
song = self.get_song(songid)
try:
self.session.delete(song)
self.session.commit()
return True
except:
log.error(u'Errow thrown %s', sys.exc_info()[1])
print u'Errow thrown ', sys.exc_info()[1]
return False
def get_authors(self):

View File

@ -20,8 +20,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
import logging
from PyQt4 import QtCore, QtGui
from openlp.core.lib import MediaManagerItem, translate, ServiceItem
from openlp.core.lib import MediaManagerItem, translate, ServiceItem, SongXMLParser
from openlp.plugins.songs.forms import EditSongForm
from openlp.plugins.songs.lib import TextListData
@ -206,6 +205,7 @@ class SongMediaItem(MediaManagerItem):
self.displayResults(search_results)
def onSongNewClick(self):
self.edit_song_form.newSong()
self.edit_song_form.exec_()
self.onSearchTextButtonClick()
@ -244,6 +244,12 @@ class SongMediaItem(MediaManagerItem):
service_item.theme = None
else:
service_item.theme = song.theme_name
if song.lyrics.startswith(u'<?xml version='):
songXML=SongXMLParser(song.lyrics)
verseList = songXML.get_verses()
for verse in verseList:
service_item.add_from_text(verse[1][:30], verse[1])
else:
verses = song.lyrics.split(u'\n\n')
for slide in verses:
service_item.add_from_text(slide[:30], slide)

View File

@ -21,8 +21,7 @@ import logging
from PyQt4 import QtCore, QtGui
from openlp.core.lib import Plugin, Event
from openlp.core.lib import EventType
from openlp.core.lib import Plugin, Event, EventType, translate
from openlp.plugins.songs.lib import SongManager, SongsTab, SongMediaItem
from openlp.plugins.songs.forms import OpenLPImportForm, OpenSongExportForm, \
OpenSongImportForm, OpenLPExportForm
@ -54,55 +53,55 @@ class SongsPlugin(Plugin):
def add_import_menu_item(self, import_menu):
self.ImportSongMenu = QtGui.QMenu(import_menu)
self.ImportSongMenu.setObjectName("ImportSongMenu")
self.ImportSongMenu.setObjectName(u'ImportSongMenu')
self.ImportOpenSongItem = QtGui.QAction(import_menu)
self.ImportOpenSongItem.setObjectName("ImportOpenSongItem")
self.ImportOpenSongItem.setObjectName(u'ImportOpenSongItem')
self.ImportOpenlp1Item = QtGui.QAction(import_menu)
self.ImportOpenlp1Item.setObjectName("ImportOpenlp1Item")
self.ImportOpenlp1Item.setObjectName(u'ImportOpenlp1Item')
self.ImportOpenlp2Item = QtGui.QAction(import_menu)
self.ImportOpenlp2Item.setObjectName("ImportOpenlp2Item")
self.ImportOpenlp2Item.setObjectName(u'ImportOpenlp2Item')
# Add to menus
self.ImportSongMenu.addAction(self.ImportOpenlp1Item)
self.ImportSongMenu.addAction(self.ImportOpenlp2Item)
self.ImportSongMenu.addAction(self.ImportOpenSongItem)
import_menu.addAction(self.ImportSongMenu.menuAction())
# Translations...
self.ImportSongMenu.setTitle(QtGui.QApplication.translate("main_window", "&Song", None, QtGui.QApplication.UnicodeUTF8))
self.ImportOpenSongItem.setText(QtGui.QApplication.translate("main_window", "OpenSong", None, QtGui.QApplication.UnicodeUTF8))
self.ImportOpenlp1Item.setText(QtGui.QApplication.translate("main_window", "openlp.org 1.0", None, QtGui.QApplication.UnicodeUTF8))
self.ImportOpenlp1Item.setToolTip(QtGui.QApplication.translate("main_window", "Export songs in openlp.org 1.0 format", None, QtGui.QApplication.UnicodeUTF8))
self.ImportOpenlp1Item.setStatusTip(QtGui.QApplication.translate("main_window", "Export songs in openlp.org 1.0 format", None, QtGui.QApplication.UnicodeUTF8))
self.ImportOpenlp2Item.setText(QtGui.QApplication.translate("main_window", "OpenLP 2.0", None, QtGui.QApplication.UnicodeUTF8))
self.ImportOpenlp2Item.setToolTip(QtGui.QApplication.translate("main_window", "Export songs in OpenLP 2.0 format", None, QtGui.QApplication.UnicodeUTF8))
self.ImportOpenlp2Item.setStatusTip(QtGui.QApplication.translate("main_window", "Export songs in OpenLP 2.0 format", None, QtGui.QApplication.UnicodeUTF8))
self.ImportSongMenu.setTitle(translate(u'main_window', u'&Song'))
self.ImportOpenSongItem.setText(translate(u'main_window', u'OpenSong'))
self.ImportOpenlp1Item.setText(translate(u'main_window', u'openlp.org 1.0'))
self.ImportOpenlp1Item.setToolTip(translate(u'main_window', u'Export songs in openlp.org 1.0 format'))
self.ImportOpenlp1Item.setStatusTip(translate(u'main_window', u'Export songs in openlp.org 1.0 format'))
self.ImportOpenlp2Item.setText(translate(u'main_window', u'OpenLP 2.0'))
self.ImportOpenlp2Item.setToolTip(translate(u'main_window', u'Export songs in OpenLP 2.0 format'))
self.ImportOpenlp2Item.setStatusTip(translate(u'main_window', u'Export songs in OpenLP 2.0 format'))
# Signals and slots
QtCore.QObject.connect(self.ImportOpenlp1Item, QtCore.SIGNAL("triggered()"), self.onImportOpenlp1ItemClick)
QtCore.QObject.connect(self.ImportOpenlp2Item, QtCore.SIGNAL("triggered()"), self.onImportOpenlp1ItemClick)
QtCore.QObject.connect(self.ImportOpenSongItem, QtCore.SIGNAL("triggered()"), self.onImportOpenSongItemClick)
QtCore.QObject.connect(self.ImportOpenlp1Item, QtCore.SIGNAL(u'triggered()'), self.onImportOpenlp1ItemClick)
QtCore.QObject.connect(self.ImportOpenlp2Item, QtCore.SIGNAL(u'triggered()'), self.onImportOpenlp1ItemClick)
QtCore.QObject.connect(self.ImportOpenSongItem, QtCore.SIGNAL(u'triggered()'), self.onImportOpenSongItemClick)
def add_export_menu_item(self, export_menu):
self.ExportSongMenu = QtGui.QMenu(export_menu)
self.ExportSongMenu.setObjectName("ExportSongMenu")
self.ExportSongMenu.setObjectName(u'ExportSongMenu')
self.ExportOpenSongItem = QtGui.QAction(export_menu)
self.ExportOpenSongItem.setObjectName("ExportOpenSongItem")
self.ExportOpenSongItem.setObjectName(u'ExportOpenSongItem')
self.ExportOpenlp1Item = QtGui.QAction(export_menu)
self.ExportOpenlp1Item.setObjectName("ExportOpenlp1Item")
self.ExportOpenlp1Item.setObjectName(u'ExportOpenlp1Item')
self.ExportOpenlp2Item = QtGui.QAction(export_menu)
self.ExportOpenlp2Item.setObjectName("ExportOpenlp2Item")
self.ExportOpenlp2Item.setObjectName(u'ExportOpenlp2Item')
# Add to menus
self.ExportSongMenu.addAction(self.ExportOpenlp1Item)
self.ExportSongMenu.addAction(self.ExportOpenlp2Item)
self.ExportSongMenu.addAction(self.ExportOpenSongItem)
export_menu.addAction(self.ExportSongMenu.menuAction())
# Translations...
self.ExportSongMenu.setTitle(QtGui.QApplication.translate("main_window", "&Song", None, QtGui.QApplication.UnicodeUTF8))
self.ExportOpenSongItem.setText(QtGui.QApplication.translate("main_window", "OpenSong", None, QtGui.QApplication.UnicodeUTF8))
self.ExportOpenlp1Item.setText(QtGui.QApplication.translate("main_window", "openlp.org 1.0", None, QtGui.QApplication.UnicodeUTF8))
self.ExportOpenlp2Item.setText(QtGui.QApplication.translate("main_window", "OpenLP 2.0", None, QtGui.QApplication.UnicodeUTF8))
self.ExportSongMenu.setTitle(translate(u'main_window', u'&Song'))
self.ExportOpenSongItem.setText(translate(u'main_window', u'OpenSong'))
self.ExportOpenlp1Item.setText(translate(u'main_window', u'openlp.org 1.0'))
self.ExportOpenlp2Item.setText(translate(u'main_window', u'OpenLP 2.0'))
# Signals and slots
QtCore.QObject.connect(self.ExportOpenlp1Item, QtCore.SIGNAL("triggered()"), self.onExportOpenlp1ItemClicked)
QtCore.QObject.connect(self.ExportOpenSongItem, QtCore.SIGNAL("triggered()"), self.onExportOpenSongItemClicked)
QtCore.QObject.connect(self.ExportOpenlp1Item, QtCore.SIGNAL(u'triggered()'), self.onExportOpenlp1ItemClicked)
QtCore.QObject.connect(self.ExportOpenSongItem, QtCore.SIGNAL(u'triggered()'), self.onExportOpenSongItemClicked)
def initialise(self):
self.media_item.displayResults(self.songmanager.get_songs())