Remove static methods and re-work code to avoid creation of additional SongImport's.

This commit is contained in:
Jonathan Corwin 2011-03-11 08:33:22 +00:00
parent b522247094
commit b4e8880671
3 changed files with 31 additions and 33 deletions

View File

@ -192,9 +192,7 @@ class OooImport(SongImport):
if slidetext.strip() == u'': if slidetext.strip() == u'':
slidetext = u'\f' slidetext = u'\f'
text += slidetext text += slidetext
songs = SongImport.process_songs_text(self.manager, text) self.process_songs_text(text)
for song in songs:
song.finish()
return return
def process_doc(self): def process_doc(self):
@ -216,6 +214,16 @@ class OooImport(SongImport):
if textportion.BreakType in (PAGE_AFTER, PAGE_BOTH): if textportion.BreakType in (PAGE_AFTER, PAGE_BOTH):
paratext += u'\f' paratext += u'\f'
text += paratext + u'\n' text += paratext + u'\n'
songs = SongImport.process_songs_text(self.manager, text) self.process_songs_text(text)
for song in songs:
song.finish() def process_songs_text(self, text):
songtexts = self.tidy_text(text).split(u'\f')
self.set_defaults()
for songtext in songtexts:
if songtext.strip():
self.process_song_text(songtext.strip())
if self.check_complete():
self.finish()
self.set_defaults()
if self.check_complete():
self.finish()

View File

@ -183,7 +183,7 @@ class SofImport(OooImport):
into line into line
""" """
text = textportion.getString() text = textportion.getString()
text = SongImport.tidy_text(text) text = self.tidy_text(text)
if text.strip() == u'': if text.strip() == u'':
return text return text
if textportion.CharWeight == BOLD: if textportion.CharWeight == BOLD:
@ -299,8 +299,15 @@ class SofImport(OooImport):
verse += line + u'\n' verse += line + u'\n'
if verse: if verse:
self.song.add_verse(verse, versetag) self.song.add_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.song.add_verse(self.currentverse, 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
self.currentverse = u'' self.currentverse = u''
self.is_chorus = False self.is_chorus = False

View File

@ -55,14 +55,13 @@ class SongImport(QtCore.QObject):
""" """
self.manager = manager self.manager = manager
QtCore.QObject.__init__(self) QtCore.QObject.__init__(self)
if kwargs: if kwargs.has_key(u'filename'):
if kwargs.has_key(u'filename'): self.import_source = kwargs[u'filename']
self.import_source = kwargs[u'filename'] elif kwargs.has_key(u'filenames'):
elif kwargs.has_key(u'filenames'): self.import_source = kwargs[u'filenames']
self.import_source = kwargs[u'filenames'] else:
else: raise KeyError(u'Keyword arguments "filename[s]" not supplied.')
raise KeyError(u'Keyword arguments "filename[s]" not supplied.') log.debug(self.import_source)
log.debug(self.import_source)
self.song = None self.song = None
self.stop_import_flag = False self.stop_import_flag = False
self.set_defaults() self.set_defaults()
@ -104,23 +103,7 @@ class SongImport(QtCore.QObject):
def register(self, import_wizard): def register(self, import_wizard):
self.import_wizard = import_wizard self.import_wizard = import_wizard
@staticmethod def tidy_text(self, text):
def process_songs_text(manager, text):
songs = []
songtexts = SongImport.tidy_text(text).split(u'\f')
song = SongImport(manager)
for songtext in songtexts:
if songtext.strip():
song.process_song_text(songtext.strip())
if song.check_complete():
songs.append(song)
song = SongImport(manager)
if song.check_complete():
songs.append(song)
return songs
@staticmethod
def tidy_text(text):
""" """
Get rid of some dodgy unicode and formatting characters we're not Get rid of some dodgy unicode and formatting characters we're not
interested in. Some can be converted to ascii. interested in. Some can be converted to ascii.
@ -241,7 +224,7 @@ class SongImport(QtCore.QObject):
self.verse_counts[verse_def[0]] = int(verse_def[1:]) self.verse_counts[verse_def[0]] = int(verse_def[1:])
self.verses.append([verse_def, verse_text.rstrip(), lang]) self.verses.append([verse_def, verse_text.rstrip(), lang])
self.verse_order_list_generated.append(verse_def) self.verse_order_list_generated.append(verse_def)
def repeat_verse(self): def repeat_verse(self):
""" """
Repeat the previous verse in the verse order Repeat the previous verse in the verse order