forked from openlp/openlp
Added warning message about missing song key
This commit is contained in:
parent
29f5e1db56
commit
fb1e1e1f06
@ -69,7 +69,8 @@ class Ui_EditVerseDialog(object):
|
||||
self.verse_type_layout.addStretch()
|
||||
self.dialog_layout.addLayout(self.verse_type_layout)
|
||||
if Registry().get('settings').value('songs/enable chords'):
|
||||
self.transpose_layout = QtWidgets.QHBoxLayout()
|
||||
self.transpose_widget = QtWidgets.QWidget()
|
||||
self.transpose_layout = QtWidgets.QHBoxLayout(self.transpose_widget)
|
||||
self.transpose_layout.setObjectName('transpose_layout')
|
||||
self.transpose_label = QtWidgets.QLabel(edit_verse_dialog)
|
||||
self.transpose_label.setObjectName('transpose_label')
|
||||
@ -82,7 +83,8 @@ class Ui_EditVerseDialog(object):
|
||||
self.transpose_down_button.setIcon(UiIcons().arrow_down)
|
||||
self.transpose_down_button.setObjectName('transpose_down')
|
||||
self.transpose_layout.addWidget(self.transpose_down_button)
|
||||
self.dialog_layout.addLayout(self.transpose_layout)
|
||||
#self.dialog_layout.addLayout(self.transpose_layout)
|
||||
self.dialog_layout.addWidget(self.transpose_widget)
|
||||
self.button_box = create_button_box(edit_verse_dialog, 'button_box', ['cancel', 'ok'])
|
||||
self.dialog_layout.addWidget(self.button_box)
|
||||
self.retranslate_ui(edit_verse_dialog)
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
import logging
|
||||
import re
|
||||
from warnings import WarningMessage
|
||||
|
||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||
|
||||
@ -122,8 +123,16 @@ class EditVerseForm(QtWidgets.QDialog, Ui_EditVerseDialog):
|
||||
The transpose up button clicked
|
||||
"""
|
||||
try:
|
||||
lyrics_stripped = re.sub(r'\[---\]',"\n", re.sub(r'---\[.*?\]---', "\n", re.sub(r'\[--}{--\]', "\n",
|
||||
self.verse_text_edit.toPlainText())))
|
||||
transposed_lyrics = transpose_lyrics(self.verse_text_edit.toPlainText(), 1)
|
||||
self.verse_text_edit.setPlainText(transposed_lyrics)
|
||||
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]'))
|
||||
except KeyError as ke:
|
||||
# Transposing failed
|
||||
critical_error_message_box(title=translate('SongsPlugin.EditVerseForm', 'Transposing failed'),
|
||||
@ -131,16 +140,26 @@ class EditVerseForm(QtWidgets.QDialog, Ui_EditVerseDialog):
|
||||
'Transposing failed because of invalid chord:\n{err_msg}'
|
||||
.format(err_msg=ke)))
|
||||
return
|
||||
self.verse_text_edit.setPlainText(transposed_lyrics)
|
||||
self.verse_text_edit.setFocus()
|
||||
self.verse_text_edit.moveCursor(QtGui.QTextCursor.End)
|
||||
|
||||
|
||||
def on_transpose_down_button_clicked(self):
|
||||
"""
|
||||
The transpose down button clicked
|
||||
"""
|
||||
try:
|
||||
lyrics_stripped = re.sub(r'\[---\]',"\n", re.sub(r'---\[.*?\]---', "\n", re.sub(r'\[--}{--\]', "\n",
|
||||
self.verse_text_edit.toPlainText())))
|
||||
transposed_lyrics = transpose_lyrics(self.verse_text_edit.toPlainText(), -1)
|
||||
self.verse_text_edit.setPlainText(transposed_lyrics)
|
||||
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]'))
|
||||
except KeyError as ke:
|
||||
# Transposing failed
|
||||
critical_error_message_box(title=translate('SongsPlugin.EditVerseForm', 'Transposing failed'),
|
||||
@ -197,12 +216,14 @@ class EditVerseForm(QtWidgets.QDialog, Ui_EditVerseDialog):
|
||||
self.verse_type_combo_box.setCurrentIndex(verse_type_index)
|
||||
self.verse_number_box.setValue(int(verse_number))
|
||||
self.insert_button.setVisible(False)
|
||||
self.transpose_widget.setVisible(False)
|
||||
else:
|
||||
if not text:
|
||||
text = '---[{tag}:1]---\n'.format(tag=VerseType.translated_names[VerseType.Verse])
|
||||
self.verse_type_combo_box.setCurrentIndex(0)
|
||||
self.verse_number_box.setValue(1)
|
||||
self.insert_button.setVisible(True)
|
||||
self.transpose_widget.setVisible(True)
|
||||
self.verse_text_edit.setPlainText(text)
|
||||
self.verse_text_edit.setFocus()
|
||||
self.verse_text_edit.moveCursor(QtGui.QTextCursor.End)
|
||||
@ -233,6 +254,14 @@ 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:
|
||||
|
Loading…
Reference in New Issue
Block a user