openlp-core team mailing list archive
-
openlp-core team
-
Mailing list archive
-
Message #01913
[Merge] lp:~m2j/openlp/work into lp:openlp
m2j has proposed merging lp:~m2j/openlp/work into lp:openlp.
Requested reviews:
OpenLP Core (openlp-core)
song verse order and some other charset things
--
https://code.launchpad.net/~m2j/openlp/work/+merge/28007
Your team OpenLP Core is requested to review the proposed merge of lp:~m2j/openlp/work into lp:openlp.
=== modified file 'openlp/plugins/songs/forms/editsongdialog.py'
--- openlp/plugins/songs/forms/editsongdialog.py 2010-06-18 19:55:45 +0000
+++ openlp/plugins/songs/forms/editsongdialog.py 2010-06-20 00:02:25 +0000
@@ -384,9 +384,6 @@
self.CommentsLayout.addWidget(self.CommentsEdit)
self.ThemeCopyCommentsLayout.addWidget(self.CommentsGroupBox)
self.ThemeTabLayout.addWidget(self.ThemeCopyCommentsWidget)
- spacerItem5 = QtGui.QSpacerItem(20, 40,
- QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding)
- self.ThemeTabLayout.addItem(spacerItem5)
self.SongTabWidget.addTab(self.ThemeTab, u'')
self.verticalLayout.addWidget(self.SongTabWidget)
self.ButtonBox = QtGui.QDialogButtonBox(EditSongDialog)
=== modified file 'openlp/plugins/songs/forms/editsongform.py'
--- openlp/plugins/songs/forms/editsongform.py 2010-06-19 11:42:33 +0000
+++ openlp/plugins/songs/forms/editsongform.py 2010-06-20 00:02:25 +0000
@@ -30,6 +30,7 @@
from openlp.core.lib import SongXMLBuilder, SongXMLParser, Receiver, translate
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 editsongdialog import Ui_EditSongDialog
@@ -90,16 +91,8 @@
self.parent.parent.render_manager.theme_manager.onAddTheme)
QtCore.QObject.connect(self.MaintenanceButton,
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.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.setObjectName(u'previewButton')
self.previewButton.setText(
@@ -247,7 +240,8 @@
self.VerseListWidget.setRowCount(
self.VerseListWidget.rowCount() + 1)
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))
self.VerseListWidget.setItem(count, 0, item)
self.VerseListWidget.resizeRowsToContents()
@@ -522,42 +516,66 @@
if len(self.TitleEditItem.displayText()) == 0:
self.SongTabWidget.setCurrentIndex(0)
self.TitleEditItem.setFocus()
- return False, translate(u'SongsPlugin.EditSongForm',
+ return u'failed', translate(u'SongsPlugin.EditSongForm',
u'You need to enter a song title.')
if self.VerseListWidget.rowCount() == 0:
self.SongTabWidget.setCurrentIndex(0)
self.VerseListWidget.setFocus()
- return False, translate(u'SongsPlugin.EditSongForm',
+ return u'failed', translate('uSongsPlugin.EditSongForm',
u'You need to enter some verses.')
if self.AuthorsListView.count() == 0:
self.SongTabWidget.setCurrentIndex(1)
self.AuthorsListView.setFocus()
- #split the verse list by space and mark lower case for testing
- taglist = unicode(translate(u'SongsPlugin.EditSongForm', u' bitpeovc'))
- for verse in unicode(self.VerseOrderEdit.text()).lower().split(u' '):
- if len(verse) > 1:
- if taglist.find(verse[0:1]) > -1 \
- and verse[1:].isdigit():
- pass
+ answer = QtGui.QMessageBox.warning(self,
+ translate(u'SongsPlugin.EditSongForm', u'Warning'),
+ translate('SongsPlugin.EditSongForm',
+ 'You have set no author.\n'
+ 'Do you want to add now a author?'),
+ QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
+ 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:
- self.SongTabWidget.setCurrentIndex(0)
- self.VerseOrderEdit.setFocus()
- return False, translate(u'SongsPlugin.EditSongForm',
- u'Invalid verse entry, values must be I,B,T,P,E,O,V,C '
- u'followed by a number')
- return True, u''
-
- def onTitleEditItemLostFocus(self):
- self.song.title = unicode(self.TitleEditItem.text())
-
- def onVerseOrderEditLostFocus(self):
- self.song.verse_order = unicode(self.VerseOrderEdit.text())
-
- def onCommentsEditLostFocus(self):
- self.song.comments = unicode(self.CommentsEdit.text())
-
- def onCCLNumberEditLostFocus(self):
- self.song.ccli_number = self.CCLNumberEdit.text()
+ 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.VerseOrderEdit.setFocus()
+ valid = verses.pop(0)
+ for verse in verses:
+ valid = valid + u', ' + verse
+ return u'failed', unicode(translate(
+ 'SongsPlugin.EditSongForm', 'The verse order is '
+ 'invalid. There is no verse corresponding to %s. '
+ 'Valid entries are %s.')) % (order_names[count], valid)
+ for count, verse in enumerate(verses):
+ if verse not in order:
+ self.SongTabWidget.setCurrentIndex(0)
+ self.VerseOrderEdit.setFocus()
+ answer = QtGui.QMessageBox.warning(self,
+ translate(u'SongsPlugin.EditSongForm', u'Warning'),
+ unicode(translate('SongsPlugin.EditSongForm',
+ '%s is not addressed in the verse order.\n'
+ 'Do you want to save anyhow?')) % \
+ order_names[count].replace(u':', u' '),
+ QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
+ if answer == QtGui.QMessageBox.No:
+ return u'aborted', u''
+ return u'passed', u''
def onCopyrightInsertButtonTriggered(self):
text = self.CopyrightEditItem.text()
@@ -593,19 +611,19 @@
self.close()
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.copyright = unicode(self.CopyrightEditItem.text())
- self.song.search_title = unicode(self.TitleEditItem.text()) + \
- u'@'+ unicode(self.AlternativeEdit.text())
+ self.song.search_title = self.song.title + u'@' + \
+ unicode(self.AlternativeEdit.text())
self.song.comments = unicode(self.CommentsEdit.toPlainText())
self.song.verse_order = unicode(self.VerseOrderEdit.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.processTitle()
self.songmanager.save_song(self.song)
@@ -617,41 +635,31 @@
sxml = SongXMLBuilder()
sxml.new_document()
sxml.add_lyrics_to_song()
- text = u' '
+ text = u''
+ multiple = []
for i in range (0, self.VerseListWidget.rowCount()):
item = self.VerseListWidget.item(i, 0)
verseId = unicode(item.data(QtCore.Qt.UserRole).toString())
bits = verseId.split(u':')
sxml.add_verse_to_lyrics(bits[0], bits[1], unicode(item.text()))
- text = text + unicode(self.VerseListWidget.item(i, 0).text()) \
- + 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'')
- text = text.replace(u'?', u'')
- self.song.search_lyrics = unicode(text)
+ text = text + re.sub(r'\W+', u' ',
+ unicode(self.VerseListWidget.item(i, 0).text())) + u' '
+ if (bits[1] > u'1') and (bits[0][0] not in multiple):
+ multiple.append(bits[0][0])
+ print bits[0][0]
+ self.song.search_lyrics = text
self.song.lyrics = unicode(sxml.extract_xml(), u'utf-8')
+ for verse in multiple:
+ self.song.verse_order = self.song.verse_order.replace(
+ verse.upper() + u' ', verse.upper() + u'1 ')
+ self.song.verse_order = self.song.verse_order.replace(
+ verse.lower() + u' ', verse.lower() + u'1 ')
except:
log.exception(u'Problem processing song Lyrics \n%s',
sxml.dump_xml())
def processTitle(self):
log.debug(u'processTitle')
- self.song.search_title = 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'')
- self.song.search_title = self.song.search_title.replace(u'?', u'')
+ self.song.search_title = \
+ re.sub(r'[\'"`,;:(){}?]+', u'', unicode(self.song.search_title))
=== modified file 'openlp/plugins/songs/lib/mediaitem.py'
--- openlp/plugins/songs/lib/mediaitem.py 2010-06-18 22:09:41 +0000
+++ openlp/plugins/songs/lib/mediaitem.py 2010-06-20 00:02:25 +0000
@@ -350,8 +350,8 @@
if len(order) == 0:
break
for verse in verseList:
- if verse[0][u'label'] == order[1:] and \
- verse[0][u'type'][0] == order[0]:
+ if verse[0][u'type'][0] == order[0] and \
+ (verse[0][u'label'] == order[1:] or not order[1:]):
verseTag = u'%s:%s' % \
(verse[0][u'type'], verse[0][u'label'])
service_item.add_from_text(
=== modified file 'openlp/plugins/songs/lib/songimport.py'
--- openlp/plugins/songs/lib/songimport.py 2010-06-15 15:22:26 +0000
+++ openlp/plugins/songs/lib/songimport.py 2010-06-20 00:02:25 +0000
@@ -24,6 +24,7 @@
###############################################################################
import string
+import re
from PyQt4 import QtGui
@@ -89,9 +90,6 @@
Get rid of some dodgy unicode and formatting characters we're not
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'\u2019', u'\'')
text = text.replace(u'\u201c', u'"')
@@ -100,15 +98,9 @@
text = text.replace(u'\u2013', u'-')
text = text.replace(u'\u2014', u'-')
# Remove surplus blank lines, spaces, trailing/leading spaces
- while text.find(u' ') >= 0:
- text = text.replace(u' ', u' ')
- text = text.replace(u'\n ', u'\n')
- 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')
+ text = re.sub(r'[ \t\v]+', u' ', text)
+ text = re.sub(r' ?(\r\n?|\n) ?', u'\n', text)
+ text = re.sub(r' ?(\n{5}|\f)+ ?', u'\f', text)
return text
def process_song_text(self, text):
@@ -264,11 +256,9 @@
def remove_punctuation(self, text):
"""
- Remove punctuation from the string for searchable fields
+ Extracts alphanumeric words for searchable fields
"""
- for character in string.punctuation:
- text = text.replace(character, u'')
- return text
+ return re.sub(r'\W+', u' ', text)
def finish(self):
"""
Follow ups