From c80d8fbcfbca61a4623a124faf3d3f11cf5f1dee Mon Sep 17 00:00:00 2001 From: STEPHANVS Date: Mon, 14 Feb 2022 14:44:08 +0100 Subject: [PATCH] Consolidate song key check/warning message --- openlp/plugins/songs/forms/editsongform.py | 11 +++++++++++ openlp/plugins/songs/forms/editverseform.py | 10 ---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 5b5bc3425..3331cbe3f 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -245,14 +245,25 @@ class EditSongForm(QtWidgets.QDialog, Ui_EditSongDialog, RegistryProperties): # Validate tags (lp#1199639) misplaced_tags = [] verse_tags = [] + chords = [] for i in range(self.verse_list_widget.rowCount()): item = self.verse_list_widget.item(i, 0) tags = self.find_tags.findall(item.text()) + stripped_text = re.sub(r'\[---\]', "\n", re.sub(r'\[--}{--\]', "\n", item.text())) + r = re.compile('\[(.*?)\]') + for match in r.finditer(stripped_text): + chords += match[1] field = item.data(QtCore.Qt.UserRole) verse_tags.append(field) if not self._validate_tags(tags): misplaced_tags.append('{field1} {field2}'.format(field1=VerseType.translated_name(field[0]), field2=field[1:])) + if Registry().get('settings').value('songs/enable chords') and not chords[0].startswith("="): + QtWidgets.QMessageBox.warning(self, translate('SongsPlugin.EditVerseForm', 'Song key warning'), + translate('SongsPlugin.EditVerseForm', + 'No song key is present or song key is not the first ' + 'chord.\nFor optimal chord experience, please, include a ' + 'song key before any chord. Ex.: [=G]')) if misplaced_tags: critical_error_message_box( message=translate('SongsPlugin.EditSongForm', diff --git a/openlp/plugins/songs/forms/editverseform.py b/openlp/plugins/songs/forms/editverseform.py index 0a5be7a59..c5498d1f8 100644 --- a/openlp/plugins/songs/forms/editverseform.py +++ b/openlp/plugins/songs/forms/editverseform.py @@ -250,16 +250,6 @@ class EditVerseForm(QtWidgets.QDialog, Ui_EditVerseDialog): """ if Registry().get('settings').value('songs/enable chords'): try: - lyrics_stripped = re.sub(r'\[---\]', "\n", - re.sub(r'---\[.*?\]---', "\n", - re.sub(r'\[--}{--\]', "\n", - self.verse_text_edit.toPlainText()))) - if not re.search(r'\[(.*?)\]', lyrics_stripped)[1].startswith("="): - QtWidgets.QMessageBox.warning(self, translate('SongsPlugin.EditVerseForm', 'Song key warning'), - translate('SongsPlugin.EditVerseForm', - 'No song key is present or song key is not the first ' - 'chord.\nFor optimal chord experience, please, include a ' - 'song key before any chord. Ex.: [=G]')) transpose_lyrics(self.verse_text_edit.toPlainText(), 0) super(EditVerseForm, self).accept() except KeyError as ke: