This commit is contained in:
Samuel Mehrbrodt 2014-04-08 16:08:07 +02:00
parent ac05205a1e
commit 1759c72f36
2 changed files with 33 additions and 1 deletions

View File

@ -173,7 +173,7 @@ def create_button(parent, name, **kwargs):
kwargs.setdefault('tooltip', translate('OpenLP.Ui', 'Move selection down one position.'))
else:
log.warn('The role "%s" is not defined in create_push_button().', role)
if kwargs.pop('class', '') == 'toolbutton':
if kwargs.pop('btn_class', '') == 'toolbutton':
button = QtGui.QToolButton(parent)
else:
button = QtGui.QPushButton(parent)

View File

@ -81,3 +81,35 @@ class TestUi(TestCase):
self.assertIsInstance(btnbox, QtGui.QDialogButtonBox)
self.assertEqual(1, len(btnbox.buttons()))
self.assertEqual(QtGui.QDialogButtonBox.HelpRole, btnbox.buttonRole(btnbox.buttons()[0]))
def test_create_button(self):
"""
Test creating a button
"""
# GIVEN: A dialog
dialog = QtGui.QDialog()
# WHEN: We create the button
btn = create_button(dialog, 'my_btn')
# THEN: We should get a button with a name
self.assertIsInstance(btn, QtGui.QPushButton)
self.assertEqual('my_btn', btn.objectName())
self.assertTrue(btn.isEnabled())
# WHEN: We create a button with some attributes
btn = create_button(dialog, 'my_btn', text='Hello', tooltip='How are you?', enabled=False)
# THEN: We should get a button with those attributes
self.assertIsInstance(btn, QtGui.QPushButton)
self.assertEqual('Hello', btn.text())
self.assertEqual('How are you?', btn.toolTip())
self.assertFalse(btn.isEnabled())
# WHEN: We create a toolbutton
btn = create_button(dialog, 'my_btn', btn_class='toolbutton')
# THEN: We should get a toolbutton
self.assertIsInstance(btn, QtGui.QToolButton)
self.assertEqual('my_btn', btn.objectName())
self.assertTrue(btn.isEnabled())