forked from openlp/openlp
Add form validation - start of
bzr-revno: 283
This commit is contained in:
parent
cc0ca326c3
commit
7022a05316
@ -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):
|
||||
@ -75,6 +76,10 @@ class AuthorsForm(QDialog, Ui_AuthorsDialog):
|
||||
self.on_ClearButton_clicked()
|
||||
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)
|
||||
|
@ -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):
|
||||
if songid == None: # We have a new Song
|
||||
self.song = Song()
|
||||
else:
|
||||
self.songid = songid
|
||||
song = self.songmanager.get_song(songid)
|
||||
self.TitleEditItem.setText(song.title)
|
||||
self.LyricsTextEdit.setText(song.lyrics)
|
||||
self.CopyrightEditItem.setText(song.copyright)
|
||||
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):
|
||||
@ -104,3 +107,38 @@ class EditSongForm(QWidget, Ui_EditSongDialog):
|
||||
"""
|
||||
self.song_book_form.load_form()
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user