Fix bug where empty lists fail to display dialogs

This commit is contained in:
Tim Bentley 2009-07-22 07:14:34 +01:00
parent e788db767a
commit 8e0901ef67
3 changed files with 42 additions and 39 deletions

View File

@ -108,24 +108,25 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog):
"""
self.currentRow = self.AuthorListWidget.currentRow()
item = self.AuthorListWidget.currentItem()
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
self.author = self.songmanager.get_author(item_id)
self.DisplayEdit.setText(self.author.display_name)
if self.author.first_name is None:
self.FirstNameEdit.setText(u'')
else:
self.FirstNameEdit.setText(self.author.first_name)
if self.author.last_name is None:
self.LastNameEdit.setText(u'')
else:
self.LastNameEdit.setText(self.author.last_name)
if len(self.author.songs) > 0:
self.MessageLabel.setText(translate(u'AuthorForm', u'Author in use "Delete" is disabled'))
self.DeleteButton.setEnabled(False)
else:
self.MessageLabel.setText(translate(u'AuthorForm', u'Author in not used'))
self.DeleteButton.setEnabled(True)
self._validate_form()
if item is not None:
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
self.author = self.songmanager.get_author(item_id)
self.DisplayEdit.setText(self.author.display_name)
if self.author.first_name is None:
self.FirstNameEdit.setText(u'')
else:
self.FirstNameEdit.setText(self.author.first_name)
if self.author.last_name is None:
self.LastNameEdit.setText(u'')
else:
self.LastNameEdit.setText(self.author.last_name)
if len(self.author.songs) > 0:
self.MessageLabel.setText(translate(u'AuthorForm', u'Author in use "Delete" is disabled'))
self.DeleteButton.setEnabled(False)
else:
self.MessageLabel.setText(translate(u'AuthorForm', u'Author in not used'))
self.DeleteButton.setEnabled(True)
self._validate_form()
self.DisplayEdit.setFocus()
def _validate_form(self):

View File

@ -106,17 +106,18 @@ class SongBookForm(QtGui.QDialog, Ui_SongBookDialog):
"""
self.currentRow = self.BookSongListWidget.currentRow()
item = self.BookSongListWidget.currentItem()
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
self.Book = self.songmanager.get_book(item_id)
self.NameEdit.setText(self.Book.name)
self.PublisherEdit.setText(self.Book.publisher)
if len(self.Book.songs) > 0:
self.MessageLabel.setText(translate(u'BookForm', u'Book in use "Delete" is disabled'))
self.DeleteButton.setEnabled(False)
else:
self.MessageLabel.setText(translate(u'BookForm', u'Book in not used'))
self.DeleteButton.setEnabled(True)
self._validate_form()
if item is not None:
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
self.Book = self.songmanager.get_book(item_id)
self.NameEdit.setText(self.Book.name)
self.PublisherEdit.setText(self.Book.publisher)
if len(self.Book.songs) > 0:
self.MessageLabel.setText(translate(u'BookForm', u'Book in use "Delete" is disabled'))
self.DeleteButton.setEnabled(False)
else:
self.MessageLabel.setText(translate(u'BookForm', u'Book in not used'))
self.DeleteButton.setEnabled(True)
self._validate_form()
self.NameEdit.setFocus()
def _validate_form(self):

View File

@ -105,16 +105,17 @@ class TopicsForm(QtGui.QDialog, Ui_TopicsDialog):
"""
self.currentRow = self.TopicsListWidget.currentRow()
item = self.TopicsListWidget.currentItem()
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
self.topic = self.songmanager.get_topic(item_id)
self.TopicNameEdit.setText(self.topic.name)
if len(self.topic.songs) > 0:
self.MessageLabel.setText(translate(u'TopicForm', u'Topic in use "Delete" is disabled'))
self.DeleteButton.setEnabled(False)
else:
self.MessageLabel.setText(translate(u'TopicForm', u'Topic in not used'))
self.DeleteButton.setEnabled(True)
self._validate_form()
if item is not None:
item_id = (item.data(QtCore.Qt.UserRole)).toInt()[0]
self.topic = self.songmanager.get_topic(item_id)
self.TopicNameEdit.setText(self.topic.name)
if len(self.topic.songs) > 0:
self.MessageLabel.setText(translate(u'TopicForm', u'Topic in use "Delete" is disabled'))
self.DeleteButton.setEnabled(False)
else:
self.MessageLabel.setText(translate(u'TopicForm', u'Topic in not used'))
self.DeleteButton.setEnabled(True)
self._validate_form()
self.TopicNameEdit.setFocus()
def _validate_form(self):