This commit is contained in:
Raoul Snyman 2013-03-18 12:16:50 +02:00
commit a3f1769818
28 changed files with 602 additions and 448 deletions

View File

@ -221,7 +221,7 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
time.sleep(0.2) time.sleep(0.2)
self._preWizard() self._preWizard()
self._performWizard() self._performWizard()
self._postWizard() self._post_wizard()
self.application.set_normal_cursor() self.application.set_normal_cursor()
def update_screen_list_combo(self): 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 # Try to give the wizard a chance to repaint itself
time.sleep(0.1) time.sleep(0.1)
def _postWizard(self): def _post_wizard(self):
""" """
Clean up the UI after the process has finished. Clean up the UI after the process has finished.
""" """

View File

@ -56,7 +56,7 @@ class Ui_SettingsDialog(object):
self.settingListWidget.setObjectName(u'settingListWidget') self.settingListWidget.setObjectName(u'settingListWidget')
self.dialogLayout.addWidget(self.settingListWidget, 0, 0, 1, 1) self.dialogLayout.addWidget(self.settingListWidget, 0, 0, 1, 1)
self.stackedLayout = QtGui.QStackedLayout() 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.dialogLayout.addLayout(self.stackedLayout, 0, 1, 1, 1)
self.button_box = create_button_box(settingsDialog, u'button_box', [u'cancel', u'ok']) self.button_box = create_button_box(settingsDialog, u'button_box', [u'cancel', u'ok'])
self.dialogLayout.addWidget(self.button_box, 1, 1, 1, 1) self.dialogLayout.addWidget(self.button_box, 1, 1, 1, 1)

View File

@ -91,8 +91,8 @@ class OpenLPWizard(QtGui.QWizard):
self.cancel_button = self.button(QtGui.QWizard.CancelButton) self.cancel_button = self.button(QtGui.QWizard.CancelButton)
self.setupUi(image) self.setupUi(image)
self.register_fields() self.register_fields()
self.customInit() self.custom_init()
self.customSignals() self.custom_signals()
self.currentIdChanged.connect(self.on_current_id_changed) self.currentIdChanged.connect(self.on_current_id_changed)
self.error_copy_to_button.clicked.connect(self.on_error_copy_to_button_clicked) 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) 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 | self.setOptions(QtGui.QWizard.IndependentPages |
QtGui.QWizard.NoBackButtonOnStartPage | QtGui.QWizard.NoBackButtonOnLastPage) QtGui.QWizard.NoBackButtonOnStartPage | QtGui.QWizard.NoBackButtonOnLastPage)
add_welcome_page(self, image) add_welcome_page(self, image)
self.addCustomPages() self.add_custom_pages()
self.addProgressPage() self.add_progress_page()
self.retranslateUi() self.retranslateUi()
def register_fields(self): def register_fields(self):
@ -116,7 +116,25 @@ class OpenLPWizard(QtGui.QWizard):
""" """
pass 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 Add the progress page for the wizard. This page informs the user how
the wizard is progressing with its task. the wizard is progressing with its task.
@ -180,7 +198,7 @@ class OpenLPWizard(QtGui.QWizard):
if self.page(pageId) == self.progress_page: if self.page(pageId) == self.progress_page:
self.pre_wizard() self.pre_wizard()
self.performWizard() self.performWizard()
self.postWizard() self.post_wizard()
else: else:
self.custom_cage_changed(pageId) self.custom_cage_changed(pageId)
@ -227,7 +245,7 @@ class OpenLPWizard(QtGui.QWizard):
self.progress_bar.setMaximum(1188) self.progress_bar.setMaximum(1188)
self.progress_bar.setValue(0) self.progress_bar.setValue(0)
def postWizard(self): def post_wizard(self):
""" """
Clean up the UI after the import has finished. Clean up the UI after the import has finished.
""" """

View File

@ -97,7 +97,7 @@ class BibleImportForm(OpenLPWizard):
next_button = self.button(QtGui.QWizard.NextButton) next_button = self.button(QtGui.QWizard.NextButton)
next_button.setEnabled(BibleFormat.get_availability(index)) next_button.setEnabled(BibleFormat.get_availability(index))
def customInit(self): def custom_init(self):
""" """
Perform any custom initialisation for bible importing. Perform any custom initialisation for bible importing.
""" """
@ -112,7 +112,7 @@ class BibleImportForm(OpenLPWizard):
self.restart() self.restart()
self.selectStack.setCurrentIndex(0) self.selectStack.setCurrentIndex(0)
def customSignals(self): def custom_signals(self):
""" """
Set up the signals used in the bible importer. Set up the signals used in the bible importer.
""" """
@ -123,7 +123,7 @@ class BibleImportForm(OpenLPWizard):
self.openSongBrowseButton.clicked.connect(self.onOpenSongBrowseButtonClicked) self.openSongBrowseButton.clicked.connect(self.onOpenSongBrowseButtonClicked)
self.openlp1BrowseButton.clicked.connect(self.onOpenlp1BrowseButtonClicked) self.openlp1BrowseButton.clicked.connect(self.onOpenlp1BrowseButtonClicked)
def addCustomPages(self): def add_custom_pages(self):
""" """
Add the bible import specific wizard pages. Add the bible import specific wizard pages.
""" """

View File

@ -107,7 +107,7 @@ class BibleUpgradeForm(OpenLPWizard):
if self.page(pageId) == self.progress_page: if self.page(pageId) == self.progress_page:
self.preWizard() self.preWizard()
self.performWizard() self.performWizard()
self.postWizard() self.post_wizard()
elif self.page(pageId) == self.selectPage and not self.files: elif self.page(pageId) == self.selectPage and not self.files:
self.next() self.next()
@ -140,21 +140,21 @@ class BibleUpgradeForm(OpenLPWizard):
success = False success = False
return success return success
def customInit(self): def custom_init(self):
""" """
Perform any custom initialisation for bible upgrading. Perform any custom initialisation for bible upgrading.
""" """
self.manager.set_process_dialog(self) self.manager.set_process_dialog(self)
self.restart() self.restart()
def customSignals(self): def custom_signals(self):
""" """
Set up the signals used in the bible importer. Set up the signals used in the bible importer.
""" """
self.backupBrowseButton.clicked.connect(self.onBackupBrowseButtonClicked) self.backupBrowseButton.clicked.connect(self.onBackupBrowseButtonClicked)
self.noBackupCheckBox.toggled.connect(self.onNoBackupCheckBoxToggled) self.noBackupCheckBox.toggled.connect(self.onNoBackupCheckBoxToggled)
def addCustomPages(self): def add_custom_pages(self):
""" """
Add the bible import specific wizard pages. Add the bible import specific wizard pages.
""" """
@ -170,7 +170,7 @@ class BibleUpgradeForm(OpenLPWizard):
self.backupInfoLabel.setObjectName(u'backupInfoLabel') self.backupInfoLabel.setObjectName(u'backupInfoLabel')
self.backupLayout.addWidget(self.backupInfoLabel) self.backupLayout.addWidget(self.backupInfoLabel)
self.selectLabel = QtGui.QLabel(self.backupPage) self.selectLabel = QtGui.QLabel(self.backupPage)
self.selectLabel.setObjectName(u'selectLabel') self.selectLabel.setObjectName(u'select_label')
self.backupLayout.addWidget(self.selectLabel) self.backupLayout.addWidget(self.selectLabel)
self.formLayout = QtGui.QFormLayout() self.formLayout = QtGui.QFormLayout()
self.formLayout.setMargin(0) self.formLayout.setMargin(0)
@ -528,7 +528,7 @@ class BibleUpgradeForm(OpenLPWizard):
if old_bible is not None: if old_bible is not None:
old_bible.close_connection() old_bible.close_connection()
def postWizard(self): def post_wizard(self):
""" """
Clean up the UI after the import has finished. 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.')) self.progress_label.setText(translate('BiblesPlugin.UpgradeWizardForm', 'Upgrade failed.'))
# Remove temp directory. # Remove temp directory.
shutil.rmtree(self.temp_dir, True) shutil.rmtree(self.temp_dir, True)
OpenLPWizard.postWizard(self) OpenLPWizard.post_wizard(self)

View File

@ -44,6 +44,7 @@ from openlp.plugins.bibles.lib.db import BiblesResourcesDB
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class BookNameForm(QDialog, Ui_BookNameDialog): class BookNameForm(QDialog, Ui_BookNameDialog):
""" """
Class to manage a dialog which help the user to refer a book name a 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) QDialog.__init__(self, parent)
self.setupUi(self) self.setupUi(self)
self.customSignals() self.custom_signals()
self.book_names = BibleStrings().BookNames self.book_names = BibleStrings().BookNames
self.book_id = False self.book_id = False
def customSignals(self): def custom_signals(self):
""" """
Set up the signals used in the booknameform. Set up the signals used in the booknameform.
""" """

View File

@ -49,7 +49,7 @@ class Ui_AuthorsDialog(object):
self.dialog_layout = QtGui.QVBoxLayout(authors_dialog) self.dialog_layout = QtGui.QVBoxLayout(authors_dialog)
self.dialog_layout.setObjectName(u'dialog_layout') self.dialog_layout.setObjectName(u'dialog_layout')
self.author_layout = QtGui.QFormLayout() 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 = QtGui.QLabel(authors_dialog)
self.first_name_label.setObjectName(u'first_name_label') self.first_name_label.setObjectName(u'first_name_label')
self.first_name_edit = QtGui.QLineEdit(authors_dialog) self.first_name_edit = QtGui.QLineEdit(authors_dialog)

View File

@ -144,4 +144,3 @@ class EditVerseForm(QtGui.QDialog, Ui_EditVerseDialog):
if not text.startswith(u'---['): if not text.startswith(u'---['):
text = u'---[%s:1]---\n%s' % (VerseType.translated_names[VerseType.Verse], text) text = u'---[%s:1]---\n%s' % (VerseType.translated_names[VerseType.Verse], text)
return text return text

View File

@ -32,32 +32,42 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import translate, build_icon from openlp.core.lib import translate, build_icon
from openlp.core.lib.ui import create_button_box 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): class Ui_MediaFilesDialog(object):
mediaFilesDialog.setWindowTitle(translate('SongsPlugin.MediaFilesForm', 'Select Media File(s)')) """
self.selectLabel.setText(translate('SongsPlugin.MediaFilesForm', 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.')) 'Select one or more audio files from the list below, and click OK to import them into this song.'))

View File

@ -48,13 +48,13 @@ class MediaFilesForm(QtGui.QDialog, Ui_MediaFilesDialog):
self.setupUi(self) self.setupUi(self)
def populateFiles(self, files): def populateFiles(self, files):
self.fileListWidget.clear() self.file_list_widget.clear()
for file in files: for file in files:
item = QtGui.QListWidgetItem(os.path.split(file)[1]) item = QtGui.QListWidgetItem(os.path.split(file)[1])
item.setData(QtCore.Qt.UserRole, file) item.setData(QtCore.Qt.UserRole, file)
self.fileListWidget.addItem(item) self.file_list_widget.addItem(item)
def getSelectedFiles(self): def getSelectedFiles(self):
return map(lambda item: item.data(QtCore.Qt.UserRole), return map(lambda item: item.data(QtCore.Qt.UserRole),
self.fileListWidget.selectedItems()) self.file_list_widget.selectedItems())

View File

@ -32,33 +32,43 @@ from PyQt4 import QtGui
from openlp.core.lib import translate from openlp.core.lib import translate
from openlp.core.lib.ui import create_button_box 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): class Ui_SongBookDialog(object):
songBookDialog.setWindowTitle(translate('SongsPlugin.SongBookForm', 'Song Book Maintenance')) """
self.nameLabel.setText(translate('SongsPlugin.SongBookForm', '&Name:')) The user interface for the song book dialog.
self.publisherLabel.setText(translate('SongsPlugin.SongBookForm', '&Publisher:')) """
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:'))

View File

@ -56,19 +56,19 @@ class SongBookForm(QtGui.QDialog, Ui_SongBookDialog):
Clear the fields on the form before displaying it. Clear the fields on the form before displaying it.
""" """
if clear: if clear:
self.nameEdit.clear() self.name_edit.clear()
self.publisherEdit.clear() self.publisher_edit.clear()
self.nameEdit.setFocus() self.name_edit.setFocus()
return QtGui.QDialog.exec_(self) return QtGui.QDialog.exec_(self)
def accept(self): def accept(self):
""" """
Override the inherited method to check that the name of the book has been typed in. 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( critical_error_message_box(
message=translate('SongsPlugin.SongBookForm', 'You need to type in a name for the book.')) message=translate('SongsPlugin.SongBookForm', 'You need to type in a name for the book.'))
self.nameEdit.setFocus() self.name_edit.setFocus()
return False return False
else: else:
return QtGui.QDialog.accept(self) return QtGui.QDialog.accept(self)

View File

@ -43,6 +43,7 @@ from openlp.plugins.songs.lib.openlyricsexport import OpenLyricsExport
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class SongExportForm(OpenLPWizard): class SongExportForm(OpenLPWizard):
""" """
This is the Song Export Wizard, which allows easy exporting of Songs to the This is the Song Export Wizard, which allows easy exporting of Songs to the
@ -60,7 +61,7 @@ class SongExportForm(OpenLPWizard):
``plugin`` ``plugin``
The songs 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 self.stop_export_flag = False
Registry().register_function(u'openlp_stop_wizard', self.stop_export) Registry().register_function(u'openlp_stop_wizard', self.stop_export)
@ -77,13 +78,7 @@ class SongExportForm(OpenLPWizard):
""" """
OpenLPWizard.setupUi(self, image) OpenLPWizard.setupUi(self, image)
def customInit(self): def custom_signals(self):
"""
Song wizard specific initialisation.
"""
pass
def customSignals(self):
""" """
Song wizard specific signals. Song wizard specific signals.
""" """
@ -93,7 +88,7 @@ class SongExportForm(OpenLPWizard):
self.checkButton.clicked.connect(self.onCheckButtonClicked) self.checkButton.clicked.connect(self.onCheckButtonClicked)
self.directoryButton.clicked.connect(self.onDirectoryButtonClicked) self.directoryButton.clicked.connect(self.onDirectoryButtonClicked)
def addCustomPages(self): def add_custom_pages(self):
""" """
Add song wizard specific pages. Add song wizard specific pages.
""" """

View File

@ -67,7 +67,7 @@ class SongImportForm(OpenLPWizard):
""" """
Set up the song wizard UI. 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) OpenLPWizard.setupUi(self, image)
self.current_format = SongFormat.OpenLyrics self.current_format = SongFormat.OpenLyrics
self.format_stack.setCurrentIndex(self.current_format) self.format_stack.setCurrentIndex(self.current_format)
@ -81,29 +81,29 @@ class SongImportForm(OpenLPWizard):
self.format_stack.setCurrentIndex(index) self.format_stack.setCurrentIndex(index)
self.source_page.emit(QtCore.SIGNAL(u'completeChanged()')) self.source_page.emit(QtCore.SIGNAL(u'completeChanged()'))
def customInit(self): def custom_init(self):
""" """
Song wizard specific initialisation. Song wizard specific initialisation.
""" """
for format in SongFormat.get_format_list(): for song_format in SongFormat.get_format_list():
if not SongFormat.get(format, u'availability'): if not SongFormat.get(song_format, u'availability'):
self.format_widgets[format][u'disabled_widget'].setVisible(True) self.format_widgets[song_format][u'disabled_widget'].setVisible(True)
self.format_widgets[format][u'import_widget'].setVisible(False) self.format_widgets[song_format][u'import_widget'].setVisible(False)
def customSignals(self): def custom_signals(self):
""" """
Song wizard specific signals. Song wizard specific signals.
""" """
for format in SongFormat.get_format_list(): for song_format in SongFormat.get_format_list():
select_mode = SongFormat.get(format, u'selectMode') select_mode = SongFormat.get(song_format, u'selectMode')
if select_mode == SongFormatSelect.MultipleFiles: if select_mode == SongFormatSelect.MultipleFiles:
self.format_widgets[format][u'addButton'].clicked.connect(self.on_add_button_clicked) self.format_widgets[song_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'removeButton'].clicked.connect(self.onRemoveButtonClicked)
else: else:
self.format_widgets[format][u'browseButton'].clicked.connect(self.on_browse_button_clicked) self.format_widgets[song_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'file_path_edit'].textChanged.connect(self.onFilepathEditTextChanged)
def addCustomPages(self): def add_custom_pages(self):
""" """
Add song wizard specific pages. Add song wizard specific pages.
""" """
@ -210,7 +210,7 @@ class SongImportForm(OpenLPWizard):
Settings().setValue(u'songs/last import type', this_format) Settings().setValue(u'songs/last import type', this_format)
select_mode, class_, error_msg = SongFormat.get(this_format, u'selectMode', u'class', u'invalidSourceMsg') select_mode, class_, error_msg = SongFormat.get(this_format, u'selectMode', u'class', u'invalidSourceMsg')
if select_mode == SongFormatSelect.MultipleFiles: 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 error_title = UiStrings().IFSp
focus_button = self.format_widgets[this_format][u'addButton'] focus_button = self.format_widgets[this_format][u'addButton']
else: else:
@ -287,14 +287,14 @@ class SongImportForm(OpenLPWizard):
SongFormat.get(this_format, u'selectMode', u'name', u'filter', u'getFilesTitle') SongFormat.get(this_format, u'selectMode', u'name', u'filter', u'getFilesTitle')
title = custom_title if custom_title else WizardStrings.OpenTypeFile % format_name title = custom_title if custom_title else WizardStrings.OpenTypeFile % format_name
if select_mode == SongFormatSelect.MultipleFiles: 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()')) self.source_page.emit(QtCore.SIGNAL(u'completeChanged()'))
def onRemoveButtonClicked(self): def onRemoveButtonClicked(self):
""" """
Remove a file from the list. 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()')) self.source_page.emit(QtCore.SIGNAL(u'completeChanged()'))
def onFilepathEditTextChanged(self): def onFilepathEditTextChanged(self):
@ -317,7 +317,7 @@ class SongImportForm(OpenLPWizard):
for format in SongFormat.get_format_list(): for format in SongFormat.get_format_list():
select_mode = SongFormat.get(format, u'selectMode') select_mode = SongFormat.get(format, u'selectMode')
if select_mode == SongFormatSelect.MultipleFiles: if select_mode == SongFormatSelect.MultipleFiles:
self.format_widgets[format][u'fileListWidget'].clear() self.format_widgets[format][u'file_list_widget'].clear()
else: else:
self.format_widgets[format][u'file_path_edit'].setText(u'') self.format_widgets[format][u'file_path_edit'].setText(u'')
self.error_report_text_edit.clear() self.error_report_text_edit.clear()
@ -349,7 +349,7 @@ class SongImportForm(OpenLPWizard):
folder=self.format_widgets[source_format][u'file_path_edit'].text()) folder=self.format_widgets[source_format][u'file_path_edit'].text())
else: else:
importer = self.plugin.importSongs(source_format, 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() importer.doImport()
self.progress_label.setText(WizardStrings.FinishedImport) self.progress_label.setText(WizardStrings.FinishedImport)
@ -440,7 +440,7 @@ class SongImportForm(OpenLPWizard):
removeButton.setObjectName(prefix + u'RemoveButton') removeButton.setObjectName(prefix + u'RemoveButton')
button_layout.addWidget(removeButton) button_layout.addWidget(removeButton)
importLayout.addLayout(button_layout) 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'button_layout'] = button_layout
self.format_widgets[this_format][u'addButton'] = addButton self.format_widgets[this_format][u'addButton'] = addButton
self.format_widgets[this_format][u'removeButton'] = removeButton 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') select_mode, format_available = SongFormat.get(this_format, u'selectMode', u'availability')
if format_available: if format_available:
if select_mode == SongFormatSelect.MultipleFiles: 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 return True
else: else:
filepath = unicode(wizard.format_widgets[this_format][u'file_path_edit'].text()) filepath = unicode(wizard.format_widgets[this_format][u'file_path_edit'].text())

View File

@ -33,123 +33,133 @@ from openlp.core.lib import UiStrings, build_icon
from openlp.core.lib.ui import create_button_box from openlp.core.lib.ui import create_button_box
from openlp.plugins.songs.lib.ui import SongStrings 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): class Ui_SongMaintenanceDialog(object):
songMaintenanceDialog.setWindowTitle(SongStrings.SongMaintenance) """
self.listItemAuthors.setText(SongStrings.Authors) The user interface for the song maintenance dialog
self.listItemTopics.setText(SongStrings.Topics) """
self.listItemBooks.setText(SongStrings.SongBooks) def setupUi(self, song_maintenance_dialog):
self.authorsAddButton.setText(UiStrings().Add) """
self.authorsEditButton.setText(UiStrings().Edit) Set up the user interface for the song maintenance dialog
self.authorsDeleteButton.setText(UiStrings().Delete) """
self.topicsAddButton.setText(UiStrings().Add) song_maintenance_dialog.setObjectName(u'song_maintenance_dialog')
self.topicsEditButton.setText(UiStrings().Edit) song_maintenance_dialog.setWindowModality(QtCore.Qt.ApplicationModal)
self.topicsDeleteButton.setText(UiStrings().Delete) song_maintenance_dialog.resize(10, 350)
self.booksAddButton.setText(UiStrings().Add) self.dialog_layout = QtGui.QGridLayout(song_maintenance_dialog)
self.booksEditButton.setText(UiStrings().Edit) self.dialog_layout.setObjectName(u'dialog_layout')
self.booksDeleteButton.setText(UiStrings().Delete) 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), typeListWidth = max(self.fontMetrics().width(SongStrings.Authors),
self.fontMetrics().width(SongStrings.Topics), self.fontMetrics().width(SongStrings.SongBooks)) 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)

View File

@ -53,47 +53,47 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
super(SongMaintenanceForm, self).__init__(parent) super(SongMaintenanceForm, self).__init__(parent)
self.setupUi(self) self.setupUi(self)
self.manager = manager self.manager = manager
self.authorform = AuthorsForm(self) self.author_form = AuthorsForm(self)
self.topicform = TopicsForm(self) self.topic_form = TopicsForm(self)
self.bookform = SongBookForm(self) self.song_book_form = SongBookForm(self)
# Disable all edit and delete buttons, as there is no row selected. # Disable all edit and delete buttons, as there is no row selected.
self.authorsDeleteButton.setEnabled(False) self.delete_author_button.setEnabled(False)
self.authorsEditButton.setEnabled(False) self.edit_author_button.setEnabled(False)
self.topicsDeleteButton.setEnabled(False) self.delete_topic_button.setEnabled(False)
self.topicsEditButton.setEnabled(False) self.edit_topic_button.setEnabled(False)
self.booksDeleteButton.setEnabled(False) self.delete_book_button.setEnabled(False)
self.booksEditButton.setEnabled(False) self.edit_book_button.setEnabled(False)
# Signals # Signals
self.authorsAddButton.clicked.connect(self.onAuthorAddButtonClicked) self.add_author_button.clicked.connect(self.on_add_author_button_clicked)
self.topicsAddButton.clicked.connect(self.onTopicAddButtonClicked) self.add_topic_button.clicked.connect(self.on_add_topic_button_clicked)
self.booksAddButton.clicked.connect(self.onBookAddButtonClicked) self.add_book_button.clicked.connect(self.on_add_book_button_clicked)
self.authorsEditButton.clicked.connect(self.onAuthorEditButtonClicked) self.edit_author_button.clicked.connect(self.on_edit_author_button_clicked)
self.topicsEditButton.clicked.connect(self.onTopicEditButtonClicked) self.edit_topic_button.clicked.connect(self.on_edit_topic_button_clicked)
self.booksEditButton.clicked.connect(self.onBookEditButtonClicked) self.edit_book_button.clicked.connect(self.on_edit_book_button_clicked)
self.authorsDeleteButton.clicked.connect(self.onAuthorDeleteButtonClicked) self.delete_author_button.clicked.connect(self.on_delete_author_button_clicked)
self.topicsDeleteButton.clicked.connect(self.onTopicDeleteButtonClicked) self.delete_topic_button.clicked.connect(self.on_delete_topic_button_clicked)
self.booksDeleteButton.clicked.connect(self.onBookDeleteButtonClicked) self.delete_book_button.clicked.connect(self.on_delete_book_button_clicked)
self.authorsListWidget.currentRowChanged.connect(self.onAuthorsListRowChanged) self.authors_list_widget.currentRowChanged.connect(self.on_authors_list_row_changed)
self.topicsListWidget.currentRowChanged.connect(self.onTopicsListRowChanged) self.topics_list_widget.currentRowChanged.connect(self.on_topics_list_row_changed)
self.booksListWidget.currentRowChanged.connect(self.onBooksListRowChanged) 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. Show the dialog.
``fromSongEdit`` ``from_song_edit``
Indicates if the maintenance dialog has been opened from song edit Indicates if the maintenance dialog has been opened from song edit
or from the media manager. Defaults to **False**. or from the media manager. Defaults to **False**.
""" """
self.fromSongEdit = fromSongEdit self.from_song_edit = from_song_edit
self.typeListWidget.setCurrentRow(0) self.type_list_widget.setCurrentRow(0)
self.resetAuthors() self.reset_authors()
self.resetTopics() self.reset_topics()
self.resetBooks() self.reset_song_books()
self.typeListWidget.setFocus() self.type_list_widget.setFocus()
return QtGui.QDialog.exec_(self) 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. Get the ID of the currently selected item.
@ -107,27 +107,27 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
else: else:
return -1 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. Delete an item.
""" """
item_id = self._getCurrentItemId(listWidget) item_id = self._get_current_item_id(list_widget)
if item_id != -1: 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 item and not item.songs:
if critical_error_message_box(dlgTitle, del_text, self, True) == QtGui.QMessageBox.Yes: if critical_error_message_box(dlg_title, del_text, self, True) == QtGui.QMessageBox.Yes:
self.manager.delete_object(itemClass, item.id) self.manager.delete_object(item_class, item.id)
resetFunc() reset_func()
else: else:
critical_error_message_box(dlgTitle, err_text) critical_error_message_box(dlg_title, err_text)
else: 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. 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) authors = self.manager.get_all_objects(Author, order_by_ref=Author.display_name)
for author in authors: for author in authors:
if author.display_name: if author.display_name:
@ -135,68 +135,72 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
else: else:
author_name = QtGui.QListWidgetItem(u' '.join([author.first_name, author.last_name])) author_name = QtGui.QListWidgetItem(u' '.join([author.first_name, author.last_name]))
author_name.setData(QtCore.Qt.UserRole, author.id) 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. Reloads the Topics list.
""" """
self.topicsListWidget.clear() self.topics_list_widget.clear()
topics = self.manager.get_all_objects(Topic, order_by_ref=Topic.name) topics = self.manager.get_all_objects(Topic, order_by_ref=Topic.name)
for topic in topics: for topic in topics:
topic_name = QtGui.QListWidgetItem(topic.name) topic_name = QtGui.QListWidgetItem(topic.name)
topic_name.setData(QtCore.Qt.UserRole, topic.id) 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. 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) books = self.manager.get_all_objects(Book, order_by_ref=Book.name)
for book in books: for book in books:
book_name = QtGui.QListWidgetItem(u'%s (%s)' % (book.name, book.publisher)) book_name = QtGui.QListWidgetItem(u'%s (%s)' % (book.name, book.publisher))
book_name.setData(QtCore.Qt.UserRole, book.id) 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*. Returns *False* if the given Author already exists, otherwise *True*.
""" """
authors = self.manager.get_all_objects(Author, authors = self.manager.get_all_objects(
and_(Author.first_name == newAuthor.first_name, Author,
Author.last_name == newAuthor.last_name, and_(
Author.display_name == newAuthor.display_name)) Author.first_name == new_author.first_name,
return self.__checkObject(authors, newAuthor, edit) 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*. Returns *False* if the given Topic already exists, otherwise *True*.
""" """
topics = self.manager.get_all_objects(Topic, Topic.name == newTopic.name) topics = self.manager.get_all_objects(Topic, Topic.name == new_topic.name)
return self.__checkObject(topics, newTopic, edit) 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*. Returns *False* if the given Topic already exists, otherwise *True*.
""" """
books = self.manager.get_all_objects(Book, books = self.manager.get_all_objects(Book,
and_(Book.name == newBook.name, Book.publisher == newBook.publisher)) and_(Book.name == new_book.name, Book.publisher == new_book.publisher))
return self.__checkObject(books, newBook, edit) 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. Utility method to check for an existing object.
``edit`` ``edit``
If we edit an item, this should be *True*. 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 # If we edit an existing object, we need to make sure that we do
# not return False when nothing has changed. # not return False when nothing has changed.
if edit: if edit:
for object in objects: for existing_object in existing_objects:
if object.id != newObject.id: if existing_object.id != new_object.id:
return False return False
return True return True
else: else:
@ -204,20 +208,20 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
else: else:
return True return True
def onAuthorAddButtonClicked(self): def on_add_author_button_clicked(self):
""" """
Add an author to the list. Add an author to the list.
""" """
self.authorform.auto_display_name = True self.author_form.auto_display_name = True
if self.authorform.exec_(): if self.author_form.exec_():
author = Author.populate( author = Author.populate(
first_name=self.authorform.first_name, first_name=self.author_form.first_name,
last_name=self.authorform.last_name, last_name=self.author_form.last_name,
display_name=self.authorform.display_name display_name=self.author_form.display_name
) )
if self.checkAuthor(author): if self.check_author_exists(author):
if self.manager.save_object(author): if self.manager.save_object(author):
self.resetAuthors() self.reset_authors()
else: else:
critical_error_message_box( critical_error_message_box(
message=translate('SongsPlugin.SongMaintenanceForm', 'Could not add your author.')) message=translate('SongsPlugin.SongMaintenanceForm', 'Could not add your author.'))
@ -225,15 +229,15 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
critical_error_message_box( critical_error_message_box(
message=translate('SongsPlugin.SongMaintenanceForm', 'This author already exists.')) message=translate('SongsPlugin.SongMaintenanceForm', 'This author already exists.'))
def onTopicAddButtonClicked(self): def on_add_topic_button_clicked(self):
""" """
Add a topic to the list. Add a topic to the list.
""" """
if self.topicform.exec_(): if self.topic_form.exec_():
topic = Topic.populate(name=self.topicform.nameEdit.text()) topic = Topic.populate(name=self.topic_form.name)
if self.checkTopic(topic): if self.check_topic_exists(topic):
if self.manager.save_object(topic): if self.manager.save_object(topic):
self.resetTopics() self.reset_topics()
else: else:
critical_error_message_box( critical_error_message_box(
message=translate('SongsPlugin.SongMaintenanceForm', 'Could not add your topic.')) message=translate('SongsPlugin.SongMaintenanceForm', 'Could not add your topic.'))
@ -241,16 +245,16 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
critical_error_message_box( critical_error_message_box(
message=translate('SongsPlugin.SongMaintenanceForm', 'This topic already exists.')) message=translate('SongsPlugin.SongMaintenanceForm', 'This topic already exists.'))
def onBookAddButtonClicked(self): def on_add_book_button_clicked(self):
""" """
Add a book to the list. Add a book to the list.
""" """
if self.bookform.exec_(): if self.song_book_form.exec_():
book = Book.populate(name=self.bookform.nameEdit.text(), book = Book.populate(name=self.song_book_form.name_edit.text(),
publisher=self.bookform.publisherEdit.text()) publisher=self.song_book_form.publisher_edit.text())
if self.checkBook(book): if self.check_song_book_exists(book):
if self.manager.save_object(book): if self.manager.save_object(book):
self.resetBooks() self.reset_song_books()
else: else:
critical_error_message_box( critical_error_message_box(
message=translate('SongsPlugin.SongMaintenanceForm', 'Could not add your book.')) message=translate('SongsPlugin.SongMaintenanceForm', 'Could not add your book.'))
@ -258,31 +262,31 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
critical_error_message_box( critical_error_message_box(
message=translate('SongsPlugin.SongMaintenanceForm', 'This book already exists.')) message=translate('SongsPlugin.SongMaintenanceForm', 'This book already exists.'))
def onAuthorEditButtonClicked(self): def on_edit_author_button_clicked(self):
""" """
Edit an author. Edit an author.
""" """
author_id = self._getCurrentItemId(self.authorsListWidget) author_id = self._get_current_item_id(self.authors_list_widget)
if author_id == -1: if author_id == -1:
return return
author = self.manager.get_object(Author, author_id) author = self.manager.get_object(Author, author_id)
self.authorform.auto_display_name = False self.author_form.auto_display_name = False
self.authorform.first_name_edit.setText(author.first_name) self.author_form.first_name_edit.setText(author.first_name)
self.authorform.last_name_edit.setText(author.last_name) self.author_form.last_name_edit.setText(author.last_name)
self.authorform.display_edit.setText(author.display_name) self.author_form.display_edit.setText(author.display_name)
# Save the author's first and last name as well as the 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. # for the case that they have to be restored.
temp_first_name = author.first_name temp_first_name = author.first_name
temp_last_name = author.last_name temp_last_name = author.last_name
temp_display_name = author.display_name temp_display_name = author.display_name
if self.authorform.exec_(False): if self.author_form.exec_(False):
author.first_name = self.authorform.first_name_edit.text() author.first_name = self.author_form.first_name_edit.text()
author.last_name = self.authorform.last_name_edit.text() author.last_name = self.author_form.last_name_edit.text()
author.display_name = self.authorform.display_edit.text() author.display_name = self.author_form.display_edit.text()
if self.checkAuthor(author, True): if self.check_author_exists(author, True):
if self.manager.save_object(author): if self.manager.save_object(author):
self.resetAuthors() self.reset_authors()
if not self.fromSongEdit: if not self.from_song_edit:
Registry().execute(u'songs_load_list') Registry().execute(u'songs_load_list')
else: else:
critical_error_message_box( critical_error_message_box(
@ -292,8 +296,8 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
'author %s use the existing author %s?') % 'author %s use the existing author %s?') %
(author.display_name, temp_display_name, author.display_name), parent=self, question=True) == \ (author.display_name, temp_display_name, author.display_name), parent=self, question=True) == \
QtGui.QMessageBox.Yes: QtGui.QMessageBox.Yes:
self.__mergeObjects(author, self.mergeAuthors, self._merge_objects(author, self.merge_authors,
self.resetAuthors) self.reset_authors)
else: else:
# We restore the author's old first and last name as well as # We restore the author's old first and last name as well as
# his display name. # his display name.
@ -302,24 +306,24 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
author.display_name = temp_display_name author.display_name = temp_display_name
critical_error_message_box( critical_error_message_box(
message=translate('SongsPlugin.SongMaintenanceForm', 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. Edit a topic.
""" """
topic_id = self._getCurrentItemId(self.topicsListWidget) topic_id = self._get_current_item_id(self.topics_list_widget)
if topic_id == -1: if topic_id == -1:
return return
topic = self.manager.get_object(Topic, topic_id) 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. # Save the topic's name for the case that he has to be restored.
temp_name = topic.name temp_name = topic.name
if self.topicform.exec_(False): if self.topic_form.exec_(False):
topic.name = self.topicform.nameEdit.text() topic.name = self.topic_form.name_edit.text()
if self.checkTopic(topic, True): if self.check_topic_exists(topic, True):
if self.manager.save_object(topic): if self.manager.save_object(topic):
self.resetTopics() self.reset_topics()
else: else:
critical_error_message_box( critical_error_message_box(
message=translate('SongsPlugin.SongMaintenanceForm', 'Could not save your changes.')) message=translate('SongsPlugin.SongMaintenanceForm', 'Could not save your changes.'))
@ -327,7 +331,7 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
message=translate('SongsPlugin.SongMaintenanceForm', message=translate('SongsPlugin.SongMaintenanceForm',
'The topic %s already exists. Would you like to make songs with topic %s use the existing topic %s?') % '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: (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: else:
# We restore the topics's old name. # We restore the topics's old name.
topic.name = temp_name topic.name = temp_name
@ -335,28 +339,28 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
message=translate('SongsPlugin.SongMaintenanceForm', message=translate('SongsPlugin.SongMaintenanceForm',
'Could not save your modified topic, because it already exists.')) 'Could not save your modified topic, because it already exists.'))
def onBookEditButtonClicked(self): def on_edit_book_button_clicked(self):
""" """
Edit a book. 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: if book_id == -1:
return return
book = self.manager.get_object(Book, book_id) book = self.manager.get_object(Book, book_id)
if book.publisher is None: if book.publisher is None:
book.publisher = u'' book.publisher = u''
self.bookform.nameEdit.setText(book.name) self.song_book_form.name_edit.setText(book.name)
self.bookform.publisherEdit.setText(book.publisher) self.song_book_form.publisher_edit.setText(book.publisher)
# Save the book's name and publisher for the case that they have to # Save the book's name and publisher for the case that they have to
# be restored. # be restored.
temp_name = book.name temp_name = book.name
temp_publisher = book.publisher temp_publisher = book.publisher
if self.bookform.exec_(False): if self.song_book_form.exec_(False):
book.name = self.bookform.nameEdit.text() book.name = self.song_book_form.name_edit.text()
book.publisher = self.bookform.publisherEdit.text() book.publisher = self.song_book_form.publisher_edit.text()
if self.checkBook(book, True): if self.check_song_book_exists(book, True):
if self.manager.save_object(book): if self.manager.save_object(book):
self.resetBooks() self.reset_song_books()
else: else:
critical_error_message_box( critical_error_message_box(
message=translate('SongsPlugin.SongMaintenanceForm', 'Could not save your changes.')) message=translate('SongsPlugin.SongMaintenanceForm', 'Could not save your changes.'))
@ -364,138 +368,148 @@ class SongMaintenanceForm(QtGui.QDialog, Ui_SongMaintenanceDialog):
message=translate('SongsPlugin.SongMaintenanceForm', message=translate('SongsPlugin.SongMaintenanceForm',
'The book %s already exists. Would you like to make songs with book %s use the existing book %s?') % '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: (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: else:
# We restore the book's old name and publisher. # We restore the book's old name and publisher.
book.name = temp_name book.name = temp_name
book.publisher = temp_publisher 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. Utility method to merge two objects to leave one in the database.
""" """
self.application.set_busy_cursor() self.application.set_busy_cursor()
merge(dbObject) merge(db_object)
reset() reset()
if not self.fromSongEdit: if not self.from_song_edit:
Registry().execute(u'songs_load_list') Registry().execute(u'songs_load_list')
self.application.set_normal_cursor() self.application.set_normal_cursor()
def mergeAuthors(self, oldAuthor): def merge_authors(self, old_author):
""" """
Merges two authors into one author. Merges two authors into one author.
``oldAuthor`` ``old_author``
The object, which was edited, that will be deleted The object, which was edited, that will be deleted
""" """
# Find the duplicate. # Find the duplicate.
existing_author = self.manager.get_object_filtered(Author, existing_author = self.manager.get_object_filtered(
and_(Author.first_name == oldAuthor.first_name, Author,
Author.last_name == oldAuthor.last_name, and_(
Author.display_name == oldAuthor.display_name, Author.first_name == old_author.first_name,
Author.id != oldAuthor.id)) Author.last_name == old_author.last_name,
# Find the songs, which have the oldAuthor as author. Author.display_name == old_author.display_name,
songs = self.manager.get_all_objects(Song, Author.id != old_author.id
Song.authors.contains(oldAuthor)) )
)
# 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: for song in songs:
# We check if the song has already existing_author as author. If # We check if the song has already existing_author as author. If
# that is not the case we add it. # that is not the case we add it.
if existing_author not in song.authors: if existing_author not in song.authors:
song.authors.append(existing_author) song.authors.append(existing_author)
song.authors.remove(oldAuthor) song.authors.remove(old_author)
self.manager.save_object(song) 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. Merges two topics into one topic.
``oldTopic`` ``old_topic``
The object, which was edited, that will be deleted The object, which was edited, that will be deleted
""" """
# Find the duplicate. # Find the duplicate.
existing_topic = self.manager.get_object_filtered(Topic, existing_topic = self.manager.get_object_filtered(
and_(Topic.name == oldTopic.name, Topic.id != oldTopic.id)) Topic,
# Find the songs, which have the oldTopic as topic. and_(
songs = self.manager.get_all_objects(Song, Song.topics.contains(oldTopic)) 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: for song in songs:
# We check if the song has already existing_topic as topic. If that # We check if the song has already existing_topic as topic. If that
# is not the case we add it. # is not the case we add it.
if existing_topic not in song.topics: if existing_topic not in song.topics:
song.topics.append(existing_topic) song.topics.append(existing_topic)
song.topics.remove(oldTopic) song.topics.remove(old_topic)
self.manager.save_object(song) 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. Merges two books into one book.
``oldBook`` ``old_song_book``
The object, which was edited, that will be deleted The object, which was edited, that will be deleted
""" """
# Find the duplicate. # Find the duplicate.
existing_book = self.manager.get_object_filtered(Book, existing_book = self.manager.get_object_filtered(
and_(Book.name == oldBook.name, Book,
Book.publisher == oldBook.publisher, and_(
Book.id != oldBook.id)) Book.name == old_song_book.name,
# Find the songs, which have the oldBook as book. Book.publisher == old_song_book.publisher,
songs = self.manager.get_all_objects(Song, Book.id != old_song_book.id
Song.song_book_id == oldBook.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: for song in songs:
song.song_book_id = existing_book.id song.song_book_id = existing_book.id
self.manager.save_object(song) 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. 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', 'Delete Author'),
translate('SongsPlugin.SongMaintenanceForm', 'Are you sure you want to delete the selected author?'), translate('SongsPlugin.SongMaintenanceForm', 'Are you sure you want to delete the selected author?'),
translate('SongsPlugin.SongMaintenanceForm', translate('SongsPlugin.SongMaintenanceForm',
'This author cannot be deleted, they are currently assigned to at least one song.')) '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. 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', 'Delete Topic'),
translate('SongsPlugin.SongMaintenanceForm', 'Are you sure you want to delete the selected topic?'), translate('SongsPlugin.SongMaintenanceForm', 'Are you sure you want to delete the selected topic?'),
translate('SongsPlugin.SongMaintenanceForm', translate('SongsPlugin.SongMaintenanceForm',
'This topic cannot be deleted, it is currently assigned to at least one song.')) '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. 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', 'Delete Book'),
translate('SongsPlugin.SongMaintenanceForm', 'Are you sure you want to delete the selected book?'), translate('SongsPlugin.SongMaintenanceForm', 'Are you sure you want to delete the selected book?'),
translate('SongsPlugin.SongMaintenanceForm', translate('SongsPlugin.SongMaintenanceForm',
'This book cannot be deleted, it is currently assigned to at least one song.')) '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. 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. The current row. If there is no current row, the value is -1.
""" """
if row == -1: if row == -1:
deleteButton.setEnabled(False) delete_button.setEnabled(False)
editButton.setEnabled(False) edit_button.setEnabled(False)
else: else:
deleteButton.setEnabled(True) delete_button.setEnabled(True)
editButton.setEnabled(True) edit_button.setEnabled(True)
def _get_application(self): def _get_application(self):
""" """
Adds the openlp to the class dynamically Adds the application to the class dynamically
""" """
if not hasattr(self, u'_application'): if not hasattr(self, u'_application'):
self._application = Registry().get(u'application') self._application = Registry().get(u'application')

View File

@ -32,26 +32,36 @@ from PyQt4 import QtGui
from openlp.core.lib import translate from openlp.core.lib import translate
from openlp.core.lib.ui import create_button_box 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): class Ui_TopicsDialog(object):
topicsDialog.setWindowTitle(translate('SongsPlugin.TopicsForm', 'Topic Maintenance')) """
self.nameLabel.setText(translate('SongsPlugin.TopicsForm', 'Topic name:')) 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:'))

View File

@ -53,18 +53,32 @@ class TopicsForm(QtGui.QDialog, Ui_TopicsDialog):
Execute the dialog. Execute the dialog.
""" """
if clear: if clear:
self.nameEdit.clear() self.name_edit.clear()
self.nameEdit.setFocus() self.name_edit.setFocus()
return QtGui.QDialog.exec_(self) return QtGui.QDialog.exec_(self)
def accept(self): def accept(self):
""" """
Override the inherited method to check before we close. 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', critical_error_message_box(message=translate('SongsPlugin.TopicsForm',
'You need to type in a topic name.')) 'You need to type in a topic name.'))
self.nameEdit.setFocus() self.name_edit.setFocus()
return False return False
else: else:
return QtGui.QDialog.accept(self) 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)

View File

@ -7,7 +7,7 @@ sip.setapi(u'QTime', 2)
sip.setapi(u'QUrl', 2) sip.setapi(u'QUrl', 2)
sip.setapi(u'QVariant', 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. # Only one QApplication can be created. Use QtGui.QApplication.instance() when you need to "create" an QApplication.
application = QtGui.QApplication([]) #application = QtGui.QApplication([])

View File

@ -29,7 +29,7 @@ class TestPluginManager(TestCase):
Settings().setValue(u'advanced/data path', self.temp_dir) Settings().setValue(u'advanced/data path', self.temp_dir)
Registry.create() Registry.create()
Registry().register(u'service_list', MagicMock()) Registry().register(u'service_list', MagicMock())
self.app = QtGui.QApplication.instance() self.app = QtGui.QApplication([])
self.main_window = QtGui.QMainWindow() self.main_window = QtGui.QMainWindow()
Registry().register(u'main_window', self.main_window) Registry().register(u'main_window', self.main_window)

View File

@ -16,7 +16,7 @@ class TestStartFileRenameForm(TestCase):
Create the UI Create the UI
""" """
Registry.create() Registry.create()
self.app = QtGui.QApplication.instance() self.app = QtGui.QApplication([])
self.main_window = QtGui.QMainWindow() self.main_window = QtGui.QMainWindow()
Registry().register(u'main_window', self.main_window) Registry().register(u'main_window', self.main_window)
self.form = filerenameform.FileRenameForm() self.form = filerenameform.FileRenameForm()

View File

@ -18,7 +18,7 @@ class TestServiceManager(TestCase):
Create the UI Create the UI
""" """
Registry.create() Registry.create()
self.app = QtGui.QApplication.instance() self.app = QtGui.QApplication([])
ScreenList.create(self.app.desktop()) ScreenList.create(self.app.desktop())
Registry().register(u'application', MagicMock()) Registry().register(u'application', MagicMock())
with patch(u'openlp.core.lib.PluginManager'): with patch(u'openlp.core.lib.PluginManager'):

View File

@ -18,7 +18,7 @@ class TestStartNoteDialog(TestCase):
Create the UI Create the UI
""" """
Registry.create() Registry.create()
self.app = QtGui.QApplication.instance() self.app = QtGui.QApplication([])
self.main_window = QtGui.QMainWindow() self.main_window = QtGui.QMainWindow()
Registry().register(u'main_window', self.main_window) Registry().register(u'main_window', self.main_window)
self.form = servicenoteform.ServiceNoteForm() self.form = servicenoteform.ServiceNoteForm()

View File

@ -18,7 +18,7 @@ class TestStartTimeDialog(TestCase):
Create the UI Create the UI
""" """
Registry.create() Registry.create()
self.app = QtGui.QApplication.instance() self.app = QtGui.QApplication([])
self.main_window = QtGui.QMainWindow() self.main_window = QtGui.QMainWindow()
Registry().register(u'main_window', self.main_window) Registry().register(u'main_window', self.main_window)
self.form = starttimeform.StartTimeForm() self.form = starttimeform.StartTimeForm()

View File

@ -10,13 +10,16 @@ from openlp.plugins.songs.forms.authorsform import AuthorsForm
class TestAuthorsForm(TestCase): class TestAuthorsForm(TestCase):
"""
Test the AuthorsForm class
"""
def setUp(self): def setUp(self):
""" """
Create the UI Create the UI
""" """
Registry.create() Registry.create()
self.app = QtGui.QApplication.instance() self.app = QtGui.QApplication([])
self.main_window = QtGui.QMainWindow() self.main_window = QtGui.QMainWindow()
Registry().register(u'main_window', self.main_window) Registry().register(u'main_window', self.main_window)
self.form = AuthorsForm() self.form = AuthorsForm()

View File

@ -11,12 +11,16 @@ from openlp.plugins.songs.forms.editsongform import EditSongForm
class TestEditSongForm(TestCase): class TestEditSongForm(TestCase):
"""
Test the EditSongForm class
"""
def setUp(self): def setUp(self):
""" """
Create the UI Create the UI
""" """
Registry.create() Registry.create()
self.app = QtGui.QApplication.instance() self.app = QtGui.QApplication([])
self.main_window = QtGui.QMainWindow() self.main_window = QtGui.QMainWindow()
Registry().register(u'main_window', self.main_window) Registry().register(u'main_window', self.main_window)
Registry().register(u'theme_manager', MagicMock()) Registry().register(u'theme_manager', MagicMock())

View File

@ -8,19 +8,18 @@ from PyQt4 import QtCore, QtGui, QtTest
from openlp.core.lib import Registry from openlp.core.lib import Registry
from openlp.plugins.songs.forms.editverseform import EditVerseForm 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): class TestEditVerseForm(TestCase):
"""
Test the EditVerseForm class
"""
def setUp(self): def setUp(self):
""" """
Create the UI Create the UI
""" """
Registry.create() Registry.create()
self.app = QtGui.QApplication.instance() self.app = QtGui.QApplication([])
self.main_window = QtGui.QMainWindow() self.main_window = QtGui.QMainWindow()
Registry().register(u'main_window', self.main_window) Registry().register(u'main_window', self.main_window)
self.form = EditVerseForm() self.form = EditVerseForm()
@ -46,12 +45,14 @@ class TestEditVerseForm(TestCase):
""" """
Test that typing into the verse text edit box returns the correct text 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 # 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 # 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') u'The verse text edit should have the typed out verse')
def insert_verse_test(self): def insert_verse_test(self):

View File

@ -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')