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) self.CopyrightEditItem.setCursorPosition(pos + 1)
def onMaintenanceButtonClicked(self): def onMaintenanceButtonClicked(self):
self.parent.song_maintenance_form.songFormLaunch = True
self.parent.song_maintenance_form.exec_() self.parent.song_maintenance_form.exec_()
self.loadAuthors() self.loadAuthors()
self.loadBooks() self.loadBooks()

View File

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

View File

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

View File

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