forked from openlp/openlp
better variable names, fixed translation issues for verse sequences
This commit is contained in:
parent
dff393b6a4
commit
aac40357ae
@ -604,14 +604,14 @@ class SlideController(QtGui.QWidget):
|
|||||||
if self.serviceItem.is_text():
|
if self.serviceItem.is_text():
|
||||||
if frame[u'verseTag']:
|
if frame[u'verseTag']:
|
||||||
# These tags are already translated.
|
# These tags are already translated.
|
||||||
versetag = frame[u'verseTag']
|
verse_def = frame[u'verseTag']
|
||||||
versetag = u'%s%s' % (versetag[0].upper(), versetag[1:])
|
verse_def = u'%s%s' % (verse_def[0].upper(), verse_def[1:])
|
||||||
twolineTag = u'%s\n%s' % (versetag[0], versetag[1:] )
|
two_line_def = u'%s\n%s' % (verse_def[0], verse_def[1:] )
|
||||||
row = twolineTag
|
row = two_line_def
|
||||||
if self.isLive:
|
if self.isLive:
|
||||||
if versetag not in self.slideList:
|
if verse_def not in self.slideList:
|
||||||
self.slideList[versetag] = framenumber
|
self.slideList[verse_def] = framenumber
|
||||||
self.songMenu.menu().addAction(versetag,
|
self.songMenu.menu().addAction(verse_def,
|
||||||
self.onSongBarHandler)
|
self.onSongBarHandler)
|
||||||
else:
|
else:
|
||||||
row += 1
|
row += 1
|
||||||
|
@ -227,17 +227,6 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
|||||||
self.copyrightEdit.setText(u'')
|
self.copyrightEdit.setText(u'')
|
||||||
self.verseListWidget.clear()
|
self.verseListWidget.clear()
|
||||||
self.verseListWidget.setRowCount(0)
|
self.verseListWidget.setRowCount(0)
|
||||||
if self.song.verse_order:
|
|
||||||
# we translate verse order
|
|
||||||
translated = []
|
|
||||||
for versetag in self.song.verse_order.split():
|
|
||||||
verseindex = VerseType.from_tag(versetag[0])
|
|
||||||
versetype = VerseType.TranslatedTags[verseindex]
|
|
||||||
versenum = versetag[1:]
|
|
||||||
translated.append(u'%s%s' % (versetype.upper(), versenum))
|
|
||||||
self.verseOrderEdit.setText(u' '.join(translated))
|
|
||||||
else:
|
|
||||||
self.verseOrderEdit.setText(u'')
|
|
||||||
if self.song.comments:
|
if self.song.comments:
|
||||||
self.commentsEdit.setPlainText(self.song.comments)
|
self.commentsEdit.setPlainText(self.song.comments)
|
||||||
else:
|
else:
|
||||||
@ -257,6 +246,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
|||||||
# This is just because occasionally the lyrics come back as a "buffer"
|
# This is just because occasionally the lyrics come back as a "buffer"
|
||||||
if isinstance(self.song.lyrics, buffer):
|
if isinstance(self.song.lyrics, buffer):
|
||||||
self.song.lyrics = unicode(self.song.lyrics)
|
self.song.lyrics = unicode(self.song.lyrics)
|
||||||
|
verse_tags_translated = False
|
||||||
if self.song.lyrics.startswith(u'<?xml version='):
|
if self.song.lyrics.startswith(u'<?xml version='):
|
||||||
songXML = SongXML()
|
songXML = SongXML()
|
||||||
verseList = songXML.get_verses(self.song.lyrics)
|
verseList = songXML.get_verses(self.song.lyrics)
|
||||||
@ -265,20 +255,22 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
|||||||
self.verseListWidget.rowCount() + 1)
|
self.verseListWidget.rowCount() + 1)
|
||||||
# This silently migrates from localized verse type markup.
|
# This silently migrates from localized verse type markup.
|
||||||
# If we trusted the database, this would be unnecessary.
|
# If we trusted the database, this would be unnecessary.
|
||||||
vtype = verse[0][u'type']
|
verse_tag = verse[0][u'type']
|
||||||
index = None
|
index = None
|
||||||
if len(vtype) > 1:
|
if len(verse_tag) > 1:
|
||||||
index = VerseType.from_translated_string(vtype)
|
index = VerseType.from_translated_string(verse_tag)
|
||||||
if index is None:
|
if index is None:
|
||||||
index = VerseType.from_string(vtype)
|
index = VerseType.from_string(verse_tag)
|
||||||
|
else:
|
||||||
|
verse_tags_translated = True
|
||||||
if index is None:
|
if index is None:
|
||||||
index = VerseType.from_tag(vtype)
|
index = VerseType.from_tag(verse_tag)
|
||||||
if index is None:
|
if index is None:
|
||||||
index = VerseType.Other
|
index = VerseType.Other
|
||||||
verse[0][u'type'] = VerseType.Tags[index]
|
verse[0][u'type'] = VerseType.Tags[index]
|
||||||
variant = u'%s%s' % (verse[0][u'type'], verse[0][u'label'])
|
verse_def = u'%s%s' % (verse[0][u'type'], verse[0][u'label'])
|
||||||
item = QtGui.QTableWidgetItem(verse[1])
|
item = QtGui.QTableWidgetItem(verse[1])
|
||||||
item.setData(QtCore.Qt.UserRole, QtCore.QVariant(variant))
|
item.setData(QtCore.Qt.UserRole, QtCore.QVariant(verse_def))
|
||||||
self.verseListWidget.setItem(count, 0, item)
|
self.verseListWidget.setItem(count, 0, item)
|
||||||
else:
|
else:
|
||||||
verses = self.song.lyrics.split(u'\n\n')
|
verses = self.song.lyrics.split(u'\n\n')
|
||||||
@ -286,10 +278,24 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
|||||||
self.verseListWidget.setRowCount(
|
self.verseListWidget.setRowCount(
|
||||||
self.verseListWidget.rowCount() + 1)
|
self.verseListWidget.rowCount() + 1)
|
||||||
item = QtGui.QTableWidgetItem(verse)
|
item = QtGui.QTableWidgetItem(verse)
|
||||||
variant = u'%s:%s' % \
|
verse_def = u'%s%s' % \
|
||||||
(VerseType.Tags[VerseType.Verse], unicode(count + 1))
|
(VerseType.Tags[VerseType.Verse], unicode(count + 1))
|
||||||
item.setData(QtCore.Qt.UserRole, QtCore.QVariant(variant))
|
item.setData(QtCore.Qt.UserRole, QtCore.QVariant(verse_def))
|
||||||
self.verseListWidget.setItem(count, 0, item)
|
self.verseListWidget.setItem(count, 0, item)
|
||||||
|
if self.song.verse_order:
|
||||||
|
# we translate verse order
|
||||||
|
translated = []
|
||||||
|
for verse_def in self.song.verse_order.split():
|
||||||
|
verse_index = None
|
||||||
|
if verse_tags_translated:
|
||||||
|
verse_index = VerseType.from_translated_tag(verse_def[0])
|
||||||
|
if verse_index is None:
|
||||||
|
verse_index = VerseType.from_tag(verse_def[0])
|
||||||
|
verse_tag = VerseType.TranslatedTags[verse_index].upper()
|
||||||
|
translated.append(u'%s%s' % (verse_tag, verse_def[1:]))
|
||||||
|
self.verseOrderEdit.setText(u' '.join(translated))
|
||||||
|
else:
|
||||||
|
self.verseOrderEdit.setText(u'')
|
||||||
self.verseListWidget.resizeRowsToContents()
|
self.verseListWidget.resizeRowsToContents()
|
||||||
self.tagRows()
|
self.tagRows()
|
||||||
# clear the results
|
# clear the results
|
||||||
@ -314,15 +320,14 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
|||||||
"""
|
"""
|
||||||
Tag the Song List rows based on the verse list
|
Tag the Song List rows based on the verse list
|
||||||
"""
|
"""
|
||||||
rowLabel = []
|
row_label = []
|
||||||
for row in range(0, self.verseListWidget.rowCount()):
|
for row in range(0, self.verseListWidget.rowCount()):
|
||||||
item = self.verseListWidget.item(row, 0)
|
item = self.verseListWidget.item(row, 0)
|
||||||
versetag = unicode(item.data(QtCore.Qt.UserRole).toString())
|
verse_def = unicode(item.data(QtCore.Qt.UserRole).toString())
|
||||||
versetype = VerseType.TranslatedTags[
|
verse_tag = VerseType.translated_tag(verse_def[0])
|
||||||
VerseType.from_tag(versetag[0])].upper()
|
row_def = u'%s%s' % (verse_tag, verse_def[1:])
|
||||||
rowTag = u'%s%s' % (versetype, versetag[1:])
|
row_label.append(row_def)
|
||||||
rowLabel.append(rowTag)
|
self.verseListWidget.setVerticalHeaderLabels(row_label)
|
||||||
self.verseListWidget.setVerticalHeaderLabels(rowLabel)
|
|
||||||
|
|
||||||
def onAuthorAddButtonClicked(self):
|
def onAuthorAddButtonClicked(self):
|
||||||
item = int(self.authorsComboBox.currentIndex())
|
item = int(self.authorsComboBox.currentIndex())
|
||||||
@ -441,11 +446,11 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
|||||||
def onVerseAddButtonClicked(self):
|
def onVerseAddButtonClicked(self):
|
||||||
self.verse_form.setVerse(u'', True)
|
self.verse_form.setVerse(u'', True)
|
||||||
if self.verse_form.exec_():
|
if self.verse_form.exec_():
|
||||||
afterText, versetype, versenum = self.verse_form.getVerse()
|
after_text, verse_tag, verse_num = self.verse_form.getVerse()
|
||||||
versetag = u'%s%s' % (versetype, versenum)
|
verse_def = u'%s%s' % (verse_tag, verse_num)
|
||||||
item = QtGui.QTableWidgetItem(afterText)
|
item = QtGui.QTableWidgetItem(afterText)
|
||||||
item.setData(QtCore.Qt.UserRole, QtCore.QVariant(versetag))
|
item.setData(QtCore.Qt.UserRole, QtCore.QVariant(verse_def))
|
||||||
item.setText(afterText)
|
item.setText(after_text)
|
||||||
self.verseListWidget.setRowCount(
|
self.verseListWidget.setRowCount(
|
||||||
self.verseListWidget.rowCount() + 1)
|
self.verseListWidget.rowCount() + 1)
|
||||||
self.verseListWidget.setItem(
|
self.verseListWidget.setItem(
|
||||||
@ -461,12 +466,12 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
|||||||
verseId = unicode(item.data(QtCore.Qt.UserRole).toString())
|
verseId = unicode(item.data(QtCore.Qt.UserRole).toString())
|
||||||
self.verse_form.setVerse(tempText, True, verseId)
|
self.verse_form.setVerse(tempText, True, verseId)
|
||||||
if self.verse_form.exec_():
|
if self.verse_form.exec_():
|
||||||
afterText, versetype, versenum = self.verse_form.getVerse()
|
after_text, verse_tag, verse_num = self.verse_form.getVerse()
|
||||||
versetag = u'%s%s' % (versetype, versenum)
|
verse_def = u'%s%s' % (verse_tag, verse_num)
|
||||||
item.setData(QtCore.Qt.UserRole, QtCore.QVariant(versetag))
|
item.setData(QtCore.Qt.UserRole, QtCore.QVariant(verse_def))
|
||||||
item.setText(afterText)
|
item.setText(after_text)
|
||||||
# number of lines has change so repaint the list moving the data
|
# number of lines has change so repaint the list moving the data
|
||||||
if len(tempText.split(u'\n')) != len(afterText.split(u'\n')):
|
if len(tempText.split(u'\n')) != len(after_text.split(u'\n')):
|
||||||
tempList = {}
|
tempList = {}
|
||||||
tempId = {}
|
tempId = {}
|
||||||
for row in range(0, self.verseListWidget.rowCount()):
|
for row in range(0, self.verseListWidget.rowCount()):
|
||||||
@ -488,10 +493,9 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
|||||||
for row in range(0, self.verseListWidget.rowCount()):
|
for row in range(0, self.verseListWidget.rowCount()):
|
||||||
item = self.verseListWidget.item(row, 0)
|
item = self.verseListWidget.item(row, 0)
|
||||||
field = unicode(item.data(QtCore.Qt.UserRole).toString())
|
field = unicode(item.data(QtCore.Qt.UserRole).toString())
|
||||||
versetypeindex = VerseType.from_tag(field[0])
|
verse_tag = VerseType.translated_name(field[0])
|
||||||
versetype = VerseType.TranslatedNames[versetypeindex]
|
verse_num = field[1:]
|
||||||
versenum = field[1:]
|
verse_list += u'---[%s:%s]---\n' % (verse_tag, verse_num)
|
||||||
verse_list += u'---[%s:%s]---\n' % (versetype, versenum)
|
|
||||||
verse_list += item.text()
|
verse_list += item.text()
|
||||||
verse_list += u'\n'
|
verse_list += u'\n'
|
||||||
self.verse_form.setVerse(verse_list)
|
self.verse_form.setVerse(verse_list)
|
||||||
@ -510,31 +514,29 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
|||||||
# handling carefully user inputted versetags
|
# handling carefully user inputted versetags
|
||||||
separator = parts.find(u':')
|
separator = parts.find(u':')
|
||||||
if separator >= 0:
|
if separator >= 0:
|
||||||
versetype = parts[0:separator].strip()
|
verse_name = parts[0:separator].strip()
|
||||||
versenum = parts[separator+1:].strip()
|
verse_num = parts[separator+1:].strip()
|
||||||
else:
|
else:
|
||||||
versetype = parts
|
verse_name = parts
|
||||||
versenum = u'1'
|
verse_num = u'1'
|
||||||
verseindex = \
|
verse_index = \
|
||||||
VerseType.from_loose_input(versetype)
|
VerseType.from_loose_input(verse_name)
|
||||||
if verseindex is None:
|
verse_tag = VerseType.Tags[verse_index]
|
||||||
verseindex = VerseType.Verse
|
|
||||||
versetype = VerseType.Tags[verseindex]
|
|
||||||
# Later we need to handle v1a as well.
|
# Later we need to handle v1a as well.
|
||||||
#regex = re.compile(r'(\d+\w.)')
|
#regex = re.compile(r'(\d+\w.)')
|
||||||
regex = re.compile(r'\D*(\d+)\D*')
|
regex = re.compile(r'\D*(\d+)\D*')
|
||||||
match = regex.match(versenum)
|
match = regex.match(verse_num)
|
||||||
if match:
|
if match:
|
||||||
versenum = match.group(1)
|
verse_num = match.group(1)
|
||||||
else:
|
else:
|
||||||
versenum = u'1'
|
verse_num = u'1'
|
||||||
variant = u'%s%s' % (versetype, versenum)
|
verse_def = u'%s%s' % (verse_tag, verse_num)
|
||||||
else:
|
else:
|
||||||
if parts.endswith(u'\n'):
|
if parts.endswith(u'\n'):
|
||||||
parts = parts.rstrip(u'\n')
|
parts = parts.rstrip(u'\n')
|
||||||
item = QtGui.QTableWidgetItem(parts)
|
item = QtGui.QTableWidgetItem(parts)
|
||||||
item.setData(QtCore.Qt.UserRole,
|
item.setData(QtCore.Qt.UserRole,
|
||||||
QtCore.QVariant(variant))
|
QtCore.QVariant(verse_def))
|
||||||
self.verseListWidget.setRowCount(
|
self.verseListWidget.setRowCount(
|
||||||
self.verseListWidget.rowCount() + 1)
|
self.verseListWidget.rowCount() + 1)
|
||||||
self.verseListWidget.setItem(
|
self.verseListWidget.setItem(
|
||||||
@ -586,29 +588,31 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
|||||||
order_names = unicode(self.verseOrderEdit.text()).split()
|
order_names = unicode(self.verseOrderEdit.text()).split()
|
||||||
for item in order_names:
|
for item in order_names:
|
||||||
if len(item) == 1:
|
if len(item) == 1:
|
||||||
order.append(VerseType.Tags[VerseType.from_translated_tag(
|
verse_index = VerseType.from_translated_tag(item)
|
||||||
item)] + u'1')
|
if verse_index is not None:
|
||||||
|
order.append(VerseType.Tags[verse_index] + u'1')
|
||||||
|
else:
|
||||||
|
order.append(u'') # it matches no verses anyway
|
||||||
else:
|
else:
|
||||||
versetag = VerseType.Tags[
|
verse_index = VerseType.from_translated_tag(item[0])
|
||||||
VerseType.from_translated_tag(item[0])]
|
if verse_index is None:
|
||||||
versenum = item[1:].lower()
|
order.append(u'') # same as above
|
||||||
order.append(u'%s%s' % (versetag, versenum))
|
else:
|
||||||
|
verse_tag = VerseType.Tags[verse_index]
|
||||||
|
verse_num = item[1:].lower()
|
||||||
|
order.append(verse_tag + verse_num)
|
||||||
verses = []
|
verses = []
|
||||||
verse_names = []
|
verse_names = []
|
||||||
for index in range(0, self.verseListWidget.rowCount()):
|
for index in range(0, self.verseListWidget.rowCount()):
|
||||||
verse = self.verseListWidget.item(index, 0)
|
verse = self.verseListWidget.item(index, 0)
|
||||||
verse = unicode(verse.data(QtCore.Qt.UserRole).toString())
|
verse = unicode(verse.data(QtCore.Qt.UserRole).toString())
|
||||||
if verse not in verse_names:
|
if verse not in verse_names:
|
||||||
verses.append(
|
verses.append(verse)
|
||||||
re.sub(r'(.)[^:]*:(.*)', r'\1\2', verse.lower()))
|
verse_names.append(u'%s%s' % (
|
||||||
verse_names.append(verse)
|
VerseType.translated_tag(verse[0]), verse[1:]))
|
||||||
for count, item in enumerate(order):
|
for count, item in enumerate(order):
|
||||||
if item not in verses:
|
if item not in verses:
|
||||||
self.songTabWidget.setCurrentIndex(0)
|
valid = u', '.join(verse_names)
|
||||||
self.verseOrderEdit.setFocus()
|
|
||||||
valid = verses.pop(0)
|
|
||||||
for verse in verses:
|
|
||||||
valid = valid + u', ' + verse.upper()
|
|
||||||
critical_error_message_box(
|
critical_error_message_box(
|
||||||
message=unicode(translate('SongsPlugin.EditSongForm',
|
message=unicode(translate('SongsPlugin.EditSongForm',
|
||||||
'The verse order is invalid. There is no verse '
|
'The verse order is invalid. There is no verse '
|
||||||
@ -619,17 +623,12 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
|||||||
if verse not in order:
|
if verse not in order:
|
||||||
self.songTabWidget.setCurrentIndex(0)
|
self.songTabWidget.setCurrentIndex(0)
|
||||||
self.verseOrderEdit.setFocus()
|
self.verseOrderEdit.setFocus()
|
||||||
versetype = verse_names[count][0]
|
|
||||||
versenum = verse_names[count][1:]
|
|
||||||
verseindex = VerseType.from_tag(versetype)
|
|
||||||
versetype = VerseType.TranslatedTags[verseindex].upper()
|
|
||||||
versename = u'%s%s' % (versetype, versenum)
|
|
||||||
answer = QtGui.QMessageBox.warning(self,
|
answer = QtGui.QMessageBox.warning(self,
|
||||||
translate('SongsPlugin.EditSongForm', 'Warning'),
|
translate('SongsPlugin.EditSongForm', 'Warning'),
|
||||||
unicode(translate('SongsPlugin.EditSongForm',
|
unicode(translate('SongsPlugin.EditSongForm',
|
||||||
'You have not used %s anywhere in the verse '
|
'You have not used %s anywhere in the verse '
|
||||||
'order. Are you sure you want to save the song '
|
'order. Are you sure you want to save the song '
|
||||||
'like this?')) % versename,
|
'like this?')) % verse_names[count],
|
||||||
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
|
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No)
|
||||||
if answer == QtGui.QMessageBox.No:
|
if answer == QtGui.QMessageBox.No:
|
||||||
return False
|
return False
|
||||||
@ -739,10 +738,10 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
|||||||
ordertext = unicode(self.verseOrderEdit.text())
|
ordertext = unicode(self.verseOrderEdit.text())
|
||||||
order = []
|
order = []
|
||||||
for item in ordertext.split():
|
for item in ordertext.split():
|
||||||
versetag = VerseType.Tags[
|
verse_tag = VerseType.Tags[
|
||||||
VerseType.from_translated_tag(item[0])]
|
VerseType.from_translated_tag(item[0])]
|
||||||
versenum = item[1:].lower()
|
verse_num = item[1:].lower()
|
||||||
order.append(u'%s%s' % (versetag, versenum))
|
order.append(u'%s%s' % (verse_tag, verse_num))
|
||||||
self.song.verse_order = u' '.join(order)
|
self.song.verse_order = u' '.join(order)
|
||||||
self.song.ccli_number = unicode(self.CCLNumberEdit.text())
|
self.song.ccli_number = unicode(self.CCLNumberEdit.text())
|
||||||
self.song.song_number = unicode(self.songBookNumberEdit.text())
|
self.song.song_number = unicode(self.songBookNumberEdit.text())
|
||||||
@ -786,14 +785,14 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
|
|||||||
for i in range(0, self.verseListWidget.rowCount()):
|
for i in range(0, self.verseListWidget.rowCount()):
|
||||||
item = self.verseListWidget.item(i, 0)
|
item = self.verseListWidget.item(i, 0)
|
||||||
verseId = unicode(item.data(QtCore.Qt.UserRole).toString())
|
verseId = unicode(item.data(QtCore.Qt.UserRole).toString())
|
||||||
versetype = verseId[0]
|
verse_tag = verseId[0]
|
||||||
versenum = verseId[1:]
|
verse_num = verseId[1:]
|
||||||
sxml.add_verse_to_lyrics(versetype, versenum,
|
sxml.add_verse_to_lyrics(verse_type, 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' '
|
||||||
if (versenum > u'1') and (versetype not in multiple):
|
if (verse_num > u'1') and (verse_tag not in multiple):
|
||||||
multiple.append(versetype)
|
multiple.append(verse_tag)
|
||||||
self.song.search_lyrics = text.lower()
|
self.song.search_lyrics = text.lower()
|
||||||
self.song.lyrics = unicode(sxml.extract_xml(), u'utf-8')
|
self.song.lyrics = unicode(sxml.extract_xml(), u'utf-8')
|
||||||
for verse in multiple:
|
for verse in multiple:
|
||||||
|
@ -57,22 +57,22 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog):
|
|||||||
QtCore.QObject.connect(self.verseTypeComboBox,
|
QtCore.QObject.connect(self.verseTypeComboBox,
|
||||||
QtCore.SIGNAL(u'currentIndexChanged(int)'),
|
QtCore.SIGNAL(u'currentIndexChanged(int)'),
|
||||||
self.onVerseTypeComboBoxChanged)
|
self.onVerseTypeComboBoxChanged)
|
||||||
self.verse_regex = re.compile(r'---\[(.+):\D*(\d+)\D*\]---')
|
self.verse_regex = re.compile(r'---\[(.+):\D*(\d.)\D*\]---')
|
||||||
|
|
||||||
def contextMenu(self, point):
|
def contextMenu(self, point):
|
||||||
item = self.serviceManagerList.itemAt(point)
|
item = self.serviceManagerList.itemAt(point)
|
||||||
|
|
||||||
def insertVerse(self, versetype, num=1):
|
def insertVerse(self, verse_tag, verse_num=1):
|
||||||
if self.verseTextEdit.textCursor().columnNumber() != 0:
|
if self.verseTextEdit.textCursor().columnNumber() != 0:
|
||||||
self.verseTextEdit.insertPlainText(u'\n')
|
self.verseTextEdit.insertPlainText(u'\n')
|
||||||
versetype = VerseType.TranslatedNames[VerseTag.from_tag(versetype)]
|
verse_tag = VerseType.translated_name(verse_tag)
|
||||||
self.verseTextEdit.insertPlainText(u'---[%s:%s]---\n' % \
|
self.verseTextEdit.insertPlainText(u'---[%s:%s]---\n' %
|
||||||
(versetype, num))
|
(verse_tag, verse_num))
|
||||||
self.verseTextEdit.setFocus()
|
self.verseTextEdit.setFocus()
|
||||||
|
|
||||||
def onInsertButtonClicked(self):
|
def onInsertButtonClicked(self):
|
||||||
vtypeindex = self.verseTypeComboBox.currentIndex()
|
verse_type_index = self.verseTypeComboBox.currentIndex()
|
||||||
self.insertVerse(VerseType.Tags[vtypeindex],
|
self.insertVerse(VerseType.Tags[verse_type_index],
|
||||||
self.verseNumberBox.value())
|
self.verseNumberBox.value())
|
||||||
|
|
||||||
def onVerseTypeComboBoxChanged(self):
|
def onVerseTypeComboBoxChanged(self):
|
||||||
@ -82,11 +82,11 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog):
|
|||||||
"""
|
"""
|
||||||
position = self.verseTextEdit.textCursor().position()
|
position = self.verseTextEdit.textCursor().position()
|
||||||
text = unicode(self.verseTextEdit.toPlainText())
|
text = unicode(self.verseTextEdit.toPlainText())
|
||||||
verse_type = VerseType.TranslatedNames[
|
verse_name = VerseType.TranslatedNames[
|
||||||
self.verseTypeComboBox.currentIndex()]
|
self.verseTypeComboBox.currentIndex()]
|
||||||
if not text:
|
if not text:
|
||||||
return
|
return
|
||||||
position = text.rfind(u'---[%s' % verse_type, 0, position)
|
position = text.rfind(u'---[%s' % verse_name, 0, position)
|
||||||
if position == -1:
|
if position == -1:
|
||||||
self.verseNumberBox.setValue(1)
|
self.verseNumberBox.setValue(1)
|
||||||
return
|
return
|
||||||
@ -97,11 +97,11 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog):
|
|||||||
text = text[:position + 4]
|
text = text[:position + 4]
|
||||||
match = self.verse_regex.match(text)
|
match = self.verse_regex.match(text)
|
||||||
if match:
|
if match:
|
||||||
verse_type = match.group(1)
|
verse_tag = match.group(1)
|
||||||
verse_number = int(match.group(2))
|
verse_num = int(match.group(2))
|
||||||
verse_type_index = VerseType.from_loose_input(verse_type)
|
verse_type_index = VerseType.from_loose_input(verse_tag)
|
||||||
if verse_type_index is not None:
|
if verse_type_index is not None:
|
||||||
self.verseNumberBox.setValue(verse_number)
|
self.verseNumberBox.setValue(verse_num)
|
||||||
|
|
||||||
def onCursorPositionChanged(self):
|
def onCursorPositionChanged(self):
|
||||||
"""
|
"""
|
||||||
@ -125,13 +125,13 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog):
|
|||||||
text = text[:position + 4]
|
text = text[:position + 4]
|
||||||
match = self.verse_regex.match(text)
|
match = self.verse_regex.match(text)
|
||||||
if match:
|
if match:
|
||||||
versetype = match.group(1)
|
verse_type = match.group(1)
|
||||||
vtypeindex = VerseType.from_loose_input(versetype)
|
verse_type_index = VerseType.from_loose_input(verse_type)
|
||||||
regex = re.compile(r'(\d+)')
|
regex = re.compile(r'(\d+)')
|
||||||
versenum = int(match.group(2))
|
verse_num = int(match.group(2))
|
||||||
if vtypeindex is not None:
|
if verse_type_index is not None:
|
||||||
self.verseTypeComboBox.setCurrentIndex(vtypeindex)
|
self.verseTypeComboBox.setCurrentIndex(verse_type_index)
|
||||||
self.verseNumberBox.setValue(versenum)
|
self.verseNumberBox.setValue(verse_num)
|
||||||
|
|
||||||
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]):
|
||||||
|
@ -48,9 +48,7 @@ class VerseType(object):
|
|||||||
u'Intro',
|
u'Intro',
|
||||||
u'Ending',
|
u'Ending',
|
||||||
u'Other']
|
u'Other']
|
||||||
Tags = []
|
Tags = [name[0].lower() for name in Names]
|
||||||
for name in Names:
|
|
||||||
Tags.append(name[0].lower())
|
|
||||||
|
|
||||||
TranslatedNames = [
|
TranslatedNames = [
|
||||||
unicode(translate('SongsPlugin.VerseType', 'Verse')),
|
unicode(translate('SongsPlugin.VerseType', 'Verse')),
|
||||||
@ -60,80 +58,129 @@ class VerseType(object):
|
|||||||
unicode(translate('SongsPlugin.VerseType', 'Intro')),
|
unicode(translate('SongsPlugin.VerseType', 'Intro')),
|
||||||
unicode(translate('SongsPlugin.VerseType', 'Ending')),
|
unicode(translate('SongsPlugin.VerseType', 'Ending')),
|
||||||
unicode(translate('SongsPlugin.VerseType', 'Other'))]
|
unicode(translate('SongsPlugin.VerseType', 'Other'))]
|
||||||
TranslatedTags = []
|
TranslatedTags = [name[0].lower() for name in TranslatedNames]
|
||||||
for name in TranslatedNames:
|
|
||||||
TranslatedTags.append(name[0].lower())
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_tag(verse_type):
|
def translated_tag(verse_tag, strict=False):
|
||||||
|
"""
|
||||||
|
Return the translated UPPERCASE tag for a given tag,
|
||||||
|
used to show translated verse tags in UI
|
||||||
|
|
||||||
|
``verse_tag``
|
||||||
|
The string to return a VerseType for
|
||||||
|
|
||||||
|
``strict``
|
||||||
|
Determines if the default Other or None should be returned
|
||||||
|
"""
|
||||||
|
if strict:
|
||||||
|
not_found_value = None
|
||||||
|
else:
|
||||||
|
not_found_value = VerseType.TranslatedTags[VerseType.Other].upper()
|
||||||
|
verse_tag = verse_tag[0].lower()
|
||||||
|
for num, tag in enumerate(VerseType.Tags):
|
||||||
|
if verse_tag == tag:
|
||||||
|
return VerseType.TranslatedTags[num].upper()
|
||||||
|
return not_found_value
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def translated_name(verse_tag, strict=False):
|
||||||
|
"""
|
||||||
|
Return the translated name for a given tag
|
||||||
|
|
||||||
|
``verse_tag``
|
||||||
|
The string to return a VerseType for
|
||||||
|
|
||||||
|
``strict``
|
||||||
|
Determines if the default Other or None should be returned
|
||||||
|
"""
|
||||||
|
if strict:
|
||||||
|
not_found_value = None
|
||||||
|
else:
|
||||||
|
not_found_value = VerseType.TranslatedNames[VerseType.Other]
|
||||||
|
verse_tag = verse_tag[0].lower()
|
||||||
|
for num, tag in enumerate(VerseType.Tags):
|
||||||
|
if verse_tag == tag:
|
||||||
|
return VerseType.TranslatedNames[num]
|
||||||
|
return not_found_value
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_tag(verse_tag, strict=False):
|
||||||
"""
|
"""
|
||||||
Return the VerseType for a given tag
|
Return the VerseType for a given tag
|
||||||
|
|
||||||
``verse_type``
|
``verse_tag``
|
||||||
|
The string to return a VerseType for
|
||||||
|
|
||||||
|
``strict``
|
||||||
|
Determines if the default Other or None should be returned
|
||||||
|
"""
|
||||||
|
if strict:
|
||||||
|
no_return_value = None
|
||||||
|
else:
|
||||||
|
no_return_value = VerseType.Other
|
||||||
|
verse_tag = verse_tag[0].lower()
|
||||||
|
for num, tag in enumerate(VerseType.Tags):
|
||||||
|
if verse_tag == tag:
|
||||||
|
return num
|
||||||
|
return no_return_value
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def from_translated_tag(verse_tag):
|
||||||
|
"""
|
||||||
|
Return the VerseType for a given tag
|
||||||
|
|
||||||
|
``verse_tag``
|
||||||
The string to return a VerseType for
|
The string to return a VerseType for
|
||||||
"""
|
"""
|
||||||
verse_type = verse_type[0].lower()
|
verse_tag = verse_tag[0].lower()
|
||||||
for num, string in enumerate(VerseType.Tags):
|
for num, tag in enumerate(VerseType.TranslatedTags):
|
||||||
if verse_type == string:
|
if verse_tag == tag:
|
||||||
return num
|
return num
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_translated_tag(verse_type):
|
def from_string(verse_name):
|
||||||
"""
|
|
||||||
Return the VerseType for a given tag
|
|
||||||
|
|
||||||
``verse_type``
|
|
||||||
The string to return a VerseType for
|
|
||||||
"""
|
|
||||||
verse_type = verse_type[0].lower()
|
|
||||||
for vtypeIndex, vtypeTag in enumerate(VerseType.TranslatedTags):
|
|
||||||
if verse_type == vtypeTag:
|
|
||||||
return vtypeIndex
|
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def from_string(verse_type):
|
|
||||||
"""
|
"""
|
||||||
Return the VerseType for a given string
|
Return the VerseType for a given string
|
||||||
|
|
||||||
``verse_type``
|
``verse_name``
|
||||||
The string to return a VerseType for
|
The string to return a VerseType for
|
||||||
"""
|
"""
|
||||||
verse_type = verse_type.lower()
|
verse_name = verse_name.lower()
|
||||||
for vtypeIndex, vtypeName in enumerate(VerseType.Names):
|
for num, name in enumerate(VerseType.Names):
|
||||||
if verse_type == vtypeName.lower():
|
if verse_name == name.lower():
|
||||||
return vtypeIndex
|
return num
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_translated_string(verse_type):
|
def from_translated_string(verse_name):
|
||||||
"""
|
"""
|
||||||
Return the VerseType for a given string
|
Return the VerseType for a given string
|
||||||
|
|
||||||
``verse_type``
|
``verse_name``
|
||||||
The string to return a VerseType for
|
The string to return a VerseType for
|
||||||
"""
|
"""
|
||||||
verse_type = verse_type.lower()
|
verse_name = verse_name.lower()
|
||||||
for num, translation in enumerate(VerseType.TranslatedNames):
|
for num, translation in enumerate(VerseType.TranslatedNames):
|
||||||
if verse_type == translation.lower():
|
if verse_name == translation.lower():
|
||||||
return num
|
return num
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def from_loose_input(verse_type):
|
def from_loose_input(verse_name):
|
||||||
"""
|
"""
|
||||||
Return the VerseType for a given string, Other if not found
|
Return the VerseType for a given string, Other if not found
|
||||||
|
|
||||||
``verse_type``
|
``verse_name``
|
||||||
The string to return a VerseType for
|
The string to return a VerseType for
|
||||||
"""
|
"""
|
||||||
verseIndex = None
|
verse_index = None
|
||||||
if len(verse_type) > 1:
|
if len(verse_name) > 1:
|
||||||
verseIndex = VerseType.from_translated_string(verse_type)
|
verse_index = VerseType.from_translated_string(verse_name)
|
||||||
if verseIndex is None:
|
if verse_index is None:
|
||||||
verseIndex = VerseType.from_string(verse_type)
|
verseIndex = VerseType.from_string(verse_name)
|
||||||
if verseIndex is None:
|
if verse_index is None:
|
||||||
verseIndex = VerseType.from_translated_tag(verse_type)
|
verse_index = VerseType.from_translated_tag(verse_name)
|
||||||
elif verseIndex is None:
|
elif verse_index is None:
|
||||||
verseIndex = VerseType.from_tag(verse_type)
|
verse_index = VerseType.from_tag(verse_name)
|
||||||
return verseIndex
|
return verse_index
|
||||||
|
|
||||||
def retrieve_windows_encoding(recommendation=None):
|
def retrieve_windows_encoding(recommendation=None):
|
||||||
"""
|
"""
|
||||||
|
@ -344,40 +344,49 @@ class SongMediaItem(MediaManagerItem):
|
|||||||
if song.lyrics.startswith(u'<?xml version='):
|
if song.lyrics.startswith(u'<?xml version='):
|
||||||
verseList = SongXML().get_verses(song.lyrics)
|
verseList = SongXML().get_verses(song.lyrics)
|
||||||
# no verse list or only 1 space (in error)
|
# no verse list or only 1 space (in error)
|
||||||
|
verse_tags_translated = False
|
||||||
|
if VerseType.from_translated_string(unicode(
|
||||||
|
verseList[0][0][u'type'])) is not None:
|
||||||
|
verse_tags_translated = True
|
||||||
if not song.verse_order.strip():
|
if not song.verse_order.strip():
|
||||||
for verse in verseList:
|
for verse in verseList:
|
||||||
# We cannot use from_loose_input() here, because database
|
# We cannot use from_loose_input() here, because database
|
||||||
# is supposed to contain English lowercase singlechar tags.
|
# is supposed to contain English lowercase singlechar tags.
|
||||||
verse_type = verse[0][u'type']
|
verse_tag = verse[0][u'type']
|
||||||
verseIndex = None
|
verse_index = None
|
||||||
if len(verse_type) > 1:
|
if len(verse_tag) > 1:
|
||||||
verseIndex = \
|
verse_index = \
|
||||||
VerseType.from_translated_string(verse_type)
|
VerseType.from_translated_string(verse_tag)
|
||||||
if verseIndex is None:
|
if verse_index is None:
|
||||||
verseIndex = VerseType.from_string(verse_type)
|
verse_index = VerseType.from_string(verse_tag)
|
||||||
if verseIndex is None:
|
if verse_index is None:
|
||||||
verseIndex = VerseType.from_tag(verse_type)
|
verse_index = VerseType.from_tag(verse_tag)
|
||||||
if verseIndex is None:
|
verse_tag = VerseType.TranslatedTags[verse_index].upper()
|
||||||
verseIndex = VerseType.Other
|
verse_def = u'%s%s' % (verse_tag, verse[0][u'label'])
|
||||||
versetype = VerseType.TranslatedTags[verseIndex].upper()
|
|
||||||
verseTag = u'%s%s' % (versetype, verse[0][u'label'])
|
|
||||||
service_item.add_from_text(
|
service_item.add_from_text(
|
||||||
verse[1][:30], unicode(verse[1]), verseTag)
|
verse[1][:30], unicode(verse[1]), verse_def)
|
||||||
else:
|
else:
|
||||||
# Loop through the verse list and expand the song accordingly.
|
# Loop through the verse list and expand the song accordingly.
|
||||||
for order in song.verse_order.lower().split():
|
for order in song.verse_order.lower().split():
|
||||||
if len(order) == 0:
|
if len(order) == 0:
|
||||||
break
|
break
|
||||||
for verse in verseList:
|
for verse in verseList:
|
||||||
if verse[0][u'type'][0] == order[0] and \
|
if verse[0][u'type'][0].lower() == order[0] and \
|
||||||
(verse[0][u'label'] == order[1:] or not order[1:]):
|
(verse[0][u'label'].lower() == order[1:] or \
|
||||||
verseindex = VerseType.from_tag(verse[0][u'type'])
|
not order[1:]):
|
||||||
versetype = VerseType.TranslatedTags[verseindex]\
|
if verse_tags_translated:
|
||||||
.upper()
|
verse_index = VerseType.from_translated_tag(
|
||||||
verseTag = u'%s%s' % (versetype,
|
verse[0][u'type'])
|
||||||
|
else:
|
||||||
|
verse_index = VerseType.from_tag(
|
||||||
|
verse[0][u'type'])
|
||||||
|
if verse_index is None:
|
||||||
|
verse_index = VerseType.Other
|
||||||
|
verse_tag = VerseType.TranslatedTags[verse_index]
|
||||||
|
verse_def = u'%s%s' % (verse_tag,
|
||||||
verse[0][u'label'])
|
verse[0][u'label'])
|
||||||
service_item.add_from_text(
|
service_item.add_from_text(
|
||||||
verse[1][:30], verse[1], verseTag)
|
verse[1][:30], verse[1], verse_def)
|
||||||
else:
|
else:
|
||||||
verses = song.lyrics.split(u'\n\n')
|
verses = song.lyrics.split(u'\n\n')
|
||||||
for slide in verses:
|
for slide in verses:
|
||||||
|
@ -465,8 +465,6 @@ class OpenLyrics(object):
|
|||||||
text += u'\n'.join([unicode(line) for line in lines.line])
|
text += u'\n'.join([unicode(line) for line in lines.line])
|
||||||
verse_name = self._get(verse, u'name')
|
verse_name = self._get(verse, u'name')
|
||||||
verse_type_index = VerseType.from_tag(verse_name[0])
|
verse_type_index = VerseType.from_tag(verse_name[0])
|
||||||
if verse_type_index is None:
|
|
||||||
verse_type_index = VerseType.Other
|
|
||||||
verse_type = VerseType.Names[verse_type_index]
|
verse_type = VerseType.Names[verse_type_index]
|
||||||
verse_number = re.compile(u'[a-zA-Z]*').sub(u'', verse_name)
|
verse_number = re.compile(u'[a-zA-Z]*').sub(u'', verse_name)
|
||||||
verse_part = re.compile(u'[0-9]*').sub(u'', verse_name[1:])
|
verse_part = re.compile(u'[0-9]*').sub(u'', verse_name[1:])
|
||||||
|
Loading…
Reference in New Issue
Block a user