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'':
slidetext = u'\f'
text += slidetext
songs = SongImport.process_songs_text(self.manager, text)
for song in songs:
song.finish()
self.process_songs_text(text)
return
def process_doc(self):
@ -216,6 +214,16 @@ class OooImport(SongImport):
if textportion.BreakType in (PAGE_AFTER, PAGE_BOTH):
paratext += u'\f'
text += paratext + u'\n'
songs = SongImport.process_songs_text(self.manager, text)
for song in songs:
song.finish()
self.process_songs_text(text)
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
"""
text = textportion.getString()
text = SongImport.tidy_text(text)
text = self.tidy_text(text)
if text.strip() == u'':
return text
if textportion.CharWeight == BOLD:
@ -299,8 +299,15 @@ class SofImport(OooImport):
verse += line + u'\n'
if verse:
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:
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.is_chorus = False

View File

@ -55,14 +55,13 @@ class SongImport(QtCore.QObject):
"""
self.manager = manager
QtCore.QObject.__init__(self)
if kwargs:
if kwargs.has_key(u'filename'):
self.import_source = kwargs[u'filename']
elif kwargs.has_key(u'filenames'):
self.import_source = kwargs[u'filenames']
else:
raise KeyError(u'Keyword arguments "filename[s]" not supplied.')
log.debug(self.import_source)
if kwargs.has_key(u'filename'):
self.import_source = kwargs[u'filename']
elif kwargs.has_key(u'filenames'):
self.import_source = kwargs[u'filenames']
else:
raise KeyError(u'Keyword arguments "filename[s]" not supplied.')
log.debug(self.import_source)
self.song = None
self.stop_import_flag = False
self.set_defaults()
@ -104,23 +103,7 @@ class SongImport(QtCore.QObject):
def register(self, import_wizard):
self.import_wizard = import_wizard
@staticmethod
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):
def tidy_text(self, text):
"""
Get rid of some dodgy unicode and formatting characters we're not
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.verses.append([verse_def, verse_text.rstrip(), lang])
self.verse_order_list_generated.append(verse_def)
def repeat_verse(self):
"""
Repeat the previous verse in the verse order