fix exception in songs with no chords

This commit is contained in:
STEPHANVS 2022-02-16 00:31:36 +01:00
parent 237f82db5c
commit bf9aba52da
No known key found for this signature in database
GPG Key ID: 4EFE47E471FD62A9
2 changed files with 12 additions and 8 deletions

View File

@ -258,11 +258,13 @@ class EditSongForm(QtWidgets.QDialog, Ui_EditSongDialog, RegistryProperties):
if not self._validate_tags(tags): if not self._validate_tags(tags):
misplaced_tags.append('{field1} {field2}'.format(field1=VerseType.translated_name(field[0]), misplaced_tags.append('{field1} {field2}'.format(field1=VerseType.translated_name(field[0]),
field2=field[1:])) field2=field[1:]))
if Registry().get('settings').value('songs/enable chords') and not chords[0].startswith("="): if Registry().get('settings').value('songs/enable chords') and len(chords) > 0 and \
not chords[0].startswith("="):
QtWidgets.QMessageBox.warning(self, translate('SongsPlugin.EditVerseForm', 'Song key warning'), QtWidgets.QMessageBox.warning(self, translate('SongsPlugin.EditVerseForm', 'Song key warning'),
translate('SongsPlugin.EditVerseForm', 'No song key is present or song key ' translate('SongsPlugin.EditVerseForm', 'No song key is present or song key '
'is not the first chord.\nFor optimal chord experience, please, ' 'is not the first chord.\nFor optimal chord experience, please, '
'include a song key\nbefore any chord. Ex.: [=G]')) 'include a song key\nbefore any chord. Ex.: [=G]'),
QtWidgets.QMessageBox.checkBox)
if misplaced_tags: if misplaced_tags:
critical_error_message_box( critical_error_message_box(
message=translate('SongsPlugin.EditSongForm', message=translate('SongsPlugin.EditSongForm',

View File

@ -124,14 +124,15 @@ class EditVerseForm(QtWidgets.QDialog, Ui_EditVerseDialog):
try: try:
lyrics_stripped = re.sub(r'\[---\]', "\n", re.sub(r'---\[.*?\]---', "\n", re.sub(r'\[--}{--\]', "\n", lyrics_stripped = re.sub(r'\[---\]', "\n", re.sub(r'---\[.*?\]---', "\n", re.sub(r'\[--}{--\]', "\n",
self.verse_text_edit.toPlainText()))) self.verse_text_edit.toPlainText())))
transposed_lyrics = transpose_lyrics(self.verse_text_edit.toPlainText(), 1) chords = re.search(r'\[(.*?)\]', lyrics_stripped)
self.verse_text_edit.setPlainText(transposed_lyrics) if chords and len(chords) > 0 and not chords[1].startswith("="):
if not re.search(r'\[(.*?)\]', lyrics_stripped)[1].startswith("="):
QtWidgets.QMessageBox.warning(self, translate('SongsPlugin.EditVerseForm', 'Song key warning'), QtWidgets.QMessageBox.warning(self, translate('SongsPlugin.EditVerseForm', 'Song key warning'),
translate('SongsPlugin.EditVerseForm', translate('SongsPlugin.EditVerseForm',
'No song key is present or song key is not the first ' 'No song key is present or song key is not the first '
'chord.\nFor optimal chord experience, please, include a ' 'chord.\nFor optimal chord experience, please, include a '
'song key\nbefore any chord. Ex.: [=G]')) 'song key\nbefore any chord. Ex.: [=G]'))
transposed_lyrics = transpose_lyrics(self.verse_text_edit.toPlainText(), 1)
self.verse_text_edit.setPlainText(transposed_lyrics)
except KeyError as ke: except KeyError as ke:
# Transposing failed # Transposing failed
critical_error_message_box(title=translate('SongsPlugin.EditVerseForm', 'Transposing failed'), critical_error_message_box(title=translate('SongsPlugin.EditVerseForm', 'Transposing failed'),
@ -149,14 +150,15 @@ class EditVerseForm(QtWidgets.QDialog, Ui_EditVerseDialog):
try: try:
lyrics_stripped = re.sub(r'\[---\]', "\n", re.sub(r'---\[.*?\]---', "\n", re.sub(r'\[--}{--\]', "\n", lyrics_stripped = re.sub(r'\[---\]', "\n", re.sub(r'---\[.*?\]---', "\n", re.sub(r'\[--}{--\]', "\n",
self.verse_text_edit.toPlainText()))) self.verse_text_edit.toPlainText())))
transposed_lyrics = transpose_lyrics(self.verse_text_edit.toPlainText(), -1) chords = re.search(r'\[(.*?)\]', lyrics_stripped)
self.verse_text_edit.setPlainText(transposed_lyrics) if chords and len(chords) > 0 and not chords[1].startswith("="):
if not re.search(r'\[(.*?)\]', lyrics_stripped)[1].startswith("="):
QtWidgets.QMessageBox.warning(self, translate('SongsPlugin.EditVerseForm', 'Song key warning'), QtWidgets.QMessageBox.warning(self, translate('SongsPlugin.EditVerseForm', 'Song key warning'),
translate('SongsPlugin.EditVerseForm', translate('SongsPlugin.EditVerseForm',
'No song key is present or song key is not the first ' 'No song key is present or song key is not the first '
'chord.\nFor optimal chord experience, please, include a ' 'chord.\nFor optimal chord experience, please, include a '
'song key\nbefore any chord. Ex.: [=G]')) 'song key\nbefore any chord. Ex.: [=G]'))
transposed_lyrics = transpose_lyrics(self.verse_text_edit.toPlainText(), -1)
self.verse_text_edit.setPlainText(transposed_lyrics)
except KeyError as ke: except KeyError as ke:
# Transposing failed # Transposing failed
critical_error_message_box(title=translate('SongsPlugin.EditVerseForm', 'Transposing failed'), critical_error_message_box(title=translate('SongsPlugin.EditVerseForm', 'Transposing failed'),