← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~googol-hush/openlp/songs into lp:openlp

 

Andreas Preikschat has proposed merging lp:~googol-hush/openlp/songs into lp:openlp.

Requested reviews:
  OpenLP Core (openlp-core)

For more details, see:
https://code.launchpad.net/~googol-hush/openlp/songs/+merge/46825

Hello!

- docs/comments
- better button handling (buttons are now disabled if now row is selected)
-- 
https://code.launchpad.net/~googol-hush/openlp/songs/+merge/46825
Your team OpenLP Core is requested to review the proposed merge of lp:~googol-hush/openlp/songs into lp:openlp.
=== modified file 'openlp/plugins/songs/forms/songmaintenanceform.py'
--- openlp/plugins/songs/forms/songmaintenanceform.py	2011-01-19 14:45:03 +0000
+++ openlp/plugins/songs/forms/songmaintenanceform.py	2011-01-19 20:36:08 +0000
@@ -50,6 +50,14 @@
         self.authorform = AuthorsForm(self)
         self.topicform = TopicsForm(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.SIGNAL(u'pressed()'), self.onAuthorAddButtonClick)
         QtCore.QObject.connect(self.topicsAddButton,
@@ -68,6 +76,15 @@
             QtCore.SIGNAL(u'pressed()'), self.onTopicDeleteButtonClick)
         QtCore.QObject.connect(self.booksDeleteButton,
             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):
         self.typeListWidget.setCurrentRow(0)
@@ -115,12 +132,6 @@
                     u' '.join([author.first_name, author.last_name]))
             author_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(author.id))
             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):
         """
@@ -132,12 +143,6 @@
             topic_name = QtGui.QListWidgetItem(topic.name)
             topic_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(topic.id))
             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):
         """
@@ -150,26 +155,22 @@
                 book.publisher))
             book_name.setData(QtCore.Qt.UserRole, QtCore.QVariant(book.id))
             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):
         """
-        Returns False if the given Author is already in the list otherwise
-        True.
+        Returns *False* if the given Author already exists, otherwise *True*.
+
+        ``edit``
+            If we edit an item, this should be *True*.
         """
         authors = self.manager.get_all_objects(Author,
             and_(Author.first_name == new_author.first_name,
                 Author.last_name == new_author.last_name,
                 Author.display_name == new_author.display_name))
+        # Check if this author already exists.
         if len(authors) > 0:
             # If we edit an existing Author, we need to make sure that we do
-            # not return False when nothing has changed (because this would
-            # cause an error message later on).
+            # not return False when nothing has changed.
             if edit:
                 for author in authors:
                     if author.id != new_author.id:
@@ -182,14 +183,16 @@
 
     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,
             Topic.name == new_topic.name)
         if len(topics) > 0:
             # If we edit an existing Topic, we need to make sure that we do
-            # not return False when nothing has changed (because this would
-            # cause an error message later on).
+            # not return False when nothing has changed.
             if edit:
                 for topic in topics:
                     if topic.id != new_topic.id:
@@ -202,15 +205,17 @@
 
     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,
             and_(Book.name == new_book.name,
                 Book.publisher == new_book.publisher))
         if len(books) > 0:
             # If we edit an existing Book, we need to make sure that we do
-            # not return False when nothing has changed (because this would
-            # cause an error message later on).
+            # not return False when nothing has changed.
             if edit:
                 for book in books:
                     if book.id != new_book.id:
@@ -390,12 +395,14 @@
         Merges two authors into one 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,
             and_(Author.first_name == old_author.first_name,
                 Author.last_name == old_author.last_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,
             Song.authors.contains(old_author))
         for song in songs:
@@ -412,10 +419,12 @@
         Merges two topics into one 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,
             Topic.name == old_topic.name)
+        # Find the songs, which have the old_topic as topic.
         songs = self.manager.get_all_objects(Song,
             Song.topics.contains(old_topic))
         for song in songs:
@@ -432,11 +441,13 @@
         Merges two books into one 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,
             and_(Book.name == old_book.name,
                 Book.publisher == old_book.publisher))
+        # Find the songs, which have the old_book as book.
         songs = self.manager.get_all_objects(Song,
             Song.song_book_id == old_book.id)
         for song in songs:
@@ -482,3 +493,46 @@
                 'This book cannot be deleted, it is currently '
                 'assigned to at least one song.'),
             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)
+


Follow ups