Custom editing fix part 1

This commit is contained in:
Tim Bentley 2009-09-09 18:30:33 +01:00
parent 05761ef442
commit cb1d5c2abb
1 changed files with 25 additions and 26 deletions

View File

@ -20,7 +20,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
from PyQt4 import Qt, QtCore, QtGui
from editcustomdialog import Ui_customEditDialog
from openlp.core.lib import SongXMLBuilder, SongXMLParser, Receiver
from openlp.core.lib import SongXMLBuilder, SongXMLParser, Receiver, translate
from openlp.plugins.custom.lib.models import CustomSlide
class EditCustomForm(QtGui.QDialog, Ui_customEditDialog):
@ -44,7 +44,6 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog):
QtCore.QObject.connect(self.ClearButton, QtCore.SIGNAL(u'pressed()'), self.onClearButtonPressed)
QtCore.QObject.connect(self.UpButton, QtCore.SIGNAL(u'pressed()'), self.onUpButtonPressed)
QtCore.QObject.connect(self.DownButton, QtCore.SIGNAL(u'pressed()'), self.onDownButtonPressed)
QtCore.QObject.connect(self.TitleEdit, QtCore.SIGNAL(u'lostFocus()'), self.validate)
QtCore.QObject.connect(self.VerseListView,
QtCore.SIGNAL(u'itemDoubleClicked(QListWidgetItem*)'), self.onVerseListViewSelected)
@ -92,12 +91,16 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog):
if id == -1:
id = 0 # Not Found
self.ThemecomboBox.setCurrentIndex(id)
self.validate()
else:
self.ThemecomboBox.setCurrentIndex(0)
def accept(self):
if self.validate():
valid , message = self._validate()
if not valid:
QtGui.QMessageBox.critical(self,
translate(u'customEditDialog', u'Error'), message,
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
return
sxml=SongXMLBuilder()
sxml.new_document()
sxml.add_lyrics_to_song()
@ -147,7 +150,6 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog):
self.VerseListView.addItem(self.VerseTextEdit.toPlainText())
self.DeleteButton.setEnabled(False)
self.VerseTextEdit.clear()
self.validate()
def onEditButtonPressed(self):
self.VerseTextEdit.setPlainText(self.VerseListView.currentItem().text())
@ -164,17 +166,14 @@ class EditCustomForm(QtGui.QDialog, Ui_customEditDialog):
self.VerseListView.takeItem(self.VerseListView.currentRow())
self.EditButton.setEnabled(False)
def validate(self):
def _validate(self):
valid = True
message = u''
if len(self.TitleEdit.displayText()) == 0:
valid = False
self.TitleEdit.setStyleSheet(u'background-color: red; color: white')
else:
self.TitleEdit.setStyleSheet(u'')
message = translate(u'customEditDialog', u'You need to enter a title \n')
# must have 1 slide
if self.VerseListView.count() == 0:
valid = False
self.VerseListView.setStyleSheet(u'background-color: red; color: white')
else:
self.VerseListView.setStyleSheet(u'')
return valid
message += translate(u'customEditDialog', u'You need to enter a slide \n')
return valid, message