diff --git a/openlp/plugins/songs/forms/authorsform.py b/openlp/plugins/songs/forms/authorsform.py index da549cd2d..0cd97e9e4 100644 --- a/openlp/plugins/songs/forms/authorsform.py +++ b/openlp/plugins/songs/forms/authorsform.py @@ -65,6 +65,7 @@ class AuthorsForm(QDialog, Ui_AuthorsDialog): if self.currentrow > c: # incase we have delete the last row of the table self.currentrow = c self.AuthorListView.selectRow(self.currentrow) # set selected row to previous selected row + self._validate_form() @pyqtSignature("") def on_DeleteButton_clicked(self): @@ -73,8 +74,12 @@ class AuthorsForm(QDialog, Ui_AuthorsDialog): """ self.songmanager.delete_author(self.author.id) self.on_ClearButton_clicked() - self.load_form() - + self.load_form() + + @pyqtSignature("") + def on_DisplayEdit_lostFocus(self): + self._validate_form() + @pyqtSignature("") def on_AddUpdateButton_clicked(self): """ @@ -88,6 +93,7 @@ class AuthorsForm(QDialog, Ui_AuthorsDialog): self.songmanager.save_author(self.author) self.on_ClearButton_clicked() self.load_form() + self._validate_form() @pyqtSignature("") @@ -99,8 +105,9 @@ class AuthorsForm(QDialog, Ui_AuthorsDialog): self.FirstNameEdit.setText("") self.LastNameEdit.setText("") self.MessageLabel.setText("") - self.DeleteButton.setEnabled(True) + self.DeleteButton.setEnabled(False) self.author = None + self._validate_form() @pyqtSignature("QTableWidgetItem*") def on_AuthorListView_itemClicked(self, item): @@ -122,3 +129,10 @@ class AuthorsForm(QDialog, Ui_AuthorsDialog): else: self.MessageLabel.setText("Author is not used") self.DeleteButton.setEnabled(True) + self._validate_form() + + def _validate_form(self): + if len(self.DisplayEdit.displayText()) == 0: # We need at lease a display name + self.AddUpdateButton.setEnabled(False) + else: + self.AddUpdateButton.setEnabled(True) diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 4dbdcc2ce..6e605f28a 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA """ -from PyQt4 import QtCore, QtGui +from PyQt4 import Qt, QtCore, QtGui from PyQt4.QtGui import QWidget from PyQt4.QtCore import pyqtSignature @@ -51,6 +51,7 @@ class EditSongForm(QWidget, Ui_EditSongDialog): self.AuthorsListView.setShowGrid(False) self.AuthorsListView.setSortingEnabled(False) self.AuthorsListView.setAlternatingRowColors(True) + self.savebutton = self.ButtonBox.button(QtGui.QDialogButtonBox.Save) def initialise(self): @@ -60,18 +61,20 @@ class EditSongForm(QWidget, Ui_EditSongDialog): self.AuthorsSelectionComboItem.addItem( i.display_name) def load_song(self, songid): - self.songid = songid - song = self.songmanager.get_song(songid) - self.TitleEditItem.setText(song.title) - self.LyricsTextEdit.setText(song.lyrics) - self.CopyrightEditItem.setText(song.copyright) + if songid == None: # We have a new Song + self.song = Song() + else: + self.songid = songid + self.song = self.songmanager.get_song(songid) + self.TitleEditItem.setText(self.song.title) + self.LyricsTextEdit.setText(self.song.lyrics) + self.CopyrightEditItem.setText(self.song.copyright) self.AuthorsListView.clear() # clear the results self.AuthorsListView.setHorizontalHeaderLabels(QtCore.QStringList(["","Author"])) self.AuthorsListView.setVerticalHeaderLabels(QtCore.QStringList([""])) self.AuthorsListView.setRowCount(0) - - for author in song.authors: + for author in self.song.authors: c = self.AuthorsListView.rowCount() self.AuthorsListView.setRowCount(c+1) twi = QtGui.QTableWidgetItem(str(author.id)) @@ -79,7 +82,7 @@ class EditSongForm(QWidget, Ui_EditSongDialog): twi = QtGui.QTableWidgetItem(str(author.display_name)) self.AuthorsListView.setItem(c , 1, twi) self.AuthorsListView.setRowHeight(c, 20) - + self._validate_song() @pyqtSignature("") def on_AddAuthorsButton_clicked(self): @@ -103,4 +106,39 @@ class EditSongForm(QWidget, Ui_EditSongDialog): Slot documentation goes here. """ self.song_book_form.load_form() - self.song_book_form.show() + self.song_book_form.show() + + def _validate_song(self): + """ + Check the validity of the form. Only display the 'save' if the data can be saved. + """ + valid = True # Lets be nice and assume the data is correct. + if len(self.TitleEditItem.displayText()) == 0: #Song title missing + valid = False + self._color_widget(self.TitleEditItem, True) + else: + self._color_widget(self.TitleEditItem, False) + if len(self.CopyrightEditItem.displayText()) == 0: #Song title missing + valid = False + self._color_widget(self.CopyrightEditItem, True) + else: + self._color_widget(self.CopyrightEditItem, False) + + if valid: + self.ButtonBox.addButton(self.savebutton, QtGui.QDialogButtonBox.AcceptRole) # hide the save button tile screen is valid + else: + self.ButtonBox.removeButton(self.savebutton) # hide the save button tile screen is valid + + def _color_widget(self, slot, invalid): + r = Qt.QPalette(slot.palette()) + if invalid == True: + r.setColor(Qt.QPalette.Base, Qt.QColor('darkRed')) + else: + r.setColor(Qt.QPalette.Base, Qt.QColor('white')) + slot.setPalette(r) + slot.setAutoFillBackground(True) + + def on_TitleEditItem_lostFocus(self): + self._validate_song() + def on_CopyrightEditItem_lostFocus(self): + self._validate_song()