← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~trb143/openlp/working into lp:openlp

 

Tim Bentley has proposed merging lp:~trb143/openlp/working into lp:openlp with lp:~m2j/openlp/work as a prerequisite.

Requested reviews:
  OpenLP Core (openlp-core)


Cleaned up song tags so all tags can have multiple instances.
fixed code to allow tags to be translated and removed all hard coded values.
fixed up song import class buy did not test it.
-- 
https://code.launchpad.net/~trb143/openlp/working/+merge/26882
Your team OpenLP Core is requested to review the proposed merge of lp:~trb143/openlp/working into lp:openlp.
=== modified file 'openlp/core/ui/slidecontroller.py'
--- openlp/core/ui/slidecontroller.py	2010-06-01 00:45:20 +0000
+++ openlp/core/ui/slidecontroller.py	2010-06-06 12:42:25 +0000
@@ -537,17 +537,9 @@
             if self.serviceItem.is_text():
                 if frame[u'verseTag']:
                     bits = frame[u'verseTag'].split(u':')
-                    tag = None
-                    #If verse handle verse number else tag only
-                    if bits[0] == self.trUtf8('Verse') or \
-                        bits[0] == self.trUtf8('Chorus'):
-                        tag = u'%s\n%s' % (bits[0][0], bits[1][0:] )
-                        tag1 = u'%s%s' % (bits[0][0], bits[1][0:] )
-                        row = tag
-                    else:
-                        tag = bits[0]
-                        tag1 = tag
-                        row = bits[0][0:1]
+                    tag = u'%s\n%s' % (bits[0][0], bits[1][0:] )
+                    tag1 = u'%s%s' % (bits[0][0], bits[1][0:] )
+                    row = tag
                 else:
                     row += 1
                 if self.isLive and frame[u'verseTag'] is not None:

=== modified file 'openlp/plugins/songs/forms/__init__.py'
--- openlp/plugins/songs/forms/__init__.py	2010-04-02 12:23:40 +0000
+++ openlp/plugins/songs/forms/__init__.py	2010-06-06 12:42:25 +0000
@@ -23,6 +23,52 @@
 # Temple Place, Suite 330, Boston, MA 02111-1307 USA                          #
 ###############################################################################
 
+from openlp.core.lib import translate
+
+class VerseType(object):
+    Verse = 0
+    Chorus = 1
+    Bridge = 2
+    PreChorus = 3
+    Intro = 4
+    Ending = 5
+    Other = 6
+
+    @staticmethod
+    def to_string(verse_type):
+        if verse_type == VerseType.Verse:
+            return translate('VerseType', 'Verse')
+        elif verse_type == VerseType.Chorus:
+            return translate('VerseType', 'Chorus')
+        elif verse_type == VerseType.Bridge:
+            return translate('VerseType', 'Bridge')
+        elif verse_type == VerseType.PreChorus:
+            return translate('VerseType', 'Pre-Chorus')
+        elif verse_type == VerseType.Intro:
+            return translate('VerseType', 'Intro')
+        elif verse_type == VerseType.Ending:
+            return translate('VerseType', 'Ending')
+        elif verse_type == VerseType.Other:
+            return translate('VerseType', 'Other')
+
+    @staticmethod
+    def from_string(verse_type):
+        verse_type = verse_type.lower()
+        if verse_type == translate('VerseType', 'verse'):
+            return VerseType.Verse
+        elif verse_type == translate('VerseType', 'chorus'):
+            return VerseType.Chorus
+        elif verse_type == translate('VerseType', 'bridge'):
+            return VerseType.Bridge
+        elif verse_type == translate('VerseType', 'pre-chorus'):
+            return VerseType.PreChorus
+        elif verse_type == translate('VerseType', 'intro'):
+            return VerseType.Intro
+        elif verse_type == translate('VerseType', 'ending'):
+            return VerseType.Ending
+        elif verse_type == translate('VerseType', 'other'):
+            return VerseType.Other
+
 from authorsform import AuthorsForm
 from topicsform import TopicsForm
 from songbookform import SongBookForm

=== modified file 'openlp/plugins/songs/forms/editsongform.py'
--- openlp/plugins/songs/forms/editsongform.py	2010-05-29 19:50:50 +0000
+++ openlp/plugins/songs/forms/editsongform.py	2010-06-06 12:42:25 +0000
@@ -469,27 +469,18 @@
             self.SongTabWidget.setCurrentIndex(1)
             self.AuthorsListView.setFocus()
         #split the verse list by space and mark lower case for testing
-        taglist = unicode(self.trUtf8(' bitped'))
+        taglist = unicode(self.trUtf8(' bitpeovc'))
         for verse in unicode(self.VerseOrderEdit.text()).lower().split(u' '):
             if len(verse) > 1:
-                if (verse[0:1] == u'%s' % self.trUtf8('v') or
-                    verse[0:1] == u'%s' % self.trUtf8('c')) \
+                if taglist.find(verse[0:1]) > -1 \
                     and verse[1:].isdigit():
                     pass
                 else:
                     self.SongTabWidget.setCurrentIndex(0)
                     self.VerseOrderEdit.setFocus()
                     return False, \
-                        self.trUtf8('Invalid verse entry - Vx or Cx')
-            else:
-                if taglist.find(verse) > -1:
-                    pass
-                else:
-                    self.SongTabWidget.setCurrentIndex(0)
-                    self.VerseOrderEdit.setFocus()
-                    return False, \
                         self.trUtf8(\
-                        'Invalid verse entry, values must be I,B,T,P,E,O,Vx,Cx')
+                        'Invalid verse entry, values must be I,B,T,P,E,O,V,C followed by a number')
         return True, u''
 
     def onTitleEditItemLostFocus(self):

=== modified file 'openlp/plugins/songs/forms/editversedialog.py'
--- openlp/plugins/songs/forms/editversedialog.py	2010-05-17 20:48:16 +0000
+++ openlp/plugins/songs/forms/editversedialog.py	2010-06-06 12:42:25 +0000
@@ -24,7 +24,9 @@
 ###############################################################################
 
 from PyQt4 import QtCore, QtGui
+
 from openlp.core.lib import translate
+from openlp.plugins.songs.forms import VerseType
 
 class Ui_EditVerseDialog(object):
     def setupUi(self, EditVerseDialog):
@@ -92,13 +94,12 @@
     def retranslateUi(self, EditVerseDialog):
         EditVerseDialog.setWindowTitle(translate('EditVerseForm', 'Edit Verse'))
         self.VerseTypeLabel.setText(translate('EditVerseForm', 'Verse Type:'))
-        self.VerseTypeComboBox.setItemText(0, translate('EditVerseForm', 'Verse'))
-        self.VerseTypeComboBox.setItemText(1, translate('EditVerseForm', 'Chorus'))
-        self.VerseTypeComboBox.setItemText(2, translate('EditVerseForm', 'Bridge'))
-        self.VerseTypeComboBox.setItemText(3, translate('EditVerseForm', 'Pre-Chorus'))
-        self.VerseTypeComboBox.setItemText(4, translate('EditVerseForm', 'Intro'))
-        self.VerseTypeComboBox.setItemText(5, translate('EditVerseForm', 'Ending'))
-        self.VerseTypeComboBox.setItemText(6, translate('EditVerseForm', 'Other'))
+        self.VerseTypeComboBox.setItemText(0, VerseType.to_string(VerseType.Verse))
+        self.VerseTypeComboBox.setItemText(1, VerseType.to_string(VerseType.Chorus))
+        self.VerseTypeComboBox.setItemText(2, VerseType.to_string(VerseType.Bridge))
+        self.VerseTypeComboBox.setItemText(3, VerseType.to_string(VerseType.PreChorus))
+        self.VerseTypeComboBox.setItemText(4, VerseType.to_string(VerseType.Intro))
+        self.VerseTypeComboBox.setItemText(5, VerseType.to_string(VerseType.Ending))
+        self.VerseTypeComboBox.setItemText(6, VerseType.to_string(VerseType.Other))
         self.InsertButton.setText(translate('EditVerseForm', 'Insert'))
 
-

=== modified file 'openlp/plugins/songs/forms/editverseform.py'
--- openlp/plugins/songs/forms/editverseform.py	2010-05-17 20:48:16 +0000
+++ openlp/plugins/songs/forms/editverseform.py	2010-06-06 12:42:25 +0000
@@ -28,55 +28,12 @@
 
 from PyQt4 import QtCore, QtGui
 
+from openlp.plugins.songs.forms import VerseType
+
 from editversedialog import Ui_EditVerseDialog
 
 log = logging.getLogger(__name__)
 
-class VerseType(object):
-    Verse = 0
-    Chorus = 1
-    Bridge = 2
-    PreChorus = 3
-    Intro = 4
-    Ending = 5
-    Other = 6
-
-    @staticmethod
-    def to_string(verse_type):
-        if verse_type == VerseType.Verse:
-            return u'Verse'
-        elif verse_type == VerseType.Chorus:
-            return u'Chorus'
-        elif verse_type == VerseType.Bridge:
-            return u'Bridge'
-        elif verse_type == VerseType.PreChorus:
-            return u'Pre-Chorus'
-        elif verse_type == VerseType.Intro:
-            return u'Intro'
-        elif verse_type == VerseType.Ending:
-            return u'Ending'
-        elif verse_type == VerseType.Other:
-            return u'Other'
-
-    @staticmethod
-    def from_string(verse_type):
-        verse_type = verse_type.lower()
-        if verse_type == u'verse':
-            return VerseType.Verse
-        elif verse_type == u'chorus':
-            return VerseType.Chorus
-        elif verse_type == u'bridge':
-            return VerseType.Bridge
-        elif verse_type == u'pre-chorus':
-            return VerseType.PreChorus
-        elif verse_type == u'intro':
-            return VerseType.Intro
-        elif verse_type == u'ending':
-            return VerseType.Ending
-        elif verse_type == u'other':
-            return VerseType.Other
-
-
 class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog):
     """
     This is the form that is used to edit the verses of the song.
@@ -97,8 +54,6 @@
             QtCore.SIGNAL(u'cursorPositionChanged()'),
             self.onCursorPositionChanged
         )
-#        QtCore.QObject.connect(self.VerseListComboBox,
-#            QtCore.SIGNAL(u'activated(int)'), self.onVerseComboChanged)
         self.verse_regex = re.compile(r'---\[([-\w]+):([\d]+)\]---')
 
     def insertVerse(self, title, num=1):
@@ -112,19 +67,21 @@
             self.VerseTextEdit.insertPlainText(u'\n')
         verse_type = self.VerseTypeComboBox.currentIndex()
         if verse_type == VerseType.Verse:
-            self.insertVerse('Verse', self.VerseNumberBox.value())
+            self.insertVerse(VerseType.to_string(VerseType.Verse),
+                self.VerseNumberBox.value())
         elif verse_type == VerseType.Chorus:
-            self.insertVerse('Chorus', self.VerseNumberBox.value())
+            self.insertVerse(VerseType.to_string(VerseType.Chorus),
+                self.VerseNumberBox.value())
         elif verse_type == VerseType.Bridge:
-            self.insertVerse('Bridge')
+            self.insertVerse(VerseType.to_string(VerseType.Bridge))
         elif verse_type == VerseType.PreChorus:
-            self.insertVerse('Pre-Chorus')
+            self.insertVerse(VerseType.to_string(VerseType.PreChorus))
         elif verse_type == VerseType.Intro:
-            self.insertVerse('Intro')
+            self.insertVerse(VerseType.to_string(VerseType.Intro))
         elif verse_type == VerseType.Ending:
-            self.insertVerse('Ending')
+            self.insertVerse(VerseType.to_string(VerseType.Ending))
         elif verse_type == VerseType.Other:
-            self.insertVerse('Other')
+            self.insertVerse(VerseType.to_string(VerseType.Other))
 
     def onCursorPositionChanged(self):
         position = self.VerseTextEdit.textCursor().position()
@@ -149,7 +106,8 @@
             self.VerseTypeComboBox.setCurrentIndex(VerseType.from_string(verse_type))
             self.VerseNumberBox.setValue(verse_number)
 
-    def setVerse(self, text, single=False, tag=u'Verse:1'):
+    def setVerse(self, text, single=False,
+        tag=u'%s:1' % VerseType.to_string(VerseType.Verse)):
         if single:
             verse_type, verse_number = tag.split(u':')
             self.VerseTypeComboBox.setCurrentIndex(VerseType.from_string(verse_type))
@@ -157,12 +115,13 @@
             self.InsertButton.setVisible(False)
         else:
             if not text:
-                text = u'---[Verse:1]---\n'
+                text = u'---[%s:1]---\n' % VerseType.to_string(VerseType.Verse)
             self.VerseTypeComboBox.setCurrentIndex(0)
             self.VerseNumberBox.setValue(1)
             self.InsertButton.setVisible(True)
         self.VerseTextEdit.setPlainText(text)
         self.VerseTextEdit.setFocus(QtCore.Qt.OtherFocusReason)
+        self.VerseTextEdit.moveCursor(QtGui.QTextCursor.End)
 
     def getVerse(self):
         return self.VerseTextEdit.toPlainText(), \
@@ -172,7 +131,6 @@
     def getVerseAll(self):
         text = self.VerseTextEdit.toPlainText()
         if not text.startsWith(u'---['):
-            text = u'---[Verse:1]---\n%s' % text
+            text = u'---[%s:1]---\n%s' % (VerseType.to_string(VerseType.Verse), text)
         return text
 
-

=== modified file 'openlp/plugins/songs/lib/__init__.py'
--- openlp/plugins/songs/lib/__init__.py	2010-04-12 07:22:56 +0000
+++ openlp/plugins/songs/lib/__init__.py	2010-06-06 12:42:25 +0000
@@ -29,3 +29,4 @@
 from sofimport import SofImport
 from oooimport import OooImport
 from songimport import SongImport
+

=== modified file 'openlp/plugins/songs/lib/mediaitem.py'
--- openlp/plugins/songs/lib/mediaitem.py	2010-05-25 23:47:26 +0000
+++ openlp/plugins/songs/lib/mediaitem.py	2010-06-06 12:42:25 +0000
@@ -334,21 +334,12 @@
                     if len(order) == 0:
                         break
                     for verse in verseList:
-                        if verse[1]:
-                            if verse[0][u'type'] == "Verse" \
-                                or verse[0][u'type'] == "Chorus":
-                                if verse[0][u'label'] == order[1:] and \
-                                    verse[0][u'type'][0] == order[0]:
-                                    verseTag = u'%s:%s' % \
-                                        (verse[0][u'type'], verse[0][u'label'])
-                                    service_item.add_from_text\
-                                        (verse[1][:30], verse[1], verseTag)
-                            else:
-                                if verse[0][u'type'][0] == order[0]:
-                                    verseTag = u'%s:%s' % \
-                                        (verse[0][u'type'], verse[0][u'label'])
-                                    service_item.add_from_text\
-                                        (verse[1][:30], verse[1], verseTag)
+                        if verse[0][u'label'] == order[1:] and \
+                            verse[0][u'type'][0] == order[0]:
+                            verseTag = u'%s:%s' % \
+                                (verse[0][u'type'], verse[0][u'label'])
+                            service_item.add_from_text\
+                                (verse[1][:30], verse[1], verseTag)
         else:
             verses = song.lyrics.split(u'\n\n')
             for slide in verses:

=== modified file 'openlp/plugins/songs/lib/songimport.py'
--- openlp/plugins/songs/lib/songimport.py	2010-05-26 15:52:33 +0000
+++ openlp/plugins/songs/lib/songimport.py	2010-06-06 12:42:25 +0000
@@ -29,20 +29,21 @@
 
 from openlp.core.lib import SongXMLBuilder
 from openlp.plugins.songs.lib.models import Song, Author, Topic, Book
-        
+from openlp.plugins.songs.forms import VerseType
+
 class SongImport(object):
     """
     Helper class for import a song from a third party source into OpenLP
 
     This class just takes the raw strings, and will work out for itself
-    whether the authors etc already exist and add them or refer to them 
+    whether the authors etc already exist and add them or refer to them
     as necessary
     """
 
     def __init__(self, song_manager):
         """
         Initialise and create defaults for properties
-        
+
         song_manager is an instance of a SongManager, through which all
         database access is performed
         """
@@ -53,13 +54,13 @@
         self.copyright = u''
         self.comment = u''
         self.theme_name = u''
-        self.ccli_number = u''    
-        self.authors = []           
-        self.topics = []            
-        self.song_book_name = u''   
-        self.song_book_pub = u''   
-        self.verse_order_list = []  
-        self.verses = []            
+        self.ccli_number = u''
+        self.authors = []
+        self.topics = []
+        self.song_book_name = u''
+        self.song_book_pub = u''
+        self.verse_order_list = []
+        self.verses = []
         self.versecount = 0
         self.choruscount = 0
         self.copyright_string = unicode(QtGui.QApplication.translate( \
@@ -128,39 +129,39 @@
                     copyright_found = True
                     self.add_copyright(line)
                 else:
-                    self.parse_author(line)   
-            return                                             
+                    self.parse_author(line)
+            return
         if len(lines) == 1:
             self.parse_author(lines[0])
             return
         if not self.get_title():
             self.set_title(lines[0])
         self.add_verse(text)
-       
+
     def get_title(self):
         """
         Return the title
         """
         return self.title
-        
+
     def get_copyright(self):
         """
         Return the copyright
         """
         return self.copyright
-        
+
     def get_song_number(self):
-        """ 
-        Return the song number 
+        """
+        Return the song number
         """
         return self.song_number
-        
+
     def set_title(self, title):
         """
         Set the title
         """
         self.title = title
- 
+
     def set_alternate_title(self, title):
         """
         Set the alternate title
@@ -168,11 +169,11 @@
         self.alternate_title = title
 
     def set_song_number(self, song_number):
-        """ 
+        """
         Set the song number
         """
         self.song_number = song_number
-        
+
     def set_song_book(self, song_book, publisher):
         """
         Set the song book name and publisher
@@ -181,7 +182,7 @@
         self.song_book_pub = publisher
 
     def add_copyright(self, copyright):
-        """ 
+        """
         Build the copyright field
         """
         if self.copyright.find(copyright) >= 0:
@@ -194,7 +195,7 @@
         """
         Add the author. OpenLP stores them individually so split by 'and', '&'
         and comma.
-        However need to check for "Mr and Mrs Smith" and turn it to 
+        However need to check for "Mr and Mrs Smith" and turn it to
         "Mr Smith" and "Mrs Smith".
         """
         for author in text.split(u','):
@@ -210,13 +211,13 @@
                     self.add_author(author2)
 
     def add_author(self, author):
-        """ 
+        """
         Add an author to the list
         """
         if author in self.authors:
             return
         self.authors.append(author)
-        
+
     def add_verse(self, verse, versetag=None):
         """
         Add a verse. This is the whole verse, lines split by \n
@@ -224,7 +225,7 @@
         choruses itself) or None, where it will assume verse
         It will also attempt to detect duplicates. In this case it will just
         add to the verse order
-        """        
+        """
         for (oldversetag, oldverse) in self.verses:
             if oldverse.strip() == verse.strip():
                 self.verse_order_list.append(oldversetag)
@@ -253,22 +254,22 @@
     def check_complete(self):
         """
         Check the mandatory fields are entered (i.e. title and a verse)
-        Author not checked here, if no author then "Author unknown" is 
+        Author not checked here, if no author then "Author unknown" is
         automatically added
         """
         if self.title == u'' or len(self.verses) == 0:
             return False
         else:
             return True
-            
-    def remove_punctuation(self, text):	
+
+    def remove_punctuation(self, text):
         """
         Remove punctuation from the string for searchable fields
         """
         for character in string.punctuation:
             text = text.replace(character, u'')
         return text
-            
+
     def finish(self):
         """
         All fields have been set to this song. Write it away
@@ -277,7 +278,7 @@
             self.authors.append(u'Author unknown')
         self.commit_song()
         #self.print_song()
-        
+
     def commit_song(self):
         """
         Write the song and it's fields to disk
@@ -293,27 +294,27 @@
         sxml.add_lyrics_to_song()
         for (versetag, versetext) in self.verses:
             if versetag[0] == u'C':
-                versetype = u'Chorus'
+                versetype = VerseType.to_string(VerseType.Chorus)
             elif versetag[0] == u'V':
-                versetype = u'Verse'
+                versetype = VerseType.to_string(VerseType.Verse)
             elif versetag[0] == u'B':
-                versetype = u'Bridge'
+                versetype = VerseType.to_string(VerseType.Bridge)
             elif versetag[0] == u'I':
-                versetype = u'Intro'
+                versetype = VerseType.to_string(VerseType.Intro)
             elif versetag[0] == u'P':
-                versetype = u'Prechorus'
+                versetype = VerseType.to_string(VerseType.PreChorus)
             elif versetag[0] == u'E':
-                versetype = u'Ending'
+                versetype = VerseType.to_string(VerseType.Ending)
             else:
-                versetype = u'Other'
+                versetype = VerseType.to_string(VerseType.Other)
             sxml.add_verse_to_lyrics(versetype, versetag[1:], versetext)
             song.search_lyrics += u' ' + self.remove_punctuation(versetext)
         song.lyrics = unicode(sxml.extract_xml(), u'utf-8')
         song.verse_order = u' '.join(self.verse_order_list)
         song.copyright = self.copyright
-        song.comment = self.comment 
-        song.theme_name = self.theme_name 
-        song.ccli_number = self.ccli_number 
+        song.comment = self.comment
+        song.theme_name = self.theme_name
+        song.ccli_number = self.ccli_number
         for authortext in self.authors:
             author = self.manager.get_author_by_name(authortext)
             if author is None:
@@ -339,15 +340,15 @@
                 self.manager.save_topic(topic)
             song.topics.append(topictext)
         self.manager.save_song(song)
-        
+
     def print_song(self):
-        """ 
-        For debugging 
+        """
+        For debugging
         """
         print u'========================================'   \
             + u'========================================'
-        print u'TITLE: ' + self.title 
-        print u'ALT TITLE: ' + self.alternate_title 
+        print u'TITLE: ' + self.title
+        print u'ALT TITLE: ' + self.alternate_title
         for (versetag, versetext) in self.verses:
             print u'VERSE ' + versetag + u': ' + versetext
         print u'ORDER: ' + u' '.join(self.verse_order_list)
@@ -361,7 +362,7 @@
             print u'BOOK PUBLISHER: ' + self.song_book_pub
         if self.song_number:
             print u'NUMBER: ' + self.song_number
-        for topictext in self.topics:        
+        for topictext in self.topics:
             print u'TOPIC: ' + topictext
         if self.comment:
             print u'COMMENT: ' + self.comment
@@ -369,5 +370,5 @@
             print u'THEME: ' + self.theme_name
         if self.ccli_number:
             print u'CCLI: ' + self.ccli_number
-            
+
 


Follow ups