From 8e0901ef67f956f854f114e095637c03040aa57b Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 22 Jul 2009 07:14:34 +0100 Subject: [PATCH] Fix bug where empty lists fail to display dialogs --- openlp/plugins/songs/forms/authorsform.py | 37 +++++++++++----------- openlp/plugins/songs/forms/songbookform.py | 23 +++++++------- openlp/plugins/songs/forms/topicsform.py | 21 ++++++------ 3 files changed, 42 insertions(+), 39 deletions(-) diff --git a/openlp/plugins/songs/forms/authorsform.py b/openlp/plugins/songs/forms/authorsform.py index f5191f094..3a8478c93 100644 --- a/openlp/plugins/songs/forms/authorsform.py +++ b/openlp/plugins/songs/forms/authorsform.py @@ -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): diff --git a/openlp/plugins/songs/forms/songbookform.py b/openlp/plugins/songs/forms/songbookform.py index 147c588fb..e4771d4a3 100644 --- a/openlp/plugins/songs/forms/songbookform.py +++ b/openlp/plugins/songs/forms/songbookform.py @@ -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): diff --git a/openlp/plugins/songs/forms/topicsform.py b/openlp/plugins/songs/forms/topicsform.py index 759e72ae3..f3fa87185 100644 --- a/openlp/plugins/songs/forms/topicsform.py +++ b/openlp/plugins/songs/forms/topicsform.py @@ -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):