From 837118bf07949b0901dfd76d6ca1d46bad7a555e Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 11 Mar 2013 10:07:17 +0200 Subject: [PATCH 1/9] Cleanup EditVerseForm and friends, and expand the test. --- openlp/plugins/songs/forms/editsongform.py | 14 +-- openlp/plugins/songs/forms/editversedialog.py | 103 +++++++++--------- openlp/plugins/songs/forms/editverseform.py | 100 +++++++++-------- .../test_editverseform.py | 19 +++- 4 files changed, 125 insertions(+), 111 deletions(-) diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 80c3c45b8..a75a0916c 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -578,9 +578,9 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.verse_delete_button.setEnabled(True) def on_verse_add_button_clicked(self): - self.verse_form.setVerse(u'', True) + self.verse_form.set_verse(u'', True) if self.verse_form.exec_(): - after_text, verse_tag, verse_num = self.verse_form.getVerse() + after_text, verse_tag, verse_num = self.verse_form.get_verse() verse_def = u'%s%s' % (verse_tag, verse_num) item = QtGui.QTableWidgetItem(after_text) item.setData(QtCore.Qt.UserRole, verse_def) @@ -596,9 +596,9 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): if item: temp_text = item.text() verse_id = item.data(QtCore.Qt.UserRole) - self.verse_form.setVerse(temp_text, True, verse_id) + self.verse_form.set_verse(temp_text, True, verse_id) if self.verse_form.exec_(): - after_text, verse_tag, verse_num = self.verse_form.getVerse() + after_text, verse_tag, verse_num = self.verse_form.get_verse() verse_def = u'%s%s' % (verse_tag, verse_num) item.setData(QtCore.Qt.UserRole, verse_def) item.setText(after_text) @@ -630,12 +630,12 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): verse_list += u'---[%s:%s]---\n' % (verse_tag, verse_num) verse_list += item.text() verse_list += u'\n' - self.verse_form.setVerse(verse_list) + self.verse_form.set_verse(verse_list) else: - self.verse_form.setVerse(u'') + self.verse_form.set_verse(u'') if not self.verse_form.exec_(): return - verse_list = self.verse_form.getVerseAll() + verse_list = self.verse_form.get_all_verses() verse_list = unicode(verse_list.replace(u'\r\n', u'\n')) self.verse_list_widget.clear() self.verse_list_widget.setRowCount(0) diff --git a/openlp/plugins/songs/forms/editversedialog.py b/openlp/plugins/songs/forms/editversedialog.py index b694d046c..b7b8f2df2 100644 --- a/openlp/plugins/songs/forms/editversedialog.py +++ b/openlp/plugins/songs/forms/editversedialog.py @@ -33,56 +33,57 @@ from openlp.core.lib import SpellTextEdit, build_icon, translate from openlp.core.lib.ui import UiStrings, create_button_box from openlp.plugins.songs.lib import VerseType -class Ui_EditVerseDialog(object): - def setupUi(self, editVerseDialog): - editVerseDialog.setObjectName(u'editVerseDialog') - editVerseDialog.resize(400, 400) - editVerseDialog.setModal(True) - self.dialogLayout = QtGui.QVBoxLayout(editVerseDialog) - self.dialogLayout.setObjectName(u'dialog_layout') - self.verseTextEdit = SpellTextEdit(editVerseDialog) - self.verseTextEdit.setObjectName(u'verseTextEdit') - self.dialogLayout.addWidget(self.verseTextEdit) - self.verseTypeLayout = QtGui.QHBoxLayout() - self.verseTypeLayout.setObjectName(u'verseTypeLayout') - self.splitButton = QtGui.QPushButton(editVerseDialog) - self.splitButton.setIcon(build_icon(u':/general/general_add.png')) - self.splitButton.setObjectName(u'splitButton') - self.verseTypeLayout.addWidget(self.splitButton) - self.verseTypeLabel = QtGui.QLabel(editVerseDialog) - self.verseTypeLabel.setObjectName(u'verseTypeLabel') - self.verseTypeLayout.addWidget(self.verseTypeLabel) - self.verseTypeComboBox = QtGui.QComboBox(editVerseDialog) - self.verseTypeComboBox.addItems([u'', u'', u'', u'', u'', u'', u'']) - self.verseTypeComboBox.setObjectName(u'verseTypeComboBox') - self.verseTypeLabel.setBuddy(self.verseTypeComboBox) - self.verseTypeLayout.addWidget(self.verseTypeComboBox) - self.verseNumberBox = QtGui.QSpinBox(editVerseDialog) - self.verseNumberBox.setMinimum(1) - self.verseNumberBox.setObjectName(u'verseNumberBox') - self.verseTypeLayout.addWidget(self.verseNumberBox) - self.insertButton = QtGui.QPushButton(editVerseDialog) - self.insertButton.setIcon(build_icon(u':/general/general_add.png')) - self.insertButton.setObjectName(u'insertButton') - self.verseTypeLayout.addWidget(self.insertButton) - self.verseTypeLayout.addStretch() - self.dialogLayout.addLayout(self.verseTypeLayout) - self.button_box = create_button_box(editVerseDialog, u'button_box', [u'cancel', u'ok']) - self.dialogLayout.addWidget(self.button_box) - self.retranslateUi(editVerseDialog) - def retranslateUi(self, editVerseDialog): - editVerseDialog.setWindowTitle(translate('SongsPlugin.EditVerseForm', 'Edit Verse')) - self.verseTypeLabel.setText(translate('SongsPlugin.EditVerseForm', '&Verse type:')) - self.verseTypeComboBox.setItemText(VerseType.Verse, VerseType.translated_names[VerseType.Verse]) - self.verseTypeComboBox.setItemText(VerseType.Chorus, VerseType.translated_names[VerseType.Chorus]) - self.verseTypeComboBox.setItemText(VerseType.Bridge, VerseType.translated_names[VerseType.Bridge]) - self.verseTypeComboBox.setItemText(VerseType.PreChorus, VerseType.translated_names[VerseType.PreChorus]) - self.verseTypeComboBox.setItemText(VerseType.Intro, VerseType.translated_names[VerseType.Intro]) - self.verseTypeComboBox.setItemText(VerseType.Ending, VerseType.translated_names[VerseType.Ending]) - self.verseTypeComboBox.setItemText(VerseType.Other, VerseType.translated_names[VerseType.Other]) - self.splitButton.setText(UiStrings().Split) - self.splitButton.setToolTip(UiStrings().SplitToolTip) - self.insertButton.setText(translate('SongsPlugin.EditVerseForm', '&Insert')) - self.insertButton.setToolTip(translate('SongsPlugin.EditVerseForm', +class Ui_EditVerseDialog(object): + def setupUi(self, edit_verse_dialog): + edit_verse_dialog.setObjectName(u'editVerseDialog') + edit_verse_dialog.resize(400, 400) + edit_verse_dialog.setModal(True) + self.dialog_layout = QtGui.QVBoxLayout(edit_verse_dialog) + self.dialog_layout.setObjectName(u'dialog_layout') + self.verse_text_edit = SpellTextEdit(edit_verse_dialog) + self.verse_text_edit.setObjectName(u'verseTextEdit') + self.dialog_layout.addWidget(self.verse_text_edit) + self.verse_type_layout = QtGui.QHBoxLayout() + self.verse_type_layout.setObjectName(u'verseTypeLayout') + self.split_button = QtGui.QPushButton(edit_verse_dialog) + self.split_button.setIcon(build_icon(u':/general/general_add.png')) + self.split_button.setObjectName(u'splitButton') + self.verse_type_layout.addWidget(self.split_button) + self.verse_type_label = QtGui.QLabel(edit_verse_dialog) + self.verse_type_label.setObjectName(u'verseTypeLabel') + self.verse_type_layout.addWidget(self.verse_type_label) + self.verse_type_combo_box = QtGui.QComboBox(edit_verse_dialog) + self.verse_type_combo_box.addItems([u'', u'', u'', u'', u'', u'', u'']) + self.verse_type_combo_box.setObjectName(u'verseTypeComboBox') + self.verse_type_label.setBuddy(self.verse_type_combo_box) + self.verse_type_layout.addWidget(self.verse_type_combo_box) + self.verse_number_box = QtGui.QSpinBox(edit_verse_dialog) + self.verse_number_box.setMinimum(1) + self.verse_number_box.setObjectName(u'verseNumberBox') + self.verse_type_layout.addWidget(self.verse_number_box) + self.insert_button = QtGui.QPushButton(edit_verse_dialog) + self.insert_button.setIcon(build_icon(u':/general/general_add.png')) + self.insert_button.setObjectName(u'insertButton') + self.verse_type_layout.addWidget(self.insert_button) + self.verse_type_layout.addStretch() + self.dialog_layout.addLayout(self.verse_type_layout) + self.button_box = create_button_box(edit_verse_dialog, u'button_box', [u'cancel', u'ok']) + self.dialog_layout.addWidget(self.button_box) + self.retranslateUi(edit_verse_dialog) + + def retranslateUi(self, edit_verse_dialog): + edit_verse_dialog.setWindowTitle(translate('SongsPlugin.EditVerseForm', 'Edit Verse')) + self.verse_type_label.setText(translate('SongsPlugin.EditVerseForm', '&Verse type:')) + self.verse_type_combo_box.setItemText(VerseType.Verse, VerseType.translated_names[VerseType.Verse]) + self.verse_type_combo_box.setItemText(VerseType.Chorus, VerseType.translated_names[VerseType.Chorus]) + self.verse_type_combo_box.setItemText(VerseType.Bridge, VerseType.translated_names[VerseType.Bridge]) + self.verse_type_combo_box.setItemText(VerseType.PreChorus, VerseType.translated_names[VerseType.PreChorus]) + self.verse_type_combo_box.setItemText(VerseType.Intro, VerseType.translated_names[VerseType.Intro]) + self.verse_type_combo_box.setItemText(VerseType.Ending, VerseType.translated_names[VerseType.Ending]) + self.verse_type_combo_box.setItemText(VerseType.Other, VerseType.translated_names[VerseType.Other]) + self.split_button.setText(UiStrings().Split) + self.split_button.setToolTip(UiStrings().SplitToolTip) + self.insert_button.setText(translate('SongsPlugin.EditVerseForm', '&Insert')) + self.insert_button.setToolTip(translate('SongsPlugin.EditVerseForm', 'Split a slide into two by inserting a verse splitter.')) diff --git a/openlp/plugins/songs/forms/editverseform.py b/openlp/plugins/songs/forms/editverseform.py index b145c0e6a..80bf719b7 100644 --- a/openlp/plugins/songs/forms/editverseform.py +++ b/openlp/plugins/songs/forms/editverseform.py @@ -50,59 +50,56 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog): """ QtGui.QDialog.__init__(self, parent) self.setupUi(self) - QtCore.QObject.connect(self.verseTextEdit, QtCore.SIGNAL('customContextMenuRequested(QPoint)'), - self.contextMenu) - QtCore.QObject.connect(self.insertButton, QtCore.SIGNAL(u'clicked()'), self.onInsertButtonClicked) - QtCore.QObject.connect(self.splitButton, QtCore.SIGNAL(u'clicked()'), self.onSplitButtonClicked) - QtCore.QObject.connect(self.verseTextEdit, QtCore.SIGNAL(u'cursorPositionChanged()'), - self.onCursorPositionChanged) - QtCore.QObject.connect(self.verseTypeComboBox, QtCore.SIGNAL(u'currentIndexChanged(int)'), - self.onVerseTypeComboBoxChanged) + self.verse_text_edit.customContextMenuRequested.connect(self.context_menu) + self.insert_button.clicked.connect(self.on_insert_button_clicked) + self.split_button.clicked.connect(self.on_split_button_clicked) + self.verse_text_edit.cursorPositionChanged.connect(self.on_cursor_position_changed) + self.verse_type_combo_box.currentIndexChanged.connect(self.on_verse_type_combo_box_changed) - def contextMenu(self, point): + def context_menu(self, point): item = self.serviceManagerList.itemAt(point) - def insertVerse(self, verse_tag, verse_num=1): - if self.verseTextEdit.textCursor().columnNumber() != 0: - self.verseTextEdit.insertPlainText(u'\n') + def insert_verse(self, verse_tag, verse_num=1): + if self.verse_text_edit.textCursor().columnNumber() != 0: + self.verse_text_edit.insertPlainText(u'\n') verse_tag = VerseType.translated_name(verse_tag) - self.verseTextEdit.insertPlainText(u'---[%s:%s]---\n' % (verse_tag, verse_num)) - self.verseTextEdit.setFocus() + self.verse_text_edit.insertPlainText(u'---[%s:%s]---\n' % (verse_tag, verse_num)) + self.verse_text_edit.setFocus() - def onSplitButtonClicked(self): - text = self.verseTextEdit.toPlainText() - position = self.verseTextEdit.textCursor().position() + def on_split_button_clicked(self): + text = self.verse_text_edit.toPlainText() + position = self.verse_text_edit.textCursor().position() insert_string = u'[---]' if position and text[position-1] != u'\n': - insert_string = u'\n' + insert_string + insert_string = u'\n' + insert_string if position == len(text) or text[position] != u'\n': - insert_string += u'\n' - self.verseTextEdit.insertPlainText(insert_string) - self.verseTextEdit.setFocus() + insert_string += u'\n' + self.verse_text_edit.insertPlainText(insert_string) + self.verse_text_edit.setFocus() - def onInsertButtonClicked(self): - verse_type_index = self.verseTypeComboBox.currentIndex() - self.insertVerse(VerseType.tags[verse_type_index], self.verseNumberBox.value()) + def on_insert_button_clicked(self): + verse_type_index = self.verse_type_combo_box.currentIndex() + self.insert_verse(VerseType.tags[verse_type_index], self.verse_number_box.value()) - def onVerseTypeComboBoxChanged(self): - self.updateSuggestedVerseNumber() + def on_verse_type_combo_box_changed(self): + self.update_suggested_verse_number() - def onCursorPositionChanged(self): - self.updateSuggestedVerseNumber() + def on_cursor_position_changed(self): + self.update_suggested_verse_number() - def updateSuggestedVerseNumber(self): + def update_suggested_verse_number(self): """ Adjusts the verse number SpinBox in regard to the selected verse type and the cursor's position. """ - position = self.verseTextEdit.textCursor().position() - text = self.verseTextEdit.toPlainText() + position = self.verse_text_edit.textCursor().position() + text = self.verse_text_edit.toPlainText() verse_name = VerseType.translated_names[ - self.verseTypeComboBox.currentIndex()] + self.verse_type_combo_box.currentIndex()] if not text: return position = text.rfind(u'---[%s' % verse_name, 0, position) if position == -1: - self.verseNumberBox.setValue(1) + self.verse_number_box.setValue(1) return text = text[position:] position = text.find(u']---') @@ -111,38 +108,39 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog): text = text[:position + 4] match = VERSE_REGEX.match(text) if match: - verse_tag = match.group(1) + # TODO: Not used, remove? + # verse_tag = match.group(1) try: verse_num = int(match.group(2)) + 1 except ValueError: verse_num = 1 - self.verseNumberBox.setValue(verse_num) + self.verse_number_box.setValue(verse_num) - def setVerse(self, text, single=False, tag=u'%s1' % VerseType.tags[VerseType.Verse]): - self.hasSingleVerse = single + def set_verse(self, text, single=False, tag=u'%s1' % VerseType.tags[VerseType.Verse]): + self.has_single_verse = single if single: verse_type_index = VerseType.from_tag(tag[0], None) verse_number = tag[1:] if verse_type_index is not None: - self.verseTypeComboBox.setCurrentIndex(verse_type_index) - self.verseNumberBox.setValue(int(verse_number)) - self.insertButton.setVisible(False) + self.verse_type_combo_box.setCurrentIndex(verse_type_index) + self.verse_number_box.setValue(int(verse_number)) + self.insert_button.setVisible(False) else: if not text: text = u'---[%s:1]---\n' % VerseType.translated_names[VerseType.Verse] - self.verseTypeComboBox.setCurrentIndex(0) - self.verseNumberBox.setValue(1) - self.insertButton.setVisible(True) - self.verseTextEdit.setPlainText(text) - self.verseTextEdit.setFocus() - self.verseTextEdit.moveCursor(QtGui.QTextCursor.End) + self.verse_type_combo_box.setCurrentIndex(0) + self.verse_number_box.setValue(1) + self.insert_button.setVisible(True) + self.verse_text_edit.setPlainText(text) + self.verse_text_edit.setFocus() + self.verse_text_edit.moveCursor(QtGui.QTextCursor.End) - def getVerse(self): - return self.verseTextEdit.toPlainText(), VerseType.tags[self.verseTypeComboBox.currentIndex()], \ - unicode(self.verseNumberBox.value()) + def get_verse(self): + return self.verse_text_edit.toPlainText(), VerseType.tags[self.verse_type_combo_box.currentIndex()], \ + unicode(self.verse_number_box.value()) - def getVerseAll(self): - text = self.verseTextEdit.toPlainText() + def get_all_verses(self): + text = self.verse_text_edit.toPlainText() if not text.startswith(u'---['): text = u'---[%s:1]---\n%s' % (VerseType.translated_names[VerseType.Verse], text) return text diff --git a/tests/interfaces/openlp_plugins_songs_forms/test_editverseform.py b/tests/interfaces/openlp_plugins_songs_forms/test_editverseform.py index cfd5ed0ef..5dbfb2a16 100644 --- a/tests/interfaces/openlp_plugins_songs_forms/test_editverseform.py +++ b/tests/interfaces/openlp_plugins_songs_forms/test_editverseform.py @@ -3,7 +3,7 @@ Package to test the openlp.plugins.songs.forms.editverseform package. """ from unittest import TestCase -from PyQt4 import QtGui +from PyQt4 import QtCore, QtGui, QtTest from openlp.core.lib import Registry from openlp.plugins.songs.forms.editverseform import EditVerseForm @@ -32,4 +32,19 @@ class TestEditVerseForm(TestCase): """ Test the EditVerseForm defaults are correct """ - self.assertEqual(self.form.verseTextEdit.toPlainText(), u'', u'The verse edit box is empty.') + # GIVEN: An EditVerseForm instance + # WHEN: The form is shown + # THEN: The default value is correct + self.assertEqual(self.form.verse_text_edit.toPlainText(), u'', u'The verse edit box is empty.') + + def insert_verse_test(self): + """ + Test that inserting a verse works as it should. + """ + # GIVEN: An instance of the EditVerseForm + # WHEN: The Insert button is clicked + QtTest.QTest.mouseClick(self.form.insert_button, QtCore.Qt.LeftButton) + + # THEN: The verse text edit should have a Verse:1 in it + self.assertIn(u'---[Verse:1]---', self.form.verse_text_edit.toPlainText(), + u'The verse text edit should have a verse identifier') \ No newline at end of file From cdbd34460a3e632f8d64cd2c9bd91be89514be4f Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 11 Mar 2013 23:10:29 +0200 Subject: [PATCH 2/9] Fix an import issue after the last cleanup. - Fix an issue with an import that changed in the last cleanup effort (as a side note, the plugins manager test is a good one to use to check for import regressions). - Clean up some test comments. --- openlp/plugins/songs/lib/__init__.py | 2 ++ .../interfaces/openlp_core_lib/test_pluginmanager.py | 2 +- .../openlp_plugins_songs_forms/test_authorsform.py | 12 ++++++------ 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/openlp/plugins/songs/lib/__init__.py b/openlp/plugins/songs/lib/__init__.py index 070d322b1..5c1485b9e 100644 --- a/openlp/plugins/songs/lib/__init__.py +++ b/openlp/plugins/songs/lib/__init__.py @@ -386,6 +386,8 @@ def clean_song(manager, song): ``song`` The song object. """ + from xml import SongXML + if isinstance(song.title, buffer): song.title = unicode(song.title) if isinstance(song.alternate_title, buffer): diff --git a/tests/interfaces/openlp_core_lib/test_pluginmanager.py b/tests/interfaces/openlp_core_lib/test_pluginmanager.py index 6a046c80c..32493ae12 100644 --- a/tests/interfaces/openlp_core_lib/test_pluginmanager.py +++ b/tests/interfaces/openlp_core_lib/test_pluginmanager.py @@ -42,7 +42,7 @@ class TestPluginManager(TestCase): def find_plugins_test(self): """ - Test the find_plugins() method to ensure it imports the correct plugins. + Test the find_plugins() method to ensure it imports the correct plugins """ # GIVEN: A plugin manager plugin_manager = PluginManager() diff --git a/tests/interfaces/openlp_plugins_songs_forms/test_authorsform.py b/tests/interfaces/openlp_plugins_songs_forms/test_authorsform.py index 5d48c4de3..48141ce24 100644 --- a/tests/interfaces/openlp_plugins_songs_forms/test_authorsform.py +++ b/tests/interfaces/openlp_plugins_songs_forms/test_authorsform.py @@ -39,7 +39,7 @@ class TestAuthorsForm(TestCase): def get_first_name_property_test(self): """ - Test that getting the first name property on the AuthorForm works correctly. + Test that getting the first name property on the AuthorForm works correctly """ # GIVEN: A first name to set first_name = u'John' @@ -52,7 +52,7 @@ class TestAuthorsForm(TestCase): def set_first_name_property_test(self): """ - Test that setting the first name property on the AuthorForm works correctly. + Test that setting the first name property on the AuthorForm works correctly """ # GIVEN: A first name to set first_name = u'James' @@ -65,7 +65,7 @@ class TestAuthorsForm(TestCase): def get_last_name_property_test(self): """ - Test that getting the last name property on the AuthorForm works correctly. + Test that getting the last name property on the AuthorForm works correctly """ # GIVEN: A last name to set last_name = u'Smith' @@ -78,7 +78,7 @@ class TestAuthorsForm(TestCase): def set_last_name_property_test(self): """ - Test that setting the last name property on the AuthorForm works correctly. + Test that setting the last name property on the AuthorForm works correctly """ # GIVEN: A last name to set last_name = u'Potter' @@ -91,7 +91,7 @@ class TestAuthorsForm(TestCase): def get_display_name_property_test(self): """ - Test that getting the display name property on the AuthorForm works correctly. + Test that getting the display name property on the AuthorForm works correctly """ # GIVEN: A display name to set display_name = u'John' @@ -104,7 +104,7 @@ class TestAuthorsForm(TestCase): def set_display_name_property_test(self): """ - Test that setting the display name property on the AuthorForm works correctly. + Test that setting the display name property on the AuthorForm works correctly """ # GIVEN: A display name to set display_name = u'John' From 04acacddd69718a2107aba955e04a700ff58767e Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 11 Mar 2013 23:24:55 +0200 Subject: [PATCH 3/9] Added another test. --- .../test_editverseform.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/interfaces/openlp_plugins_songs_forms/test_editverseform.py b/tests/interfaces/openlp_plugins_songs_forms/test_editverseform.py index 5dbfb2a16..8b2fa97a4 100644 --- a/tests/interfaces/openlp_plugins_songs_forms/test_editverseform.py +++ b/tests/interfaces/openlp_plugins_songs_forms/test_editverseform.py @@ -39,7 +39,7 @@ class TestEditVerseForm(TestCase): def insert_verse_test(self): """ - Test that inserting a verse works as it should. + Test that clicking the insert button inserts the correct verse marker """ # GIVEN: An instance of the EditVerseForm # WHEN: The Insert button is clicked @@ -47,4 +47,17 @@ class TestEditVerseForm(TestCase): # THEN: The verse text edit should have a Verse:1 in it self.assertIn(u'---[Verse:1]---', self.form.verse_text_edit.toPlainText(), - u'The verse text edit should have a verse identifier') \ No newline at end of file + u'The verse text edit should have a verse marker') + + def insert_verse_2_test(self): + """ + Test that clicking the up button on the spin box and then clicking the insert button inserts the correct marker + """ + # GIVEN: An instance of the EditVerseForm + # WHEN: The spin button and then the Insert button are clicked + QtTest.QTest.keyClick(self.form.verse_number_box, QtCore.Qt.Key_Up) + QtTest.QTest.mouseClick(self.form.insert_button, QtCore.Qt.LeftButton) + + # THEN: The verse text edit should have a Verse:1 in it + self.assertIn(u'---[Verse:2]---', self.form.verse_text_edit.toPlainText(), + u'The verse text edit should have a "Verse 2" marker') From 4ec065e8045a125b6982077fd7e4f536c86b880f Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 11 Mar 2013 23:47:55 +0200 Subject: [PATCH 4/9] Added another test or two. --- .../openlp_core_ui/test_filerenamedialog.py | 1 + .../test_editverseform.py | 31 +++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py index 4fc0fa24b..fe34c1431 100644 --- a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py +++ b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py @@ -8,6 +8,7 @@ from openlp.core.lib import Registry from openlp.core.ui import filerenameform from PyQt4 import QtGui, QtTest + class TestStartFileRenameForm(TestCase): def setUp(self): diff --git a/tests/interfaces/openlp_plugins_songs_forms/test_editverseform.py b/tests/interfaces/openlp_plugins_songs_forms/test_editverseform.py index 8b2fa97a4..403808841 100644 --- a/tests/interfaces/openlp_plugins_songs_forms/test_editverseform.py +++ b/tests/interfaces/openlp_plugins_songs_forms/test_editverseform.py @@ -8,6 +8,11 @@ from PyQt4 import QtCore, QtGui, QtTest from openlp.core.lib import Registry from openlp.plugins.songs.forms.editverseform import EditVerseForm +VERSE_TEXT = u"""The Lord told Noah to build Him an arky arky, +Lord told Noah to build Him an arky arky, +Build it out of gopher barky barky, +Children of the Lord.""" + class TestEditVerseForm(TestCase): def setUp(self): @@ -37,6 +42,18 @@ class TestEditVerseForm(TestCase): # THEN: The default value is correct self.assertEqual(self.form.verse_text_edit.toPlainText(), u'', u'The verse edit box is empty.') + def type_verse_text_tests(self): + """ + Test that typing into the verse text edit box returns the correct text + """ + # GIVEN: An instance of the EditVerseForm + # WHEN: Some verse text is typed into the text edit + QtTest.QTest.keyClicks(self.form.verse_text_edit, VERSE_TEXT) + + # THEN: The verse text edit should have the verse text in it + self.assertEqual(VERSE_TEXT, self.form.verse_text_edit.toPlainText(), + u'The verse text edit should have the typed out verse') + def insert_verse_test(self): """ Test that clicking the insert button inserts the correct verse marker @@ -61,3 +78,17 @@ class TestEditVerseForm(TestCase): # THEN: The verse text edit should have a Verse:1 in it self.assertIn(u'---[Verse:2]---', self.form.verse_text_edit.toPlainText(), u'The verse text edit should have a "Verse 2" marker') + + def insert_chorus_test(self): + """ + Test that clicking the verse type combo box and then clicking the insert button inserts the correct marker + """ + # GIVEN: An instance of the EditVerseForm + # WHEN: The verse type combo box and then the Insert button are clicked + QtTest.QTest.keyClick(self.form.verse_type_combo_box, QtCore.Qt.Key_Down) + QtTest.QTest.mouseClick(self.form.insert_button, QtCore.Qt.LeftButton) + + # THEN: The verse text edit should have a Chorus:1 in it + self.assertIn(u'---[Chorus:1]---', self.form.verse_text_edit.toPlainText(), + u'The verse text edit should have a "Chorus 1" marker') + From 470e48c65a7235dbac377dcc80a893002b17c70e Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Wed, 13 Mar 2013 09:08:41 +0200 Subject: [PATCH 5/9] Some more cleanups and an empty test. --- openlp/plugins/songs/forms/editversedialog.py | 16 ++++++++-------- .../test_editsongform.py | 3 +++ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/openlp/plugins/songs/forms/editversedialog.py b/openlp/plugins/songs/forms/editversedialog.py index b7b8f2df2..a64731f02 100644 --- a/openlp/plugins/songs/forms/editversedialog.py +++ b/openlp/plugins/songs/forms/editversedialog.py @@ -36,35 +36,35 @@ from openlp.plugins.songs.lib import VerseType class Ui_EditVerseDialog(object): def setupUi(self, edit_verse_dialog): - edit_verse_dialog.setObjectName(u'editVerseDialog') + edit_verse_dialog.setObjectName(u'edit_verse_dialog') edit_verse_dialog.resize(400, 400) edit_verse_dialog.setModal(True) self.dialog_layout = QtGui.QVBoxLayout(edit_verse_dialog) self.dialog_layout.setObjectName(u'dialog_layout') self.verse_text_edit = SpellTextEdit(edit_verse_dialog) - self.verse_text_edit.setObjectName(u'verseTextEdit') + self.verse_text_edit.setObjectName(u'verse_text_edit') self.dialog_layout.addWidget(self.verse_text_edit) self.verse_type_layout = QtGui.QHBoxLayout() - self.verse_type_layout.setObjectName(u'verseTypeLayout') + self.verse_type_layout.setObjectName(u'verse_type_layout') self.split_button = QtGui.QPushButton(edit_verse_dialog) self.split_button.setIcon(build_icon(u':/general/general_add.png')) - self.split_button.setObjectName(u'splitButton') + self.split_button.setObjectName(u'split_button') self.verse_type_layout.addWidget(self.split_button) self.verse_type_label = QtGui.QLabel(edit_verse_dialog) - self.verse_type_label.setObjectName(u'verseTypeLabel') + self.verse_type_label.setObjectName(u'verse_type_label') self.verse_type_layout.addWidget(self.verse_type_label) self.verse_type_combo_box = QtGui.QComboBox(edit_verse_dialog) self.verse_type_combo_box.addItems([u'', u'', u'', u'', u'', u'', u'']) - self.verse_type_combo_box.setObjectName(u'verseTypeComboBox') + self.verse_type_combo_box.setObjectName(u'verse_type_combo_box') self.verse_type_label.setBuddy(self.verse_type_combo_box) self.verse_type_layout.addWidget(self.verse_type_combo_box) self.verse_number_box = QtGui.QSpinBox(edit_verse_dialog) self.verse_number_box.setMinimum(1) - self.verse_number_box.setObjectName(u'verseNumberBox') + self.verse_number_box.setObjectName(u'verse_number_box') self.verse_type_layout.addWidget(self.verse_number_box) self.insert_button = QtGui.QPushButton(edit_verse_dialog) self.insert_button.setIcon(build_icon(u':/general/general_add.png')) - self.insert_button.setObjectName(u'insertButton') + self.insert_button.setObjectName(u'insert_button') self.verse_type_layout.addWidget(self.insert_button) self.verse_type_layout.addStretch() self.dialog_layout.addLayout(self.verse_type_layout) diff --git a/tests/interfaces/openlp_plugins_songs_forms/test_editsongform.py b/tests/interfaces/openlp_plugins_songs_forms/test_editsongform.py index a84eb6e67..2d1b53c49 100644 --- a/tests/interfaces/openlp_plugins_songs_forms/test_editsongform.py +++ b/tests/interfaces/openlp_plugins_songs_forms/test_editsongform.py @@ -38,3 +38,6 @@ class TestEditSongForm(TestCase): self.assertFalse(self.form.verse_delete_button.isEnabled(), u'The verse delete button should not be enabled') self.assertFalse(self.form.author_remove_button.isEnabled(), u'The author remove button should not be enabled') self.assertFalse(self.form.topic_remove_button.isEnabled(), u'The topic remove button should not be enabled') + + def is_verse_edit_form_executed_test(self): + pass \ No newline at end of file From 211bd38bbf8c0031bdfada8998bc47d11098f6da Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Wed, 13 Mar 2013 22:44:06 +0200 Subject: [PATCH 6/9] Some minor PyLint cleanups --- openlp/plugins/songs/forms/editsongform.py | 2 +- openlp/plugins/songs/forms/songbookform.py | 3 +++ openlp/plugins/songs/forms/topicsform.py | 3 +++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index a75a0916c..a37ef636a 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -797,7 +797,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): """ Free up autocompletion memory on dialog exit """ - log.debug (u'SongEditForm.clearCaches') + log.debug(u'SongEditForm.clearCaches') self.authors = [] self.themes = [] self.books = [] diff --git a/openlp/plugins/songs/forms/songbookform.py b/openlp/plugins/songs/forms/songbookform.py index 85b8e9011..691f58ffc 100644 --- a/openlp/plugins/songs/forms/songbookform.py +++ b/openlp/plugins/songs/forms/songbookform.py @@ -26,6 +26,9 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### +""" +This module contains the song book form +""" from PyQt4 import QtGui diff --git a/openlp/plugins/songs/forms/topicsform.py b/openlp/plugins/songs/forms/topicsform.py index 70e86efe4..3a9fcfb25 100644 --- a/openlp/plugins/songs/forms/topicsform.py +++ b/openlp/plugins/songs/forms/topicsform.py @@ -26,6 +26,9 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### +""" +This module contains the topic edit form. +""" from PyQt4 import QtGui From 27f13d8f98f2a833a12881197b0a6f2eef357c26 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Thu, 14 Mar 2013 23:12:26 +0200 Subject: [PATCH 7/9] Fix up some object names --- openlp/plugins/songs/forms/editversedialog.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/openlp/plugins/songs/forms/editversedialog.py b/openlp/plugins/songs/forms/editversedialog.py index b7b8f2df2..a64731f02 100644 --- a/openlp/plugins/songs/forms/editversedialog.py +++ b/openlp/plugins/songs/forms/editversedialog.py @@ -36,35 +36,35 @@ from openlp.plugins.songs.lib import VerseType class Ui_EditVerseDialog(object): def setupUi(self, edit_verse_dialog): - edit_verse_dialog.setObjectName(u'editVerseDialog') + edit_verse_dialog.setObjectName(u'edit_verse_dialog') edit_verse_dialog.resize(400, 400) edit_verse_dialog.setModal(True) self.dialog_layout = QtGui.QVBoxLayout(edit_verse_dialog) self.dialog_layout.setObjectName(u'dialog_layout') self.verse_text_edit = SpellTextEdit(edit_verse_dialog) - self.verse_text_edit.setObjectName(u'verseTextEdit') + self.verse_text_edit.setObjectName(u'verse_text_edit') self.dialog_layout.addWidget(self.verse_text_edit) self.verse_type_layout = QtGui.QHBoxLayout() - self.verse_type_layout.setObjectName(u'verseTypeLayout') + self.verse_type_layout.setObjectName(u'verse_type_layout') self.split_button = QtGui.QPushButton(edit_verse_dialog) self.split_button.setIcon(build_icon(u':/general/general_add.png')) - self.split_button.setObjectName(u'splitButton') + self.split_button.setObjectName(u'split_button') self.verse_type_layout.addWidget(self.split_button) self.verse_type_label = QtGui.QLabel(edit_verse_dialog) - self.verse_type_label.setObjectName(u'verseTypeLabel') + self.verse_type_label.setObjectName(u'verse_type_label') self.verse_type_layout.addWidget(self.verse_type_label) self.verse_type_combo_box = QtGui.QComboBox(edit_verse_dialog) self.verse_type_combo_box.addItems([u'', u'', u'', u'', u'', u'', u'']) - self.verse_type_combo_box.setObjectName(u'verseTypeComboBox') + self.verse_type_combo_box.setObjectName(u'verse_type_combo_box') self.verse_type_label.setBuddy(self.verse_type_combo_box) self.verse_type_layout.addWidget(self.verse_type_combo_box) self.verse_number_box = QtGui.QSpinBox(edit_verse_dialog) self.verse_number_box.setMinimum(1) - self.verse_number_box.setObjectName(u'verseNumberBox') + self.verse_number_box.setObjectName(u'verse_number_box') self.verse_type_layout.addWidget(self.verse_number_box) self.insert_button = QtGui.QPushButton(edit_verse_dialog) self.insert_button.setIcon(build_icon(u':/general/general_add.png')) - self.insert_button.setObjectName(u'insertButton') + self.insert_button.setObjectName(u'insert_button') self.verse_type_layout.addWidget(self.insert_button) self.verse_type_layout.addStretch() self.dialog_layout.addLayout(self.verse_type_layout) From 1a37d306a9127ca4e885bf71080e40741c021fd7 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Fri, 15 Mar 2013 00:22:18 +0200 Subject: [PATCH 8/9] More cleanups --- openlp/core/ui/firsttimeform.py | 4 +- openlp/core/ui/settingsdialog.py | 2 +- openlp/core/ui/wizard.py | 32 +- .../plugins/bibles/forms/bibleimportform.py | 6 +- .../plugins/bibles/forms/bibleupgradeform.py | 14 +- openlp/plugins/bibles/forms/booknameform.py | 5 +- openlp/plugins/songs/forms/authorsdialog.py | 2 +- openlp/plugins/songs/forms/editverseform.py | 1 - .../plugins/songs/forms/mediafilesdialog.py | 62 +-- openlp/plugins/songs/forms/mediafilesform.py | 6 +- openlp/plugins/songs/forms/songbookdialog.py | 68 ++-- openlp/plugins/songs/forms/songbookform.py | 10 +- openlp/plugins/songs/forms/songexportform.py | 13 +- openlp/plugins/songs/forms/songimportform.py | 42 +-- .../songs/forms/songmaintenancedialog.py | 244 ++++++------ .../songs/forms/songmaintenanceform.py | 354 +++++++++--------- openlp/plugins/songs/forms/topicsdialog.py | 54 +-- openlp/plugins/songs/forms/topicsform.py | 22 +- tests/interfaces/__init__.py | 4 +- .../openlp_core_lib/test_pluginmanager.py | 2 +- .../openlp_core_ui/test_filerenamedialog.py | 2 +- .../openlp_core_ui/test_servicemanager.py | 2 +- .../openlp_core_ui/test_servicenotedialog.py | 2 +- .../openlp_core_ui/test_starttimedialog.py | 2 +- .../test_authorsform.py | 5 +- .../test_editsongform.py | 6 +- .../test_editverseform.py | 19 +- .../test_topicsform.py | 65 ++++ 28 files changed, 602 insertions(+), 448 deletions(-) create mode 100644 tests/interfaces/openlp_plugins_songs_forms/test_topicsform.py diff --git a/openlp/core/ui/firsttimeform.py b/openlp/core/ui/firsttimeform.py index dd60ca968..e828db597 100644 --- a/openlp/core/ui/firsttimeform.py +++ b/openlp/core/ui/firsttimeform.py @@ -221,7 +221,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): time.sleep(0.2) self._preWizard() self._performWizard() - self._postWizard() + self._post_wizard() self.application.set_normal_cursor() def update_screen_list_combo(self): @@ -380,7 +380,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard): # Try to give the wizard a chance to repaint itself time.sleep(0.1) - def _postWizard(self): + def _post_wizard(self): """ Clean up the UI after the process has finished. """ diff --git a/openlp/core/ui/settingsdialog.py b/openlp/core/ui/settingsdialog.py index fd61ae612..ddbb9356a 100644 --- a/openlp/core/ui/settingsdialog.py +++ b/openlp/core/ui/settingsdialog.py @@ -56,7 +56,7 @@ class Ui_SettingsDialog(object): self.settingListWidget.setObjectName(u'settingListWidget') self.dialogLayout.addWidget(self.settingListWidget, 0, 0, 1, 1) self.stackedLayout = QtGui.QStackedLayout() - self.stackedLayout.setObjectName(u'stackedLayout') + self.stackedLayout.setObjectName(u'stacked_layout') self.dialogLayout.addLayout(self.stackedLayout, 0, 1, 1, 1) self.button_box = create_button_box(settingsDialog, u'button_box', [u'cancel', u'ok']) self.dialogLayout.addWidget(self.button_box, 1, 1, 1, 1) diff --git a/openlp/core/ui/wizard.py b/openlp/core/ui/wizard.py index 23ce68a3f..d0a6cf422 100644 --- a/openlp/core/ui/wizard.py +++ b/openlp/core/ui/wizard.py @@ -91,8 +91,8 @@ class OpenLPWizard(QtGui.QWizard): self.cancel_button = self.button(QtGui.QWizard.CancelButton) self.setupUi(image) self.register_fields() - self.customInit() - self.customSignals() + self.custom_init() + self.custom_signals() self.currentIdChanged.connect(self.on_current_id_changed) self.error_copy_to_button.clicked.connect(self.on_error_copy_to_button_clicked) self.error_save_to_button.clicked.connect(self.on_error_save_to_button_clicked) @@ -106,8 +106,8 @@ class OpenLPWizard(QtGui.QWizard): self.setOptions(QtGui.QWizard.IndependentPages | QtGui.QWizard.NoBackButtonOnStartPage | QtGui.QWizard.NoBackButtonOnLastPage) add_welcome_page(self, image) - self.addCustomPages() - self.addProgressPage() + self.add_custom_pages() + self.add_progress_page() self.retranslateUi() def register_fields(self): @@ -116,7 +116,25 @@ class OpenLPWizard(QtGui.QWizard): """ pass - def addProgressPage(self): + def custom_init(self): + """ + Hook method for custom initialisation + """ + pass + + def custom_signals(self): + """ + Hook method for adding custom signals + """ + pass + + def add_custom_pages(self): + """ + Hook method for wizards to add extra pages + """ + pass + + def add_progress_page(self): """ Add the progress page for the wizard. This page informs the user how the wizard is progressing with its task. @@ -180,7 +198,7 @@ class OpenLPWizard(QtGui.QWizard): if self.page(pageId) == self.progress_page: self.pre_wizard() self.performWizard() - self.postWizard() + self.post_wizard() else: self.custom_cage_changed(pageId) @@ -227,7 +245,7 @@ class OpenLPWizard(QtGui.QWizard): self.progress_bar.setMaximum(1188) self.progress_bar.setValue(0) - def postWizard(self): + def post_wizard(self): """ Clean up the UI after the import has finished. """ diff --git a/openlp/plugins/bibles/forms/bibleimportform.py b/openlp/plugins/bibles/forms/bibleimportform.py index 9ca2c3e6e..8f94771fd 100644 --- a/openlp/plugins/bibles/forms/bibleimportform.py +++ b/openlp/plugins/bibles/forms/bibleimportform.py @@ -97,7 +97,7 @@ class BibleImportForm(OpenLPWizard): next_button = self.button(QtGui.QWizard.NextButton) next_button.setEnabled(BibleFormat.get_availability(index)) - def customInit(self): + def custom_init(self): """ Perform any custom initialisation for bible importing. """ @@ -112,7 +112,7 @@ class BibleImportForm(OpenLPWizard): self.restart() self.selectStack.setCurrentIndex(0) - def customSignals(self): + def custom_signals(self): """ Set up the signals used in the bible importer. """ @@ -123,7 +123,7 @@ class BibleImportForm(OpenLPWizard): self.openSongBrowseButton.clicked.connect(self.onOpenSongBrowseButtonClicked) self.openlp1BrowseButton.clicked.connect(self.onOpenlp1BrowseButtonClicked) - def addCustomPages(self): + def add_custom_pages(self): """ Add the bible import specific wizard pages. """ diff --git a/openlp/plugins/bibles/forms/bibleupgradeform.py b/openlp/plugins/bibles/forms/bibleupgradeform.py index 0e9af1dd9..7c1017a11 100644 --- a/openlp/plugins/bibles/forms/bibleupgradeform.py +++ b/openlp/plugins/bibles/forms/bibleupgradeform.py @@ -107,7 +107,7 @@ class BibleUpgradeForm(OpenLPWizard): if self.page(pageId) == self.progress_page: self.preWizard() self.performWizard() - self.postWizard() + self.post_wizard() elif self.page(pageId) == self.selectPage and not self.files: self.next() @@ -140,21 +140,21 @@ class BibleUpgradeForm(OpenLPWizard): success = False return success - def customInit(self): + def custom_init(self): """ Perform any custom initialisation for bible upgrading. """ self.manager.set_process_dialog(self) self.restart() - def customSignals(self): + def custom_signals(self): """ Set up the signals used in the bible importer. """ self.backupBrowseButton.clicked.connect(self.onBackupBrowseButtonClicked) self.noBackupCheckBox.toggled.connect(self.onNoBackupCheckBoxToggled) - def addCustomPages(self): + def add_custom_pages(self): """ Add the bible import specific wizard pages. """ @@ -170,7 +170,7 @@ class BibleUpgradeForm(OpenLPWizard): self.backupInfoLabel.setObjectName(u'backupInfoLabel') self.backupLayout.addWidget(self.backupInfoLabel) self.selectLabel = QtGui.QLabel(self.backupPage) - self.selectLabel.setObjectName(u'selectLabel') + self.selectLabel.setObjectName(u'select_label') self.backupLayout.addWidget(self.selectLabel) self.formLayout = QtGui.QFormLayout() self.formLayout.setMargin(0) @@ -528,7 +528,7 @@ class BibleUpgradeForm(OpenLPWizard): if old_bible is not None: old_bible.close_connection() - def postWizard(self): + def post_wizard(self): """ Clean up the UI after the import has finished. """ @@ -559,4 +559,4 @@ class BibleUpgradeForm(OpenLPWizard): self.progress_label.setText(translate('BiblesPlugin.UpgradeWizardForm', 'Upgrade failed.')) # Remove temp directory. shutil.rmtree(self.temp_dir, True) - OpenLPWizard.postWizard(self) + OpenLPWizard.post_wizard(self) diff --git a/openlp/plugins/bibles/forms/booknameform.py b/openlp/plugins/bibles/forms/booknameform.py index 5c5371759..c8abaa227 100644 --- a/openlp/plugins/bibles/forms/booknameform.py +++ b/openlp/plugins/bibles/forms/booknameform.py @@ -44,6 +44,7 @@ from openlp.plugins.bibles.lib.db import BiblesResourcesDB log = logging.getLogger(__name__) + class BookNameForm(QDialog, Ui_BookNameDialog): """ Class to manage a dialog which help the user to refer a book name a @@ -57,11 +58,11 @@ class BookNameForm(QDialog, Ui_BookNameDialog): """ QDialog.__init__(self, parent) self.setupUi(self) - self.customSignals() + self.custom_signals() self.book_names = BibleStrings().BookNames self.book_id = False - def customSignals(self): + def custom_signals(self): """ Set up the signals used in the booknameform. """ diff --git a/openlp/plugins/songs/forms/authorsdialog.py b/openlp/plugins/songs/forms/authorsdialog.py index b4ef6e71b..2668847bf 100644 --- a/openlp/plugins/songs/forms/authorsdialog.py +++ b/openlp/plugins/songs/forms/authorsdialog.py @@ -49,7 +49,7 @@ class Ui_AuthorsDialog(object): self.dialog_layout = QtGui.QVBoxLayout(authors_dialog) self.dialog_layout.setObjectName(u'dialog_layout') self.author_layout = QtGui.QFormLayout() - self.author_layout.setObjectName(u'authorLayout') + self.author_layout.setObjectName(u'author_layout') self.first_name_label = QtGui.QLabel(authors_dialog) self.first_name_label.setObjectName(u'first_name_label') self.first_name_edit = QtGui.QLineEdit(authors_dialog) diff --git a/openlp/plugins/songs/forms/editverseform.py b/openlp/plugins/songs/forms/editverseform.py index 80bf719b7..b3a5a332d 100644 --- a/openlp/plugins/songs/forms/editverseform.py +++ b/openlp/plugins/songs/forms/editverseform.py @@ -144,4 +144,3 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog): if not text.startswith(u'---['): text = u'---[%s:1]---\n%s' % (VerseType.translated_names[VerseType.Verse], text) return text - diff --git a/openlp/plugins/songs/forms/mediafilesdialog.py b/openlp/plugins/songs/forms/mediafilesdialog.py index dd2c4b01a..647e14278 100644 --- a/openlp/plugins/songs/forms/mediafilesdialog.py +++ b/openlp/plugins/songs/forms/mediafilesdialog.py @@ -32,32 +32,42 @@ from PyQt4 import QtCore, QtGui from openlp.core.lib import translate, build_icon from openlp.core.lib.ui import create_button_box -class Ui_MediaFilesDialog(object): - def setupUi(self, mediaFilesDialog): - mediaFilesDialog.setObjectName(u'mediaFilesDialog') - mediaFilesDialog.setWindowModality(QtCore.Qt.ApplicationModal) - mediaFilesDialog.resize(400, 300) - mediaFilesDialog.setModal(True) - mediaFilesDialog.setWindowIcon(build_icon(u':/icon/openlp-logo-16x16.png')) - self.filesVerticalLayout = QtGui.QVBoxLayout(mediaFilesDialog) - self.filesVerticalLayout.setSpacing(8) - self.filesVerticalLayout.setMargin(8) - self.filesVerticalLayout.setObjectName(u'filesVerticalLayout') - self.selectLabel = QtGui.QLabel(mediaFilesDialog) - self.selectLabel.setWordWrap(True) - self.selectLabel.setObjectName(u'selectLabel') - self.filesVerticalLayout.addWidget(self.selectLabel) - self.fileListWidget = QtGui.QListWidget(mediaFilesDialog) - self.fileListWidget.setAlternatingRowColors(True) - self.fileListWidget.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) - self.fileListWidget.setObjectName(u'fileListWidget') - self.filesVerticalLayout.addWidget(self.fileListWidget) - self.button_box = create_button_box(mediaFilesDialog, u'button_box', [u'cancel', u'ok']) - self.filesVerticalLayout.addWidget(self.button_box) - self.retranslateUi(mediaFilesDialog) - def retranslateUi(self, mediaFilesDialog): - mediaFilesDialog.setWindowTitle(translate('SongsPlugin.MediaFilesForm', 'Select Media File(s)')) - self.selectLabel.setText(translate('SongsPlugin.MediaFilesForm', +class Ui_MediaFilesDialog(object): + """ + The user interface for the media files dialog. + """ + def setupUi(self, media_files_dialog): + """ + Set up the user interface. + """ + media_files_dialog.setObjectName(u'media_files_dialog') + media_files_dialog.setWindowModality(QtCore.Qt.ApplicationModal) + media_files_dialog.resize(400, 300) + media_files_dialog.setModal(True) + media_files_dialog.setWindowIcon(build_icon(u':/icon/openlp-logo-16x16.png')) + self.files_vertical_layout = QtGui.QVBoxLayout(media_files_dialog) + self.files_vertical_layout.setSpacing(8) + self.files_vertical_layout.setMargin(8) + self.files_vertical_layout.setObjectName(u'files_vertical_layout') + self.select_label = QtGui.QLabel(media_files_dialog) + self.select_label.setWordWrap(True) + self.select_label.setObjectName(u'select_label') + self.files_vertical_layout.addWidget(self.select_label) + self.file_list_widget = QtGui.QListWidget(media_files_dialog) + self.file_list_widget.setAlternatingRowColors(True) + self.file_list_widget.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) + self.file_list_widget.setObjectName(u'file_list_widget') + self.files_vertical_layout.addWidget(self.file_list_widget) + self.button_box = create_button_box(media_files_dialog, u'button_box', [u'cancel', u'ok']) + self.files_vertical_layout.addWidget(self.button_box) + self.retranslateUi(media_files_dialog) + + def retranslateUi(self, media_files_dialog): + """ + Translate the UI on the fly. + """ + media_files_dialog.setWindowTitle(translate('SongsPlugin.MediaFilesForm', 'Select Media File(s)')) + self.select_label.setText(translate('SongsPlugin.MediaFilesForm', 'Select one or more audio files from the list below, and click OK to import them into this song.')) diff --git a/openlp/plugins/songs/forms/mediafilesform.py b/openlp/plugins/songs/forms/mediafilesform.py index 49ffde644..6010f7606 100644 --- a/openlp/plugins/songs/forms/mediafilesform.py +++ b/openlp/plugins/songs/forms/mediafilesform.py @@ -48,13 +48,13 @@ class MediaFilesForm(QtGui.QDialog, Ui_MediaFilesDialog): self.setupUi(self) def populateFiles(self, files): - self.fileListWidget.clear() + self.file_list_widget.clear() for file in files: item = QtGui.QListWidgetItem(os.path.split(file)[1]) item.setData(QtCore.Qt.UserRole, file) - self.fileListWidget.addItem(item) + self.file_list_widget.addItem(item) def getSelectedFiles(self): return map(lambda item: item.data(QtCore.Qt.UserRole), - self.fileListWidget.selectedItems()) + self.file_list_widget.selectedItems()) diff --git a/openlp/plugins/songs/forms/songbookdialog.py b/openlp/plugins/songs/forms/songbookdialog.py index 7c6bf40aa..f4f655fa7 100644 --- a/openlp/plugins/songs/forms/songbookdialog.py +++ b/openlp/plugins/songs/forms/songbookdialog.py @@ -32,33 +32,43 @@ from PyQt4 import QtGui from openlp.core.lib import translate from openlp.core.lib.ui import create_button_box -class Ui_SongBookDialog(object): - def setupUi(self, songBookDialog): - songBookDialog.setObjectName(u'songBookDialog') - songBookDialog.resize(300, 10) - self.dialogLayout = QtGui.QVBoxLayout(songBookDialog) - self.dialogLayout.setObjectName(u'dialog_layout') - self.bookLayout = QtGui.QFormLayout() - self.bookLayout.setObjectName(u'bookLayout') - self.nameLabel = QtGui.QLabel(songBookDialog) - self.nameLabel.setObjectName(u'nameLabel') - self.nameEdit = QtGui.QLineEdit(songBookDialog) - self.nameEdit.setObjectName(u'nameEdit') - self.nameLabel.setBuddy(self.nameEdit) - self.bookLayout.addRow(self.nameLabel, self.nameEdit) - self.publisherLabel = QtGui.QLabel(songBookDialog) - self.publisherLabel.setObjectName(u'publisherLabel') - self.publisherEdit = QtGui.QLineEdit(songBookDialog) - self.publisherEdit.setObjectName(u'publisherEdit') - self.publisherLabel.setBuddy(self.publisherEdit) - self.bookLayout.addRow(self.publisherLabel, self.publisherEdit) - self.dialogLayout.addLayout(self.bookLayout) - self.button_box = create_button_box(songBookDialog, u'button_box', [u'cancel', u'save']) - self.dialogLayout.addWidget(self.button_box) - self.retranslateUi(songBookDialog) - songBookDialog.setMaximumHeight(songBookDialog.sizeHint().height()) - def retranslateUi(self, songBookDialog): - songBookDialog.setWindowTitle(translate('SongsPlugin.SongBookForm', 'Song Book Maintenance')) - self.nameLabel.setText(translate('SongsPlugin.SongBookForm', '&Name:')) - self.publisherLabel.setText(translate('SongsPlugin.SongBookForm', '&Publisher:')) +class Ui_SongBookDialog(object): + """ + The user interface for the song book dialog. + """ + def setupUi(self, song_book_dialog): + """ + Set up the user interface. + """ + song_book_dialog.setObjectName(u'song_book_dialog') + song_book_dialog.resize(300, 10) + self.dialog_layout = QtGui.QVBoxLayout(song_book_dialog) + self.dialog_layout.setObjectName(u'dialog_layout') + self.book_layout = QtGui.QFormLayout() + self.book_layout.setObjectName(u'book_layout') + self.name_label = QtGui.QLabel(song_book_dialog) + self.name_label.setObjectName(u'name_label') + self.name_edit = QtGui.QLineEdit(song_book_dialog) + self.name_edit.setObjectName(u'name_edit') + self.name_label.setBuddy(self.name_edit) + self.book_layout.addRow(self.name_label, self.name_edit) + self.publisher_label = QtGui.QLabel(song_book_dialog) + self.publisher_label.setObjectName(u'publisher_label') + self.publisher_edit = QtGui.QLineEdit(song_book_dialog) + self.publisher_edit.setObjectName(u'publisher_edit') + self.publisher_label.setBuddy(self.publisher_edit) + self.book_layout.addRow(self.publisher_label, self.publisher_edit) + self.dialog_layout.addLayout(self.book_layout) + self.button_box = create_button_box(song_book_dialog, u'button_box', [u'cancel', u'save']) + self.dialog_layout.addWidget(self.button_box) + self.retranslateUi(song_book_dialog) + song_book_dialog.setMaximumHeight(song_book_dialog.sizeHint().height()) + + def retranslateUi(self, song_book_dialog): + """ + Translate the UI on the fly. + """ + song_book_dialog.setWindowTitle(translate('SongsPlugin.SongBookForm', 'Song Book Maintenance')) + self.name_label.setText(translate('SongsPlugin.SongBookForm', '&Name:')) + self.publisher_label.setText(translate('SongsPlugin.SongBookForm', '&Publisher:')) diff --git a/openlp/plugins/songs/forms/songbookform.py b/openlp/plugins/songs/forms/songbookform.py index 691f58ffc..52806ab82 100644 --- a/openlp/plugins/songs/forms/songbookform.py +++ b/openlp/plugins/songs/forms/songbookform.py @@ -56,19 +56,19 @@ class SongBookForm(QtGui.QDialog, Ui_SongBookDialog): Clear the fields on the form before displaying it. """ if clear: - self.nameEdit.clear() - self.publisherEdit.clear() - self.nameEdit.setFocus() + self.name_edit.clear() + self.publisher_edit.clear() + self.name_edit.setFocus() return QtGui.QDialog.exec_(self) def accept(self): """ Override the inherited method to check that the name of the book has been typed in. """ - if not self.nameEdit.text(): + if not self.name_edit.text(): critical_error_message_box( message=translate('SongsPlugin.SongBookForm', 'You need to type in a name for the book.')) - self.nameEdit.setFocus() + self.name_edit.setFocus() return False else: return QtGui.QDialog.accept(self) diff --git a/openlp/plugins/songs/forms/songexportform.py b/openlp/plugins/songs/forms/songexportform.py index 78b00a00b..79f21a454 100644 --- a/openlp/plugins/songs/forms/songexportform.py +++ b/openlp/plugins/songs/forms/songexportform.py @@ -43,6 +43,7 @@ from openlp.plugins.songs.lib.openlyricsexport import OpenLyricsExport log = logging.getLogger(__name__) + class SongExportForm(OpenLPWizard): """ This is the Song Export Wizard, which allows easy exporting of Songs to the @@ -60,7 +61,7 @@ class SongExportForm(OpenLPWizard): ``plugin`` The songs plugin. """ - OpenLPWizard.__init__(self, parent, plugin, u'songExportWizard', u':/wizards/wizard_exportsong.bmp') + OpenLPWizard.__init__(self, parent, plugin, u'song_export_wizard', u':/wizards/wizard_exportsong.bmp') self.stop_export_flag = False Registry().register_function(u'openlp_stop_wizard', self.stop_export) @@ -77,13 +78,7 @@ class SongExportForm(OpenLPWizard): """ OpenLPWizard.setupUi(self, image) - def customInit(self): - """ - Song wizard specific initialisation. - """ - pass - - def customSignals(self): + def custom_signals(self): """ Song wizard specific signals. """ @@ -93,7 +88,7 @@ class SongExportForm(OpenLPWizard): self.checkButton.clicked.connect(self.onCheckButtonClicked) self.directoryButton.clicked.connect(self.onDirectoryButtonClicked) - def addCustomPages(self): + def add_custom_pages(self): """ Add song wizard specific pages. """ diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index f956e13a7..537d7552b 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -67,7 +67,7 @@ class SongImportForm(OpenLPWizard): """ Set up the song wizard UI. """ - self.format_widgets = dict([(format, {}) for format in SongFormat.get_format_list()]) + self.format_widgets = dict([(song_format, {}) for song_format in SongFormat.get_format_list()]) OpenLPWizard.setupUi(self, image) self.current_format = SongFormat.OpenLyrics self.format_stack.setCurrentIndex(self.current_format) @@ -81,29 +81,29 @@ class SongImportForm(OpenLPWizard): self.format_stack.setCurrentIndex(index) self.source_page.emit(QtCore.SIGNAL(u'completeChanged()')) - def customInit(self): + def custom_init(self): """ Song wizard specific initialisation. """ - for format in SongFormat.get_format_list(): - if not SongFormat.get(format, u'availability'): - self.format_widgets[format][u'disabled_widget'].setVisible(True) - self.format_widgets[format][u'import_widget'].setVisible(False) + for song_format in SongFormat.get_format_list(): + if not SongFormat.get(song_format, u'availability'): + self.format_widgets[song_format][u'disabled_widget'].setVisible(True) + self.format_widgets[song_format][u'import_widget'].setVisible(False) - def customSignals(self): + def custom_signals(self): """ Song wizard specific signals. """ - for format in SongFormat.get_format_list(): - select_mode = SongFormat.get(format, u'selectMode') + for song_format in SongFormat.get_format_list(): + select_mode = SongFormat.get(song_format, u'selectMode') if select_mode == SongFormatSelect.MultipleFiles: - self.format_widgets[format][u'addButton'].clicked.connect(self.on_add_button_clicked) - self.format_widgets[format][u'removeButton'].clicked.connect(self.onRemoveButtonClicked) + self.format_widgets[song_format][u'addButton'].clicked.connect(self.on_add_button_clicked) + self.format_widgets[song_format][u'removeButton'].clicked.connect(self.onRemoveButtonClicked) else: - self.format_widgets[format][u'browseButton'].clicked.connect(self.on_browse_button_clicked) - self.format_widgets[format][u'file_path_edit'].textChanged.connect(self.onFilepathEditTextChanged) + self.format_widgets[song_format][u'browseButton'].clicked.connect(self.on_browse_button_clicked) + self.format_widgets[song_format][u'file_path_edit'].textChanged.connect(self.onFilepathEditTextChanged) - def addCustomPages(self): + def add_custom_pages(self): """ Add song wizard specific pages. """ @@ -210,7 +210,7 @@ class SongImportForm(OpenLPWizard): Settings().setValue(u'songs/last import type', this_format) select_mode, class_, error_msg = SongFormat.get(this_format, u'selectMode', u'class', u'invalidSourceMsg') if select_mode == SongFormatSelect.MultipleFiles: - import_source = self.get_list_of_files(self.format_widgets[this_format][u'fileListWidget']) + import_source = self.get_list_of_files(self.format_widgets[this_format][u'file_list_widget']) error_title = UiStrings().IFSp focus_button = self.format_widgets[this_format][u'addButton'] else: @@ -287,14 +287,14 @@ class SongImportForm(OpenLPWizard): SongFormat.get(this_format, u'selectMode', u'name', u'filter', u'getFilesTitle') title = custom_title if custom_title else WizardStrings.OpenTypeFile % format_name if select_mode == SongFormatSelect.MultipleFiles: - self.get_files(title, self.format_widgets[this_format][u'fileListWidget'], ext_filter) + self.get_files(title, self.format_widgets[this_format][u'file_list_widget'], ext_filter) self.source_page.emit(QtCore.SIGNAL(u'completeChanged()')) def onRemoveButtonClicked(self): """ Remove a file from the list. """ - self.remove_selected_items(self.format_widgets[self.current_format][u'fileListWidget']) + self.remove_selected_items(self.format_widgets[self.current_format][u'file_list_widget']) self.source_page.emit(QtCore.SIGNAL(u'completeChanged()')) def onFilepathEditTextChanged(self): @@ -317,7 +317,7 @@ class SongImportForm(OpenLPWizard): for format in SongFormat.get_format_list(): select_mode = SongFormat.get(format, u'selectMode') if select_mode == SongFormatSelect.MultipleFiles: - self.format_widgets[format][u'fileListWidget'].clear() + self.format_widgets[format][u'file_list_widget'].clear() else: self.format_widgets[format][u'file_path_edit'].setText(u'') self.error_report_text_edit.clear() @@ -349,7 +349,7 @@ class SongImportForm(OpenLPWizard): folder=self.format_widgets[source_format][u'file_path_edit'].text()) else: importer = self.plugin.importSongs(source_format, - filenames=self.get_list_of_files(self.format_widgets[source_format][u'fileListWidget'])) + filenames=self.get_list_of_files(self.format_widgets[source_format][u'file_list_widget'])) importer.doImport() self.progress_label.setText(WizardStrings.FinishedImport) @@ -440,7 +440,7 @@ class SongImportForm(OpenLPWizard): removeButton.setObjectName(prefix + u'RemoveButton') button_layout.addWidget(removeButton) importLayout.addLayout(button_layout) - self.format_widgets[this_format][u'fileListWidget'] = fileListWidget + self.format_widgets[this_format][u'file_list_widget'] = fileListWidget self.format_widgets[this_format][u'button_layout'] = button_layout self.format_widgets[this_format][u'addButton'] = addButton self.format_widgets[this_format][u'removeButton'] = removeButton @@ -512,7 +512,7 @@ class SongImportSourcePage(QtGui.QWizardPage): select_mode, format_available = SongFormat.get(this_format, u'selectMode', u'availability') if format_available: if select_mode == SongFormatSelect.MultipleFiles: - if wizard.format_widgets[this_format][u'fileListWidget'].count() > 0: + if wizard.format_widgets[this_format][u'file_list_widget'].count() > 0: return True else: filepath = unicode(wizard.format_widgets[this_format][u'file_path_edit'].text()) diff --git a/openlp/plugins/songs/forms/songmaintenancedialog.py b/openlp/plugins/songs/forms/songmaintenancedialog.py index f7941e15b..5268091d8 100644 --- a/openlp/plugins/songs/forms/songmaintenancedialog.py +++ b/openlp/plugins/songs/forms/songmaintenancedialog.py @@ -33,123 +33,133 @@ from openlp.core.lib import UiStrings, build_icon from openlp.core.lib.ui import create_button_box from openlp.plugins.songs.lib.ui import SongStrings -class Ui_SongMaintenanceDialog(object): - def setupUi(self, songMaintenanceDialog): - songMaintenanceDialog.setObjectName(u'songMaintenanceDialog') - songMaintenanceDialog.setWindowModality(QtCore.Qt.ApplicationModal) - songMaintenanceDialog.resize(10, 350) - self.dialogLayout = QtGui.QGridLayout(songMaintenanceDialog) - self.dialogLayout.setObjectName(u'dialog_layout') - self.typeListWidget = QtGui.QListWidget(songMaintenanceDialog) - self.typeListWidget.setIconSize(QtCore.QSize(32, 32)) - self.typeListWidget.setUniformItemSizes(True) - self.typeListWidget.setObjectName(u'typeListWidget') - self.listItemAuthors = QtGui.QListWidgetItem(self.typeListWidget) - self.listItemAuthors.setIcon(build_icon(u':/songs/author_maintenance.png')) - self.listItemTopics = QtGui.QListWidgetItem(self.typeListWidget) - self.listItemTopics.setIcon(build_icon(u':/songs/topic_maintenance.png')) - self.listItemBooks = QtGui.QListWidgetItem(self.typeListWidget) - self.listItemBooks.setIcon(build_icon(u':/songs/book_maintenance.png')) - self.dialogLayout.addWidget(self.typeListWidget, 0, 0) - self.stackedLayout = QtGui.QStackedLayout() - self.stackedLayout.setObjectName(u'stackedLayout') - # authors page - self.authorsPage = QtGui.QWidget(songMaintenanceDialog) - self.authorsPage.setObjectName(u'authorsPage') - self.authorsLayout = QtGui.QVBoxLayout(self.authorsPage) - self.authorsLayout.setObjectName(u'authors_layout') - self.authorsListWidget = QtGui.QListWidget(self.authorsPage) - self.authorsListWidget.setObjectName(u'authorsListWidget') - self.authorsLayout.addWidget(self.authorsListWidget) - self.authorsButtonsLayout = QtGui.QHBoxLayout() - self.authorsButtonsLayout.setObjectName(u'authorsButtonsLayout') - self.authorsButtonsLayout.addStretch() - self.authorsAddButton = QtGui.QPushButton(self.authorsPage) - self.authorsAddButton.setIcon(build_icon(u':/songs/author_add.png')) - self.authorsAddButton.setObjectName(u'authorsAddButton') - self.authorsButtonsLayout.addWidget(self.authorsAddButton) - self.authorsEditButton = QtGui.QPushButton(self.authorsPage) - self.authorsEditButton.setIcon(build_icon(u':/songs/author_edit.png')) - self.authorsEditButton.setObjectName(u'authorsEditButton') - self.authorsButtonsLayout.addWidget(self.authorsEditButton) - self.authorsDeleteButton = QtGui.QPushButton(self.authorsPage) - self.authorsDeleteButton.setIcon(build_icon(u':/songs/author_delete.png')) - self.authorsDeleteButton.setObjectName(u'authorsDeleteButton') - self.authorsButtonsLayout.addWidget(self.authorsDeleteButton) - self.authorsLayout.addLayout(self.authorsButtonsLayout) - self.stackedLayout.addWidget(self.authorsPage) - # topics page - self.topicsPage = QtGui.QWidget(songMaintenanceDialog) - self.topicsPage.setObjectName(u'topicsPage') - self.topicsLayout = QtGui.QVBoxLayout(self.topicsPage) - self.topicsLayout.setObjectName(u'topics_layout') - self.topicsListWidget = QtGui.QListWidget(self.topicsPage) - self.topicsListWidget.setObjectName(u'topicsListWidget') - self.topicsLayout.addWidget(self.topicsListWidget) - self.topicsButtonsLayout = QtGui.QHBoxLayout() - self.topicsButtonsLayout.setObjectName(u'topicsButtonLayout') - self.topicsButtonsLayout.addStretch() - self.topicsAddButton = QtGui.QPushButton(self.topicsPage) - self.topicsAddButton.setIcon(build_icon(u':/songs/topic_add.png')) - self.topicsAddButton.setObjectName(u'topicsAddButton') - self.topicsButtonsLayout.addWidget(self.topicsAddButton) - self.topicsEditButton = QtGui.QPushButton(self.topicsPage) - self.topicsEditButton.setIcon(build_icon(u':/songs/topic_edit.png')) - self.topicsEditButton.setObjectName(u'topicsEditButton') - self.topicsButtonsLayout.addWidget(self.topicsEditButton) - self.topicsDeleteButton = QtGui.QPushButton(self.topicsPage) - self.topicsDeleteButton.setIcon(build_icon(u':/songs/topic_delete.png')) - self.topicsDeleteButton.setObjectName(u'topicsDeleteButton') - self.topicsButtonsLayout.addWidget(self.topicsDeleteButton) - self.topicsLayout.addLayout(self.topicsButtonsLayout) - self.stackedLayout.addWidget(self.topicsPage) - # song books page - self.booksPage = QtGui.QWidget(songMaintenanceDialog) - self.booksPage.setObjectName(u'booksPage') - self.booksLayout = QtGui.QVBoxLayout(self.booksPage) - self.booksLayout.setObjectName(u'booksLayout') - self.booksListWidget = QtGui.QListWidget(self.booksPage) - self.booksListWidget.setObjectName(u'booksListWidget') - self.booksLayout.addWidget(self.booksListWidget) - self.booksButtonsLayout = QtGui.QHBoxLayout() - self.booksButtonsLayout.setObjectName(u'booksButtonLayout') - self.booksButtonsLayout.addStretch() - self.booksAddButton = QtGui.QPushButton(self.booksPage) - self.booksAddButton.setIcon(build_icon(u':/songs/book_add.png')) - self.booksAddButton.setObjectName(u'booksAddButton') - self.booksButtonsLayout.addWidget(self.booksAddButton) - self.booksEditButton = QtGui.QPushButton(self.booksPage) - self.booksEditButton.setIcon(build_icon(u':/songs/book_edit.png')) - self.booksEditButton.setObjectName(u'booksEditButton') - self.booksButtonsLayout.addWidget(self.booksEditButton) - self.booksDeleteButton = QtGui.QPushButton(self.booksPage) - self.booksDeleteButton.setIcon(build_icon(u':/songs/book_delete.png')) - self.booksDeleteButton.setObjectName(u'booksDeleteButton') - self.booksButtonsLayout.addWidget(self.booksDeleteButton) - self.booksLayout.addLayout(self.booksButtonsLayout) - self.stackedLayout.addWidget(self.booksPage) - # - self.dialogLayout.addLayout(self.stackedLayout, 0, 1) - self.button_box = create_button_box(songMaintenanceDialog, u'button_box', [u'close']) - self.dialogLayout.addWidget(self.button_box, 1, 0, 1, 2) - self.retranslateUi(songMaintenanceDialog) - self.stackedLayout.setCurrentIndex(0) - self.typeListWidget.currentRowChanged.connect(self.stackedLayout.setCurrentIndex) - def retranslateUi(self, songMaintenanceDialog): - songMaintenanceDialog.setWindowTitle(SongStrings.SongMaintenance) - self.listItemAuthors.setText(SongStrings.Authors) - self.listItemTopics.setText(SongStrings.Topics) - self.listItemBooks.setText(SongStrings.SongBooks) - self.authorsAddButton.setText(UiStrings().Add) - self.authorsEditButton.setText(UiStrings().Edit) - self.authorsDeleteButton.setText(UiStrings().Delete) - self.topicsAddButton.setText(UiStrings().Add) - self.topicsEditButton.setText(UiStrings().Edit) - self.topicsDeleteButton.setText(UiStrings().Delete) - self.booksAddButton.setText(UiStrings().Add) - self.booksEditButton.setText(UiStrings().Edit) - self.booksDeleteButton.setText(UiStrings().Delete) +class Ui_SongMaintenanceDialog(object): + """ + The user interface for the song maintenance dialog + """ + def setupUi(self, song_maintenance_dialog): + """ + Set up the user interface for the song maintenance dialog + """ + song_maintenance_dialog.setObjectName(u'song_maintenance_dialog') + song_maintenance_dialog.setWindowModality(QtCore.Qt.ApplicationModal) + song_maintenance_dialog.resize(10, 350) + self.dialog_layout = QtGui.QGridLayout(song_maintenance_dialog) + self.dialog_layout.setObjectName(u'dialog_layout') + self.type_list_widget = QtGui.QListWidget(song_maintenance_dialog) + self.type_list_widget.setIconSize(QtCore.QSize(32, 32)) + self.type_list_widget.setUniformItemSizes(True) + self.type_list_widget.setObjectName(u'type_list_widget') + self.authors_list_item = QtGui.QListWidgetItem(self.type_list_widget) + self.authors_list_item.setIcon(build_icon(u':/songs/author_maintenance.png')) + self.topics_list_item = QtGui.QListWidgetItem(self.type_list_widget) + self.topics_list_item.setIcon(build_icon(u':/songs/topic_maintenance.png')) + self.books_list_item = QtGui.QListWidgetItem(self.type_list_widget) + self.books_list_item.setIcon(build_icon(u':/songs/book_maintenance.png')) + self.dialog_layout.addWidget(self.type_list_widget, 0, 0) + self.stacked_layout = QtGui.QStackedLayout() + self.stacked_layout.setObjectName(u'stacked_layout') + # authors page + self.authors_page = QtGui.QWidget(song_maintenance_dialog) + self.authors_page.setObjectName(u'authors_page') + self.authors_layout = QtGui.QVBoxLayout(self.authors_page) + self.authors_layout.setObjectName(u'authors_layout') + self.authors_list_widget = QtGui.QListWidget(self.authors_page) + self.authors_list_widget.setObjectName(u'authors_list_widget') + self.authors_layout.addWidget(self.authors_list_widget) + self.authors_buttons_layout = QtGui.QHBoxLayout() + self.authors_buttons_layout.setObjectName(u'authors_buttons_layout') + self.authors_buttons_layout.addStretch() + self.add_author_button = QtGui.QPushButton(self.authors_page) + self.add_author_button.setIcon(build_icon(u':/songs/author_add.png')) + self.add_author_button.setObjectName(u'add_author_button') + self.authors_buttons_layout.addWidget(self.add_author_button) + self.edit_author_button = QtGui.QPushButton(self.authors_page) + self.edit_author_button.setIcon(build_icon(u':/songs/author_edit.png')) + self.edit_author_button.setObjectName(u'edit_author_button') + self.authors_buttons_layout.addWidget(self.edit_author_button) + self.delete_author_button = QtGui.QPushButton(self.authors_page) + self.delete_author_button.setIcon(build_icon(u':/songs/author_delete.png')) + self.delete_author_button.setObjectName(u'delete_author_button') + self.authors_buttons_layout.addWidget(self.delete_author_button) + self.authors_layout.addLayout(self.authors_buttons_layout) + self.stacked_layout.addWidget(self.authors_page) + # topics page + self.topics_page = QtGui.QWidget(song_maintenance_dialog) + self.topics_page.setObjectName(u'topics_page') + self.topics_layout = QtGui.QVBoxLayout(self.topics_page) + self.topics_layout.setObjectName(u'topics_layout') + self.topics_list_widget = QtGui.QListWidget(self.topics_page) + self.topics_list_widget.setObjectName(u'topics_list_widget') + self.topics_layout.addWidget(self.topics_list_widget) + self.topics_buttons_layout = QtGui.QHBoxLayout() + self.topics_buttons_layout.setObjectName(u'topicsButtonLayout') + self.topics_buttons_layout.addStretch() + self.add_topic_button = QtGui.QPushButton(self.topics_page) + self.add_topic_button.setIcon(build_icon(u':/songs/topic_add.png')) + self.add_topic_button.setObjectName(u'add_topic_button') + self.topics_buttons_layout.addWidget(self.add_topic_button) + self.edit_topic_button = QtGui.QPushButton(self.topics_page) + self.edit_topic_button.setIcon(build_icon(u':/songs/topic_edit.png')) + self.edit_topic_button.setObjectName(u'edit_topic_button') + self.topics_buttons_layout.addWidget(self.edit_topic_button) + self.delete_topic_button = QtGui.QPushButton(self.topics_page) + self.delete_topic_button.setIcon(build_icon(u':/songs/topic_delete.png')) + self.delete_topic_button.setObjectName(u'delete_topic_button') + self.topics_buttons_layout.addWidget(self.delete_topic_button) + self.topics_layout.addLayout(self.topics_buttons_layout) + self.stacked_layout.addWidget(self.topics_page) + # song books page + self.books_page = QtGui.QWidget(song_maintenance_dialog) + self.books_page.setObjectName(u'books_page') + self.books_layout = QtGui.QVBoxLayout(self.books_page) + self.books_layout.setObjectName(u'books_layout') + self.song_books_list_widget = QtGui.QListWidget(self.books_page) + self.song_books_list_widget.setObjectName(u'song_books_list_widget') + self.books_layout.addWidget(self.song_books_list_widget) + self.books_buttons_layout = QtGui.QHBoxLayout() + self.books_buttons_layout.setObjectName(u'booksButtonLayout') + self.books_buttons_layout.addStretch() + self.add_book_button = QtGui.QPushButton(self.books_page) + self.add_book_button.setIcon(build_icon(u':/songs/book_add.png')) + self.add_book_button.setObjectName(u'add_book_button') + self.books_buttons_layout.addWidget(self.add_book_button) + self.edit_book_button = QtGui.QPushButton(self.books_page) + self.edit_book_button.setIcon(build_icon(u':/songs/book_edit.png')) + self.edit_book_button.setObjectName(u'edit_book_button') + self.books_buttons_layout.addWidget(self.edit_book_button) + self.delete_book_button = QtGui.QPushButton(self.books_page) + self.delete_book_button.setIcon(build_icon(u':/songs/book_delete.png')) + self.delete_book_button.setObjectName(u'delete_book_button') + self.books_buttons_layout.addWidget(self.delete_book_button) + self.books_layout.addLayout(self.books_buttons_layout) + self.stacked_layout.addWidget(self.books_page) + # + self.dialog_layout.addLayout(self.stacked_layout, 0, 1) + self.button_box = create_button_box(song_maintenance_dialog, u'button_box', [u'close']) + self.dialog_layout.addWidget(self.button_box, 1, 0, 1, 2) + self.retranslateUi(song_maintenance_dialog) + self.stacked_layout.setCurrentIndex(0) + self.type_list_widget.currentRowChanged.connect(self.stacked_layout.setCurrentIndex) + + def retranslateUi(self, song_maintenance_dialog): + """ + Translate the UI on the fly. + """ + song_maintenance_dialog.setWindowTitle(SongStrings.SongMaintenance) + self.authors_list_item.setText(SongStrings.Authors) + self.topics_list_item.setText(SongStrings.Topics) + self.books_list_item.setText(SongStrings.SongBooks) + self.add_author_button.setText(UiStrings().Add) + self.edit_author_button.setText(UiStrings().Edit) + self.delete_author_button.setText(UiStrings().Delete) + self.add_topic_button.setText(UiStrings().Add) + self.edit_topic_button.setText(UiStrings().Edit) + self.delete_topic_button.setText(UiStrings().Delete) + self.add_book_button.setText(UiStrings().Add) + self.edit_book_button.setText(UiStrings().Edit) + self.delete_book_button.setText(UiStrings().Delete) typeListWidth = max(self.fontMetrics().width(SongStrings.Authors), self.fontMetrics().width(SongStrings.Topics), self.fontMetrics().width(SongStrings.SongBooks)) - self.typeListWidget.setFixedWidth(typeListWidth + self.typeListWidget.iconSize().width() + 32) + self.type_list_widget.setFixedWidth(typeListWidth + self.type_list_widget.iconSize().width() + 32) diff --git a/openlp/plugins/songs/forms/songmaintenanceform.py b/openlp/plugins/songs/forms/songmaintenanceform.py index e02d4794d..9f003b2a0 100644 --- a/openlp/plugins/songs/forms/songmaintenanceform.py +++ b/openlp/plugins/songs/forms/songmaintenanceform.py @@ -53,47 +53,47 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): super(SongMaintenanceForm, self).__init__(parent) self.setupUi(self) self.manager = manager - self.authorform = AuthorsForm(self) - self.topicform = TopicsForm(self) - self.bookform = SongBookForm(self) + self.author_form = AuthorsForm(self) + self.topic_form = TopicsForm(self) + self.song_book_form = SongBookForm(self) # Disable all edit and delete buttons, as there is no row selected. - self.authorsDeleteButton.setEnabled(False) - self.authorsEditButton.setEnabled(False) - self.topicsDeleteButton.setEnabled(False) - self.topicsEditButton.setEnabled(False) - self.booksDeleteButton.setEnabled(False) - self.booksEditButton.setEnabled(False) + self.delete_author_button.setEnabled(False) + self.edit_author_button.setEnabled(False) + self.delete_topic_button.setEnabled(False) + self.edit_topic_button.setEnabled(False) + self.delete_book_button.setEnabled(False) + self.edit_book_button.setEnabled(False) # Signals - self.authorsAddButton.clicked.connect(self.onAuthorAddButtonClicked) - self.topicsAddButton.clicked.connect(self.onTopicAddButtonClicked) - self.booksAddButton.clicked.connect(self.onBookAddButtonClicked) - self.authorsEditButton.clicked.connect(self.onAuthorEditButtonClicked) - self.topicsEditButton.clicked.connect(self.onTopicEditButtonClicked) - self.booksEditButton.clicked.connect(self.onBookEditButtonClicked) - self.authorsDeleteButton.clicked.connect(self.onAuthorDeleteButtonClicked) - self.topicsDeleteButton.clicked.connect(self.onTopicDeleteButtonClicked) - self.booksDeleteButton.clicked.connect(self.onBookDeleteButtonClicked) - self.authorsListWidget.currentRowChanged.connect(self.onAuthorsListRowChanged) - self.topicsListWidget.currentRowChanged.connect(self.onTopicsListRowChanged) - self.booksListWidget.currentRowChanged.connect(self.onBooksListRowChanged) + self.add_author_button.clicked.connect(self.on_add_author_button_clicked) + self.add_topic_button.clicked.connect(self.on_add_topic_button_clicked) + self.add_book_button.clicked.connect(self.on_add_book_button_clicked) + self.edit_author_button.clicked.connect(self.on_edit_author_button_clicked) + self.edit_topic_button.clicked.connect(self.on_edit_topic_button_clicked) + self.edit_book_button.clicked.connect(self.on_edit_book_button_clicked) + self.delete_author_button.clicked.connect(self.on_delete_author_button_clicked) + self.delete_topic_button.clicked.connect(self.on_delete_topic_button_clicked) + self.delete_book_button.clicked.connect(self.on_delete_book_button_clicked) + self.authors_list_widget.currentRowChanged.connect(self.on_authors_list_row_changed) + self.topics_list_widget.currentRowChanged.connect(self.on_topics_list_row_changed) + self.song_books_list_widget.currentRowChanged.connect(self.on_song_books_list_row_changed) - def exec_(self, fromSongEdit=False): + def exec_(self, from_song_edit=False): """ Show the dialog. - ``fromSongEdit`` + ``from_song_edit`` Indicates if the maintenance dialog has been opened from song edit or from the media manager. Defaults to **False**. """ - self.fromSongEdit = fromSongEdit - self.typeListWidget.setCurrentRow(0) - self.resetAuthors() - self.resetTopics() - self.resetBooks() - self.typeListWidget.setFocus() + self.from_song_edit = from_song_edit + self.type_list_widget.setCurrentRow(0) + self.reset_authors() + self.reset_topics() + self.reset_song_books() + self.type_list_widget.setFocus() return QtGui.QDialog.exec_(self) - def _getCurrentItemId(self, list_widget): + def _get_current_item_id(self, list_widget): """ Get the ID of the currently selected item. @@ -107,27 +107,27 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): else: return -1 - def _deleteItem(self, itemClass, listWidget, resetFunc, dlgTitle, del_text, err_text): + def _delete_item(self, item_class, list_widget, reset_func, dlg_title, del_text, err_text): """ Delete an item. """ - item_id = self._getCurrentItemId(listWidget) + item_id = self._get_current_item_id(list_widget) if item_id != -1: - item = self.manager.get_object(itemClass, item_id) + item = self.manager.get_object(item_class, item_id) if item and not item.songs: - if critical_error_message_box(dlgTitle, del_text, self, True) == QtGui.QMessageBox.Yes: - self.manager.delete_object(itemClass, item.id) - resetFunc() + if critical_error_message_box(dlg_title, del_text, self, True) == QtGui.QMessageBox.Yes: + self.manager.delete_object(item_class, item.id) + reset_func() else: - critical_error_message_box(dlgTitle, err_text) + critical_error_message_box(dlg_title, err_text) else: - critical_error_message_box(dlgTitle, UiStrings().NISs) + critical_error_message_box(dlg_title, UiStrings().NISs) - def resetAuthors(self): + def reset_authors(self): """ Reloads the Authors list. """ - self.authorsListWidget.clear() + self.authors_list_widget.clear() authors = self.manager.get_all_objects(Author, order_by_ref=Author.display_name) for author in authors: if author.display_name: @@ -135,68 +135,72 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): else: author_name = QtGui.QListWidgetItem(u' '.join([author.first_name, author.last_name])) author_name.setData(QtCore.Qt.UserRole, author.id) - self.authorsListWidget.addItem(author_name) + self.authors_list_widget.addItem(author_name) - def resetTopics(self): + def reset_topics(self): """ Reloads the Topics list. """ - self.topicsListWidget.clear() + self.topics_list_widget.clear() topics = self.manager.get_all_objects(Topic, order_by_ref=Topic.name) for topic in topics: topic_name = QtGui.QListWidgetItem(topic.name) topic_name.setData(QtCore.Qt.UserRole, topic.id) - self.topicsListWidget.addItem(topic_name) + self.topics_list_widget.addItem(topic_name) - def resetBooks(self): + def reset_song_books(self): """ Reloads the Books list. """ - self.booksListWidget.clear() + self.song_books_list_widget.clear() books = self.manager.get_all_objects(Book, order_by_ref=Book.name) for book in books: book_name = QtGui.QListWidgetItem(u'%s (%s)' % (book.name, book.publisher)) book_name.setData(QtCore.Qt.UserRole, book.id) - self.booksListWidget.addItem(book_name) + self.song_books_list_widget.addItem(book_name) - def checkAuthor(self, newAuthor, edit=False): + def check_author_exists(self, new_author, edit=False): """ Returns *False* if the given Author already exists, otherwise *True*. """ - authors = self.manager.get_all_objects(Author, - and_(Author.first_name == newAuthor.first_name, - Author.last_name == newAuthor.last_name, - Author.display_name == newAuthor.display_name)) - return self.__checkObject(authors, newAuthor, edit) + authors = self.manager.get_all_objects( + Author, + and_( + Author.first_name == new_author.first_name, + Author.last_name == new_author.last_name, + Author.display_name == new_author.display_name + ) + ) + return self.__check_object_exists(authors, new_author, edit) - def checkTopic(self, newTopic, edit=False): + def check_topic_exists(self, new_topic, edit=False): """ Returns *False* if the given Topic already exists, otherwise *True*. """ - topics = self.manager.get_all_objects(Topic, Topic.name == newTopic.name) - return self.__checkObject(topics, newTopic, edit) + topics = self.manager.get_all_objects(Topic, Topic.name == new_topic.name) + return self.__check_object_exists(topics, new_topic, edit) - def checkBook(self, newBook, edit=False): + def check_song_book_exists(self, new_book, edit=False): """ Returns *False* if the given Topic already exists, otherwise *True*. """ books = self.manager.get_all_objects(Book, - and_(Book.name == newBook.name, Book.publisher == newBook.publisher)) - return self.__checkObject(books, newBook, edit) + and_(Book.name == new_book.name, Book.publisher == new_book.publisher)) + return self.__check_object_exists(books, new_book, edit) - def __checkObject(self, objects, newObject, edit): + def __check_object_exists(self, existing_objects, new_object, edit): """ Utility method to check for an existing object. ``edit`` If we edit an item, this should be *True*. """ - if objects: + if existing_objects: # If we edit an existing object, we need to make sure that we do # not return False when nothing has changed. if edit: - for object in objects: - if object.id != newObject.id: + for existing_object in existing_objects: + if existing_object.id != new_object.id: return False return True else: @@ -204,20 +208,20 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): else: return True - def onAuthorAddButtonClicked(self): + def on_add_author_button_clicked(self): """ Add an author to the list. """ - self.authorform.auto_display_name = True - if self.authorform.exec_(): + self.author_form.auto_display_name = True + if self.author_form.exec_(): author = Author.populate( - first_name=self.authorform.first_name, - last_name=self.authorform.last_name, - display_name=self.authorform.display_name + first_name=self.author_form.first_name, + last_name=self.author_form.last_name, + display_name=self.author_form.display_name ) - if self.checkAuthor(author): + if self.check_author_exists(author): if self.manager.save_object(author): - self.resetAuthors() + self.reset_authors() else: critical_error_message_box( message=translate('SongsPlugin.SongMaintenanceForm', 'Could not add your author.')) @@ -225,15 +229,15 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): critical_error_message_box( message=translate('SongsPlugin.SongMaintenanceForm', 'This author already exists.')) - def onTopicAddButtonClicked(self): + def on_add_topic_button_clicked(self): """ Add a topic to the list. """ - if self.topicform.exec_(): - topic = Topic.populate(name=self.topicform.nameEdit.text()) - if self.checkTopic(topic): + if self.topic_form.exec_(): + topic = Topic.populate(name=self.topic_form.name) + if self.check_topic_exists(topic): if self.manager.save_object(topic): - self.resetTopics() + self.reset_topics() else: critical_error_message_box( message=translate('SongsPlugin.SongMaintenanceForm', 'Could not add your topic.')) @@ -241,16 +245,16 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): critical_error_message_box( message=translate('SongsPlugin.SongMaintenanceForm', 'This topic already exists.')) - def onBookAddButtonClicked(self): + def on_add_book_button_clicked(self): """ Add a book to the list. """ - if self.bookform.exec_(): - book = Book.populate(name=self.bookform.nameEdit.text(), - publisher=self.bookform.publisherEdit.text()) - if self.checkBook(book): + if self.song_book_form.exec_(): + book = Book.populate(name=self.song_book_form.name_edit.text(), + publisher=self.song_book_form.publisher_edit.text()) + if self.check_song_book_exists(book): if self.manager.save_object(book): - self.resetBooks() + self.reset_song_books() else: critical_error_message_box( message=translate('SongsPlugin.SongMaintenanceForm', 'Could not add your book.')) @@ -258,31 +262,31 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): critical_error_message_box( message=translate('SongsPlugin.SongMaintenanceForm', 'This book already exists.')) - def onAuthorEditButtonClicked(self): + def on_edit_author_button_clicked(self): """ Edit an author. """ - author_id = self._getCurrentItemId(self.authorsListWidget) + author_id = self._get_current_item_id(self.authors_list_widget) if author_id == -1: return author = self.manager.get_object(Author, author_id) - self.authorform.auto_display_name = False - self.authorform.first_name_edit.setText(author.first_name) - self.authorform.last_name_edit.setText(author.last_name) - self.authorform.display_edit.setText(author.display_name) + self.author_form.auto_display_name = False + self.author_form.first_name_edit.setText(author.first_name) + self.author_form.last_name_edit.setText(author.last_name) + self.author_form.display_edit.setText(author.display_name) # Save the author's first and last name as well as the display name # for the case that they have to be restored. temp_first_name = author.first_name temp_last_name = author.last_name temp_display_name = author.display_name - if self.authorform.exec_(False): - author.first_name = self.authorform.first_name_edit.text() - author.last_name = self.authorform.last_name_edit.text() - author.display_name = self.authorform.display_edit.text() - if self.checkAuthor(author, True): + if self.author_form.exec_(False): + author.first_name = self.author_form.first_name_edit.text() + author.last_name = self.author_form.last_name_edit.text() + author.display_name = self.author_form.display_edit.text() + if self.check_author_exists(author, True): if self.manager.save_object(author): - self.resetAuthors() - if not self.fromSongEdit: + self.reset_authors() + if not self.from_song_edit: Registry().execute(u'songs_load_list') else: critical_error_message_box( @@ -292,8 +296,8 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): 'author %s use the existing author %s?') % (author.display_name, temp_display_name, author.display_name), parent=self, question=True) == \ QtGui.QMessageBox.Yes: - self.__mergeObjects(author, self.mergeAuthors, - self.resetAuthors) + self._merge_objects(author, self.merge_authors, + self.reset_authors) else: # We restore the author's old first and last name as well as # his display name. @@ -302,24 +306,24 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): author.display_name = temp_display_name critical_error_message_box( message=translate('SongsPlugin.SongMaintenanceForm', - 'Could not save your modified author, because the author already exists.')) + 'Could not save your modified author, because the author already exists.')) - def onTopicEditButtonClicked(self): + def on_edit_topic_button_clicked(self): """ Edit a topic. """ - topic_id = self._getCurrentItemId(self.topicsListWidget) + topic_id = self._get_current_item_id(self.topics_list_widget) if topic_id == -1: return topic = self.manager.get_object(Topic, topic_id) - self.topicform.nameEdit.setText(topic.name) + self.topic_form.name = topic.name # Save the topic's name for the case that he has to be restored. temp_name = topic.name - if self.topicform.exec_(False): - topic.name = self.topicform.nameEdit.text() - if self.checkTopic(topic, True): + if self.topic_form.exec_(False): + topic.name = self.topic_form.name_edit.text() + if self.check_topic_exists(topic, True): if self.manager.save_object(topic): - self.resetTopics() + self.reset_topics() else: critical_error_message_box( message=translate('SongsPlugin.SongMaintenanceForm', 'Could not save your changes.')) @@ -327,7 +331,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): message=translate('SongsPlugin.SongMaintenanceForm', 'The topic %s already exists. Would you like to make songs with topic %s use the existing topic %s?') % (topic.name, temp_name, topic.name), parent=self, question=True) == QtGui.QMessageBox.Yes: - self.__mergeObjects(topic, self.mergeTopics, self.resetTopics) + self._merge_objects(topic, self.merge_topics, self.reset_topics) else: # We restore the topics's old name. topic.name = temp_name @@ -335,28 +339,28 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): message=translate('SongsPlugin.SongMaintenanceForm', 'Could not save your modified topic, because it already exists.')) - def onBookEditButtonClicked(self): + def on_edit_book_button_clicked(self): """ Edit a book. """ - book_id = self._getCurrentItemId(self.booksListWidget) + book_id = self._get_current_item_id(self.song_books_list_widget) if book_id == -1: return book = self.manager.get_object(Book, book_id) if book.publisher is None: book.publisher = u'' - self.bookform.nameEdit.setText(book.name) - self.bookform.publisherEdit.setText(book.publisher) + self.song_book_form.name_edit.setText(book.name) + self.song_book_form.publisher_edit.setText(book.publisher) # Save the book's name and publisher for the case that they have to # be restored. temp_name = book.name temp_publisher = book.publisher - if self.bookform.exec_(False): - book.name = self.bookform.nameEdit.text() - book.publisher = self.bookform.publisherEdit.text() - if self.checkBook(book, True): + if self.song_book_form.exec_(False): + book.name = self.song_book_form.name_edit.text() + book.publisher = self.song_book_form.publisher_edit.text() + if self.check_song_book_exists(book, True): if self.manager.save_object(book): - self.resetBooks() + self.reset_song_books() else: critical_error_message_box( message=translate('SongsPlugin.SongMaintenanceForm', 'Could not save your changes.')) @@ -364,138 +368,148 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): message=translate('SongsPlugin.SongMaintenanceForm', 'The book %s already exists. Would you like to make songs with book %s use the existing book %s?') % (book.name, temp_name, book.name), parent=self, question=True) == QtGui.QMessageBox.Yes: - self.__mergeObjects(book, self.mergeBooks, self.resetBooks) + self._merge_objects(book, self.merge_song_books, self.reset_song_books) else: # We restore the book's old name and publisher. book.name = temp_name book.publisher = temp_publisher - def __mergeObjects(self, dbObject, merge, reset): + def _merge_objects(self, db_object, merge, reset): """ Utility method to merge two objects to leave one in the database. """ self.application.set_busy_cursor() - merge(dbObject) + merge(db_object) reset() - if not self.fromSongEdit: + if not self.from_song_edit: Registry().execute(u'songs_load_list') self.application.set_normal_cursor() - def mergeAuthors(self, oldAuthor): + def merge_authors(self, old_author): """ Merges two authors into one author. - ``oldAuthor`` + ``old_author`` The object, which was edited, that will be deleted """ # Find the duplicate. - existing_author = self.manager.get_object_filtered(Author, - and_(Author.first_name == oldAuthor.first_name, - Author.last_name == oldAuthor.last_name, - Author.display_name == oldAuthor.display_name, - Author.id != oldAuthor.id)) - # Find the songs, which have the oldAuthor as author. - songs = self.manager.get_all_objects(Song, - Song.authors.contains(oldAuthor)) + existing_author = self.manager.get_object_filtered( + Author, + and_( + Author.first_name == old_author.first_name, + Author.last_name == old_author.last_name, + Author.display_name == old_author.display_name, + Author.id != old_author.id + ) + ) + # Find the songs, which have the old_author as author. + songs = self.manager.get_all_objects(Song, Song.authors.contains(old_author)) for song in songs: # We check if the song has already existing_author as author. If # that is not the case we add it. if existing_author not in song.authors: song.authors.append(existing_author) - song.authors.remove(oldAuthor) + song.authors.remove(old_author) self.manager.save_object(song) - self.manager.delete_object(Author, oldAuthor.id) + self.manager.delete_object(Author, old_author.id) - def mergeTopics(self, oldTopic): + def merge_topics(self, old_topic): """ Merges two topics into one topic. - ``oldTopic`` + ``old_topic`` The object, which was edited, that will be deleted """ # Find the duplicate. - existing_topic = self.manager.get_object_filtered(Topic, - and_(Topic.name == oldTopic.name, Topic.id != oldTopic.id)) - # Find the songs, which have the oldTopic as topic. - songs = self.manager.get_all_objects(Song, Song.topics.contains(oldTopic)) + existing_topic = self.manager.get_object_filtered( + Topic, + and_( + Topic.name == old_topic.name, Topic.id != old_topic.id + ) + ) + # Find the songs, which have the old_topic as topic. + songs = self.manager.get_all_objects(Song, Song.topics.contains(old_topic)) for song in songs: # We check if the song has already existing_topic as topic. If that # is not the case we add it. if existing_topic not in song.topics: song.topics.append(existing_topic) - song.topics.remove(oldTopic) + song.topics.remove(old_topic) self.manager.save_object(song) - self.manager.delete_object(Topic, oldTopic.id) + self.manager.delete_object(Topic, old_topic.id) - def mergeBooks(self, oldBook): + def merge_song_books(self, old_song_book): """ Merges two books into one book. - ``oldBook`` + ``old_song_book`` The object, which was edited, that will be deleted """ # Find the duplicate. - existing_book = self.manager.get_object_filtered(Book, - and_(Book.name == oldBook.name, - Book.publisher == oldBook.publisher, - Book.id != oldBook.id)) - # Find the songs, which have the oldBook as book. - songs = self.manager.get_all_objects(Song, - Song.song_book_id == oldBook.id) + existing_book = self.manager.get_object_filtered( + Book, + and_( + Book.name == old_song_book.name, + Book.publisher == old_song_book.publisher, + Book.id != old_song_book.id + ) + ) + # Find the songs, which have the old_song_book as book. + songs = self.manager.get_all_objects(Song, Song.song_book_id == old_song_book.id) for song in songs: song.song_book_id = existing_book.id self.manager.save_object(song) - self.manager.delete_object(Book, oldBook.id) + self.manager.delete_object(Book, old_song_book.id) - def onAuthorDeleteButtonClicked(self): + def on_delete_author_button_clicked(self): """ Delete the author if the author is not attached to any songs. """ - self._deleteItem(Author, self.authorsListWidget, self.resetAuthors, + self._delete_item(Author, self.authors_list_widget, self.reset_authors, translate('SongsPlugin.SongMaintenanceForm', 'Delete Author'), translate('SongsPlugin.SongMaintenanceForm', 'Are you sure you want to delete the selected author?'), translate('SongsPlugin.SongMaintenanceForm', 'This author cannot be deleted, they are currently assigned to at least one song.')) - def onTopicDeleteButtonClicked(self): + def on_delete_topic_button_clicked(self): """ Delete the Book if the Book is not attached to any songs. """ - self._deleteItem(Topic, self.topicsListWidget, self.resetTopics, + self._delete_item(Topic, self.topics_list_widget, self.reset_topics, translate('SongsPlugin.SongMaintenanceForm', 'Delete Topic'), translate('SongsPlugin.SongMaintenanceForm', 'Are you sure you want to delete the selected topic?'), translate('SongsPlugin.SongMaintenanceForm', 'This topic cannot be deleted, it is currently assigned to at least one song.')) - def onBookDeleteButtonClicked(self): + def on_delete_book_button_clicked(self): """ Delete the Book if the Book is not attached to any songs. """ - self._deleteItem(Book, self.booksListWidget, self.resetBooks, + self._delete_item(Book, self.song_books_list_widget, self.reset_song_books, translate('SongsPlugin.SongMaintenanceForm', 'Delete Book'), translate('SongsPlugin.SongMaintenanceForm', 'Are you sure you want to delete the selected book?'), translate('SongsPlugin.SongMaintenanceForm', 'This book cannot be deleted, it is currently assigned to at least one song.')) - def onAuthorsListRowChanged(self, row): + def on_authors_list_row_changed(self, row): """ - Called when the *authorsListWidget*'s current row has changed. + Called when the *authors_list_widget*'s current row has changed. """ - self.__rowChange(row, self.authorsEditButton, self.authorsDeleteButton) + self._row_change(row, self.edit_author_button, self.delete_author_button) - def onTopicsListRowChanged(self, row): + def on_topics_list_row_changed(self, row): """ - Called when the *topicsListWidget*'s current row has changed. + Called when the *topics_list_widget*'s current row has changed. """ - self.__rowChange(row, self.topicsEditButton, self.topicsDeleteButton) + self._row_change(row, self.edit_topic_button, self.delete_topic_button) - def onBooksListRowChanged(self, row): + def on_song_books_list_row_changed(self, row): """ - Called when the *booksListWidget*'s current row has changed. + Called when the *song_books_list_widget*'s current row has changed. """ - self.__rowChange(row, self.booksEditButton, self.booksDeleteButton) + self._row_change(row, self.edit_book_button, self.delete_book_button) - def __rowChange(self, row, editButton, deleteButton): + def _row_change(self, row, edit_button, delete_button): """ Utility method to toggle if buttons are enabled. @@ -503,15 +517,15 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog): The current row. If there is no current row, the value is -1. """ if row == -1: - deleteButton.setEnabled(False) - editButton.setEnabled(False) + delete_button.setEnabled(False) + edit_button.setEnabled(False) else: - deleteButton.setEnabled(True) - editButton.setEnabled(True) + delete_button.setEnabled(True) + edit_button.setEnabled(True) def _get_application(self): """ - Adds the openlp to the class dynamically + Adds the application to the class dynamically """ if not hasattr(self, u'_application'): self._application = Registry().get(u'application') diff --git a/openlp/plugins/songs/forms/topicsdialog.py b/openlp/plugins/songs/forms/topicsdialog.py index 9b1a8c11c..d7997cd14 100644 --- a/openlp/plugins/songs/forms/topicsdialog.py +++ b/openlp/plugins/songs/forms/topicsdialog.py @@ -32,26 +32,36 @@ from PyQt4 import QtGui from openlp.core.lib import translate from openlp.core.lib.ui import create_button_box -class Ui_TopicsDialog(object): - def setupUi(self, topicsDialog): - topicsDialog.setObjectName(u'topicsDialog') - topicsDialog.resize(300, 10) - self.dialogLayout = QtGui.QVBoxLayout(topicsDialog) - self.dialogLayout.setObjectName(u'dialog_layout') - self.nameLayout = QtGui.QFormLayout() - self.nameLayout.setObjectName(u'nameLayout') - self.nameLabel = QtGui.QLabel(topicsDialog) - self.nameLabel.setObjectName(u'nameLabel') - self.nameEdit = QtGui.QLineEdit(topicsDialog) - self.nameEdit.setObjectName(u'nameEdit') - self.nameLabel.setBuddy(self.nameEdit) - self.nameLayout.addRow(self.nameLabel, self.nameEdit) - self.dialogLayout.addLayout(self.nameLayout) - self.button_box = create_button_box(topicsDialog, u'button_box', [u'cancel', u'save']) - self.dialogLayout.addWidget(self.button_box) - self.retranslateUi(topicsDialog) - topicsDialog.setMaximumHeight(topicsDialog.sizeHint().height()) - def retranslateUi(self, topicsDialog): - topicsDialog.setWindowTitle(translate('SongsPlugin.TopicsForm', 'Topic Maintenance')) - self.nameLabel.setText(translate('SongsPlugin.TopicsForm', 'Topic name:')) +class Ui_TopicsDialog(object): + """ + The user interface for the topics dialog. + """ + def setupUi(self, topics_dialog): + """ + Set up the user interface for the topics dialog. + """ + topics_dialog.setObjectName(u'topics_dialog') + topics_dialog.resize(300, 10) + self.dialog_layout = QtGui.QVBoxLayout(topics_dialog) + self.dialog_layout.setObjectName(u'dialog_layout') + self.name_layout = QtGui.QFormLayout() + self.name_layout.setObjectName(u'name_layout') + self.name_label = QtGui.QLabel(topics_dialog) + self.name_label.setObjectName(u'name_label') + self.name_edit = QtGui.QLineEdit(topics_dialog) + self.name_edit.setObjectName(u'name_edit') + self.name_label.setBuddy(self.name_edit) + self.name_layout.addRow(self.name_label, self.name_edit) + self.dialog_layout.addLayout(self.name_layout) + self.button_box = create_button_box(topics_dialog, u'button_box', [u'cancel', u'save']) + self.dialog_layout.addWidget(self.button_box) + self.retranslateUi(topics_dialog) + topics_dialog.setMaximumHeight(topics_dialog.sizeHint().height()) + + def retranslateUi(self, topics_dialog): + """ + Translate the UI on the fly. + """ + topics_dialog.setWindowTitle(translate('SongsPlugin.TopicsForm', 'Topic Maintenance')) + self.name_label.setText(translate('SongsPlugin.TopicsForm', 'Topic name:')) diff --git a/openlp/plugins/songs/forms/topicsform.py b/openlp/plugins/songs/forms/topicsform.py index 3a9fcfb25..f936f6618 100644 --- a/openlp/plugins/songs/forms/topicsform.py +++ b/openlp/plugins/songs/forms/topicsform.py @@ -53,18 +53,32 @@ class TopicsForm(QtGui.QDialog, Ui_TopicsDialog): Execute the dialog. """ if clear: - self.nameEdit.clear() - self.nameEdit.setFocus() + self.name_edit.clear() + self.name_edit.setFocus() return QtGui.QDialog.exec_(self) def accept(self): """ Override the inherited method to check before we close. """ - if not self.nameEdit.text(): + if not self.name_edit.text(): critical_error_message_box(message=translate('SongsPlugin.TopicsForm', 'You need to type in a topic name.')) - self.nameEdit.setFocus() + self.name_edit.setFocus() return False else: return QtGui.QDialog.accept(self) + + def _get_name(self): + """ + Return the name of the topic. + """ + return self.name_edit.text() + + def _set_name(self, value): + """ + Set the topic name. + """ + self.name_edit.setText(value) + + name = property(_get_name, _set_name) diff --git a/tests/interfaces/__init__.py b/tests/interfaces/__init__.py index f14948f08..fa4fdcb2f 100644 --- a/tests/interfaces/__init__.py +++ b/tests/interfaces/__init__.py @@ -7,7 +7,7 @@ sip.setapi(u'QTime', 2) sip.setapi(u'QUrl', 2) sip.setapi(u'QVariant', 2) -from PyQt4 import QtGui +#from PyQt4 import QtGui # Only one QApplication can be created. Use QtGui.QApplication.instance() when you need to "create" an QApplication. -application = QtGui.QApplication([]) +#application = QtGui.QApplication([]) diff --git a/tests/interfaces/openlp_core_lib/test_pluginmanager.py b/tests/interfaces/openlp_core_lib/test_pluginmanager.py index 32493ae12..189c36c70 100644 --- a/tests/interfaces/openlp_core_lib/test_pluginmanager.py +++ b/tests/interfaces/openlp_core_lib/test_pluginmanager.py @@ -29,7 +29,7 @@ class TestPluginManager(TestCase): Settings().setValue(u'advanced/data path', self.temp_dir) Registry.create() Registry().register(u'service_list', MagicMock()) - self.app = QtGui.QApplication.instance() + self.app = QtGui.QApplication([]) self.main_window = QtGui.QMainWindow() Registry().register(u'main_window', self.main_window) diff --git a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py index fe34c1431..cca26ca19 100644 --- a/tests/interfaces/openlp_core_ui/test_filerenamedialog.py +++ b/tests/interfaces/openlp_core_ui/test_filerenamedialog.py @@ -16,7 +16,7 @@ class TestStartFileRenameForm(TestCase): Create the UI """ Registry.create() - self.app = QtGui.QApplication.instance() + self.app = QtGui.QApplication([]) self.main_window = QtGui.QMainWindow() Registry().register(u'main_window', self.main_window) self.form = filerenameform.FileRenameForm() diff --git a/tests/interfaces/openlp_core_ui/test_servicemanager.py b/tests/interfaces/openlp_core_ui/test_servicemanager.py index db161022b..4e309e889 100644 --- a/tests/interfaces/openlp_core_ui/test_servicemanager.py +++ b/tests/interfaces/openlp_core_ui/test_servicemanager.py @@ -18,7 +18,7 @@ class TestServiceManager(TestCase): Create the UI """ Registry.create() - self.app = QtGui.QApplication.instance() + self.app = QtGui.QApplication([]) ScreenList.create(self.app.desktop()) Registry().register(u'application', MagicMock()) with patch(u'openlp.core.lib.PluginManager'): diff --git a/tests/interfaces/openlp_core_ui/test_servicenotedialog.py b/tests/interfaces/openlp_core_ui/test_servicenotedialog.py index 5a305b79c..a62d26d14 100644 --- a/tests/interfaces/openlp_core_ui/test_servicenotedialog.py +++ b/tests/interfaces/openlp_core_ui/test_servicenotedialog.py @@ -18,7 +18,7 @@ class TestStartNoteDialog(TestCase): Create the UI """ Registry.create() - self.app = QtGui.QApplication.instance() + self.app = QtGui.QApplication([]) self.main_window = QtGui.QMainWindow() Registry().register(u'main_window', self.main_window) self.form = servicenoteform.ServiceNoteForm() diff --git a/tests/interfaces/openlp_core_ui/test_starttimedialog.py b/tests/interfaces/openlp_core_ui/test_starttimedialog.py index e096b46a5..e23225060 100644 --- a/tests/interfaces/openlp_core_ui/test_starttimedialog.py +++ b/tests/interfaces/openlp_core_ui/test_starttimedialog.py @@ -18,7 +18,7 @@ class TestStartTimeDialog(TestCase): Create the UI """ Registry.create() - self.app = QtGui.QApplication.instance() + self.app = QtGui.QApplication([]) self.main_window = QtGui.QMainWindow() Registry().register(u'main_window', self.main_window) self.form = starttimeform.StartTimeForm() diff --git a/tests/interfaces/openlp_plugins_songs_forms/test_authorsform.py b/tests/interfaces/openlp_plugins_songs_forms/test_authorsform.py index 48141ce24..389323d8f 100644 --- a/tests/interfaces/openlp_plugins_songs_forms/test_authorsform.py +++ b/tests/interfaces/openlp_plugins_songs_forms/test_authorsform.py @@ -10,13 +10,16 @@ from openlp.plugins.songs.forms.authorsform import AuthorsForm class TestAuthorsForm(TestCase): + """ + Test the AuthorsForm class + """ def setUp(self): """ Create the UI """ Registry.create() - self.app = QtGui.QApplication.instance() + self.app = QtGui.QApplication([]) self.main_window = QtGui.QMainWindow() Registry().register(u'main_window', self.main_window) self.form = AuthorsForm() diff --git a/tests/interfaces/openlp_plugins_songs_forms/test_editsongform.py b/tests/interfaces/openlp_plugins_songs_forms/test_editsongform.py index a84eb6e67..307fd9803 100644 --- a/tests/interfaces/openlp_plugins_songs_forms/test_editsongform.py +++ b/tests/interfaces/openlp_plugins_songs_forms/test_editsongform.py @@ -11,12 +11,16 @@ from openlp.plugins.songs.forms.editsongform import EditSongForm class TestEditSongForm(TestCase): + """ + Test the EditSongForm class + """ + def setUp(self): """ Create the UI """ Registry.create() - self.app = QtGui.QApplication.instance() + self.app = QtGui.QApplication([]) self.main_window = QtGui.QMainWindow() Registry().register(u'main_window', self.main_window) Registry().register(u'theme_manager', MagicMock()) diff --git a/tests/interfaces/openlp_plugins_songs_forms/test_editverseform.py b/tests/interfaces/openlp_plugins_songs_forms/test_editverseform.py index 403808841..b0510bc52 100644 --- a/tests/interfaces/openlp_plugins_songs_forms/test_editverseform.py +++ b/tests/interfaces/openlp_plugins_songs_forms/test_editverseform.py @@ -8,19 +8,18 @@ from PyQt4 import QtCore, QtGui, QtTest from openlp.core.lib import Registry from openlp.plugins.songs.forms.editverseform import EditVerseForm -VERSE_TEXT = u"""The Lord told Noah to build Him an arky arky, -Lord told Noah to build Him an arky arky, -Build it out of gopher barky barky, -Children of the Lord.""" - class TestEditVerseForm(TestCase): + """ + Test the EditVerseForm class + """ + def setUp(self): """ Create the UI """ Registry.create() - self.app = QtGui.QApplication.instance() + self.app = QtGui.QApplication([]) self.main_window = QtGui.QMainWindow() Registry().register(u'main_window', self.main_window) self.form = EditVerseForm() @@ -46,12 +45,14 @@ class TestEditVerseForm(TestCase): """ Test that typing into the verse text edit box returns the correct text """ - # GIVEN: An instance of the EditVerseForm + # GIVEN: An instance of the EditVerseForm and some text to type + text = 'Amazing Grace, how sweet the sound!' + # WHEN: Some verse text is typed into the text edit - QtTest.QTest.keyClicks(self.form.verse_text_edit, VERSE_TEXT) + QtTest.QTest.keyClicks(self.form.verse_text_edit, text) # THEN: The verse text edit should have the verse text in it - self.assertEqual(VERSE_TEXT, self.form.verse_text_edit.toPlainText(), + self.assertEqual(text, self.form.verse_text_edit.toPlainText(), u'The verse text edit should have the typed out verse') def insert_verse_test(self): diff --git a/tests/interfaces/openlp_plugins_songs_forms/test_topicsform.py b/tests/interfaces/openlp_plugins_songs_forms/test_topicsform.py new file mode 100644 index 000000000..0898f027d --- /dev/null +++ b/tests/interfaces/openlp_plugins_songs_forms/test_topicsform.py @@ -0,0 +1,65 @@ +""" +Package to test the openlp.plugins.songs.forms.topicsform package. +""" +from unittest import TestCase + +from PyQt4 import QtGui + +from openlp.core.lib import Registry +from openlp.plugins.songs.forms.topicsform import TopicsForm + + +class TestTopicsForm(TestCase): + """ + Test the TopicsForm class + """ + + 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 = TopicsForm() + + 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 TopicsForm defaults are correct + """ + self.assertEqual(self.form.name_edit.text(), u'', u'The first name edit should be empty') + + def get_name_property_test(self): + """ + Test that getting the name property on the TopicsForm works correctly + """ + # GIVEN: A topic name to set + topic_name = u'Salvation' + + # WHEN: The name_edit's text is set + self.form.name_edit.setText(topic_name) + + # THEN: The name property should have the correct value + self.assertEqual(self.form.name, topic_name, u'The name property should be correct') + + def set_name_property_test(self): + """ + Test that setting the name property on the TopicsForm works correctly + """ + # GIVEN: A topic name to set + topic_name = u'James' + + # WHEN: The name property is set + self.form.name = topic_name + + # THEN: The name_edit should have the correct value + self.assertEqual(self.form.name_edit.text(), topic_name, u'The topic name should be set correctly') From 697639db415d44ca38adce1ee6c9dc3c8cf506e1 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 18 Mar 2013 13:58:52 +0200 Subject: [PATCH 9/9] Fixed up an issue with some tests that arose in the merge from HEAD --- tests/interfaces/openlp_core_ui/test_settings_form.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/interfaces/openlp_core_ui/test_settings_form.py b/tests/interfaces/openlp_core_ui/test_settings_form.py index 09d4a22eb..0d2f496fa 100644 --- a/tests/interfaces/openlp_core_ui/test_settings_form.py +++ b/tests/interfaces/openlp_core_ui/test_settings_form.py @@ -5,7 +5,7 @@ from unittest import TestCase from mock import MagicMock, patch -from PyQt4 import QtCore, QtTest +from PyQt4 import QtCore, QtTest, QtGui from openlp.core.ui import settingsform from openlp.core.lib import Registry, ScreenList @@ -31,6 +31,7 @@ class TestSettingsForm(TestCase): self.dummy2 = MagicMock() self.dummy3 = MagicMock() self.desktop = MagicMock() + self.app = QtGui.QApplication([]) self.desktop.primaryScreen.return_value = SCREEN[u'primary'] self.desktop.screenCount.return_value = SCREEN[u'number'] self.desktop.screenGeometry.return_value = SCREEN[u'size'] @@ -43,6 +44,7 @@ class TestSettingsForm(TestCase): Delete all the C++ objects at the end so that we don't have a segfault """ del self.form + del self.app def basic_cancel_test(self): """