← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~googol-hush/openlp/songs into lp:openlp

 

Andreas Preikschat has proposed merging lp:~googol-hush/openlp/songs into lp:openlp.

Requested reviews:
  Tim Bentley (trb143)
  Raoul Snyman (raoul-snyman)


- added the <u>Underline</u> tag
- clean ups

SongBeamerImport:
- clean ups and tweaks
- fixed a bug which would drop the first line of a verse, when it does not have any "verse type"
- convert SongBeamer's html tags to OpenLP specific style
-- 
https://code.launchpad.net/~googol-hush/openlp/songs/+merge/42539
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/core/lib/__init__.py'
--- openlp/core/lib/__init__.py	2010-10-30 11:09:52 +0000
+++ openlp/core/lib/__init__.py	2010-12-02 19:45:21 +0000
@@ -38,48 +38,51 @@
 # TODO make external and configurable in alpha 4 via a settings dialog
 html_expands = []
 
-html_expands.append({u'desc':u'Red', u'start tag':u'{r}',
-    u'start html':u'<span style="-webkit-text-fill-color:red">',
-    u'end tag':u'{/r}', u'end html':u'</span>', u'protected':False})
-html_expands.append({u'desc':u'Black', u'start tag':u'{b}',
-    u'start html':u'<span style="-webkit-text-fill-color:black">',
-    u'end tag':u'{/b}', u'end html':u'</span>', u'protected':False})
-html_expands.append({u'desc':u'Blue', u'start tag':u'{bl}',
-    u'start html':u'<span style="-webkit-text-fill-color:blue">',
-    u'end tag':u'{/bl}', u'end html':u'</span>', u'protected':False})
-html_expands.append({u'desc':u'Yellow', u'start tag':u'{y}',
-    u'start html':u'<span style="-webkit-text-fill-color:yellow">',
-    u'end tag':u'{/y}', u'end html':u'</span>', u'protected':False})
-html_expands.append({u'desc':u'Green', u'start tag':u'{g}',
-    u'start html':u'<span style="-webkit-text-fill-color:green">',
-    u'end tag':u'{/g}', u'end html':u'</span>', u'protected':False})
-html_expands.append({u'desc':u'Pink', u'start tag':u'{pk}',
-    u'start html':u'<span style="-webkit-text-fill-color:#CC33CC">',
-    u'end tag':u'{/pk}', u'end html':u'</span>', u'protected':False})
-html_expands.append({u'desc':u'Orange', u'start tag':u'{o}',
-    u'start html':u'<span style="-webkit-text-fill-color:#CC0033">',
-    u'end tag':u'{/o}', u'end html':u'</span>', u'protected':False})
-html_expands.append({u'desc':u'Purple', u'start tag':u'{pp}',
-    u'start html':u'<span style="-webkit-text-fill-color:#9900FF">',
-    u'end tag':u'{/pp}', u'end html':u'</span>', u'protected':False})
-html_expands.append({u'desc':u'White', u'start tag':u'{w}',
-    u'start html':u'<span style="-webkit-text-fill-color:white">',
-    u'end tag':u'{/w}', u'end html':u'</span>', u'protected':False})
-html_expands.append({u'desc':u'Superscript', u'start tag':u'{su}',
-    u'start html':u'<sup>', u'end tag':u'{/su}', u'end html':u'</sup>',
-    u'protected':True})
-html_expands.append({u'desc':u'Subscript', u'start tag':u'{sb}',
-    u'start html':u'<sub>', u'end tag':u'{/sb}', u'end html':u'</sub>',
-    u'protected':True})
-html_expands.append({u'desc':u'Paragraph', u'start tag':u'{p}',
-    u'start html':u'<p>', u'end tag':u'{/p}', u'end html':u'</p>',
-    u'protected':True})
-html_expands.append({u'desc':u'Bold', u'start tag':u'{st}',
-    u'start html':u'<strong>', u'end tag':u'{/st}', u'end html':u'</strong>',
-    u'protected':True})
-html_expands.append({u'desc':u'Italics', u'start tag':u'{it}',
-    u'start html':u'<em>', u'end tag':u'{/it}', u'end html':u'</em>',
-    u'protected':True})
+html_expands.append({u'desc': u'Red', u'start tag': u'{r}',
+    u'start html': u'<span style="-webkit-text-fill-color:red">',
+    u'end tag': u'{/r}', u'end html': u'</span>', u'protected': False})
+html_expands.append({u'desc': u'Black', u'start tag': u'{b}',
+    u'start html': u'<span style="-webkit-text-fill-color:black">',
+    u'end tag': u'{/b}', u'end html': u'</span>', u'protected': False})
+html_expands.append({u'desc': u'Blue', u'start tag': u'{bl}',
+    u'start html': u'<span style="-webkit-text-fill-color:blue">',
+    u'end tag': u'{/bl}', u'end html': u'</span>', u'protected': False})
+html_expands.append({u'desc': u'Yellow', u'start tag': u'{y}',
+    u'start html': u'<span style="-webkit-text-fill-color:yellow">',
+    u'end tag': u'{/y}', u'end html': u'</span>', u'protected': False})
+html_expands.append({u'desc': u'Green', u'start tag': u'{g}',
+    u'start html': u'<span style="-webkit-text-fill-color:green">',
+    u'end tag': u'{/g}', u'end html': u'</span>', u'protected': False})
+html_expands.append({u'desc': u'Pink', u'start tag': u'{pk}',
+    u'start html': u'<span style="-webkit-text-fill-color:#CC33CC">',
+    u'end tag': u'{/pk}', u'end html': u'</span>', u'protected': False})
+html_expands.append({u'desc': u'Orange', u'start tag': u'{o}',
+    u'start html': u'<span style="-webkit-text-fill-color:#CC0033">',
+    u'end tag': u'{/o}', u'end html': u'</span>', u'protected': False})
+html_expands.append({u'desc': u'Purple', u'start tag': u'{pp}',
+    u'start html': u'<span style="-webkit-text-fill-color:#9900FF">',
+    u'end tag': u'{/pp}', u'end html': u'</span>', u'protected': False})
+html_expands.append({u'desc': u'White', u'start tag': u'{w}',
+    u'start html': u'<span style="-webkit-text-fill-color:white">',
+    u'end tag': u'{/w}', u'end html': u'</span>', u'protected': False})
+html_expands.append({u'desc': u'Superscript', u'start tag': u'{su}',
+    u'start html': u'<sup>', u'end tag': u'{/su}', u'end html': u'</sup>',
+    u'protected': True})
+html_expands.append({u'desc': u'Subscript', u'start tag': u'{sb}',
+    u'start html': u'<sub>', u'end tag': u'{/sb}', u'end html': u'</sub>',
+    u'protected': True})
+html_expands.append({u'desc': u'Paragraph', u'start tag': u'{p}',
+    u'start html': u'<p>', u'end tag': u'{/p}', u'end html': u'</p>',
+    u'protected': True})
+html_expands.append({u'desc': u'Bold', u'start tag': u'{st}',
+    u'start html': u'<strong>', u'end tag': u'{/st}', u'end html': u'</strong>',
+    u'protected': True})
+html_expands.append({u'desc': u'Italics', u'start tag': u'{it}',
+    u'start html': u'<em>', u'end tag': u'{/it}', u'end html': u'</em>',
+    u'protected': True})
+html_expands.append({u'desc': u'Underline', u'start tag': u'{u}',
+    u'start html': u'<span style="text-decoration: underline;">',
+    u'end tag': u'{/u}', u'end html': u'</span>', u'protected': True})
 
 def translate(context, text, comment=None):
     """

=== modified file 'openlp/plugins/songs/forms/songimportform.py'
--- openlp/plugins/songs/forms/songimportform.py	2010-10-16 19:38:23 +0000
+++ openlp/plugins/songs/forms/songimportform.py	2010-12-02 19:45:21 +0000
@@ -507,8 +507,7 @@
                 filenames=self.getListOfFiles(
                     self.songBeamerFileListWidget)
             )
-        success = importer.do_import()
-        if success:
+        if importer.do_import():
             # reload songs
             self.importProgressLabel.setText(
                 translate('SongsPlugin.SongImportForm', 'Finished import.'))

=== modified file 'openlp/plugins/songs/lib/songbeamerimport.py'
--- openlp/plugins/songs/lib/songbeamerimport.py	2010-10-21 15:31:22 +0000
+++ openlp/plugins/songs/lib/songbeamerimport.py	2010-12-02 19:45:21 +0000
@@ -57,15 +57,17 @@
         u'Unknown': u'O'
         }
 
+
 class SongBeamerImport(SongImport):
     """
-        Import Song Beamer files(s)
-        Song Beamer file format is text based
-        in the beginning are one or more control tags written
+    Import Song Beamer files(s)
+    Song Beamer file format is text based
+    in the beginning are one or more control tags written
     """
     def __init__(self, master_manager, **kwargs):
         """
         Initialise the import.
+
         ``master_manager``
             The song manager for the running OpenLP installation.
         """
@@ -88,6 +90,7 @@
                 # TODO: check that it is a valid SongBeamer file
                 self.current_verse = u'' 
                 self.current_verse_type = u'V'
+                read_verses = False
                 self.file_name = os.path.split(file)[1]
                 self.import_wizard.incrementProgressBar(
                     "Importing %s" % (self.file_name),  0)
@@ -100,134 +103,182 @@
                 else:
                     return False
                 for line in self.songData:
-                    line = line.strip()
-                    if line.startswith('#'):
-                        log.debug(u'find tag: %s' % line)
-                        if not self.parse_tags(line):
-                            return False
-                    elif line.startswith('---'):
-                        log.debug(u'find ---')
-                        if len(self.current_verse) > 0:
-                            self.add_verse(self.current_verse, 
+                    # Just make sure that the line is of the type 'Unicode'.
+                    line = unicode(line).strip()
+                    if line.startswith(u'#') and not read_verses:
+                        self.parse_tags(line)
+                    elif line.startswith(u'---'):
+                        if self.current_verse:
+                            self.replace_html_tags()
+                            self.add_verse(self.current_verse,
                                 self.current_verse_type)
                             self.current_verse = u'' 
                             self.current_verse_type = u'V'
-                        self.read_verse = True
-                        self.verse_start = True
-                    elif self.read_verse:
-                        if self.verse_start:
-                            self.check_verse_marks(line)
-                            self.verse_start = False
+                        read_verses = True
+                        verse_start = True
+                    elif read_verses:
+                        if verse_start:
+                            verse_start = False
+                            if not self.check_verse_marks(line):
+                                self.current_verse = u'%s\n' % line
                         else:
                             self.current_verse += u'%s\n' % line
-                if len(self.current_verse) > 0:
+                if self.current_verse:
+                    self.replace_html_tags()
                     self.add_verse(self.current_verse, self.current_verse_type)
                 self.finish()
                 self.import_wizard.incrementProgressBar(
                     "Importing %s" % (self.file_name))
             return True
 
+    def replace_html_tags(self):
+        """
+        This can be called to replace SongBeamer's specific (html) tags with
+        OpenLP's specific (html) tags.
+        """
+        tag_pairs = [
+            (u'<b>', u'{st}'),
+            (u'</b>', u'{/st}'),
+            (u'<i>', u'{it}'),
+            (u'</i>', u'{/it}'),
+            (u'<u>', u'{u}'),
+            (u'</u>', u'{/u}'),
+            (u'<br>', u'{st}'),
+            (u'</br>', u'{st}'),
+            (u'</ br>', u'{st}'),
+            (u'<p>', u'{p}'),
+            (u'</p>', u'{/p}'),
+            (u'<super>', u'{su}'),
+            (u'</super>', u'{/su}'),
+            (u'<sub>', u'{sb}'),
+            (u'</sub>', u'{/sb}'),
+            (u'<wordwrap>', u''),
+            (u'</wordwrap>', u''),
+            (u'<strike>', u''),
+            (u'</strike>', u'')
+            ]
+        for pair in tag_pairs:
+            self.current_verse = self.current_verse.replace(pair[0], pair[1])
+        # TODO: check for unsupported tags (see wiki) and remove them as well.
+
     def parse_tags(self, line):
-        tag_val = line.split('=')
-        if len(tag_val[0]) == 0 or len(tag_val[1]) == 0:
-            return True
-        if tag_val[0] == '#(c)':
+        """
+        Parses a meta data line.
+
+        ``line``
+            The line in the file. It should consist of a tag and a value
+            for this tag (unicode)::
+
+                u'#Title=Nearer my God to Thee'
+        """
+        tag_val = line.split(u'=', 1)
+        if len(tag_val) == 1:
+            return
+        if not tag_val[0] or not tag_val[1]:
+            return
+        if tag_val[0] == u'#(c)':
             self.add_copyright(tag_val[1])
-        elif tag_val[0] == '#AddCopyrightInfo':
-            pass
-        elif tag_val[0] == '#Author':
-            #TODO split Authors
-            self.add_author(tag_val[1])
-        elif tag_val[0] == '#BackgroundImage':
-            pass
-        elif tag_val[0] == '#Bible':
-            pass
-        elif tag_val[0] == '#Categories':
+        elif tag_val[0] == u'#AddCopyrightInfo':
+            pass
+        elif tag_val[0] == u'#Author':
+            self.parse_author(tag_val[1])
+        elif tag_val[0] == u'#BackgroundImage':
+            pass
+        elif tag_val[0] == u'#Bible':
+            pass
+        elif tag_val[0] == u'#Categories':
             self.topics = line.split(',')
-        elif tag_val[0] == '#CCLI':
+        elif tag_val[0] == u'#CCLI':
             self.ccli_number = tag_val[1]
-        elif tag_val[0] == '#Chords':
-            pass
-        elif tag_val[0] == '#ChurchSongID':
-            pass
-        elif tag_val[0] == '#ColorChords':
-            pass
-        elif tag_val[0] == '#Comments':
+        elif tag_val[0] == u'#Chords':
+            pass
+        elif tag_val[0] == u'#ChurchSongID':
+            pass
+        elif tag_val[0] == u'#ColorChords':
+            pass
+        elif tag_val[0] == u'#Comments':
             self.comments = tag_val[1]
-        elif tag_val[0] == '#Editor':
-            pass
-        elif tag_val[0] == '#Font':
-            pass
-        elif tag_val[0] == '#FontLang2':
-            pass
-        elif tag_val[0] == '#FontSize':
-            pass
-        elif tag_val[0] == '#Format':
-            pass
-        elif tag_val[0] == '#Format_PreLine':
-            pass
-        elif tag_val[0] == '#Format_PrePage':
-            pass
-        elif tag_val[0] == '#ID':
-            pass
-        elif tag_val[0] == '#Key':
-            pass
-        elif tag_val[0] == '#Keywords':
-            pass
-        elif tag_val[0] == '#LangCount':
-            pass
-        elif tag_val[0] == '#Melody':
-            #TODO split Authors
-            self.add_author(tag_val[1])
-        elif tag_val[0] == '#NatCopyright':
-            pass
-        elif tag_val[0] == '#OTitle':
-            pass
-        elif tag_val[0] == '#OutlineColor':
-            pass
-        elif tag_val[0] == '#OutlinedFont':
-            pass
-        elif tag_val[0] == '#QuickFind':
-            pass
-        elif tag_val[0] == '#Rights':
+        elif tag_val[0] == u'#Editor':
+            pass
+        elif tag_val[0] == u'#Font':
+            pass
+        elif tag_val[0] == u'#FontLang2':
+            pass
+        elif tag_val[0] == u'#FontSize':
+            pass
+        elif tag_val[0] == u'#Format':
+            pass
+        elif tag_val[0] == u'#Format_PreLine':
+            pass
+        elif tag_val[0] == u'#Format_PrePage':
+            pass
+        elif tag_val[0] == u'#ID':
+            pass
+        elif tag_val[0] == u'#Key':
+            pass
+        elif tag_val[0] == u'#Keywords':
+            pass
+        elif tag_val[0] == u'#LangCount':
+            pass
+        elif tag_val[0] == u'#Melody':
+            self.parse_author(tag_val[1])
+        elif tag_val[0] == u'#NatCopyright':
+            pass
+        elif tag_val[0] == u'#OTitle':
+            pass
+        elif tag_val[0] == u'#OutlineColor':
+            pass
+        elif tag_val[0] == u'#OutlinedFont':
+            pass
+        elif tag_val[0] == u'#QuickFind':
+            pass
+        elif tag_val[0] == u'#Rights':
             song_book_pub = tag_val[1]
-        elif tag_val[0] == '#Songbook':
+        elif tag_val[0] == u'#Songbook':
             book_num = tag_val[1].split(' / ')
             self.song_book_name = book_num[0]
             if len(book_num) == book_num[1]:
                 self.song_number = u''
-        elif tag_val[0] == '#Speed':
-            pass
-        elif tag_val[0] == '#TextAlign':
-            pass
-        elif tag_val[0] == '#Title':
+        elif tag_val[0] == u'#Speed':
+            pass
+        elif tag_val[0] == u'#TextAlign':
+            pass
+        elif tag_val[0] == u'#Title':
             self.title = u'%s' % tag_val[1]
-        elif tag_val[0] == '#TitleAlign':
-            pass
-        elif tag_val[0] == '#TitleFontSize':
-            pass
-        elif tag_val[0] == '#TitleLang2':
-            pass
-        elif tag_val[0] == '#TitleLang3':
-            pass
-        elif tag_val[0] == '#TitleLang4':
-            pass
-        elif tag_val[0] == '#Translation':
-            pass
-        elif tag_val[0] == '#Transpose':
-            pass
-        elif tag_val[0] == '#TransposeAccidental':
-            pass
-        elif tag_val[0] == '#Version':
-            pass
-        else:
-            pass
-        return True
+        elif tag_val[0] == u'#TitleAlign':
+            pass
+        elif tag_val[0] == u'#TitleFontSize':
+            pass
+        elif tag_val[0] == u'#TitleLang2':
+            pass
+        elif tag_val[0] == u'#TitleLang3':
+            pass
+        elif tag_val[0] == u'#TitleLang4':
+            pass
+        elif tag_val[0] == u'#Translation':
+            pass
+        elif tag_val[0] == u'#Transpose':
+            pass
+        elif tag_val[0] == u'#TransposeAccidental':
+            pass
+        elif tag_val[0] == u'#Version':
+            pass
 
     def check_verse_marks(self, line):
-        marks = line.split(' ')
+        """
+        Check and add the verse's MarkType. Returns ``True`` if the given line
+        contains a correct verse mark otherwise ``False``.
+
+        ``line``
+            The line to check for marks (unicode).
+        """
+        marks = line.split(u' ')
         if len(marks) <= 2 and marks[0] in SongBeamerTypes.MarkTypes:
             self.current_verse_type = SongBeamerTypes.MarkTypes[marks[0]]
             if len(marks) == 2:
-                #TODO: may check, because of only digits are allowed
-                self.current_verse_type += marks[1]
+                # If we have a digit, we append it to current_verse_type.
+                if marks[1].isdigit():
+                    self.current_verse_type += marks[1]
+            return True
+        else:
+            return False

=== modified file 'openlp/plugins/songs/lib/songimport.py'
--- openlp/plugins/songs/lib/songimport.py	2010-11-03 22:22:48 +0000
+++ openlp/plugins/songs/lib/songimport.py	2010-12-02 19:45:21 +0000
@@ -254,7 +254,8 @@
         All fields have been set to this song. Write it away
         """
         if not self.authors:
-            self.authors.append(u'Author unknown')
+            self.authors.append(unicode(translate('SongsPlugin.SongImport',
+                'Author unknown')))
         self.commit_song()
 
     def commit_song(self):


Follow ups