forked from openlp/openlp
docs, comments, better button handling
This commit is contained in:
parent
37f451473a
commit
9504df4f6f
@ -50,6 +50,14 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
|||||||
self.authorform = AuthorsForm(self)
|
self.authorform = AuthorsForm(self)
|
||||||
self.topicform = TopicsForm(self)
|
self.topicform = TopicsForm(self)
|
||||||
self.bookform = SongBookForm(self)
|
self.bookform = SongBookForm(self)
|
||||||
|
# Disable all edit and delete buttons, as there is no row selected.
|
||||||
|
self.authorsDeleteButton.setEnabled(False)
|
||||||
|
self.authorsEditButton.setEnabled(False)
|
||||||
|
self.topicsDeleteButton.setEnabled(False)
|
||||||
|
self.topicsEditButton.setEnabled(False)
|
||||||
|
self.booksDeleteButton.setEnabled(False)
|
||||||
|
self.booksEditButton.setEnabled(False)
|
||||||
|
# Signals
|
||||||
QtCore.QObject.connect(self.authorsAddButton,
|
QtCore.QObject.connect(self.authorsAddButton,
|
||||||
QtCore.SIGNAL(u'pressed()'), self.onAuthorAddButtonClick)
|
QtCore.SIGNAL(u'pressed()'), self.onAuthorAddButtonClick)
|
||||||
QtCore.QObject.connect(self.topicsAddButton,
|
QtCore.QObject.connect(self.topicsAddButton,
|
||||||
@ -68,6 +76,15 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
|||||||
QtCore.SIGNAL(u'pressed()'), self.onTopicDeleteButtonClick)
|
QtCore.SIGNAL(u'pressed()'), self.onTopicDeleteButtonClick)
|
||||||
QtCore.QObject.connect(self.booksDeleteButton,
|
QtCore.QObject.connect(self.booksDeleteButton,
|
||||||
QtCore.SIGNAL(u'pressed()'), self.onBookDeleteButtonClick)
|
QtCore.SIGNAL(u'pressed()'), self.onBookDeleteButtonClick)
|
||||||
|
QtCore.QObject.connect(self.authorsListWidget,
|
||||||
|
QtCore.SIGNAL(u'currentRowChanged(int)'),
|
||||||
|
self.onAuthorsListRowChanged)
|
||||||
|
QtCore.QObject.connect(self.topicsListWidget,
|
||||||
|
QtCore.SIGNAL(u'currentRowChanged(int)'),
|
||||||
|
self.onTopicsListRowChanged)
|
||||||
|
QtCore.QObject.connect(self.booksListWidget,
|
||||||
|
QtCore.SIGNAL(u'currentRowChanged(int)'),
|
||||||
|
self.onBooksListRowChanged)
|
||||||
|
|
||||||
def exec_(self):
|
def exec_(self):
|
||||||
self.typeListWidget.setCurrentRow(0)
|
self.typeListWidget.setCurrentRow(0)
|
||||||
@ -115,12 +132,6 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
|||||||
u' '.join([author.first_name, author.last_name]))
|
u' '.join([author.first_name, author.last_name]))
|
||||||
author_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(author.id))
|
author_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(author.id))
|
||||||
self.authorsListWidget.addItem(author_name)
|
self.authorsListWidget.addItem(author_name)
|
||||||
if self.authorsListWidget.count() == 0:
|
|
||||||
self.authorsDeleteButton.setEnabled(False)
|
|
||||||
self.authorsEditButton.setEnabled(False)
|
|
||||||
else:
|
|
||||||
self.authorsDeleteButton.setEnabled(True)
|
|
||||||
self.authorsEditButton.setEnabled(True)
|
|
||||||
|
|
||||||
def resetTopics(self):
|
def resetTopics(self):
|
||||||
"""
|
"""
|
||||||
@ -132,12 +143,6 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
|||||||
topic_name = QtGui.QListWidgetItem(topic.name)
|
topic_name = QtGui.QListWidgetItem(topic.name)
|
||||||
topic_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(topic.id))
|
topic_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(topic.id))
|
||||||
self.topicsListWidget.addItem(topic_name)
|
self.topicsListWidget.addItem(topic_name)
|
||||||
if self.topicsListWidget.count() == 0:
|
|
||||||
self.topicsDeleteButton.setEnabled(False)
|
|
||||||
self.topicsEditButton.setEnabled(False)
|
|
||||||
else:
|
|
||||||
self.topicsDeleteButton.setEnabled(True)
|
|
||||||
self.topicsEditButton.setEnabled(True)
|
|
||||||
|
|
||||||
def resetBooks(self):
|
def resetBooks(self):
|
||||||
"""
|
"""
|
||||||
@ -150,26 +155,22 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
|||||||
book.publisher))
|
book.publisher))
|
||||||
book_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(book.id))
|
book_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(book.id))
|
||||||
self.booksListWidget.addItem(book_name)
|
self.booksListWidget.addItem(book_name)
|
||||||
if self.booksListWidget.count() == 0:
|
|
||||||
self.booksDeleteButton.setEnabled(False)
|
|
||||||
self.booksEditButton.setEnabled(False)
|
|
||||||
else:
|
|
||||||
self.booksDeleteButton.setEnabled(True)
|
|
||||||
self.booksEditButton.setEnabled(True)
|
|
||||||
|
|
||||||
def checkAuthor(self, new_author, edit=False):
|
def checkAuthor(self, new_author, edit=False):
|
||||||
"""
|
"""
|
||||||
Returns False if the given Author is already in the list otherwise
|
Returns *False* if the given Author already exists, otherwise *True*.
|
||||||
True.
|
|
||||||
|
``edit``
|
||||||
|
If we edit an item, this should be *True*.
|
||||||
"""
|
"""
|
||||||
authors = self.manager.get_all_objects(Author,
|
authors = self.manager.get_all_objects(Author,
|
||||||
and_(Author.first_name == new_author.first_name,
|
and_(Author.first_name == new_author.first_name,
|
||||||
Author.last_name == new_author.last_name,
|
Author.last_name == new_author.last_name,
|
||||||
Author.display_name == new_author.display_name))
|
Author.display_name == new_author.display_name))
|
||||||
|
# Check if this author already exists.
|
||||||
if len(authors) > 0:
|
if len(authors) > 0:
|
||||||
# If we edit an existing Author, we need to make sure that we do
|
# If we edit an existing Author, we need to make sure that we do
|
||||||
# not return False when nothing has changed (because this would
|
# not return False when nothing has changed.
|
||||||
# cause an error message later on).
|
|
||||||
if edit:
|
if edit:
|
||||||
for author in authors:
|
for author in authors:
|
||||||
if author.id != new_author.id:
|
if author.id != new_author.id:
|
||||||
@ -182,14 +183,16 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
|||||||
|
|
||||||
def checkTopic(self, new_topic, edit=False):
|
def checkTopic(self, new_topic, edit=False):
|
||||||
"""
|
"""
|
||||||
Returns False if the given Topic is already in the list otherwise True.
|
Returns *False* if the given Topic already exists, otherwise *True*.
|
||||||
|
|
||||||
|
``edit``
|
||||||
|
If we edit an item, this should be *True*.
|
||||||
"""
|
"""
|
||||||
topics = self.manager.get_all_objects(Topic,
|
topics = self.manager.get_all_objects(Topic,
|
||||||
Topic.name == new_topic.name)
|
Topic.name == new_topic.name)
|
||||||
if len(topics) > 0:
|
if len(topics) > 0:
|
||||||
# If we edit an existing Topic, we need to make sure that we do
|
# If we edit an existing Topic, we need to make sure that we do
|
||||||
# not return False when nothing has changed (because this would
|
# not return False when nothing has changed.
|
||||||
# cause an error message later on).
|
|
||||||
if edit:
|
if edit:
|
||||||
for topic in topics:
|
for topic in topics:
|
||||||
if topic.id != new_topic.id:
|
if topic.id != new_topic.id:
|
||||||
@ -202,15 +205,17 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
|||||||
|
|
||||||
def checkBook(self, new_book, edit=False):
|
def checkBook(self, new_book, edit=False):
|
||||||
"""
|
"""
|
||||||
Returns False if the given Book is already in the list otherwise True.
|
Returns *False* if the given Topic already exists, otherwise *True*.
|
||||||
|
|
||||||
|
``edit``
|
||||||
|
If we edit an item, this should be *True*.
|
||||||
"""
|
"""
|
||||||
books = self.manager.get_all_objects(Book,
|
books = self.manager.get_all_objects(Book,
|
||||||
and_(Book.name == new_book.name,
|
and_(Book.name == new_book.name,
|
||||||
Book.publisher == new_book.publisher))
|
Book.publisher == new_book.publisher))
|
||||||
if len(books) > 0:
|
if len(books) > 0:
|
||||||
# If we edit an existing Book, we need to make sure that we do
|
# If we edit an existing Book, we need to make sure that we do
|
||||||
# not return False when nothing has changed (because this would
|
# not return False when nothing has changed.
|
||||||
# cause an error message later on).
|
|
||||||
if edit:
|
if edit:
|
||||||
for book in books:
|
for book in books:
|
||||||
if book.id != new_book.id:
|
if book.id != new_book.id:
|
||||||
@ -390,12 +395,14 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
|||||||
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 was edited. It will be deleted.
|
||||||
"""
|
"""
|
||||||
|
# Find the duplicate.
|
||||||
existing_author = self.manager.get_object_filtered(Author,
|
existing_author = self.manager.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,
|
||||||
Author.display_name == old_author.display_name))
|
Author.display_name == old_author.display_name))
|
||||||
|
# Find the songs, which have the old_author as author.
|
||||||
songs = self.manager.get_all_objects(Song,
|
songs = self.manager.get_all_objects(Song,
|
||||||
Song.authors.contains(old_author))
|
Song.authors.contains(old_author))
|
||||||
for song in songs:
|
for song in songs:
|
||||||
@ -412,10 +419,12 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
|||||||
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 was edited. It will be deleted.
|
||||||
"""
|
"""
|
||||||
|
# Find the duplicate.
|
||||||
existing_topic = self.manager.get_object_filtered(Topic,
|
existing_topic = self.manager.get_object_filtered(Topic,
|
||||||
Topic.name == old_topic.name)
|
Topic.name == old_topic.name)
|
||||||
|
# Find the songs, which have the old_topic as topic.
|
||||||
songs = self.manager.get_all_objects(Song,
|
songs = self.manager.get_all_objects(Song,
|
||||||
Song.topics.contains(old_topic))
|
Song.topics.contains(old_topic))
|
||||||
for song in songs:
|
for song in songs:
|
||||||
@ -432,11 +441,13 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
|||||||
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 was edited. It will be deleted.
|
||||||
"""
|
"""
|
||||||
|
# Find the duplicate.
|
||||||
existing_book = self.manager.get_object_filtered(Book,
|
existing_book = self.manager.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))
|
||||||
|
# Find the songs, which have the old_book as book.
|
||||||
songs = self.manager.get_all_objects(Song,
|
songs = self.manager.get_all_objects(Song,
|
||||||
Song.song_book_id == old_book.id)
|
Song.song_book_id == old_book.id)
|
||||||
for song in songs:
|
for song in songs:
|
||||||
@ -482,3 +493,45 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
|
|||||||
'This book cannot be deleted, it is currently '
|
'This book cannot be deleted, it is currently '
|
||||||
'assigned to at least one song.'),
|
'assigned to at least one song.'),
|
||||||
translate('SongsPlugin.SongMaintenanceForm', 'No book selected!'))
|
translate('SongsPlugin.SongMaintenanceForm', 'No book selected!'))
|
||||||
|
|
||||||
|
def onAuthorsListRowChanged(self, row):
|
||||||
|
"""
|
||||||
|
Called when the *authorsListWidget* current's row has changed.
|
||||||
|
|
||||||
|
``row``
|
||||||
|
The current row. If there is no current row, the value is -1
|
||||||
|
"""
|
||||||
|
if row == -1:
|
||||||
|
self.authorsDeleteButton.setEnabled(False)
|
||||||
|
self.authorsEditButton.setEnabled(False)
|
||||||
|
else:
|
||||||
|
self.authorsDeleteButton.setEnabled(True)
|
||||||
|
self.authorsEditButton.setEnabled(True)
|
||||||
|
|
||||||
|
def onTopicsListRowChanged(self, row):
|
||||||
|
"""
|
||||||
|
Called when the *booksListWidget* current's row has changed.
|
||||||
|
|
||||||
|
``row``
|
||||||
|
The current row. If there is no current row, the value is -1.
|
||||||
|
"""
|
||||||
|
if row == -1:
|
||||||
|
self.topicsDeleteButton.setEnabled(False)
|
||||||
|
self.topicsEditButton.setEnabled(False)
|
||||||
|
else:
|
||||||
|
self.topicsDeleteButton.setEnabled(True)
|
||||||
|
self.topicsEditButton.setEnabled(True)
|
||||||
|
|
||||||
|
def onBooksListRowChanged(self, row):
|
||||||
|
"""
|
||||||
|
Called when the *booksListWidget* current's row has changed.
|
||||||
|
|
||||||
|
``row``
|
||||||
|
The current row. If there is no current row, the value is -1.
|
||||||
|
"""
|
||||||
|
if row == -1:
|
||||||
|
self.booksDeleteButton.setEnabled(False)
|
||||||
|
self.booksEditButton.setEnabled(False)
|
||||||
|
else:
|
||||||
|
self.booksDeleteButton.setEnabled(True)
|
||||||
|
self.booksEditButton.setEnabled(True)
|
||||||
|
Loading…
Reference in New Issue
Block a user