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