More code cleanups.

- Corrected more naming conventions
- Changed old-style signal-slot connections
- Added properties to the author form
This commit is contained in:
Raoul Snyman 2013-02-10 22:04:47 +02:00
parent 0f7f17f79c
commit 761bb6339d
7 changed files with 178 additions and 17 deletions

View File

@ -73,9 +73,9 @@ class Ui_CustomEditDialog(object):
self.buttonLayout.addWidget(self.deleteButton)
self.buttonLayout.addStretch()
self.upButton = create_button(customEditDialog, u'up_button', role=u'up', enabled=False,
click=customEditDialog.on_up_button_clicked)
click=customEditDialog.onUpButtonClicked)
self.downButton = create_button(customEditDialog, u'down_button', role=u'down', enabled=False,
click=customEditDialog.on_down_button_clicked)
click=customEditDialog.onDownButtonClicked)
self.buttonLayout.addWidget(self.upButton)
self.buttonLayout.addWidget(self.downButton)
self.centralLayout.addLayout(self.buttonLayout)

View File

@ -120,3 +120,39 @@ class AuthorsForm(QtGui.QDialog, Ui_AuthorsDialog):
return False
else:
return QtGui.QDialog.accept(self)
def _get_first_name(self):
"""
Get the value of the first name from the UI widget.
"""
return self.first_name_edit.text()
def _set_first_name(self, value):
"""
Set the value of the first name in the UI widget.
"""
self.first_name_edit.setText(value)
first_name = property(_get_first_name, _set_first_name)
def _get_last_name(self):
"""
Get the value of the last name from the UI widget.
"""
return self.last_name_edit.text()
def _set_last_name(self, value):
"""
Set the value of the last name in the UI widget.
"""
self.last_name_edit.setText(value)
last_name = property(_get_last_name, _set_last_name)
def _get_display_name(self):
return self.display_edit.text()
def _set_display_name(self, value):
self.display_edit.setText(value)
display_name = property(_get_display_name, _set_display_name)

View File

@ -70,16 +70,13 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog):
self.setupUi(self)
# Connecting signals and slots
self.author_add_button.clicked.connect(self.on_author_add_button_clicked)
QtCore.QObject.connect(self.author_remove_button, QtCore.SIGNAL(u'clicked()'), self.onAuthorRemoveButtonClicked)
QtCore.QObject.connect(self.authors_list_view, QtCore.SIGNAL(u'itemClicked(QListWidgetItem*)'),
self.onAuthorsListViewClicked)
QtCore.QObject.connect(self.topic_add_button, QtCore.SIGNAL(u'clicked()'), self.onTopicAddButtonClicked)
QtCore.QObject.connect(self.topic_remove_button, QtCore.SIGNAL(u'clicked()'), self.onTopicRemoveButtonClicked)
QtCore.QObject.connect(self.topics_list_view, QtCore.SIGNAL(u'itemClicked(QListWidgetItem*)'),
self.onTopicListViewClicked)
QtCore.QObject.connect(self.copyright_insert_button, QtCore.SIGNAL(u'clicked()'),
self.onCopyrightInsertButtonTriggered)
QtCore.QObject.connect(self.verse_add_button, QtCore.SIGNAL(u'clicked()'), self.onVerseAddButtonClicked)
self.author_remove_button.clicked.connect(self.onAuthorRemoveButtonClicked)
self.authors_list_view.itemClicked.connect(self.onAuthorsListViewClicked)
self.topic_add_button.clicked.connect(self.onTopicAddButtonClicked)
self.topic_remove_button.clicked.connect(self.onTopicRemoveButtonClicked)
self.topics_list_view.itemClicked.connect(self.onTopicListViewClicked)
self.copyright_insert_button.clicked.connect(self.onCopyrightInsertButtonTriggered)
self.verse_add_button.clicked.connect(self.onVerseAddButtonClicked)
QtCore.QObject.connect(self.verse_list_widget, QtCore.SIGNAL(u'doubleClicked(QModelIndex)'),
self.onVerseEditButtonClicked)
QtCore.QObject.connect(self.verse_edit_button, QtCore.SIGNAL(u'clicked()'), self.onVerseEditButtonClicked)

View File

@ -212,9 +212,10 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
self.authorform.auto_display_name = True
if self.authorform.exec_():
author = Author.populate(
first_name=self.authorform.first_name_edit.text(),
last_name=self.authorform.last_name_edit.text(),
display_name=self.authorform.display_edit.text())
first_name=self.authorform.first_name,
last_name=self.authorform.last_name,
display_name=self.authorform.display_name
)
if self.checkAuthor(author):
if self.manager.save_object(author):
self.resetAuthors()

View File

@ -1,5 +1,5 @@
"""
Package to test the openlp.core.ui package.
Package to test the openlp.core.ui package.
"""
from unittest import TestCase
@ -91,4 +91,4 @@ class TestStartTimeDialog(TestCase):
self.assertEqual(self.form.hourSpinBox.value(), 0)
self.assertEqual(self.form.minuteSpinBox.value(), 2)
self.assertEqual(self.form.secondSpinBox.value(), 3)
self.assertEqual(self.form.item[u'service_item'].start_time, 123, u'The start time should have changed')
self.assertEqual(self.form.item[u'service_item'].start_time, 123, u'The start time should have changed')

View File

@ -0,0 +1 @@
__author__ = 'raoul'

View File

@ -0,0 +1,126 @@
"""
Package to test the openlp.core.ui package.
"""
import sip
sip.setapi(u'QDate', 2)
sip.setapi(u'QDateTime', 2)
sip.setapi(u'QString', 2)
sip.setapi(u'QTextStream', 2)
sip.setapi(u'QTime', 2)
sip.setapi(u'QUrl', 2)
sip.setapi(u'QVariant', 2)
from unittest import TestCase
from PyQt4 import QtGui
from openlp.plugins.songs.forms.authorsform import AuthorsForm
from openlp.core.lib import Registry
class TestAuthorsForm(TestCase):
def setUp(self):
"""
Create the UI
"""
Registry.create()
self.app = QtGui.QApplication([])
self.main_window = QtGui.QMainWindow()
Registry().register(u'main_window', self.main_window)
self.form = AuthorsForm()
def tearDown(self):
"""
Delete all the C++ objects at the end so that we don't have a segfault
"""
del self.form
del self.main_window
del self.app
def ui_defaults_test(self):
"""
Test the AuthorForm defaults are correct
"""
self.assertEqual(self.form.first_name_edit.text(), u'', u'The first name edit should be empty')
self.assertEqual(self.form.last_name_edit.text(), u'', u'The last name edit should be empty')
self.assertEqual(self.form.display_edit.text(), u'', u'The display name edit should be empty')
def get_first_name_property_test(self):
"""
Test that getting the first name property on the AuthorForm works correctly.
"""
# GIVEN: A first name to set
first_name = u'John'
# WHEN: The first_name_edit's text is set
self.form.first_name_edit.setText(first_name)
# THEN: The first_name property should have the correct value
self.assertEqual(self.form.first_name, first_name, u'The first name property should be correct')
def set_first_name_property_test(self):
"""
Test that setting the first name property on the AuthorForm works correctly.
"""
# GIVEN: A first name to set
first_name = u'James'
# WHEN: The first_name property is set
self.form.first_name = first_name
# THEN: The first_name_edit should have the correct value
self.assertEqual(self.form.first_name_edit.text(), first_name, u'The first name should be set correctly')
def get_last_name_property_test(self):
"""
Test that getting the last name property on the AuthorForm works correctly.
"""
# GIVEN: A last name to set
last_name = u'Smith'
# WHEN: The last_name_edit's text is set
self.form.last_name_edit.setText(last_name)
# THEN: The last_name property should have the correct value
self.assertEqual(self.form.last_name, last_name, u'The last name property should be correct')
def set_last_name_property_test(self):
"""
Test that setting the last name property on the AuthorForm works correctly.
"""
# GIVEN: A last name to set
last_name = u'Potter'
# WHEN: The last_name property is set
self.form.last_name = last_name
# THEN: The last_name_edit should have the correct value
self.assertEqual(self.form.last_name_edit.text(), last_name, u'The last name should be set correctly')
def get_display_name_property_test(self):
"""
Test that getting the display name property on the AuthorForm works correctly.
"""
# GIVEN: A display name to set
display_name = u'John'
# WHEN: The display_name_edit's text is set
self.form.display_name_edit.setText(display_name)
# THEN: The display_name property should have the correct value
self.assertEqual(self.form.display_name, display_name, u'The display name property should be correct')
def set_display_name_property_test(self):
"""
Test that setting the display name property on the AuthorForm works correctly.
"""
# GIVEN: A display name to set
display_name = u'John'
# WHEN: The display_name property is set
self.form.display_name = display_name
# THEN: The display_name_edit should have the correct value
self.assertEqual(self.form.display_name_edit.text(), display_name, u'The display name should be set correctly')