single character verse entries

This commit is contained in:
M2j 2010-06-19 23:54:53 +02:00
parent 0f7c997214
commit 735ae40996
3 changed files with 73 additions and 85 deletions

View File

@ -30,6 +30,7 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import SongXMLBuilder, SongXMLParser, Receiver, translate from openlp.core.lib import SongXMLBuilder, SongXMLParser, Receiver, translate
from openlp.plugins.songs.forms import EditVerseForm from openlp.plugins.songs.forms import EditVerseForm
from openlp.plugins.songs.lib import VerseType
from openlp.plugins.songs.lib.models import Song, Author, Topic, Book from openlp.plugins.songs.lib.models import Song, Author, Topic, Book
from editsongdialog import Ui_EditSongDialog from editsongdialog import Ui_EditSongDialog
@ -90,16 +91,8 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self.parent.parent.render_manager.theme_manager.onAddTheme) self.parent.parent.render_manager.theme_manager.onAddTheme)
QtCore.QObject.connect(self.MaintenanceButton, QtCore.QObject.connect(self.MaintenanceButton,
QtCore.SIGNAL(u'clicked()'), self.onMaintenanceButtonClicked) QtCore.SIGNAL(u'clicked()'), self.onMaintenanceButtonClicked)
QtCore.QObject.connect(self.TitleEditItem,
QtCore.SIGNAL(u'editingFinished()'), self.onTitleEditItemLostFocus)
QtCore.QObject.connect(self.CCLNumberEdit,
QtCore.SIGNAL(u'lostFocus()'), self.onCCLNumberEditLostFocus)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'theme_update_list'), self.loadThemes) QtCore.SIGNAL(u'theme_update_list'), self.loadThemes)
QtCore.QObject.connect(self.CommentsEdit,
QtCore.SIGNAL(u'lostFocus()'), self.onCommentsEditLostFocus)
QtCore.QObject.connect(self.VerseOrderEdit,
QtCore.SIGNAL(u'lostFocus()'), self.onVerseOrderEditLostFocus)
self.previewButton = QtGui.QPushButton() self.previewButton = QtGui.QPushButton()
self.previewButton.setObjectName(u'previewButton') self.previewButton.setObjectName(u'previewButton')
self.previewButton.setText( self.previewButton.setText(
@ -247,7 +240,8 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self.VerseListWidget.setRowCount( self.VerseListWidget.setRowCount(
self.VerseListWidget.rowCount() + 1) self.VerseListWidget.rowCount() + 1)
item = QtGui.QTableWidgetItem(verse) item = QtGui.QTableWidgetItem(verse)
variant = u'Verse:%s' % unicode(count + 1) variant = u'%s:%s' % \
(VerseType.to_string(VerseType.Verse), unicode(count + 1))
item.setData(QtCore.Qt.UserRole, QtCore.QVariant(variant)) item.setData(QtCore.Qt.UserRole, QtCore.QVariant(variant))
self.VerseListWidget.setItem(count, 0, item) self.VerseListWidget.setItem(count, 0, item)
self.VerseListWidget.resizeRowsToContents() self.VerseListWidget.resizeRowsToContents()
@ -519,42 +513,63 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
if len(self.TitleEditItem.displayText()) == 0: if len(self.TitleEditItem.displayText()) == 0:
self.SongTabWidget.setCurrentIndex(0) self.SongTabWidget.setCurrentIndex(0)
self.TitleEditItem.setFocus() self.TitleEditItem.setFocus()
return False, translate(u'SongsPlugin.EditSongForm', return u'failed', translate(u'SongsPlugin.EditSongForm',
u'You need to enter a song title.') u'You need to enter a song title.')
if self.VerseListWidget.rowCount() == 0: if self.VerseListWidget.rowCount() == 0:
self.SongTabWidget.setCurrentIndex(0) self.SongTabWidget.setCurrentIndex(0)
self.VerseListWidget.setFocus() self.VerseListWidget.setFocus()
return False, translate(u'SongsPlugin.EditSongForm', return u'failed', translate('uSongsPlugin.EditSongForm',
u'You need to enter some verses.') u'You need to enter some verses.')
if self.AuthorsListView.count() == 0: if self.AuthorsListView.count() == 0:
self.SongTabWidget.setCurrentIndex(1) self.SongTabWidget.setCurrentIndex(1)
self.AuthorsListView.setFocus() self.AuthorsListView.setFocus()
#split the verse list by space and mark lower case for testing answer = QtGui.QMessageBox.warning(self,
taglist = unicode(translate(u'SongsPlugin.EditSongForm', u' bitpeovc')) translate(u'SongsPlugin.EditSongForm', u'Warning'),
for verse in unicode(self.VerseOrderEdit.text()).lower().split(u' '): translate('SongsPlugin.EditSongForm',
if len(verse) > 1: 'You have set no author.\n'
if taglist.find(verse[0:1]) > -1 \ 'Do you want to add now a author?'),
and verse[1:].isdigit(): QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
pass if answer == QtGui.QMessageBox.Yes:
return u'aborted', u''
if self.song.verse_order:
order = []
order_names = self.song.verse_order.split(u' ')
for item in order_names:
if len(item) == 1:
order.append(item.lower() + u'1')
else: else:
order.append(item.lower())
verses = []
verse_names = []
for index in range (0, self.VerseListWidget.rowCount()):
verse = self.VerseListWidget.item(index, 0)
verse = unicode(verse.data(QtCore.Qt.UserRole).toString())
if verse not in verse_names:
verses.append(
re.sub(r'(.)[^:]*:(.*)', r'\1\2', verse.lower()))
verse_names.append(verse)
for count, item in enumerate(order):
if item not in verses:
self.SongTabWidget.setCurrentIndex(0) self.SongTabWidget.setCurrentIndex(0)
self.VerseOrderEdit.setFocus() self.VerseOrderEdit.setFocus()
return False, translate(u'SongsPlugin.EditSongForm', return u'failed', unicode(translate(
u'Invalid verse entry, values must be I,B,T,P,E,O,V,C ' 'SongsPlugin.EditSongForm', 'The verse order is '
u'followed by a number') 'invalid. There is no verse corresponding to %s.')) % \
return True, u'' order_names[count]
for count, verse in enumerate(verses):
def onTitleEditItemLostFocus(self): if verse not in order:
self.song.title = unicode(self.TitleEditItem.text()) self.SongTabWidget.setCurrentIndex(0)
self.VerseOrderEdit.setFocus()
def onVerseOrderEditLostFocus(self): answer = QtGui.QMessageBox.warning(self,
self.song.verse_order = unicode(self.VerseOrderEdit.text()) translate(u'SongsPlugin.EditSongForm', u'Warning'),
unicode(translate('SongsPlugin.EditSongForm',
def onCommentsEditLostFocus(self): '%s is not addressed in the verse order.\n'
self.song.comments = unicode(self.CommentsEdit.text()) 'Do you want to save anyhow?')) % \
order_names[count].replace(u':', u' '),
def onCCLNumberEditLostFocus(self): QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
self.song.ccli_number = self.CCLNumberEdit.text() if answer == QtGui.QMessageBox.No:
return u'aborted', u''
return u'passed', u''
def onCopyrightInsertButtonTriggered(self): def onCopyrightInsertButtonTriggered(self):
text = self.CopyrightEditItem.text() text = self.CopyrightEditItem.text()
@ -590,19 +605,19 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self.close() self.close()
def saveSong(self): def saveSong(self):
valid, message = self._validate_song()
if not valid:
QtGui.QMessageBox.critical(
self, translate(u'SongsPlugin.EditSongForm', u'Error'), message,
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
return False
self.song.title = unicode(self.TitleEditItem.text()) self.song.title = unicode(self.TitleEditItem.text())
self.song.copyright = unicode(self.CopyrightEditItem.text()) self.song.copyright = unicode(self.CopyrightEditItem.text())
self.song.search_title = unicode(self.TitleEditItem.text()) + \ self.song.search_title = self.song.title + u'@' + \
u'@'+ unicode(self.AlternativeEdit.text()) unicode(self.AlternativeEdit.text())
self.song.comments = unicode(self.CommentsEdit.toPlainText()) self.song.comments = unicode(self.CommentsEdit.toPlainText())
self.song.verse_order = unicode(self.VerseOrderEdit.text()) self.song.verse_order = unicode(self.VerseOrderEdit.text())
self.song.ccli_number = unicode(self.CCLNumberEdit.text()) self.song.ccli_number = unicode(self.CCLNumberEdit.text())
status, message = self._validate_song()
if status == u'failed':
QtGui.QMessageBox.critical(self,
translate(u'SongsPlugin.EditSongForm', u'Error'), message)
if status != u'passed':
return False
self.processLyrics() self.processLyrics()
self.processTitle() self.processTitle()
self.songmanager.save_song(self.song) self.songmanager.save_song(self.song)
@ -614,24 +629,15 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
sxml = SongXMLBuilder() sxml = SongXMLBuilder()
sxml.new_document() sxml.new_document()
sxml.add_lyrics_to_song() sxml.add_lyrics_to_song()
text = u' ' text = u''
for i in range (0, self.VerseListWidget.rowCount()): for i in range (0, self.VerseListWidget.rowCount()):
item = self.VerseListWidget.item(i, 0) item = self.VerseListWidget.item(i, 0)
verseId = unicode(item.data(QtCore.Qt.UserRole).toString()) verseId = unicode(item.data(QtCore.Qt.UserRole).toString())
bits = verseId.split(u':') bits = verseId.split(u':')
sxml.add_verse_to_lyrics(bits[0], bits[1], unicode(item.text())) sxml.add_verse_to_lyrics(bits[0], bits[1], unicode(item.text()))
text = text + unicode(self.VerseListWidget.item(i, 0).text()) \ text = text + re.sub(r'\W+', u' ',
+ u' ' unicode(self.VerseListWidget.item(i, 0).text())) + u' '
text = text.replace(u'\'', u'') self.song.search_lyrics = text
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(), u'utf-8') self.song.lyrics = unicode(sxml.extract_xml(), u'utf-8')
except: except:
log.exception(u'Problem processing song Lyrics \n%s', log.exception(u'Problem processing song Lyrics \n%s',
@ -639,16 +645,6 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
def processTitle(self): def processTitle(self):
log.debug(u'processTitle') log.debug(u'processTitle')
self.song.search_title = unicode(self.song.search_title) self.song.search_title = \
self.song.search_title = self.song.search_title.replace(u'\'', u'') re.sub(r'[\'"`,;:(){}?]+', u'', unicode(self.song.search_title))
self.song.search_title = self.song.search_title.replace(u'\"', u'')
self.song.search_title = self.song.search_title.replace(u'`', u'')
self.song.search_title = self.song.search_title.replace(u',', u'')
self.song.search_title = self.song.search_title.replace(u';', u'')
self.song.search_title = self.song.search_title.replace(u':', u'')
self.song.search_title = self.song.search_title.replace(u'(', u'')
self.song.search_title = self.song.search_title.replace(u')', u'')
self.song.search_title = self.song.search_title.replace(u'{', 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

@ -23,6 +23,7 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Temple Place, Suite 330, Boston, MA 02111-1307 USA #
############################################################################### ###############################################################################
import re
import logging import logging
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
@ -160,6 +161,7 @@ class SongMediaItem(MediaManagerItem):
def onSearchTextButtonClick(self): def onSearchTextButtonClick(self):
search_keywords = unicode(self.SearchTextEdit.displayText()) search_keywords = unicode(self.SearchTextEdit.displayText())
search_keywords = re.sub(r'\W+', u' ', search_keywords)
search_results = [] search_results = []
search_type = self.SearchTypeComboBox.currentIndex() search_type = self.SearchTypeComboBox.currentIndex()
if search_type == 0: if search_type == 0:
@ -350,8 +352,8 @@ class SongMediaItem(MediaManagerItem):
if len(order) == 0: if len(order) == 0:
break break
for verse in verseList: for verse in verseList:
if verse[0][u'label'] == order[1:] and \ if verse[0][u'type'][0] == order[0] and \
verse[0][u'type'][0] == order[0]: (verse[0][u'label'] == order[1:] or not order[1:]):
verseTag = u'%s:%s' % \ verseTag = u'%s:%s' % \
(verse[0][u'type'], verse[0][u'label']) (verse[0][u'type'], verse[0][u'label'])
service_item.add_from_text( service_item.add_from_text(

View File

@ -24,6 +24,7 @@
############################################################################### ###############################################################################
import string import string
import re
from PyQt4 import QtGui from PyQt4 import QtGui
@ -89,9 +90,6 @@ class SongImport(object):
Get rid of some dodgy unicode and formatting characters we're not Get rid of some dodgy unicode and formatting characters we're not
interested in. Some can be converted to ascii. interested in. Some can be converted to ascii.
""" """
text = text.replace(u'\t', u' ')
text = text.replace(u'\r\n', u'\n')
text = text.replace(u'\r', u'\n')
text = text.replace(u'\u2018', u'\'') text = text.replace(u'\u2018', u'\'')
text = text.replace(u'\u2019', u'\'') text = text.replace(u'\u2019', u'\'')
text = text.replace(u'\u201c', u'"') text = text.replace(u'\u201c', u'"')
@ -100,15 +98,9 @@ class SongImport(object):
text = text.replace(u'\u2013', u'-') text = text.replace(u'\u2013', u'-')
text = text.replace(u'\u2014', u'-') text = text.replace(u'\u2014', u'-')
# Remove surplus blank lines, spaces, trailing/leading spaces # Remove surplus blank lines, spaces, trailing/leading spaces
while text.find(u' ') >= 0: text = re.sub(r'[ \t\v]+', u' ', text)
text = text.replace(u' ', u' ') text = re.sub(r' ?(\r\n?|\n) ?', u'\n', text)
text = text.replace(u'\n ', u'\n') text = re.sub(r' ?(\n{5}|\f)+ ?', u'\f', text)
text = text.replace(u' \n', u'\n')
text = text.replace(u'\n\n\n\n\n', u'\f')
text = text.replace(u'\f ', u'\f')
text = text.replace(u' \f', u'\f')
while text.find(u'\f\f') >= 0:
text = text.replace(u'\f\f', u'\f')
return text return text
def process_song_text(self, text): def process_song_text(self, text):
@ -264,11 +256,9 @@ class SongImport(object):
def remove_punctuation(self, text): def remove_punctuation(self, text):
""" """
Remove punctuation from the string for searchable fields Extracts alphanumeric words for searchable fields
""" """
for character in string.punctuation: return re.sub(r'\W+', u' ', text)
text = text.replace(character, u'')
return text
def finish(self): def finish(self):
""" """