diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index b6946a628..a90a4c194 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -38,48 +38,51 @@ log = logging.getLogger(__name__) # 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'', - u'end tag':u'{/r}', u'end html':u'', u'protected':False}) -html_expands.append({u'desc':u'Black', u'start tag':u'{b}', - u'start html':u'', - u'end tag':u'{/b}', u'end html':u'', u'protected':False}) -html_expands.append({u'desc':u'Blue', u'start tag':u'{bl}', - u'start html':u'', - u'end tag':u'{/bl}', u'end html':u'', u'protected':False}) -html_expands.append({u'desc':u'Yellow', u'start tag':u'{y}', - u'start html':u'', - u'end tag':u'{/y}', u'end html':u'', u'protected':False}) -html_expands.append({u'desc':u'Green', u'start tag':u'{g}', - u'start html':u'', - u'end tag':u'{/g}', u'end html':u'', u'protected':False}) -html_expands.append({u'desc':u'Pink', u'start tag':u'{pk}', - u'start html':u'', - u'end tag':u'{/pk}', u'end html':u'', u'protected':False}) -html_expands.append({u'desc':u'Orange', u'start tag':u'{o}', - u'start html':u'', - u'end tag':u'{/o}', u'end html':u'', u'protected':False}) -html_expands.append({u'desc':u'Purple', u'start tag':u'{pp}', - u'start html':u'', - u'end tag':u'{/pp}', u'end html':u'', u'protected':False}) -html_expands.append({u'desc':u'White', u'start tag':u'{w}', - u'start html':u'', - u'end tag':u'{/w}', u'end html':u'', u'protected':False}) -html_expands.append({u'desc':u'Superscript', u'start tag':u'{su}', - u'start html':u'', u'end tag':u'{/su}', u'end html':u'', - u'protected':True}) -html_expands.append({u'desc':u'Subscript', u'start tag':u'{sb}', - u'start html':u'', u'end tag':u'{/sb}', u'end html':u'', - u'protected':True}) -html_expands.append({u'desc':u'Paragraph', u'start tag':u'{p}', - u'start html':u'

', u'end tag':u'{/p}', u'end html':u'

', - u'protected':True}) -html_expands.append({u'desc':u'Bold', u'start tag':u'{st}', - u'start html':u'', u'end tag':u'{/st}', u'end html':u'', - u'protected':True}) -html_expands.append({u'desc':u'Italics', u'start tag':u'{it}', - u'start html':u'', u'end tag':u'{/it}', u'end html':u'', - u'protected':True}) +html_expands.append({u'desc': u'Red', u'start tag': u'{r}', + u'start html': u'', + u'end tag': u'{/r}', u'end html': u'', u'protected': False}) +html_expands.append({u'desc': u'Black', u'start tag': u'{b}', + u'start html': u'', + u'end tag': u'{/b}', u'end html': u'', u'protected': False}) +html_expands.append({u'desc': u'Blue', u'start tag': u'{bl}', + u'start html': u'', + u'end tag': u'{/bl}', u'end html': u'', u'protected': False}) +html_expands.append({u'desc': u'Yellow', u'start tag': u'{y}', + u'start html': u'', + u'end tag': u'{/y}', u'end html': u'', u'protected': False}) +html_expands.append({u'desc': u'Green', u'start tag': u'{g}', + u'start html': u'', + u'end tag': u'{/g}', u'end html': u'', u'protected': False}) +html_expands.append({u'desc': u'Pink', u'start tag': u'{pk}', + u'start html': u'', + u'end tag': u'{/pk}', u'end html': u'', u'protected': False}) +html_expands.append({u'desc': u'Orange', u'start tag': u'{o}', + u'start html': u'', + u'end tag': u'{/o}', u'end html': u'', u'protected': False}) +html_expands.append({u'desc': u'Purple', u'start tag': u'{pp}', + u'start html': u'', + u'end tag': u'{/pp}', u'end html': u'', u'protected': False}) +html_expands.append({u'desc': u'White', u'start tag': u'{w}', + u'start html': u'', + u'end tag': u'{/w}', u'end html': u'', u'protected': False}) +html_expands.append({u'desc': u'Superscript', u'start tag': u'{su}', + u'start html': u'', u'end tag': u'{/su}', u'end html': u'', + u'protected': True}) +html_expands.append({u'desc': u'Subscript', u'start tag': u'{sb}', + u'start html': u'', u'end tag': u'{/sb}', u'end html': u'', + u'protected': True}) +html_expands.append({u'desc': u'Paragraph', u'start tag': u'{p}', + u'start html': u'

', u'end tag': u'{/p}', u'end html': u'

', + u'protected': True}) +html_expands.append({u'desc': u'Bold', u'start tag': u'{st}', + u'start html': u'', u'end tag': u'{/st}', u'end html': u'', + u'protected': True}) +html_expands.append({u'desc': u'Italics', u'start tag': u'{it}', + u'start html': u'', u'end tag': u'{/it}', u'end html': u'', + u'protected': True}) +html_expands.append({u'desc': u'Underline', u'start tag': u'{u}', + u'start html': u'', + u'end tag': u'{/u}', u'end html': u'', u'protected': True}) def translate(context, text, comment=None): """ diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index 014c66a51..67ef4d8c1 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -507,8 +507,7 @@ class SongImportForm(QtGui.QWizard, Ui_SongImportWizard): 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.')) diff --git a/openlp/plugins/songs/lib/songbeamerimport.py b/openlp/plugins/songs/lib/songbeamerimport.py index 8b07d2b32..44e8805c9 100644 --- a/openlp/plugins/songs/lib/songbeamerimport.py +++ b/openlp/plugins/songs/lib/songbeamerimport.py @@ -57,15 +57,17 @@ class SongBeamerTypes(object): 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 @@ class SongBeamerImport(SongImport): # 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 @@ class SongBeamerImport(SongImport): 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'', u'{st}'), + (u'', u'{/st}'), + (u'', u'{it}'), + (u'', u'{/it}'), + (u'', u'{u}'), + (u'', u'{/u}'), + (u'
', u'{st}'), + (u'
', u'{st}'), + (u'', u'{st}'), + (u'

', u'{p}'), + (u'

', u'{/p}'), + (u'', u'{su}'), + (u'', u'{/su}'), + (u'', u'{sb}'), + (u'', u'{/sb}'), + (u'', u''), + (u'', u''), + (u'', u''), + (u'', 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': + elif tag_val[0] == u'#AddCopyrightInfo': pass - elif tag_val[0] == '#Author': - #TODO split Authors - self.add_author(tag_val[1]) - elif tag_val[0] == '#BackgroundImage': + elif tag_val[0] == u'#Author': + self.parse_author(tag_val[1]) + elif tag_val[0] == u'#BackgroundImage': pass - elif tag_val[0] == '#Bible': + elif tag_val[0] == u'#Bible': pass - elif tag_val[0] == '#Categories': + 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': + elif tag_val[0] == u'#Chords': pass - elif tag_val[0] == '#ChurchSongID': + elif tag_val[0] == u'#ChurchSongID': pass - elif tag_val[0] == '#ColorChords': + elif tag_val[0] == u'#ColorChords': pass - elif tag_val[0] == '#Comments': + elif tag_val[0] == u'#Comments': self.comments = tag_val[1] - elif tag_val[0] == '#Editor': + elif tag_val[0] == u'#Editor': pass - elif tag_val[0] == '#Font': + elif tag_val[0] == u'#Font': pass - elif tag_val[0] == '#FontLang2': + elif tag_val[0] == u'#FontLang2': pass - elif tag_val[0] == '#FontSize': + elif tag_val[0] == u'#FontSize': pass - elif tag_val[0] == '#Format': + elif tag_val[0] == u'#Format': pass - elif tag_val[0] == '#Format_PreLine': + elif tag_val[0] == u'#Format_PreLine': pass - elif tag_val[0] == '#Format_PrePage': + elif tag_val[0] == u'#Format_PrePage': pass - elif tag_val[0] == '#ID': + elif tag_val[0] == u'#ID': pass - elif tag_val[0] == '#Key': + elif tag_val[0] == u'#Key': pass - elif tag_val[0] == '#Keywords': + elif tag_val[0] == u'#Keywords': pass - elif tag_val[0] == '#LangCount': + elif tag_val[0] == u'#LangCount': pass - elif tag_val[0] == '#Melody': - #TODO split Authors - self.add_author(tag_val[1]) - elif tag_val[0] == '#NatCopyright': + elif tag_val[0] == u'#Melody': + self.parse_author(tag_val[1]) + elif tag_val[0] == u'#NatCopyright': pass - elif tag_val[0] == '#OTitle': + elif tag_val[0] == u'#OTitle': pass - elif tag_val[0] == '#OutlineColor': + elif tag_val[0] == u'#OutlineColor': pass - elif tag_val[0] == '#OutlinedFont': + elif tag_val[0] == u'#OutlinedFont': pass - elif tag_val[0] == '#QuickFind': + elif tag_val[0] == u'#QuickFind': pass - elif tag_val[0] == '#Rights': + 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': + elif tag_val[0] == u'#Speed': pass - elif tag_val[0] == '#TextAlign': + elif tag_val[0] == u'#TextAlign': pass - elif tag_val[0] == '#Title': + elif tag_val[0] == u'#Title': self.title = u'%s' % tag_val[1] - elif tag_val[0] == '#TitleAlign': + elif tag_val[0] == u'#TitleAlign': pass - elif tag_val[0] == '#TitleFontSize': + elif tag_val[0] == u'#TitleFontSize': pass - elif tag_val[0] == '#TitleLang2': + elif tag_val[0] == u'#TitleLang2': pass - elif tag_val[0] == '#TitleLang3': + elif tag_val[0] == u'#TitleLang3': pass - elif tag_val[0] == '#TitleLang4': + elif tag_val[0] == u'#TitleLang4': pass - elif tag_val[0] == '#Translation': + elif tag_val[0] == u'#Translation': pass - elif tag_val[0] == '#Transpose': + elif tag_val[0] == u'#Transpose': pass - elif tag_val[0] == '#TransposeAccidental': + elif tag_val[0] == u'#TransposeAccidental': pass - elif tag_val[0] == '#Version': + elif tag_val[0] == u'#Version': pass - else: - pass - return True 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 diff --git a/openlp/plugins/songs/lib/songimport.py b/openlp/plugins/songs/lib/songimport.py index 2c1de83a2..ea36d55b5 100644 --- a/openlp/plugins/songs/lib/songimport.py +++ b/openlp/plugins/songs/lib/songimport.py @@ -254,7 +254,8 @@ class SongImport(QtCore.QObject): 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):