Fix song maintenance as subform (Bug #612282)

This commit is contained in:
Jon Tibble 2010-08-27 23:49:27 +01:00
parent 3645c9400e
commit bb31492609
4 changed files with 115 additions and 111 deletions

View File

@ -600,6 +600,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self.CopyrightEditItem.setCursorPosition(pos + 1)
def onMaintenanceButtonClicked(self):
self.parent.song_maintenance_form.songFormLaunch = True
self.parent.song_maintenance_form.exec_()
self.loadAuthors()
self.loadBooks()

View File

@ -30,77 +30,78 @@ from openlp.core.lib import build_icon, translate
from openlp.plugins.songs.lib import VerseType
class Ui_EditVerseDialog(object):
def setupUi(self, EditVerseDialog):
EditVerseDialog.setObjectName(u'EditVerseDialog')
EditVerseDialog.resize(474, 442)
EditVerseDialog.setModal(True)
self.EditVerseLayout = QtGui.QVBoxLayout(EditVerseDialog)
self.EditVerseLayout.setSpacing(8)
self.EditVerseLayout.setMargin(8)
self.EditVerseLayout.setObjectName(u'EditVerseLayout')
self.VerseTextEdit = QtGui.QPlainTextEdit(EditVerseDialog)
self.VerseTextEdit.setObjectName(u'VerseTextEdit')
self.EditVerseLayout.addWidget(self.VerseTextEdit)
self.VerseTypeLayout = QtGui.QHBoxLayout()
self.VerseTypeLayout.setSpacing(8)
self.VerseTypeLayout.setObjectName(u'VerseTypeLayout')
self.VerseTypeLabel = QtGui.QLabel(EditVerseDialog)
self.VerseTypeLabel.setObjectName(u'VerseTypeLabel')
self.VerseTypeLayout.addWidget(self.VerseTypeLabel)
self.VerseTypeComboBox = QtGui.QComboBox(EditVerseDialog)
self.VerseTypeComboBox.setObjectName(u'VerseTypeComboBox')
self.VerseTypeComboBox.addItem(u'')
self.VerseTypeComboBox.addItem(u'')
self.VerseTypeComboBox.addItem(u'')
self.VerseTypeComboBox.addItem(u'')
self.VerseTypeComboBox.addItem(u'')
self.VerseTypeComboBox.addItem(u'')
self.VerseTypeComboBox.addItem(u'')
self.VerseTypeLayout.addWidget(self.VerseTypeComboBox)
self.VerseNumberBox = QtGui.QSpinBox(EditVerseDialog)
self.VerseNumberBox.setMinimum(1)
self.VerseNumberBox.setObjectName(u'VerseNumberBox')
self.VerseTypeLayout.addWidget(self.VerseNumberBox)
self.InsertButton = QtGui.QPushButton(EditVerseDialog)
self.InsertButton.setIcon(build_icon(u':/general/general_add.png'))
self.InsertButton.setObjectName(u'InsertButton')
self.VerseTypeLayout.addWidget(self.InsertButton)
self.VerseTypeSpacer = QtGui.QSpacerItem(40, 20,
def setupUi(self, editVerseDialog):
editVerseDialog.setObjectName(u'editVerseDialog')
editVerseDialog.resize(474, 442)
editVerseDialog.setModal(True)
self.editVerseLayout = QtGui.QVBoxLayout(editVerseDialog)
self.editVerseLayout.setSpacing(8)
self.editVerseLayout.setMargin(8)
self.editVerseLayout.setObjectName(u'editVerseLayout')
self.verseTextEdit = QtGui.QPlainTextEdit(editVerseDialog)
self.verseTextEdit.setObjectName(u'verseTextEdit')
self.editVerseLayout.addWidget(self.verseTextEdit)
self.verseTypeLayout = QtGui.QHBoxLayout()
self.verseTypeLayout.setSpacing(8)
self.verseTypeLayout.setObjectName(u'verseTypeLayout')
self.verseTypeLabel = QtGui.QLabel(editVerseDialog)
self.verseTypeLabel.setObjectName(u'verseTypeLabel')
self.verseTypeLayout.addWidget(self.verseTypeLabel)
self.verseTypeComboBox = QtGui.QComboBox(editVerseDialog)
self.verseTypeComboBox.setObjectName(u'verseTypeComboBox')
self.verseTypeLabel.setBuddy(self.verseTypeComboBox)
self.verseTypeComboBox.addItem(u'')
self.verseTypeComboBox.addItem(u'')
self.verseTypeComboBox.addItem(u'')
self.verseTypeComboBox.addItem(u'')
self.verseTypeComboBox.addItem(u'')
self.verseTypeComboBox.addItem(u'')
self.verseTypeComboBox.addItem(u'')
self.verseTypeLayout.addWidget(self.verseTypeComboBox)
self.verseNumberBox = QtGui.QSpinBox(editVerseDialog)
self.verseNumberBox.setMinimum(1)
self.verseNumberBox.setObjectName(u'verseNumberBox')
self.verseTypeLayout.addWidget(self.verseNumberBox)
self.insertButton = QtGui.QPushButton(editVerseDialog)
self.insertButton.setIcon(build_icon(u':/general/general_add.png'))
self.insertButton.setObjectName(u'insertButton')
self.verseTypeLayout.addWidget(self.insertButton)
self.verseTypeSpacer = QtGui.QSpacerItem(40, 20,
QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
self.VerseTypeLayout.addItem(self.VerseTypeSpacer)
self.EditVerseLayout.addLayout(self.VerseTypeLayout)
self.EditButtonBox = QtGui.QDialogButtonBox(EditVerseDialog)
self.EditButtonBox.setOrientation(QtCore.Qt.Horizontal)
self.EditButtonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel |
self.verseTypeLayout.addItem(self.verseTypeSpacer)
self.editVerseLayout.addLayout(self.verseTypeLayout)
self.editButtonBox = QtGui.QDialogButtonBox(editVerseDialog)
self.editButtonBox.setOrientation(QtCore.Qt.Horizontal)
self.editButtonBox.setStandardButtons(QtGui.QDialogButtonBox.Cancel |
QtGui.QDialogButtonBox.Save)
self.EditButtonBox.setObjectName(u'EditButtonBox')
self.EditVerseLayout.addWidget(self.EditButtonBox)
self.editButtonBox.setObjectName(u'editButtonBox')
self.editVerseLayout.addWidget(self.editButtonBox)
self.retranslateUi(EditVerseDialog)
QtCore.QObject.connect(self.EditButtonBox, QtCore.SIGNAL(u'accepted()'),
EditVerseDialog.accept)
QtCore.QObject.connect(self.EditButtonBox, QtCore.SIGNAL(u'rejected()'),
EditVerseDialog.reject)
QtCore.QMetaObject.connectSlotsByName(EditVerseDialog)
self.retranslateUi(editVerseDialog)
QtCore.QObject.connect(self.editButtonBox, QtCore.SIGNAL(u'accepted()'),
editVerseDialog.accept)
QtCore.QObject.connect(self.editButtonBox, QtCore.SIGNAL(u'rejected()'),
editVerseDialog.reject)
QtCore.QMetaObject.connectSlotsByName(editVerseDialog)
def retranslateUi(self, EditVerseDialog):
EditVerseDialog.setWindowTitle(
def retranslateUi(self, editVerseDialog):
editVerseDialog.setWindowTitle(
translate('SongsPlugin.EditVerseForm', 'Edit Verse'))
self.VerseTypeLabel.setText(
self.verseTypeLabel.setText(
translate('SongsPlugin.EditVerseForm', '&Verse type:'))
self.VerseTypeComboBox.setItemText(0,
self.verseTypeComboBox.setItemText(0,
VerseType.to_string(VerseType.Verse))
self.VerseTypeComboBox.setItemText(1,
self.verseTypeComboBox.setItemText(1,
VerseType.to_string(VerseType.Chorus))
self.VerseTypeComboBox.setItemText(2,
self.verseTypeComboBox.setItemText(2,
VerseType.to_string(VerseType.Bridge))
self.VerseTypeComboBox.setItemText(3,
self.verseTypeComboBox.setItemText(3,
VerseType.to_string(VerseType.PreChorus))
self.VerseTypeComboBox.setItemText(4,
self.verseTypeComboBox.setItemText(4,
VerseType.to_string(VerseType.Intro))
self.VerseTypeComboBox.setItemText(5,
self.verseTypeComboBox.setItemText(5,
VerseType.to_string(VerseType.Ending))
self.VerseTypeComboBox.setItemText(6,
self.verseTypeComboBox.setItemText(6,
VerseType.to_string(VerseType.Other))
self.InsertButton.setText(
self.insertButton.setText(
translate('SongsPlugin.EditVerseForm', '&Insert'))

View File

@ -45,34 +45,29 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog):
"""
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
QtCore.QObject.connect(
self.InsertButton,
QtCore.SIGNAL(u'clicked()'),
self.onInsertButtonClicked
)
QtCore.QObject.connect(
self.VerseTextEdit,
QtCore.QObject.connect(self.insertButton, QtCore.SIGNAL(u'clicked()'),
self.onInsertButtonClicked)
QtCore.QObject.connect(self.verseTextEdit,
QtCore.SIGNAL(u'cursorPositionChanged()'),
self.onCursorPositionChanged
)
self.onCursorPositionChanged)
self.verse_regex = re.compile(r'---\[([-\w]+):([\d]+)\]---')
def insertVerse(self, title, num=1):
if self.VerseTextEdit.textCursor().columnNumber() != 0:
self.VerseTextEdit.insertPlainText(u'\n')
self.VerseTextEdit.insertPlainText(u'---[%s:%s]---\n' % (title, num))
self.VerseTextEdit.setFocus()
if self.verseTextEdit.textCursor().columnNumber() != 0:
self.verseTextEdit.insertPlainText(u'\n')
self.verseTextEdit.insertPlainText(u'---[%s:%s]---\n' % (title, num))
self.verseTextEdit.setFocus()
def onInsertButtonClicked(self):
if self.VerseTextEdit.textCursor().columnNumber() != 0:
self.VerseTextEdit.insertPlainText(u'\n')
verse_type = self.VerseTypeComboBox.currentIndex()
if self.verseTextEdit.textCursor().columnNumber() != 0:
self.verseTextEdit.insertPlainText(u'\n')
verse_type = self.verseTypeComboBox.currentIndex()
if verse_type == VerseType.Verse:
self.insertVerse(VerseType.to_string(VerseType.Verse),
self.VerseNumberBox.value())
self.verseNumberBox.value())
elif verse_type == VerseType.Chorus:
self.insertVerse(VerseType.to_string(VerseType.Chorus),
self.VerseNumberBox.value())
self.verseNumberBox.value())
elif verse_type == VerseType.Bridge:
self.insertVerse(VerseType.to_string(VerseType.Bridge))
elif verse_type == VerseType.PreChorus:
@ -85,8 +80,8 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog):
self.insertVerse(VerseType.to_string(VerseType.Other))
def onCursorPositionChanged(self):
position = self.VerseTextEdit.textCursor().position()
text = unicode(self.VerseTextEdit.toPlainText())
position = self.verseTextEdit.textCursor().position()
text = unicode(self.verseTextEdit.toPlainText())
if not text:
return
if text.rfind(u'[', 0, position) > text.rfind(u']', 0, position) and \
@ -106,8 +101,8 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog):
verse_number = int(match.group(2))
verse_type_index = VerseType.from_string(verse_type)
if verse_type_index is not None:
self.VerseTypeComboBox.setCurrentIndex(verse_type_index)
self.VerseNumberBox.setValue(verse_number)
self.verseTypeComboBox.setCurrentIndex(verse_type_index)
self.verseNumberBox.setValue(verse_number)
def setVerse(self, text, single=False,
tag=u'%s:1' % VerseType.to_string(VerseType.Verse)):
@ -115,26 +110,26 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog):
verse_type, verse_number = tag.split(u':')
verse_type_index = VerseType.from_string(verse_type)
if verse_type_index is not None:
self.VerseTypeComboBox.setCurrentIndex(verse_type_index)
self.VerseNumberBox.setValue(int(verse_number))
self.InsertButton.setVisible(False)
self.verseTypeComboBox.setCurrentIndex(verse_type_index)
self.verseNumberBox.setValue(int(verse_number))
self.insertButton.setVisible(False)
else:
if not text:
text = u'---[%s:1]---\n' % VerseType.to_string(VerseType.Verse)
self.VerseTypeComboBox.setCurrentIndex(0)
self.VerseNumberBox.setValue(1)
self.InsertButton.setVisible(True)
self.VerseTextEdit.setPlainText(text)
self.VerseTextEdit.setFocus(QtCore.Qt.OtherFocusReason)
self.VerseTextEdit.moveCursor(QtGui.QTextCursor.End)
self.verseTypeComboBox.setCurrentIndex(0)
self.verseNumberBox.setValue(1)
self.insertButton.setVisible(True)
self.verseTextEdit.setPlainText(text)
self.verseTextEdit.setFocus(QtCore.Qt.OtherFocusReason)
self.verseTextEdit.moveCursor(QtGui.QTextCursor.End)
def getVerse(self):
return self.VerseTextEdit.toPlainText(), \
VerseType.to_string(self.VerseTypeComboBox.currentIndex()), \
unicode(self.VerseNumberBox.value())
return self.verseTextEdit.toPlainText(), \
VerseType.to_string(self.verseTypeComboBox.currentIndex()), \
unicode(self.verseNumberBox.value())
def getVerseAll(self):
text = self.VerseTextEdit.toPlainText()
text = self.verseTextEdit.toPlainText()
if not text.startsWith(u'---['):
text = u'---[%s:1]---\n%s' % (VerseType.to_string(VerseType.Verse),
text)

View File

@ -42,6 +42,8 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
"""
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
self.songFormLaunch = False
self.commitOnSave = True
self.songmanager = songmanager
self.authorform = AuthorsForm(self)
self.topicform = TopicsForm(self)
@ -70,6 +72,11 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
self.resetAuthors()
self.resetTopics()
self.resetBooks()
if self.songFormLaunch:
self.commitOnSave = False
self.songFormLaunch = False
else:
self.commitOnSave = True
self.TypeListWidget.setFocus()
return QtGui.QDialog.exec_(self)
@ -227,7 +234,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
last_name=unicode(self.authorform.LastNameEdit.text()),
display_name=unicode(self.authorform.DisplayEdit.text()))
if self.checkAuthor(author):
if self.songmanager.save_object(author):
if self.songmanager.save_object(author, self.commitOnSave):
self.resetAuthors()
else:
QtGui.QMessageBox.critical(self,
@ -244,7 +251,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
if self.topicform.exec_():
topic = Topic.populate(name=unicode(self.topicform.NameEdit.text()))
if self.checkTopic(topic):
if self.songmanager.save_object(topic):
if self.songmanager.save_object(topic, self.commitOnSave):
self.resetTopics()
else:
QtGui.QMessageBox.critical(self,
@ -262,7 +269,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
book = Book.populate(name=unicode(self.bookform.NameEdit.text()),
publisher=unicode(self.bookform.PublisherEdit.text()))
if self.checkBook(book):
if self.songmanager.save_object(book):
if self.songmanager.save_object(book, self.commitOnSave):
self.resetBooks()
else:
QtGui.QMessageBox.critical(self,
@ -295,7 +302,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
author.display_name = unicode(
self.authorform.DisplayEdit.text())
if self.checkAuthor(author, True):
if self.songmanager.save_object(author):
if self.songmanager.save_object(author, self.commitOnSave):
self.resetAuthors()
Receiver.send_message(u'songs_load_list')
else:
@ -337,7 +344,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
if self.topicform.exec_(False):
topic.name = unicode(self.topicform.NameEdit.text())
if self.checkTopic(topic, True):
if self.songmanager.save_object(topic):
if self.songmanager.save_object(topic, self.commitOnSave):
self.resetTopics()
else:
QtGui.QMessageBox.critical(self,
@ -380,7 +387,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
book.name = unicode(self.bookform.NameEdit.text())
book.publisher = unicode(self.bookform.PublisherEdit.text())
if self.checkBook(book, True):
if self.songmanager.save_object(book):
if self.songmanager.save_object(book, self.commitOnSave):
self.resetBooks()
else:
QtGui.QMessageBox.critical(self,
@ -404,12 +411,12 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
book.publisher = temp_publisher
def mergeAuthors(self, old_author):
'''
"""
Merges two authors into one author.
``old_author``
The author which will be deleted afterwards.
'''
"""
existing_author = self.songmanager.get_object_filtered(Author,
and_(Author.first_name == old_author.first_name,
Author.last_name == old_author.last_name,
@ -422,16 +429,16 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
if existing_author not in song.authors:
song.authors.append(existing_author)
song.authors.remove(old_author)
self.songmanager.save_object(song)
self.songmanager.save_object(song, self.commitOnSave)
self.songmanager.delete_object(Author, old_author.id)
def mergeTopics(self, old_topic):
'''
"""
Merges two topics into one topic.
``old_topic``
The topic which will be deleted afterwards.
'''
"""
existing_topic = self.songmanager.get_object_filtered(Topic,
Topic.name == old_topic.name)
songs = self.songmanager.get_all_objects(Song,
@ -442,16 +449,16 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
if existing_topic not in song.topics:
song.topics.append(existing_topic)
song.topics.remove(old_topic)
self.songmanager.save_object(song)
self.songmanager.save_object(song, self.commitOnSave)
self.songmanager.delete_object(Topic, old_topic.id)
def mergeBooks(self, old_book):
'''
"""
Merges two books into one book.
``old_book``
The book which will be deleted afterwards.
'''
"""
existing_book = self.songmanager.get_object_filtered(Book,
and_(Book.name == old_book.name,
Book.publisher == old_book.publisher))
@ -459,7 +466,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
Song.song_book_id == old_book.id)
for song in songs:
song.song_book_id = existing_book.id
self.songmanager.save_object(song)
self.songmanager.save_object(song, self.commitOnSave)
self.songmanager.delete_object(Book, old_book.id)
def onAuthorDeleteButtonClick(self):