SOF fixes, auto add chorus to verse order again

This commit is contained in:
Jonathan Corwin 2011-03-11 08:46:21 +00:00
parent b4e8880671
commit 7336575067
1 changed files with 37 additions and 36 deletions

View File

@ -72,6 +72,7 @@ class SofImport(OooImport):
to SongImport for writing song to disk to SongImport for writing song to disk
""" """
OooImport.__init__(self, manager, **kwargs) OooImport.__init__(self, manager, **kwargs)
self.song = False
def process_ooo_document(self): def process_ooo_document(self):
""" """
@ -94,8 +95,8 @@ class SofImport(OooImport):
if paragraph.supportsService("com.sun.star.text.Paragraph"): if paragraph.supportsService("com.sun.star.text.Paragraph"):
self.process_paragraph(paragraph) self.process_paragraph(paragraph)
if self.song: if self.song:
self.song.finish() self.finish()
self.song = None self.song = False
def process_paragraph(self, paragraph): def process_paragraph(self, paragraph):
""" """
@ -143,7 +144,7 @@ class SofImport(OooImport):
self.blanklines += 1 self.blanklines += 1
if self.blanklines > 1: if self.blanklines > 1:
return return
if self.song.title != u'': if self.title != u'':
self.finish_verse() self.finish_verse()
return return
self.blanklines = 0 self.blanklines = 0
@ -161,17 +162,17 @@ class SofImport(OooImport):
self.skip_to_close_bracket = True self.skip_to_close_bracket = True
return return
if text.startswith(u'Copyright'): if text.startswith(u'Copyright'):
self.song.add_copyright(text) self.add_copyright(text)
return return
if text == u'(Repeat)': if text == u'(Repeat)':
self.finish_verse() self.finish_verse()
self.song.repeat_verse() self.repeat_verse()
return return
if self.song.title == u'': if self.title == u'':
if self.song.copyright == u'': if self.copyright == u'':
self.add_author(text) self.add_sof_author(text)
else: else:
self.song.add_copyright(text) self.add_copyright(text)
return return
self.add_verse_line(text) self.add_verse_line(text)
@ -188,10 +189,10 @@ class SofImport(OooImport):
return text return text
if textportion.CharWeight == BOLD: if textportion.CharWeight == BOLD:
boldtext = text.strip() boldtext = text.strip()
if boldtext.isdigit() and self.song.song_number == '': if boldtext.isdigit() and self.song_number == '':
self.add_songnumber(boldtext) self.add_songnumber(boldtext)
return u'' return u''
if self.song.title == u'': if self.title == u'':
text = self.uncap_text(text) text = self.uncap_text(text)
self.add_title(text) self.add_title(text)
return text return text
@ -207,10 +208,11 @@ class SofImport(OooImport):
""" """
if self.song: if self.song:
self.finish_verse() self.finish_verse()
if not self.song.check_complete(): if not self.check_complete():
return return
self.song.finish() self.finish()
self.song = SongImport(self.manager) self.song = True
self.set_defaults()
self.skip_to_close_bracket = False self.skip_to_close_bracket = False
self.is_chorus = False self.is_chorus = False
self.italics = False self.italics = False
@ -221,17 +223,17 @@ class SofImport(OooImport):
Add a song number, store as alternate title. Also use the song Add a song number, store as alternate title. Also use the song
number to work out which songbook we're in number to work out which songbook we're in
""" """
self.song.song_number = song_no self.song_number = song_no
self.song.alternate_title = song_no + u'.' self.alternate_title = song_no + u'.'
self.song.song_book_pub = u'Kingsway Publications' self.song_book_pub = u'Kingsway Publications'
if int(song_no) <= 640: if int(song_no) <= 640:
self.song.song_book = u'Songs of Fellowship 1' self.song_book = u'Songs of Fellowship 1'
elif int(song_no) <= 1150: elif int(song_no) <= 1150:
self.song.song_book = u'Songs of Fellowship 2' self.song_book = u'Songs of Fellowship 2'
elif int(song_no) <= 1690: elif int(song_no) <= 1690:
self.song.song_book = u'Songs of Fellowship 3' self.song_book = u'Songs of Fellowship 3'
else: else:
self.song.song_book = u'Songs of Fellowship 4' self.song_book = u'Songs of Fellowship 4'
def add_title(self, text): def add_title(self, text):
""" """
@ -243,10 +245,10 @@ class SofImport(OooImport):
title = title[1:] title = title[1:]
if title.endswith(u','): if title.endswith(u','):
title = title[:-1] title = title[:-1]
self.song.title = title self.title = title
self.import_wizard.incrementProgressBar(u'Processing song ' + title, 0) self.import_wizard.incrementProgressBar(u'Processing song ' + title, 0)
def add_author(self, text): def add_sof_author(self, text):
""" """
Add the author. OpenLP stores them individually so split by 'and', '&' Add the author. OpenLP stores them individually so split by 'and', '&'
and comma. and comma.
@ -254,7 +256,7 @@ class SofImport(OooImport):
"Mr Smith" and "Mrs Smith". "Mr Smith" and "Mrs Smith".
""" """
text = text.replace(u' and ', u' & ') text = text.replace(u' and ', u' & ')
self.song.parse_author(text) self.parse_author(text)
def add_verse_line(self, text): def add_verse_line(self, text):
""" """
@ -262,7 +264,7 @@ class SofImport(OooImport):
we're beyond the second line of first verse, then this indicates we're beyond the second line of first verse, then this indicates
a change of verse. Italics are a chorus a change of verse. Italics are a chorus
""" """
if self.italics != self.is_chorus and ((len(self.song.verses) > 0) or if self.italics != self.is_chorus and ((len(self.verses) > 0) or
(self.currentverse.count(u'\n') > 1)): (self.currentverse.count(u'\n') > 1)):
self.finish_verse() self.finish_verse()
if self.italics: if self.italics:
@ -282,14 +284,14 @@ class SofImport(OooImport):
splitat = None splitat = None
else: else:
versetag = u'V' versetag = u'V'
splitat = self.verse_splits(self.song.song_number) splitat = self.verse_splits(self.song_number)
if splitat: if splitat:
ln = 0 ln = 0
verse = u'' verse = u''
for line in self.currentverse.split(u'\n'): for line in self.currentverse.split(u'\n'):
ln += 1 ln += 1
if line == u'' or ln > splitat: if line == u'' or ln > splitat:
self.song.add_verse(verse, versetag) self.add_sof_verse(verse, versetag)
ln = 0 ln = 0
if line: if line:
verse = line + u'\n' verse = line + u'\n'
@ -298,18 +300,17 @@ class SofImport(OooImport):
else: else:
verse += line + u'\n' verse += line + u'\n'
if verse: if verse:
self.song.add_verse(verse, versetag) self.add_sof_verse(verse, versetag)
if not self.is_chorus and \
u'C1' in self.verse_order_list_generated:
self.verse_order_list_generated.append(u'C1')
self.verse_order_list_generated_useful = True
else: else:
self.song.add_verse(self.currentverse, versetag) self.add_sof_verse(self.currentverse, versetag)
self.currentverse = u''
self.is_chorus = False
def add_sof_verse(self, lyrics, tag):
self.add_verse(lyrics, tag)
if not self.is_chorus and u'C1' in self.verse_order_list_generated: if not self.is_chorus and u'C1' in self.verse_order_list_generated:
self.verse_order_list_generated.append(u'C1') self.verse_order_list_generated.append(u'C1')
self.verse_order_list_generated_useful = True self.verse_order_list_generated_useful = True
self.currentverse = u''
self.is_chorus = False
def uncap_text(self, text): def uncap_text(self, text):
""" """