forked from openlp/openlp
more variable name changes
This commit is contained in:
parent
aac40357ae
commit
1651e42bca
@ -787,7 +787,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
||||
verseId = unicode(item.data(QtCore.Qt.UserRole).toString())
|
||||
verse_tag = verseId[0]
|
||||
verse_num = verseId[1:]
|
||||
sxml.add_verse_to_lyrics(verse_type, verse_num,
|
||||
sxml.add_verse_to_lyrics(verse_tag, verse_num,
|
||||
unicode(item.text()))
|
||||
text = text + self.whitespace.sub(u' ',
|
||||
unicode(self.verseListWidget.item(i, 0).text())) + u' '
|
||||
|
@ -127,11 +127,10 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog):
|
||||
if match:
|
||||
verse_type = match.group(1)
|
||||
verse_type_index = VerseType.from_loose_input(verse_type)
|
||||
regex = re.compile(r'(\d+)')
|
||||
verse_num = int(match.group(2))
|
||||
verse_number = int(match.group(2))
|
||||
if verse_type_index is not None:
|
||||
self.verseTypeComboBox.setCurrentIndex(verse_type_index)
|
||||
self.verseNumberBox.setValue(verse_num)
|
||||
self.verseNumberBox.setValue(verse_number)
|
||||
|
||||
def setVerse(self, text, single=False,
|
||||
tag=u'%s1' % VerseType.Tags[VerseType.Verse]):
|
||||
|
@ -175,7 +175,7 @@ class VerseType(object):
|
||||
if len(verse_name) > 1:
|
||||
verse_index = VerseType.from_translated_string(verse_name)
|
||||
if verse_index is None:
|
||||
verseIndex = VerseType.from_string(verse_name)
|
||||
verse_index = VerseType.from_string(verse_name)
|
||||
if verse_index is None:
|
||||
verse_index = VerseType.from_translated_tag(verse_name)
|
||||
elif verse_index is None:
|
||||
|
@ -161,8 +161,8 @@ class OpenSongImport(SongImport):
|
||||
self.import_wizard.incrementProgressBar(
|
||||
unicode(translate('SongsPlugin.ImportWizardForm',
|
||||
'Importing %s...')) % os.path.split(filename)[-1])
|
||||
songfile = open(filename)
|
||||
if self.do_import_file(songfile) and self.commit and \
|
||||
song_file = open(filename)
|
||||
if self.do_import_file(song_file) and self.commit and \
|
||||
not self.stop_import_flag:
|
||||
self.finish()
|
||||
else:
|
||||
@ -209,92 +209,92 @@ class OpenSongImport(SongImport):
|
||||
verses = {}
|
||||
# keep track of verses appearance order
|
||||
our_verse_order = []
|
||||
# default versetype
|
||||
versetype = u'v'
|
||||
versenum = u'1'
|
||||
# default verse
|
||||
verse_tag = u'v'
|
||||
verse_num = u'1'
|
||||
# for the case where song has several sections with same marker
|
||||
inst = 1
|
||||
lyrics = unicode(root.lyrics)
|
||||
for thisline in lyrics.split(u'\n'):
|
||||
for this_line in lyrics.split(u'\n'):
|
||||
# remove comments
|
||||
semicolon = thisline.find(u';')
|
||||
semicolon = this_line.find(u';')
|
||||
if semicolon >= 0:
|
||||
thisline = thisline[:semicolon]
|
||||
thisline = thisline.strip()
|
||||
if not len(thisline):
|
||||
this_line = this_line[:semicolon]
|
||||
this_line = this_line.strip()
|
||||
if not len(this_line):
|
||||
continue
|
||||
# skip guitar chords and page and column breaks
|
||||
if thisline.startswith(u'.') or thisline.startswith(u'---') \
|
||||
or thisline.startswith(u'-!!'):
|
||||
if this_line.startswith(u'.') or this_line.startswith(u'---') \
|
||||
or this_line.startswith(u'-!!'):
|
||||
continue
|
||||
# verse/chorus/etc. marker
|
||||
if thisline.startswith(u'['):
|
||||
if this_line.startswith(u'['):
|
||||
# drop the square brackets
|
||||
right_bracket = thisline.find(u']')
|
||||
content = thisline[1:right_bracket].lower()
|
||||
right_bracket = this_line.find(u']')
|
||||
content = this_line[1:right_bracket].lower()
|
||||
# have we got any digits?
|
||||
# If so, versenumber is everything from the digits
|
||||
# If so, verse number is everything from the digits
|
||||
# to the end (even if there are some alpha chars on the end)
|
||||
match = re.match(u'(.*)(\d+.*)', content)
|
||||
if match is not None:
|
||||
versetype = match.group(1)
|
||||
versenum = match.group(2)
|
||||
verse_tag = match.group(1)
|
||||
verse_num = match.group(2)
|
||||
else:
|
||||
# otherwise we assume number 1 and take the whole prefix as
|
||||
# the versetype
|
||||
versetype = content
|
||||
versenum = u'1'
|
||||
# the verse tag
|
||||
verse_tag = content
|
||||
verse_num = u'1'
|
||||
inst = 1
|
||||
if [versetype, versenum, inst] in our_verse_order \
|
||||
and verses.has_key(versetype) \
|
||||
and verses[versetype].has_key(versenum):
|
||||
inst = len(verses[versetype][versenum])+1
|
||||
our_verse_order.append([versetype, versenum, inst])
|
||||
if [verse_tag, verse_num, inst] in our_verse_order \
|
||||
and verses.has_key(verse_tag) \
|
||||
and verses[verse_tag].has_key(verse_num):
|
||||
inst = len(verses[verse_tag][verse_num])+1
|
||||
our_verse_order.append([verse_tag, verse_num, inst])
|
||||
continue
|
||||
# number at start of line.. it's verse number
|
||||
if thisline[0].isdigit():
|
||||
versenum = thisline[0]
|
||||
thisline = thisline[1:].strip()
|
||||
our_verse_order.append([versetype, versenum, inst])
|
||||
if not verses.has_key(versetype):
|
||||
verses[versetype] = {}
|
||||
if not verses[versetype].has_key(versenum):
|
||||
verses[versetype][versenum] = {}
|
||||
if not verses[versetype][versenum].has_key(inst):
|
||||
verses[versetype][versenum][inst] = []
|
||||
if this_line[0].isdigit():
|
||||
verse_num = this_line[0]
|
||||
this_line = this_line[1:].strip()
|
||||
our_verse_order.append([verse_tag, verse_num, inst])
|
||||
if not verses.has_key(verse_tag):
|
||||
verses[verse_tag] = {}
|
||||
if not verses[verse_tag].has_key(verse_num):
|
||||
verses[verse_tag][verse_num] = {}
|
||||
if not verses[verse_tag][verse_num].has_key(inst):
|
||||
verses[verse_tag][verse_num][inst] = []
|
||||
# Tidy text and remove the ____s from extended words
|
||||
thisline = self.tidy_text(thisline)
|
||||
thisline = thisline.replace(u'_', u'')
|
||||
thisline = thisline.replace(u'|', u'\n')
|
||||
verses[versetype][versenum][inst].append(thisline)
|
||||
this_line = self.tidy_text(this_line)
|
||||
this_line = this_line.replace(u'_', u'')
|
||||
this_line = this_line.replace(u'|', u'\n')
|
||||
verses[verse_tag][verse_num][inst].append(this_line)
|
||||
# done parsing
|
||||
# add verses in original order
|
||||
for (versetype, versenum, inst) in our_verse_order:
|
||||
vtag = u'%s%s' % (versetype, versenum)
|
||||
lines = u'\n'.join(verses[versetype][versenum][inst])
|
||||
self.add_verse(lines, vtag)
|
||||
for (verse_tag, verse_num, inst) in our_verse_order:
|
||||
verse_def = u'%s%s' % (verse_tag, verse_num)
|
||||
lines = u'\n'.join(verses[verse_tag][verse_num][inst])
|
||||
self.add_verse(lines, verse_def)
|
||||
# figure out the presentation order, if present
|
||||
if u'presentation' in fields and root.presentation != u'':
|
||||
order = unicode(root.presentation)
|
||||
# We make all the tags in the lyrics lower case, so match that here
|
||||
# and then split into a list on the whitespace
|
||||
order = order.lower().split()
|
||||
for tag in order:
|
||||
match = re.match(u'(.*)(\d+.*)', tag)
|
||||
for verse_def in order:
|
||||
match = re.match(u'(.*)(\d+.*)', verse_def)
|
||||
if match is not None:
|
||||
versetype = match.group(1)
|
||||
versenum = match.group(2)
|
||||
if not len(versetype):
|
||||
versetype = u'v'
|
||||
verse_tag = match.group(1)
|
||||
verse_num = match.group(2)
|
||||
if not len(verse_tag):
|
||||
verse_tag = u'v'
|
||||
else:
|
||||
# Assume it's no.1 if there are no digits
|
||||
versetype = tag
|
||||
versenum = u'1'
|
||||
vtagString = u'%s%s' % (versetype, versenum)
|
||||
if verses.has_key(versetype) \
|
||||
and verses[versetype].has_key(versenum):
|
||||
self.verse_order_list.append(vtagString)
|
||||
verse_tag = verse_def
|
||||
verse_num = u'1'
|
||||
verse_def = u'%s%s' % (verse_tag, verse_num)
|
||||
if verses.has_key(verse_tag) \
|
||||
and verses[verse_tag].has_key(verse_num):
|
||||
self.verse_order_list.append(verse_def)
|
||||
else:
|
||||
log.info(u'Got order %s but not in versetags, dropping'
|
||||
u'this item from presentation order', vtagString)
|
||||
log.info(u'Got order %s but not in verse tags, dropping'
|
||||
u'this item from presentation order', verse_def)
|
||||
return True
|
||||
|
@ -200,39 +200,38 @@ class SongImport(QtCore.QObject):
|
||||
return
|
||||
self.media_files.append(filename)
|
||||
|
||||
def add_verse(self, versetext, versetag=u'v', lang=None):
|
||||
def add_verse(self, verse_text, verse_def=u'v', lang=None):
|
||||
"""
|
||||
Add a verse. This is the whole verse, lines split by \\n. It will also
|
||||
attempt to detect duplicates. In this case it will just add to the verse
|
||||
order.
|
||||
|
||||
``versetext``
|
||||
``verse_text``
|
||||
The text of the verse.
|
||||
|
||||
``versetag``
|
||||
The verse tag can be V1/C1/B etc, or 'V' and 'C' (will count the
|
||||
``verse_def``
|
||||
The verse tag can be v1/c1/b etc, or 'v' and 'c' (will count the
|
||||
verses/choruses itself) or None, where it will assume verse.
|
||||
|
||||
``lang``
|
||||
The language code (ISO-639) of the verse, for example *en* or *de*.
|
||||
|
||||
"""
|
||||
for (oldversetag, oldverse, oldlang) in self.verses:
|
||||
if oldverse.strip() == versetext.strip():
|
||||
# this verse is already present
|
||||
self.verse_order_list_generated.append(oldversetag)
|
||||
for (old_verse_def, old_verse, old_lang) in self.verses:
|
||||
if old_verse.strip() == verse_text.strip():
|
||||
self.verse_order_list_generated.append(old_verse_def)
|
||||
self.verse_order_list_generated_useful = True
|
||||
return
|
||||
if versetag[0] in self.versecounts:
|
||||
self.versecounts[versetag[0]] += 1
|
||||
if verse_def[0] in self.verse_counts:
|
||||
self.verse_counts[verse_def[0]] += 1
|
||||
else:
|
||||
self.versecounts[versetag[0]] = 1
|
||||
if len(versetag) == 1:
|
||||
versetag += unicode(self.versecounts[versetag[0]])
|
||||
elif int(versetag[1:]) > self.versecounts[versetag[0]]:
|
||||
self.versecounts[versetag[0]] = int(versetag[1:])
|
||||
self.verses.append([versetag, versetext.rstrip(), lang])
|
||||
self.verse_order_list_generated.append(versetag)
|
||||
self.verse_counts[verse_def[0]] = 1
|
||||
if len(verse_def) == 1:
|
||||
verse_def += unicode(self.versecounts[verse_def[0]])
|
||||
elif int(verse_def[1:]) > self.versecounts[verse_def[0]]:
|
||||
self.versecounts[verse_def[0]] = int(verse_def[1:])
|
||||
self.verses.append([verse_def, versetext.rstrip(), lang])
|
||||
self.verse_order_list_generated.append(verse_def)
|
||||
|
||||
def repeat_verse(self):
|
||||
"""
|
||||
@ -277,28 +276,29 @@ class SongImport(QtCore.QObject):
|
||||
verses_changed_to_other = {}
|
||||
sxml = SongXML()
|
||||
other_count = 1
|
||||
for (versetag, versetext, lang) in self.verses:
|
||||
if versetag[0].lower() in VerseType.Tags:
|
||||
versetype = versetag[0].lower()
|
||||
for (verse_def, verse_text, lang) in self.verses:
|
||||
if verse_def[0].lower() in VerseType.Tags:
|
||||
verse_def = verse_def[0].lower()
|
||||
else:
|
||||
newversetag = u'%s%d' % (VerseType.Tags[VerseType.Other],
|
||||
new_verse_def = u'%s%d' % (VerseType.Tags[VerseType.Other],
|
||||
other_count)
|
||||
verses_changed_to_other[versetag] = newversetag
|
||||
verses_changed_to_other[verse_def] = new_verse_def
|
||||
other_count += 1
|
||||
versetype = VerseType.Tags[VerseType.Other]
|
||||
log.info(u'Versetype %s changing to %s' , versetag, newversetag)
|
||||
versetag = newversetag
|
||||
sxml.add_verse_to_lyrics(versetype, versetag[1:], versetext, lang)
|
||||
song.search_lyrics += u' ' + self.remove_punctuation(versetext)
|
||||
verse_tag = VerseType.Tags[VerseType.Other]
|
||||
log.info(u'Versetype %s changing to %s' , verse_def,
|
||||
new_verse_def)
|
||||
verse_def = new_verse_def
|
||||
sxml.add_verse_to_lyrics(verse_tag, verse_def[1:], verse_text, lang)
|
||||
song.search_lyrics += u' ' + self.remove_punctuation(verse_text)
|
||||
song.search_lyrics = song.search_lyrics.lower()
|
||||
song.lyrics = unicode(sxml.extract_xml(), u'utf-8')
|
||||
if not len(self.verse_order_list) and \
|
||||
self.verse_order_list_generated_useful:
|
||||
self.verse_order_list = self.verse_order_list_generated
|
||||
for i, current_verse_tag in enumerate(self.verse_order_list):
|
||||
if verses_changed_to_other.has_key(current_verse_tag):
|
||||
for i, current_verse_def in enumerate(self.verse_order_list):
|
||||
if verses_changed_to_other.has_key(current_verse_def):
|
||||
self.verse_order_list[i] = \
|
||||
verses_changed_to_other[current_verse_tag]
|
||||
verses_changed_to_other[current_verse_def]
|
||||
song.verse_order = u' '.join(self.verse_order_list)
|
||||
song.copyright = self.copyright
|
||||
song.comments = self.comments
|
||||
@ -343,8 +343,8 @@ class SongImport(QtCore.QObject):
|
||||
+ u'========================================'
|
||||
print u'TITLE: ' + self.title
|
||||
print u'ALT TITLE: ' + self.alternate_title
|
||||
for (versetag, versetext, lang) in self.verses:
|
||||
print u'VERSE ' + versetag + u': ' + versetext
|
||||
for (verse_def, verse_text, lang) in self.verses:
|
||||
print u'VERSE ' + verse_def + u': ' + verse_text
|
||||
print u'ORDER: ' + u' '.join(self.verse_order_list)
|
||||
print u'GENERATED ORDER: ' + u' '.join(self.verse_order_list_generated)
|
||||
for author in self.authors:
|
||||
|
Loading…
Reference in New Issue
Block a user