diff --git a/openlp/core/lib/eventreceiver.py b/openlp/core/lib/eventreceiver.py index bd0403c8a..d29652c35 100644 --- a/openlp/core/lib/eventreceiver.py +++ b/openlp/core/lib/eventreceiver.py @@ -200,12 +200,6 @@ class EventReceiver(QtCore.QObject): ``{plugin}_unblank`` Requests a plugin to handle an unblank screen event. - ``{plugin}_edit`` - Requests a plugin edit a database item with the key as the payload. - - ``{plugin}_edit_clear`` - Editing has been completed. - ``{plugin}_load_list`` Tells the the plugin to reload the media manager list. diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 100f248c0..33c0eb1d1 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -99,7 +99,7 @@ class MediaManagerItem(QtGui.QWidget): self.plugin = plugin visible_title = self.plugin.getString(StringContent.VisibleName) self.title = unicode(visible_title[u'title']) - Registry().register(self.title, self) + Registry().register(self.plugin.name, self) self.settingsSection = self.plugin.name self.icon = None if icon: @@ -436,8 +436,8 @@ class MediaManagerItem(QtGui.QWidget): """ pass - def generateSlideData(self, serviceItem, item=None, xmlVersion=False, - remote=False, context=ServiceItemContext.Live): + def generateSlideData(self, serviceItem, item=None, xmlVersion=False, remote=False, + context=ServiceItemContext.Live): raise NotImplementedError(u'MediaManagerItem.generateSlideData needs to be defined by the plugin') def onDoubleClicked(self): @@ -470,7 +470,7 @@ class MediaManagerItem(QtGui.QWidget): serviceItem = self.buildServiceItem() if serviceItem: serviceItem.from_plugin = True - self.preview_controller.addServiceItem(serviceItem) + self.preview_controller.add_service_item(serviceItem) if keepFocus: self.listView.setFocus() @@ -496,7 +496,7 @@ class MediaManagerItem(QtGui.QWidget): serviceItem.from_plugin = True if remote: serviceItem.will_auto_start = True - self.live_controller.addServiceItem(serviceItem) + self.live_controller.add_service_item(serviceItem) def createItemFromId(self, item_id): item = QtGui.QListWidgetItem() @@ -507,13 +507,13 @@ class MediaManagerItem(QtGui.QWidget): """ Add a selected item to the current service """ - if not self.listView.selectedIndexes() and not self.remoteTriggered: + if not self.listView.selectedIndexes(): QtGui.QMessageBox.information(self, UiStrings().NISp, translate('OpenLP.MediaManagerItem', 'You must select one or more items to add.')) else: # Is it possible to process multiple list items to generate # multiple service items? - if self.singleServiceItem or self.remoteTriggered: + if self.singleServiceItem: log.debug(u'%s Add requested', self.plugin.name) self.addToService(replace=self.remoteTriggered) else: @@ -525,7 +525,7 @@ class MediaManagerItem(QtGui.QWidget): serviceItem = self.buildServiceItem(item, True, remote=remote, context=ServiceItemContext.Service) if serviceItem: serviceItem.from_plugin = False - self.service_manager.addServiceItem(serviceItem, replace=replace) + self.service_manager.add_service_item(serviceItem, replace=replace) def onAddEditClick(self): """ @@ -536,13 +536,13 @@ class MediaManagerItem(QtGui.QWidget): translate('OpenLP.MediaManagerItem', 'You must select one or more items.')) else: log.debug(u'%s Add requested', self.plugin.name) - serviceItem = self.plugin.serviceManager.getServiceItem() + serviceItem = self.service_manager.get_service_item() if not serviceItem: QtGui.QMessageBox.information(self, UiStrings().NISs, translate('OpenLP.MediaManagerItem', 'You must select an existing service item to add to.')) elif self.plugin.name == serviceItem.name: self.generateSlideData(serviceItem) - self.service_manager.addServiceItem(serviceItem, replace=True) + self.service_manager.add_service_item(serviceItem, replace=True) else: # Turn off the remote edit update message indicator QtGui.QMessageBox.information(self, translate('OpenLP.MediaManagerItem', 'Invalid Service Item'), @@ -554,8 +554,7 @@ class MediaManagerItem(QtGui.QWidget): """ serviceItem = ServiceItem(self.plugin) serviceItem.add_icon(self.plugin.iconPath) - if self.generateSlideData(serviceItem, item, xmlVersion, remote, - context): + if self.generateSlideData(serviceItem, item, xmlVersion, remote, context): return serviceItem else: return None @@ -681,10 +680,11 @@ class MediaManagerItem(QtGui.QWidget): def _get_service_manager(self): """ - Adds the plugin manager to the class dynamically + Adds the service manager to the class dynamically """ if not hasattr(self, u'_service_manager'): self._service_manager = Registry().get(u'service_manager') return self._service_manager - service_manager = property(_get_service_manager) \ No newline at end of file + service_manager = property(_get_service_manager) + diff --git a/openlp/core/lib/registry.py b/openlp/core/lib/registry.py index a30ed4ba3..3a42a14c5 100644 --- a/openlp/core/lib/registry.py +++ b/openlp/core/lib/registry.py @@ -30,6 +30,7 @@ Provide Registry Services """ import logging +import sys log = logging.getLogger(__name__) @@ -54,8 +55,13 @@ class Registry(object): log.info(u'Registry Initialising') registry = cls() registry.service_list = {} + registry.running_under_test = False + # Allow the tests to remove Registry entries but not the live system + if u'nosetest' in sys.argv[0]: + registry.running_under_test = True return registry + def get(self, key): """ Extracts the registry value from the list based on the key passed in @@ -75,3 +81,16 @@ class Registry(object): raise KeyError(u'Duplicate service exception %s' % key) else: self.service_list[key] = reference + + def remove(self, key): + """ + Removes the registry value from the list based on the key passed in + (Only valid and active for testing framework) + """ + if self.running_under_test == False: + log.error(u'Invalid Method call for key %s' % key) + raise KeyError(u'Invalid Method call for key %s' % key) + return + if key in self.service_list: + del self.service_list[key] + diff --git a/openlp/core/lib/settings.py b/openlp/core/lib/settings.py index ba1e63fb9..0591871cc 100644 --- a/openlp/core/lib/settings.py +++ b/openlp/core/lib/settings.py @@ -165,7 +165,7 @@ class Settings(QtCore.QSettings): u'shortcuts/importBibleItem': [], u'shortcuts/modeDefaultItem': [], u'shortcuts/modeLiveItem': [], - u'shortcuts/makeLive': [QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return], + u'shortcuts/make_live': [QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return], u'shortcuts/moveUp': [QtCore.Qt.Key_PageUp], u'shortcuts/moveTop': [QtCore.Qt.Key_Home], u'shortcuts/modeSetupItem': [], @@ -242,6 +242,7 @@ class Settings(QtCore.QSettings): (u'songs/last directory 1', u'songs/last directory import', []), (u'bibles/last directory 1', u'bibles/last directory import', []), (u'songusage/last directory 1', u'songusage/last directory export', []), + (u'shortcuts/makeLive', u'shortcuts/make_live', []), (u'advanced/stylesheet fix', u'', []), (u'media/background color', u'players/background color', []) ] diff --git a/openlp/core/ui/aboutdialog.py b/openlp/core/ui/aboutdialog.py index 7a823017b..a07434b12 100644 --- a/openlp/core/ui/aboutdialog.py +++ b/openlp/core/ui/aboutdialog.py @@ -74,8 +74,8 @@ class Ui_AboutDialog(object): self.aboutNotebook.addTab(self.licenseTab, u'') self.aboutDialogLayout.addWidget(self.aboutNotebook) self.volunteerButton = create_button(None, u'volunteerButton', icon=u':/system/system_volunteer.png') - self.buttonBox = create_button_box(aboutDialog, u'buttonBox', [u'close'], [self.volunteerButton]) - self.aboutDialogLayout.addWidget(self.buttonBox) + self.button_box = create_button_box(aboutDialog, u'button_box', [u'close'], [self.volunteerButton]) + self.aboutDialogLayout.addWidget(self.button_box) self.retranslateUi(aboutDialog) self.aboutNotebook.setCurrentIndex(0) diff --git a/openlp/core/ui/exceptiondialog.py b/openlp/core/ui/exceptiondialog.py index 76a92938d..e3736de53 100644 --- a/openlp/core/ui/exceptiondialog.py +++ b/openlp/core/ui/exceptiondialog.py @@ -70,9 +70,9 @@ class Ui_ExceptionDialog(object): icon=u':/general/general_save.png', click=self.onSaveReportButtonClicked) self.attachFileButton = create_button(exceptionDialog, u'attachFileButton', icon=u':/general/general_open.png', click=self.onAttachFileButtonClicked) - self.buttonBox = create_button_box(exceptionDialog, u'buttonBox', + self.button_box = create_button_box(exceptionDialog, u'button_box', [u'close'], [self.sendReportButton, self.saveReportButton, self.attachFileButton]) - self.exceptionLayout.addWidget(self.buttonBox) + self.exceptionLayout.addWidget(self.button_box) self.retranslateUi(exceptionDialog) QtCore.QObject.connect(self.descriptionTextEdit, diff --git a/openlp/core/ui/filerenamedialog.py b/openlp/core/ui/filerenamedialog.py index 956058d06..5cd67a20b 100644 --- a/openlp/core/ui/filerenamedialog.py +++ b/openlp/core/ui/filerenamedialog.py @@ -37,7 +37,7 @@ class Ui_FileRenameDialog(object): fileRenameDialog.setObjectName(u'fileRenameDialog') fileRenameDialog.resize(300, 10) self.dialogLayout = QtGui.QGridLayout(fileRenameDialog) - self.dialogLayout.setObjectName(u'dialogLayout') + self.dialogLayout.setObjectName(u'dialog_layout') self.fileNameLabel = QtGui.QLabel(fileRenameDialog) self.fileNameLabel.setObjectName(u'fileNameLabel') self.dialogLayout.addWidget(self.fileNameLabel, 0, 0) @@ -45,8 +45,8 @@ class Ui_FileRenameDialog(object): self.fileNameEdit.setValidator(QtGui.QRegExpValidator(QtCore.QRegExp(r'[^/\\?*|<>\[\]":+%]+'), self)) self.fileNameEdit.setObjectName(u'fileNameEdit') self.dialogLayout.addWidget(self.fileNameEdit, 0, 1) - self.buttonBox = create_button_box(fileRenameDialog, u'buttonBox', [u'cancel', u'ok']) - self.dialogLayout.addWidget(self.buttonBox, 1, 0, 1, 2) + self.button_box = create_button_box(fileRenameDialog, u'button_box', [u'cancel', u'ok']) + self.dialogLayout.addWidget(self.button_box, 1, 0, 1, 2) self.retranslateUi(fileRenameDialog) self.setMaximumHeight(self.sizeHint().height()) diff --git a/openlp/core/ui/firsttimelanguagedialog.py b/openlp/core/ui/firsttimelanguagedialog.py index b4b2e374c..eae9dc198 100644 --- a/openlp/core/ui/firsttimelanguagedialog.py +++ b/openlp/core/ui/firsttimelanguagedialog.py @@ -39,7 +39,7 @@ class Ui_FirstTimeLanguageDialog(object): self.dialogLayout = QtGui.QVBoxLayout(languageDialog) self.dialogLayout.setContentsMargins(8, 8, 8, 8) self.dialogLayout.setSpacing(8) - self.dialogLayout.setObjectName(u'dialogLayout') + self.dialogLayout.setObjectName(u'dialog_layout') self.infoLabel = QtGui.QLabel(languageDialog) self.infoLabel.setObjectName(u'infoLabel') self.dialogLayout.addWidget(self.infoLabel) @@ -53,8 +53,8 @@ class Ui_FirstTimeLanguageDialog(object): self.languageComboBox.setObjectName("languageComboBox") self.languageLayout.addWidget(self.languageComboBox) self.dialogLayout.addLayout(self.languageLayout) - self.buttonBox = create_button_box(languageDialog, u'buttonBox', [u'cancel', u'ok']) - self.dialogLayout.addWidget(self.buttonBox) + self.button_box = create_button_box(languageDialog, u'button_box', [u'cancel', u'ok']) + self.dialogLayout.addWidget(self.button_box) self.retranslateUi(languageDialog) self.setMaximumHeight(self.sizeHint().height()) diff --git a/openlp/core/ui/formattingtagdialog.py b/openlp/core/ui/formattingtagdialog.py index 9d98ec38e..c9cdb15df 100644 --- a/openlp/core/ui/formattingtagdialog.py +++ b/openlp/core/ui/formattingtagdialog.py @@ -110,8 +110,8 @@ class Ui_FormattingTagDialog(object): self.savePushButton.setObjectName(u'savePushButton') self.dataGridLayout.addWidget(self.savePushButton, 4, 2, 1, 1) self.listdataGridLayout.addWidget(self.editGroupBox, 2, 0, 1, 1) - self.buttonBox = create_button_box(formattingTagDialog, u'buttonBox', [u'close']) - self.listdataGridLayout.addWidget(self.buttonBox, 3, 0, 1, 1) + self.button_box = create_button_box(formattingTagDialog, u'button_box', [u'close']) + self.listdataGridLayout.addWidget(self.button_box, 3, 0, 1, 1) self.retranslateUi(formattingTagDialog) diff --git a/openlp/core/ui/formattingtagform.py b/openlp/core/ui/formattingtagform.py index 5ff9f7b01..2e72bdd65 100644 --- a/openlp/core/ui/formattingtagform.py +++ b/openlp/core/ui/formattingtagform.py @@ -53,7 +53,7 @@ class FormattingTagForm(QtGui.QDialog, Ui_FormattingTagDialog): QtCore.QObject.connect(self.newPushButton, QtCore.SIGNAL(u'clicked()'), self.onNewClicked) QtCore.QObject.connect(self.savePushButton, QtCore.SIGNAL(u'clicked()'), self.onSavedClicked) QtCore.QObject.connect(self.deletePushButton, QtCore.SIGNAL(u'clicked()'), self.onDeleteClicked) - QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(u'rejected()'), self.close) + QtCore.QObject.connect(self.button_box, QtCore.SIGNAL(u'rejected()'), self.close) QtCore.QObject.connect(self.descriptionLineEdit, QtCore.SIGNAL(u'textEdited(QString)'), self.onTextEdited) QtCore.QObject.connect(self.tagLineEdit, QtCore.SIGNAL(u'textEdited(QString)'), self.onTextEdited) QtCore.QObject.connect(self.startTagLineEdit, QtCore.SIGNAL(u'textEdited(QString)'), self.onTextEdited) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 6ab3f7f0a..77e954943 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -174,25 +174,25 @@ class Ui_MainWindow(object): icon=u':/general/general_new.png', shortcuts=[QtGui.QKeySequence(u'Ctrl+N')], category=UiStrings().File, - triggers=self.serviceManagerContents.onNewServiceClicked) + triggers=self.serviceManagerContents.on_new_service_clicked) self.fileOpenItem = create_action(mainWindow, u'fileOpenItem', icon=u':/general/general_open.png', shortcuts=[QtGui.QKeySequence(u'Ctrl+O')], category=UiStrings().File, - triggers=self.serviceManagerContents.onLoadServiceClicked) + triggers=self.serviceManagerContents.on_load_service_clicked) self.fileSaveItem = create_action(mainWindow, u'fileSaveItem', icon=u':/general/general_save.png', shortcuts=[QtGui.QKeySequence(u'Ctrl+S')], category=UiStrings().File, - triggers=self.serviceManagerContents.saveFile) + triggers=self.serviceManagerContents.save_file) self.fileSaveAsItem = create_action(mainWindow, u'fileSaveAsItem', shortcuts=[QtGui.QKeySequence(u'Ctrl+Shift+S')], category=UiStrings().File, - triggers=self.serviceManagerContents.saveFileAs) + triggers=self.serviceManagerContents.save_file_as) self.printServiceOrderItem = create_action(mainWindow, u'printServiceItem', shortcuts=[QtGui.QKeySequence(u'Ctrl+P')], category=UiStrings().File, - triggers=self.serviceManagerContents.printServiceOrder) + triggers=self.serviceManagerContents.print_service_order) self.fileExitItem = create_action(mainWindow, u'fileExitItem', icon=u':/system/system_exit.png', shortcuts=[QtGui.QKeySequence(u'Alt+F4')], @@ -528,7 +528,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'live_display_blank_check'), self.blankCheck) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_screen_changed'), self.screenChanged) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'mainwindow_status_text'), self.showStatusMessage) - QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'cleanup'), self.cleanUp) + QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'cleanup'), self.clean_up) # Media Manager QtCore.QObject.connect(self.mediaToolBox, QtCore.SIGNAL(u'currentChanged(int)'), self.onMediaToolBoxChanged) Receiver.send_message(u'cursor_busy') @@ -618,9 +618,9 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): filename = args[0] if not isinstance(filename, unicode): filename = unicode(filename, sys.getfilesystemencoding()) - self.serviceManagerContents.loadFile(filename) + self.serviceManagerContents.load_file(filename) elif Settings().value(self.generalSettingsSection + u'/auto open'): - self.serviceManagerContents.loadLastFile() + self.serviceManagerContents.load_Last_file() view_mode = Settings().value(u'%s/view mode' % self.generalSettingsSection) if view_mode == u'default': self.modeDefaultItem.setChecked(True) @@ -866,7 +866,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): 'be applied the next time you start OpenLP.'), QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok)) self.settingsImported = True - self.cleanUp() + self.clean_up() QtCore.QCoreApplication.exit() def onSettingsExportItemClicked(self): @@ -999,18 +999,18 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): return # If we just did a settings import, close without saving changes. if self.settingsImported: - self.cleanUp(False) + self.clean_up(False) event.accept() - if self.serviceManagerContents.isModified(): - ret = self.serviceManagerContents.saveModifiedService() + if self.serviceManagerContents.is_modified(): + ret = self.serviceManagerContents.save_modified_service() if ret == QtGui.QMessageBox.Save: - if self.serviceManagerContents.decideSaveMethod(): - self.cleanUp() + if self.serviceManagerContents.decide_save_method(): + self.clean_up() event.accept() else: event.ignore() elif ret == QtGui.QMessageBox.Discard: - self.cleanUp() + self.clean_up() event.accept() else: event.ignore() @@ -1021,15 +1021,15 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No), QtGui.QMessageBox.Yes) if ret == QtGui.QMessageBox.Yes: - self.cleanUp() + self.clean_up() event.accept() else: event.ignore() else: - self.cleanUp() + self.clean_up() event.accept() - def cleanUp(self, save_settings=True): + def clean_up(self, save_settings=True): """ Runs all the cleanup code before OpenLP shuts down. @@ -1223,7 +1223,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): action = create_action(self, u'', text=u'&%d %s' % (fileId + 1, os.path.splitext(os.path.basename( unicode(filename)))[0]), data=filename, - triggers=self.serviceManagerContents.onRecentServiceClicked) + triggers=self.serviceManagerContents.on_recent_service_clicked) self.recentFilesMenu.addAction(action) clearRecentFilesAction = create_action(self, u'', text=translate('OpenLP.MainWindow', 'Clear List', 'Clear List of recent files'), diff --git a/openlp/core/ui/media/mediacontroller.py b/openlp/core/ui/media/mediacontroller.py index 73f311186..0ac91c226 100644 --- a/openlp/core/ui/media/mediacontroller.py +++ b/openlp/core/ui/media/mediacontroller.py @@ -131,14 +131,14 @@ class MediaController(object): for item in player.audio_extensions_list: if not item in self.audio_extensions_list: self.audio_extensions_list.append(item) - self.service_manager.supportedSuffixes(item[2:]) + self.service_manager.supported_suffixes(item[2:]) self.video_extensions_list = [] for player in self.mediaPlayers.values(): if player.isActive: for item in player.video_extensions_list: if item not in self.video_extensions_list: self.video_extensions_list.extend(item) - self.service_manager.supportedSuffixes(item[2:]) + self.service_manager.supported_suffixes(item[2:]) def register_players(self, player): """ diff --git a/openlp/core/ui/media/playertab.py b/openlp/core/ui/media/playertab.py index a0cab2e48..eb1a36ca6 100644 --- a/openlp/core/ui/media/playertab.py +++ b/openlp/core/ui/media/playertab.py @@ -194,7 +194,7 @@ class PlayerTab(SettingsTab): set_media_players(self.usedPlayers, override_player) player_string_changed = True if player_string_changed: - self.parent.resetSupportedSuffixes() + self.parent.reset_supported_suffixes() Receiver.send_message(u'mediaitem_media_rebuild') Receiver.send_message(u'config_screen_changed') diff --git a/openlp/core/ui/plugindialog.py b/openlp/core/ui/plugindialog.py index 06bfbe0c2..401cab924 100644 --- a/openlp/core/ui/plugindialog.py +++ b/openlp/core/ui/plugindialog.py @@ -67,8 +67,8 @@ class Ui_PluginViewDialog(object): self.pluginInfoLayout.addRow(self.aboutLabel, self.aboutTextBrowser) self.listLayout.addWidget(self.pluginInfoGroupBox) self.pluginLayout.addLayout(self.listLayout) - self.buttonBox = create_button_box(pluginViewDialog, u'buttonBox', [u'ok']) - self.pluginLayout.addWidget(self.buttonBox) + self.button_box = create_button_box(pluginViewDialog, u'button_box', [u'ok']) + self.pluginLayout.addWidget(self.button_box) self.retranslateUi(pluginViewDialog) def retranslateUi(self, pluginViewDialog): diff --git a/openlp/core/ui/printserviceform.py b/openlp/core/ui/printserviceform.py index 0cdba6c9b..d10fe7ba0 100644 --- a/openlp/core/ui/printserviceform.py +++ b/openlp/core/ui/printserviceform.py @@ -33,7 +33,7 @@ import os from PyQt4 import QtCore, QtGui from lxml import html -from openlp.core.lib import translate, get_text_file_string, Receiver, Settings, UiStrings +from openlp.core.lib import translate, get_text_file_string, Receiver, Settings, UiStrings, Registry from openlp.core.ui.printservicedialog import Ui_PrintServiceDialog, ZoomSize from openlp.core.utils import AppLocation @@ -108,13 +108,11 @@ http://doc.trolltech.com/4.7/richtext-html-subset.html#css-properties class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog): - def __init__(self, mainWindow, serviceManager): + def __init__(self): """ Constructor """ - QtGui.QDialog.__init__(self, mainWindow) - self.mainWindow = mainWindow - self.serviceManager = serviceManager + QtGui.QDialog.__init__(self, self.main_window) self.printer = QtGui.QPrinter() self.printDialog = QtGui.QPrintDialog(self.printer, self) self.document = QtGui.QTextDocument() @@ -140,7 +138,8 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog): QtCore.QObject.connect(self.zoomComboBox, QtCore.SIGNAL(u'currentIndexChanged(int)'), self.displaySizeChanged) QtCore.QObject.connect(self.plainCopy, QtCore.SIGNAL(u'triggered()'), self.copyText) QtCore.QObject.connect(self.htmlCopy, QtCore.SIGNAL(u'triggered()'), self.copyHtmlText) - QtCore.QObject.connect(self.slideTextCheckBox, QtCore.SIGNAL(u'stateChanged(int)'), self.onSlideTextCheckBoxChanged) + QtCore.QObject.connect(self.slideTextCheckBox, QtCore.SIGNAL(u'stateChanged(int)'), + self.onSlideTextCheckBoxChanged) self.updatePreviewText() def toggleOptions(self, checked): @@ -170,7 +169,7 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog): self._addElement(u'body', parent=html_data) self._addElement(u'h1', cgi.escape(self.titleLineEdit.text()), html_data.body, classId=u'serviceTitle') - for index, item in enumerate(self.serviceManager.serviceItems): + for index, item in enumerate(self.service_manager.serviceItems): self._addPreviewItem(html_data.body, item[u'service_item'], index) # Add the custom service notes: if self.footerTextEdit.toPlainText(): @@ -319,14 +318,14 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog): # remove the icon from the text clipboard_text = clipboard_text.replace(u'\ufffc\xa0', u'') # and put it all on the clipboard - self.mainWindow.clipboard.setText(clipboard_text) + self.main_window.clipboard.setText(clipboard_text) def copyHtmlText(self): """ Copies the display text to the clipboard as Html """ self.update_song_usage() - self.mainWindow.clipboard.setText(self.document.toHtml()) + self.main_window.clipboard.setText(self.document.toHtml()) def printServiceOrder(self): """ @@ -392,6 +391,26 @@ class PrintServiceForm(QtGui.QDialog, Ui_PrintServiceDialog): # Only continue when we include the song's text. if not self.slideTextCheckBox.isChecked(): return - for item in self.serviceManager.serviceItems: + for item in self.service_manager.serviceItems: # Trigger Audit requests Receiver.send_message(u'print_service_started', [item[u'service_item']]) + + def _get_service_manager(self): + """ + Adds the service manager to the class dynamically + """ + if not hasattr(self, u'_service_manager'): + self._service_manager = Registry().get(u'service_manager') + return self._service_manager + + service_manager = property(_get_service_manager) + + def _get_main_window(self): + """ + Adds the main window to the class dynamically + """ + if not hasattr(self, u'_main_window'): + self._main_window = Registry().get(u'main_window') + return self._main_window + + main_window = property(_get_main_window) \ No newline at end of file diff --git a/openlp/core/ui/serviceitemeditdialog.py b/openlp/core/ui/serviceitemeditdialog.py index b8537d557..638bf4460 100644 --- a/openlp/core/ui/serviceitemeditdialog.py +++ b/openlp/core/ui/serviceitemeditdialog.py @@ -35,29 +35,29 @@ from openlp.core.lib.ui import create_button_box, create_button class Ui_ServiceItemEditDialog(object): def setupUi(self, serviceItemEditDialog): serviceItemEditDialog.setObjectName(u'serviceItemEditDialog') - self.dialogLayout = QtGui.QGridLayout(serviceItemEditDialog) - self.dialogLayout.setContentsMargins(8, 8, 8, 8) - self.dialogLayout.setSpacing(8) - self.dialogLayout.setObjectName(u'dialogLayout') - self.listWidget = QtGui.QListWidget(serviceItemEditDialog) - self.listWidget.setAlternatingRowColors(True) - self.listWidget.setObjectName(u'listWidget') - self.dialogLayout.addWidget(self.listWidget, 0, 0) - self.buttonLayout = QtGui.QVBoxLayout() - self.buttonLayout.setObjectName(u'buttonLayout') - self.deleteButton = create_button(serviceItemEditDialog, u'deleteButton', role=u'delete', - click=serviceItemEditDialog.onDeleteButtonClicked) - self.buttonLayout.addWidget(self.deleteButton) - self.buttonLayout.addStretch() - self.upButton = create_button(serviceItemEditDialog, u'upButton', role=u'up', - click=serviceItemEditDialog.onUpButtonClicked) - self.downButton = create_button(serviceItemEditDialog, u'downButton', role=u'down', - click=serviceItemEditDialog.onDownButtonClicked) - self.buttonLayout.addWidget(self.upButton) - self.buttonLayout.addWidget(self.downButton) - self.dialogLayout.addLayout(self.buttonLayout, 0, 1) - self.buttonBox = create_button_box(serviceItemEditDialog, u'buttonBox', [u'cancel', u'save']) - self.dialogLayout.addWidget(self.buttonBox, 1, 0, 1, 2) + self.dialog_layout = QtGui.QGridLayout(serviceItemEditDialog) + self.dialog_layout.setContentsMargins(8, 8, 8, 8) + self.dialog_layout.setSpacing(8) + self.dialog_layout.setObjectName(u'dialog_layout') + self.list_widget = QtGui.QListWidget(serviceItemEditDialog) + self.list_widget.setAlternatingRowColors(True) + self.list_widget.setObjectName(u'list_widget') + self.dialog_layout.addWidget(self.list_widget, 0, 0) + self.button_layout = QtGui.QVBoxLayout() + self.button_layout.setObjectName(u'button_layout') + self.delete_button = create_button(serviceItemEditDialog, u'deleteButton', role=u'delete', + click=serviceItemEditDialog.on_delete_button_clicked) + self.button_layout.addWidget(self.delete_button) + self.button_layout.addStretch() + self.up_button = create_button(serviceItemEditDialog, u'upButton', role=u'up', + click=serviceItemEditDialog.on_up_button_clicked) + self.down_button = create_button(serviceItemEditDialog, u'downButton', role=u'down', + click=serviceItemEditDialog.on_down_button_clicked) + self.button_layout.addWidget(self.up_button) + self.button_layout.addWidget(self.down_button) + self.dialog_layout.addLayout(self.button_layout, 0, 1) + self.button_box = create_button_box(serviceItemEditDialog, u'button_box', [u'cancel', u'save']) + self.dialog_layout.addWidget(self.button_box, 1, 0, 1, 2) self.retranslateUi(serviceItemEditDialog) def retranslateUi(self, serviceItemEditDialog): diff --git a/openlp/core/ui/serviceitemeditform.py b/openlp/core/ui/serviceitemeditform.py index 5392d6418..58d8a5399 100644 --- a/openlp/core/ui/serviceitemeditform.py +++ b/openlp/core/ui/serviceitemeditform.py @@ -28,6 +28,7 @@ ############################################################################### from PyQt4 import QtCore, QtGui +from openlp.core.lib import Registry from serviceitemeditdialog import Ui_ServiceItemEditDialog @@ -35,91 +36,92 @@ class ServiceItemEditForm(QtGui.QDialog, Ui_ServiceItemEditDialog): """ This is the form that is used to edit the verses of the song. """ - def __init__(self, parent=None): + def __init__(self): """ Constructor """ - QtGui.QDialog.__init__(self, parent) + QtGui.QDialog.__init__(self, self.main_window) self.setupUi(self) - self.itemList = [] - QtCore.QObject.connect(self.listWidget, QtCore.SIGNAL(u'currentRowChanged(int)'), self.onCurrentRowChanged) + self.item_list = [] + QtCore.QObject.connect(self.list_widget, QtCore.SIGNAL(u'currentRowChanged(int)'), + self.on_current_row_changed) - def setServiceItem(self, item): + def set_service_item(self, item): self.item = item - self.itemList = [] + self.item_list = [] if self.item.is_image(): self.data = True for frame in self.item._raw_frames: - self.itemList.append(frame) - self.loadData() - self.listWidget.setCurrentItem(self.listWidget.currentItem()) + self.item_list.append(frame) + self.load_data() + self.list_widget.setCurrentItem(self.list_widget.currentItem()) - def getServiceItem(self): + def get_service_item(self): if self.data: self.item._raw_frames = [] if self.item.is_image(): - for item in self.itemList: + for item in self.item_list: self.item.add_from_image(item[u'path'], item[u'title']) self.item.render() return self.item - def loadData(self): + def load_data(self): """ Loads the image list. """ - self.listWidget.clear() - for frame in self.itemList: + self.list_widget.clear() + for frame in self.item_list: item_name = QtGui.QListWidgetItem(frame[u'title']) - self.listWidget.addItem(item_name) + self.list_widget.addItem(item_name) - def onDeleteButtonClicked(self): + def on_delete_button_clicked(self): """ Delete the current row. """ - item = self.listWidget.currentItem() + item = self.list_widget.currentItem() if not item: return - row = self.listWidget.row(item) - self.itemList.pop(row) - self.loadData() - if row == self.listWidget.count(): - self.listWidget.setCurrentRow(row - 1) + row = self.list_widget.row(item) + self.item_list.pop(row) + self.load_data() + if row == self.list_widget.count(): + self.list_widget.setCurrentRow(row - 1) else: - self.listWidget.setCurrentRow(row) + self.list_widget.setCurrentRow(row) - def onUpButtonClicked(self): + def on_up_button_clicked(self): """ Move the current row up in the list. """ - self.__moveItem(u'up') + self.__move_item(u'up') - def onDownButtonClicked(self): + def on_down_button_clicked(self): """ Move the current row down in the list """ - self.__moveItem(u'down') + self.__move_item(u'down') - def __moveItem(self, direction=u''): + def __move_item(self, direction=u''): """ Move the current item. """ if not direction: return - item = self.listWidget.currentItem() + item = self.list_widget.currentItem() if not item: return - row = self.listWidget.row(item) - temp = self.itemList[row] - self.itemList.pop(row) + row = self.list_widget.row(item) + temp = self.item_list[row] + self.item_list.pop(row) if direction == u'up': row -= 1 else: row += 1 - self.itemList.insert(row, temp) - self.loadData() - self.listWidget.setCurrentRow(row) + self.item_list.insert(row, temp) + self.load_data() + self.list_widget.setCurrentRow(row) - def onCurrentRowChanged(self, row): + def on_current_row_changed(self, row): """ Called when the currentRow has changed. @@ -127,19 +129,29 @@ class ServiceItemEditForm(QtGui.QDialog, Ui_ServiceItemEditDialog): The row number (int). """ # Disable all buttons, as no row is selected or only one image is left. - if row == -1 or self.listWidget.count() == 1: - self.downButton.setEnabled(False) - self.upButton.setEnabled(False) - self.deleteButton.setEnabled(False) + if row == -1 or self.list_widget.count() == 1: + self.down_button.setEnabled(False) + self.up_button.setEnabled(False) + self.delete_button.setEnabled(False) else: # Check if we are at the end of the list. - if self.listWidget.count() == row + 1: - self.downButton.setEnabled(False) + if self.list_widget.count() == row + 1: + self.down_button.setEnabled(False) else: - self.downButton.setEnabled(True) + self.down_button.setEnabled(True) # Check if we are at the beginning of the list. if row == 0: - self.upButton.setEnabled(False) + self.up_button.setEnabled(False) else: - self.upButton.setEnabled(True) - self.deleteButton.setEnabled(True) + self.up_button.setEnabled(True) + self.delete_button.setEnabled(True) + + def _get_main_window(self): + """ + Adds the main window to the class dynamically + """ + if not hasattr(self, u'_main_window'): + self._main_window = Registry().get(u'main_window') + return self._main_window + + main_window = property(_get_main_window) \ No newline at end of file diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index c757f14d0..fe1023bbf 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -57,13 +57,16 @@ class ServiceManagerList(QtGui.QTreeWidget): self.serviceManager = serviceManager def keyPressEvent(self, event): + """ + Capture Key press and respond accordingly. + """ if isinstance(event, QtGui.QKeyEvent): # here accept the event and do something if event.key() == QtCore.Qt.Key_Up: - self.serviceManager.onMoveSelectionUp() + self.serviceManager.on_move_selection_up() event.accept() elif event.key() == QtCore.Qt.Key_Down: - self.serviceManager.onMoveSelectionDown() + self.serviceManager.on_move_selection_down() event.accept() elif event.key() == QtCore.Qt.Key_Delete: self.serviceManager.onDeleteFromService() @@ -85,13 +88,197 @@ class ServiceManagerList(QtGui.QTreeWidget): event.ignore() return drag = QtGui.QDrag(self) - mimeData = QtCore.QMimeData() - drag.setMimeData(mimeData) - mimeData.setText(u'ServiceManager') + mime_data = QtCore.QMimeData() + drag.setMimeData(mime_data) + mime_data.setText(u'ServiceManager') drag.start(QtCore.Qt.CopyAction) +class ServiceManagerDialog(object): + """ + """ + def setup_ui(self,widget): + # Create the top toolbar + self.toolbar = OpenLPToolbar(self) + self.toolbar.addToolbarAction(u'newService', text=UiStrings().NewService, icon=u':/general/general_new.png', + tooltip=UiStrings().CreateService, triggers=self.on_new_service_clicked) + self.toolbar.addToolbarAction(u'openService', text=UiStrings().OpenService, icon=u':/general/general_open.png', + tooltip=translate('OpenLP.ServiceManager', 'Load an existing service.'), triggers=self.on_load_service_clicked) + self.toolbar.addToolbarAction(u'saveService', text=UiStrings().SaveService, icon=u':/general/general_save.png', + tooltip=translate('OpenLP.ServiceManager', 'Save this service.'), triggers=self.decide_save_method) + self.toolbar.addSeparator() + self.theme_label = QtGui.QLabel(u'%s:' % UiStrings().Theme, self) + self.theme_label.setMargin(3) + self.theme_label.setObjectName(u'theme_label') + self.toolbar.addToolbarWidget(self.theme_label) + self.theme_combo_box = QtGui.QComboBox(self.toolbar) + self.theme_combo_box.setToolTip(translate('OpenLP.ServiceManager', 'Select a theme for the service.')) + self.theme_combo_box.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToMinimumContentsLength) + self.theme_combo_box.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed) + self.theme_combo_box.setObjectName(u'theme_combo_box') + self.toolbar.addToolbarWidget(self.theme_combo_box) + self.toolbar.setObjectName(u'toolbar') + self.layout.addWidget(self.toolbar) + # Create the service manager list + self.service_manager_list = ServiceManagerList(self) + self.service_manager_list.setEditTriggers( + QtGui.QAbstractItemView.CurrentChanged | + QtGui.QAbstractItemView.DoubleClicked | + QtGui.QAbstractItemView.EditKeyPressed) + self.service_manager_list.setDragDropMode(QtGui.QAbstractItemView.DragDrop) + self.service_manager_list.setAlternatingRowColors(True) + self.service_manager_list.setHeaderHidden(True) + self.service_manager_list.setExpandsOnDoubleClick(False) + self.service_manager_list.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) + QtCore.QObject.connect(self.service_manager_list, QtCore.SIGNAL('customContextMenuRequested(QPoint)'), + self.context_menu) + self.service_manager_list.setObjectName(u'service_manager_list') + # enable drop + self.service_manager_list.__class__.dragEnterEvent = self.drag_enter_event + self.service_manager_list.__class__.dragMoveEvent = self.drag_enter_event + self.service_manager_list.__class__.dropEvent = self.drop_event + self.layout.addWidget(self.service_manager_list) + # Add the bottom toolbar + self.order_toolbar = OpenLPToolbar(self) + action_list = ActionList.get_instance() + action_list.add_category(UiStrings().Service, CategoryOrder.standardToolbar) + self.service_manager_list.moveTop = self.order_toolbar.addToolbarAction(u'moveTop', + text=translate('OpenLP.ServiceManager', 'Move to &top'), icon=u':/services/service_top.png', + tooltip=translate('OpenLP.ServiceManager', 'Move item to the top of the service.'), + shortcuts=[QtCore.Qt.Key_Home], category=UiStrings().Service, triggers=self.onServiceTop) + self.service_manager_list.moveUp = self.order_toolbar.addToolbarAction(u'moveUp', + text=translate('OpenLP.ServiceManager', 'Move &up'), icon=u':/services/service_up.png', + tooltip=translate('OpenLP.ServiceManager', 'Move item up one position in the service.'), + shortcuts=[QtCore.Qt.Key_PageUp], category=UiStrings().Service, triggers=self.onServiceUp) + self.service_manager_list.moveDown = self.order_toolbar.addToolbarAction(u'moveDown', + text=translate('OpenLP.ServiceManager', 'Move &down'), icon=u':/services/service_down.png', + tooltip=translate('OpenLP.ServiceManager', 'Move item down one position in the service.'), + shortcuts=[QtCore.Qt.Key_PageDown], category=UiStrings().Service, triggers=self.onServiceDown) + self.service_manager_list.moveBottom = self.order_toolbar.addToolbarAction(u'moveBottom', + text=translate('OpenLP.ServiceManager', 'Move to &bottom'), icon=u':/services/service_bottom.png', + tooltip=translate('OpenLP.ServiceManager', 'Move item to the end of the service.'), + shortcuts=[QtCore.Qt.Key_End], category=UiStrings().Service, triggers=self.onServiceEnd) + self.service_manager_list.down = self.order_toolbar.addToolbarAction(u'down', + text=translate('OpenLP.ServiceManager', 'Move &down'), + tooltip=translate('OpenLP.ServiceManager', 'Moves the selection down the window.'), visible=False, + shortcuts=[QtCore.Qt.Key_Down], triggers=self.on_move_selection_down) + action_list.add_action(self.service_manager_list.down) + self.service_manager_list.up = self.order_toolbar.addToolbarAction(u'up', + text=translate('OpenLP.ServiceManager', 'Move up'), tooltip=translate('OpenLP.ServiceManager', + 'Moves the selection up the window.'), visible=False, shortcuts=[QtCore.Qt.Key_Up], + triggers=self.on_move_selection_up) + action_list.add_action(self.service_manager_list.up) + self.order_toolbar.addSeparator() + self.service_manager_list.delete = self.order_toolbar.addToolbarAction(u'delete', + text=translate('OpenLP.ServiceManager', '&Delete From Service'), icon=u':/general/general_delete.png', + tooltip=translate('OpenLP.ServiceManager', 'Delete the selected item from the service.'), + shortcuts=[QtCore.Qt.Key_Delete], triggers=self.onDeleteFromService) + self.order_toolbar.addSeparator() + self.service_manager_list.expand = self.order_toolbar.addToolbarAction(u'expand', + text=translate('OpenLP.ServiceManager', '&Expand all'), icon=u':/services/service_expand_all.png', + tooltip=translate('OpenLP.ServiceManager', 'Expand all the service items.'), + shortcuts=[QtCore.Qt.Key_Plus], category=UiStrings().Service, triggers=self.onExpandAll) + self.service_manager_list.collapse = self.order_toolbar.addToolbarAction(u'collapse', + text=translate('OpenLP.ServiceManager', '&Collapse all'), icon=u':/services/service_collapse_all.png', + tooltip=translate('OpenLP.ServiceManager', 'Collapse all the service items.'), + shortcuts=[QtCore.Qt.Key_Minus], category=UiStrings().Service, triggers=self.onCollapseAll) + self.order_toolbar.addSeparator() + self.service_manager_list.make_live = self.order_toolbar.addToolbarAction(u'make_live', + text=translate('OpenLP.ServiceManager', 'Go Live'), icon=u':/general/general_live.png', + tooltip=translate('OpenLP.ServiceManager', 'Send the selected item to Live.'), + shortcuts=[QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return], category=UiStrings().Service, triggers=self.make_live) + self.layout.addWidget(self.order_toolbar) + # Connect up our signals and slots + QtCore.QObject.connect(self.theme_combo_box, QtCore.SIGNAL(u'activated(int)'), + self.on_theme_combo_box_selected) + QtCore.QObject.connect(self.service_manager_list, QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), + self.on_make_live) + QtCore.QObject.connect(self.service_manager_list, QtCore.SIGNAL(u'itemCollapsed(QTreeWidgetItem*)'), + self.collapsed) + QtCore.QObject.connect(self.service_manager_list, QtCore.SIGNAL(u'itemExpanded(QTreeWidgetItem*)'), + self.expanded) + QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'theme_update_list'), self.update_theme_list) + QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'servicemanager_preview_live'), + self.preview_live) + QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'servicemanager_next_item'), self.next_item) + QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'servicemanager_previous_item'), + self.previous_item) + QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'servicemanager_set_item'), self.on_set_item) + QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_updated'), self.config_updated) + QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_screen_changed'), + self.regenerate_service_Items) + QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'theme_update_global'), self.themeChange) + QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'service_item_update'), self.serviceItemUpdate) + # Last little bits of setting up + self.service_theme = Settings().value(self.main_window.serviceManagerSettingsSection + u'/service theme') + self.servicePath = AppLocation.get_section_data_path(u'servicemanager') + # build the drag and drop context menu + self.dndMenu = QtGui.QMenu() + self.newAction = self.dndMenu.addAction(translate('OpenLP.ServiceManager', '&Add New Item')) + self.newAction.setIcon(build_icon(u':/general/general_edit.png')) + self.addToAction = self.dndMenu.addAction(translate('OpenLP.ServiceManager', '&Add to Selected Item')) + self.addToAction.setIcon(build_icon(u':/general/general_edit.png')) + # build the context menu + self.menu = QtGui.QMenu() + self.edit_action = create_widget_action(self.menu, text=translate('OpenLP.ServiceManager', '&Edit Item'), + icon=u':/general/general_edit.png', triggers=self.remote_edit) + self.maintain_action = create_widget_action(self.menu, text=translate('OpenLP.ServiceManager', '&Reorder Item'), + icon=u':/general/general_edit.png', triggers=self.on_service_item_edit_form) + self.notes_action = create_widget_action(self.menu, text=translate('OpenLP.ServiceManager', '&Notes'), + icon=u':/services/service_notes.png', triggers=self.on_service_item_note_form) + self.time_action = create_widget_action(self.menu, text=translate('OpenLP.ServiceManager', '&Start Time'), + icon=u':/media/media_time.png', triggers=self.on_start_time_form) + self.auto_start_action = create_widget_action(self.menu, text=u'', + icon=u':/media/auto-start_active.png', triggers=self.on_auto_start) + # Add already existing delete action to the menu. + self.menu.addAction(self.service_manager_list.delete) + self.create_custom_action = create_widget_action(self.menu, + text=translate('OpenLP.ServiceManager', 'Create New &Custom Slide'), + icon=u':/general/general_edit.png', triggers=self.create_custom) + self.menu.addSeparator() + # Add AutoPlay menu actions + self.auto_play_slides_group = QtGui.QMenu(translate('OpenLP.ServiceManager', '&Auto play slides')) + self.menu.addMenu(self.auto_play_slides_group) + self.auto_play_slides_loop = create_widget_action(self.auto_play_slides_group, + text=translate('OpenLP.ServiceManager', 'Auto play slides &Loop'), + checked=False, triggers=self.toggle_auto_play_slides_loop) + self.auto_play_slides_once = create_widget_action(self.auto_play_slides_group, + text=translate('OpenLP.ServiceManager', 'Auto play slides &Once'), + checked=False, triggers=self.toggle_auto_play_slides_once) + self.auto_play_slides_group.addSeparator() + self.timed_slide_interval = create_widget_action(self.auto_play_slides_group, + text=translate('OpenLP.ServiceManager', '&Delay between slides'), + checked=False, triggers=self.on_timed_slide_interval) + self.menu.addSeparator() + self.preview_action = create_widget_action(self.menu, text=translate('OpenLP.ServiceManager', 'Show &Preview'), + icon=u':/general/general_preview.png', triggers=self.make_preview) + # Add already existing make live action to the menu. + self.menu.addAction(self.service_manager_list.make_live) + self.menu.addSeparator() + self.theme_menu = QtGui.QMenu(translate('OpenLP.ServiceManager', '&Change Item Theme')) + self.menu.addMenu(self.theme_menu) + self.service_manager_list.addActions( + [self.service_manager_list.moveDown, + self.service_manager_list.moveUp, + self.service_manager_list.make_live, + self.service_manager_list.moveTop, + self.service_manager_list.moveBottom, + self.service_manager_list.up, + self.service_manager_list.down, + self.service_manager_list.expand, + self.service_manager_list.collapse + ]) -class ServiceManager(QtGui.QWidget): + def drag_enter_event(self, event): + """ + Accept Drag events + + ``event`` + Handle of the event pint passed + """ + event.accept() + + +class ServiceManager(QtGui.QWidget, ServiceManagerDialog): """ Manages the services. This involves taking text strings from plugins and adding them to the service. This service can then be zipped up with all @@ -106,191 +293,26 @@ class ServiceManager(QtGui.QWidget): self.active = build_icon(QtGui.QImage(u':/media/auto-start_active.png')) self.inactive = build_icon(QtGui.QImage(u':/media/auto-start_inactive.png')) Registry().register(u'service_manager', self) - self.serviceItems = [] + self.service_items = [] self.suffixes = [] - self.dropPosition = 0 - self.expandTabs = False + self.drop_position = 0 + self.expand_tabs = False self.service_id = 0 # is a new service and has not been saved self._modified = False - self._fileName = u'' + self._file_name = u'' self.service_has_all_original_files = True - self.serviceNoteForm = ServiceNoteForm(self.main_window) - self.serviceItemEditForm = ServiceItemEditForm(self.main_window) - self.startTimeForm = StartTimeForm(self.main_window) + self.serviceNoteForm = ServiceNoteForm() + self.serviceItemEditForm = ServiceItemEditForm() + self.startTimeForm = StartTimeForm() # start with the layout self.layout = QtGui.QVBoxLayout(self) self.layout.setSpacing(0) self.layout.setMargin(0) - # Create the top toolbar - self.toolbar = OpenLPToolbar(self) - self.toolbar.addToolbarAction(u'newService', text=UiStrings().NewService, icon=u':/general/general_new.png', - tooltip=UiStrings().CreateService, triggers=self.onNewServiceClicked) - self.toolbar.addToolbarAction(u'openService', text=UiStrings().OpenService, icon=u':/general/general_open.png', - tooltip=translate('OpenLP.ServiceManager', 'Load an existing service.'), triggers=self.onLoadServiceClicked) - self.toolbar.addToolbarAction(u'saveService', text=UiStrings().SaveService, icon=u':/general/general_save.png', - tooltip=translate('OpenLP.ServiceManager', 'Save this service.'), triggers=self.decideSaveMethod) - self.toolbar.addSeparator() - self.themeLabel = QtGui.QLabel(u'%s:' % UiStrings().Theme, self) - self.themeLabel.setMargin(3) - self.themeLabel.setObjectName(u'themeLabel') - self.toolbar.addToolbarWidget(self.themeLabel) - self.themeComboBox = QtGui.QComboBox(self.toolbar) - self.themeComboBox.setToolTip(translate('OpenLP.ServiceManager', 'Select a theme for the service.')) - self.themeComboBox.setSizeAdjustPolicy(QtGui.QComboBox.AdjustToMinimumContentsLength) - self.themeComboBox.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed) - self.themeComboBox.setObjectName(u'themeComboBox') - self.toolbar.addToolbarWidget(self.themeComboBox) - self.toolbar.setObjectName(u'toolbar') - self.layout.addWidget(self.toolbar) - # Create the service manager list - self.serviceManagerList = ServiceManagerList(self) - self.serviceManagerList.setEditTriggers( - QtGui.QAbstractItemView.CurrentChanged | - QtGui.QAbstractItemView.DoubleClicked | - QtGui.QAbstractItemView.EditKeyPressed) - self.serviceManagerList.setDragDropMode(QtGui.QAbstractItemView.DragDrop) - self.serviceManagerList.setAlternatingRowColors(True) - self.serviceManagerList.setHeaderHidden(True) - self.serviceManagerList.setExpandsOnDoubleClick(False) - self.serviceManagerList.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) - QtCore.QObject.connect(self.serviceManagerList, QtCore.SIGNAL('customContextMenuRequested(QPoint)'), - self.contextMenu) - self.serviceManagerList.setObjectName(u'serviceManagerList') - # enable drop - self.serviceManagerList.__class__.dragEnterEvent = self.dragEnterEvent - self.serviceManagerList.__class__.dragMoveEvent = self.dragEnterEvent - self.serviceManagerList.__class__.dropEvent = self.dropEvent - self.layout.addWidget(self.serviceManagerList) - # Add the bottom toolbar - self.orderToolbar = OpenLPToolbar(self) - action_list = ActionList.get_instance() - action_list.add_category(UiStrings().Service, CategoryOrder.standardToolbar) - self.serviceManagerList.moveTop = self.orderToolbar.addToolbarAction(u'moveTop', - text=translate('OpenLP.ServiceManager', 'Move to &top'), icon=u':/services/service_top.png', - tooltip=translate('OpenLP.ServiceManager', 'Move item to the top of the service.'), - shortcuts=[QtCore.Qt.Key_Home], category=UiStrings().Service, triggers=self.onServiceTop) - self.serviceManagerList.moveUp = self.orderToolbar.addToolbarAction(u'moveUp', - text=translate('OpenLP.ServiceManager', 'Move &up'), icon=u':/services/service_up.png', - tooltip=translate('OpenLP.ServiceManager', 'Move item up one position in the service.'), - shortcuts=[QtCore.Qt.Key_PageUp], category=UiStrings().Service, triggers=self.onServiceUp) - self.serviceManagerList.moveDown = self.orderToolbar.addToolbarAction(u'moveDown', - text=translate('OpenLP.ServiceManager', 'Move &down'), icon=u':/services/service_down.png', - tooltip=translate('OpenLP.ServiceManager', 'Move item down one position in the service.'), - shortcuts=[QtCore.Qt.Key_PageDown], category=UiStrings().Service, triggers=self.onServiceDown) - self.serviceManagerList.moveBottom = self.orderToolbar.addToolbarAction(u'moveBottom', - text=translate('OpenLP.ServiceManager', 'Move to &bottom'), icon=u':/services/service_bottom.png', - tooltip=translate('OpenLP.ServiceManager', 'Move item to the end of the service.'), - shortcuts=[QtCore.Qt.Key_End], category=UiStrings().Service, triggers=self.onServiceEnd) - self.serviceManagerList.down = self.orderToolbar.addToolbarAction(u'down', - text=translate('OpenLP.ServiceManager', 'Move &down'), - tooltip=translate('OpenLP.ServiceManager', 'Moves the selection down the window.'), visible=False, - shortcuts=[QtCore.Qt.Key_Down], triggers=self.onMoveSelectionDown) - action_list.add_action(self.serviceManagerList.down) - self.serviceManagerList.up = self.orderToolbar.addToolbarAction(u'up', - text=translate('OpenLP.ServiceManager', 'Move up'), tooltip=translate('OpenLP.ServiceManager', - 'Moves the selection up the window.'), visible=False, shortcuts=[QtCore.Qt.Key_Up], - triggers=self.onMoveSelectionUp) - action_list.add_action(self.serviceManagerList.up) - self.orderToolbar.addSeparator() - self.serviceManagerList.delete = self.orderToolbar.addToolbarAction(u'delete', - text=translate('OpenLP.ServiceManager', '&Delete From Service'), icon=u':/general/general_delete.png', - tooltip=translate('OpenLP.ServiceManager', 'Delete the selected item from the service.'), - shortcuts=[QtCore.Qt.Key_Delete], triggers=self.onDeleteFromService) - self.orderToolbar.addSeparator() - self.serviceManagerList.expand = self.orderToolbar.addToolbarAction(u'expand', - text=translate('OpenLP.ServiceManager', '&Expand all'), icon=u':/services/service_expand_all.png', - tooltip=translate('OpenLP.ServiceManager', 'Expand all the service items.'), - shortcuts=[QtCore.Qt.Key_Plus], category=UiStrings().Service, triggers=self.onExpandAll) - self.serviceManagerList.collapse = self.orderToolbar.addToolbarAction(u'collapse', - text=translate('OpenLP.ServiceManager', '&Collapse all'), icon=u':/services/service_collapse_all.png', - tooltip=translate('OpenLP.ServiceManager', 'Collapse all the service items.'), - shortcuts=[QtCore.Qt.Key_Minus], category=UiStrings().Service, triggers=self.onCollapseAll) - self.orderToolbar.addSeparator() - self.serviceManagerList.makeLive = self.orderToolbar.addToolbarAction(u'makeLive', - text=translate('OpenLP.ServiceManager', 'Go Live'), icon=u':/general/general_live.png', - tooltip=translate('OpenLP.ServiceManager', 'Send the selected item to Live.'), - shortcuts=[QtCore.Qt.Key_Enter, QtCore.Qt.Key_Return], category=UiStrings().Service, triggers=self.makeLive) - self.layout.addWidget(self.orderToolbar) - # Connect up our signals and slots - QtCore.QObject.connect(self.themeComboBox, QtCore.SIGNAL(u'activated(int)'), self.onThemeComboBoxSelected) - QtCore.QObject.connect(self.serviceManagerList, QtCore.SIGNAL(u'doubleClicked(QModelIndex)'), self.onMakeLive) - QtCore.QObject.connect(self.serviceManagerList, QtCore.SIGNAL(u'itemCollapsed(QTreeWidgetItem*)'), - self.collapsed) - QtCore.QObject.connect(self.serviceManagerList, QtCore.SIGNAL(u'itemExpanded(QTreeWidgetItem*)'), self.expanded) - QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'theme_update_list'), self.updateThemeList) - QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'servicemanager_preview_live'), self.previewLive) - QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'servicemanager_next_item'), self.nextItem) - QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'servicemanager_previous_item'), - self.previousItem) - QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'servicemanager_set_item'), self.onSetItem) - QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_updated'), self.configUpdated) - QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_screen_changed'), - self.regenerateServiceItems) - QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'theme_update_global'), self.themeChange) - QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'service_item_update'), self.serviceItemUpdate) - # Last little bits of setting up - self.service_theme = Settings().value(self.main_window.serviceManagerSettingsSection + u'/service theme') - self.servicePath = AppLocation.get_section_data_path(u'servicemanager') - # build the drag and drop context menu - self.dndMenu = QtGui.QMenu() - self.newAction = self.dndMenu.addAction(translate('OpenLP.ServiceManager', '&Add New Item')) - self.newAction.setIcon(build_icon(u':/general/general_edit.png')) - self.addToAction = self.dndMenu.addAction(translate('OpenLP.ServiceManager', '&Add to Selected Item')) - self.addToAction.setIcon(build_icon(u':/general/general_edit.png')) - # build the context menu - self.menu = QtGui.QMenu() - self.editAction = create_widget_action(self.menu, text=translate('OpenLP.ServiceManager', '&Edit Item'), - icon=u':/general/general_edit.png', triggers=self.remoteEdit) - self.maintainAction = create_widget_action(self.menu, text=translate('OpenLP.ServiceManager', '&Reorder Item'), - icon=u':/general/general_edit.png', triggers=self.onServiceItemEditForm) - self.notesAction = create_widget_action(self.menu, text=translate('OpenLP.ServiceManager', '&Notes'), - icon=u':/services/service_notes.png', triggers=self.onServiceItemNoteForm) - self.timeAction = create_widget_action(self.menu, text=translate('OpenLP.ServiceManager', '&Start Time'), - icon=u':/media/media_time.png', triggers=self.onStartTimeForm) - self.autoStartAction = create_widget_action(self.menu, text=u'', - icon=u':/media/auto-start_active.png', triggers=self.onAutoStart) - # Add already existing delete action to the menu. - self.menu.addAction(self.serviceManagerList.delete) - self.create_custom_action = create_widget_action(self.menu, - text=translate('OpenLP.ServiceManager', 'Create New &Custom Slide'), - icon=u':/general/general_edit.png', triggers=self.create_custom) - self.menu.addSeparator() - # Add AutoPlay menu actions - self.autoPlaySlidesGroup = QtGui.QMenu(translate('OpenLP.ServiceManager', '&Auto play slides')) - self.menu.addMenu(self.autoPlaySlidesGroup) - self.autoPlaySlidesLoop = create_widget_action(self.autoPlaySlidesGroup, - text=translate('OpenLP.ServiceManager', 'Auto play slides &Loop'), - checked=False, triggers=self.toggleAutoPlaySlidesLoop) - self.autoPlaySlidesOnce = create_widget_action(self.autoPlaySlidesGroup, - text=translate('OpenLP.ServiceManager', 'Auto play slides &Once'), - checked=False, triggers=self.toggleAutoPlaySlidesOnce) - self.autoPlaySlidesGroup.addSeparator() - self.timedSlideInterval = create_widget_action(self.autoPlaySlidesGroup, - text=translate('OpenLP.ServiceManager', '&Delay between slides'), - checked=False, triggers=self.onTimedSlideInterval) - self.menu.addSeparator() - self.previewAction = create_widget_action(self.menu, text=translate('OpenLP.ServiceManager', 'Show &Preview'), - icon=u':/general/general_preview.png', triggers=self.makePreview) - # Add already existing make live action to the menu. - self.menu.addAction(self.serviceManagerList.makeLive) - self.menu.addSeparator() - self.themeMenu = QtGui.QMenu(translate('OpenLP.ServiceManager', '&Change Item Theme')) - self.menu.addMenu(self.themeMenu) - self.serviceManagerList.addActions( - [self.serviceManagerList.moveDown, - self.serviceManagerList.moveUp, - self.serviceManagerList.makeLive, - self.serviceManagerList.moveTop, - self.serviceManagerList.moveBottom, - self.serviceManagerList.up, - self.serviceManagerList.down, - self.serviceManagerList.expand, - self.serviceManagerList.collapse - ]) - self.configUpdated() + self.setup_ui(self) + self.config_updated() - def setModified(self, modified=True): + def set_modified(self, modified=True): """ Setter for property "modified". Sets whether or not the current service has been modified. @@ -298,50 +320,50 @@ class ServiceManager(QtGui.QWidget): if modified: self.service_id += 1 self._modified = modified - serviceFile = self.shortFileName() or translate('OpenLP.ServiceManager', 'Untitled Service') - self.main_window.setServiceModified(modified, serviceFile) + service_file = self.short_file_name() or translate('OpenLP.ServiceManager', 'Untitled Service') + self.main_window.setServiceModified(modified, service_file) - def isModified(self): + def is_modified(self): """ Getter for boolean property "modified". """ return self._modified - def setFileName(self, fileName): + def set_file_name(self, file_name): """ Setter for service file. """ - self._fileName = unicode(fileName) - self.main_window.setServiceModified(self.isModified(), self.shortFileName()) - Settings().setValue(u'servicemanager/last file', fileName) - self._saveLite = self._fileName.endswith(u'.oszl') + self._file_name = unicode(file_name) + self.main_window.setServiceModified(self.is_modified(), self.short_file_name()) + Settings().setValue(u'servicemanager/last file', file_name) + self._saveLite = self._file_name.endswith(u'.oszl') - def fileName(self): + def file_name(self): """ Return the current file name including path. """ - return self._fileName + return self._file_name - def shortFileName(self): + def short_file_name(self): """ Return the current file name, excluding the path. """ - return split_filename(self._fileName)[1] + return split_filename(self._file_name)[1] - def configUpdated(self): + def config_updated(self): """ Triggered when Config dialog is updated. """ - self.expandTabs = Settings().value(u'advanced/expand service item') + self.expand_tabs = Settings().value(u'advanced/expand service item') - def resetSupportedSuffixes(self): + def reset_supported_suffixes(self): """ Resets the Suffixes list. """ self.suffixes = [] - def supportedSuffixes(self, suffix): + def supported_suffixes(self, suffix): """ Adds Suffixes supported to the master list. Called from Plugins. @@ -351,48 +373,48 @@ class ServiceManager(QtGui.QWidget): if not suffix in self.suffixes: self.suffixes.append(suffix) - def onNewServiceClicked(self): + def on_new_service_clicked(self): """ Create a new service. """ - if self.isModified(): - result = self.saveModifiedService() + if self.is_modified(): + result = self.save_modified_service() if result == QtGui.QMessageBox.Cancel: return False elif result == QtGui.QMessageBox.Save: - if not self.decideSaveMethod(): + if not self.decide_save_method(): return False - self.newFile() + self.new_file() - def onLoadServiceClicked(self, loadFile=None): + def on_load_service_clicked(self, load_file=None): """ Loads the service file and saves the existing one it there is one unchanged - ``loadFile`` + ``load_file`` The service file to the loaded. Will be None is from menu so selection will be required. """ - if self.isModified(): - result = self.saveModifiedService() + if self.is_modified(): + result = self.save_modified_service() if result == QtGui.QMessageBox.Cancel: return False elif result == QtGui.QMessageBox.Save: - self.decideSaveMethod() - if not loadFile: - fileName = QtGui.QFileDialog.getOpenFileName(self.main_window, + self.decide_save_method() + if not load_file: + file_name = QtGui.QFileDialog.getOpenfile_name(self.main_window, translate('OpenLP.ServiceManager', 'Open File'), SettingsManager.get_last_dir(self.main_window.serviceManagerSettingsSection), translate('OpenLP.ServiceManager', 'OpenLP Service Files (*.osz *.oszl)')) - if not fileName: + if not file_name: return False else: - fileName = loadFile + file_name = load_file Settings().setValue(self.main_window.serviceManagerSettingsSection + u'/last directory', - split_filename(fileName)[0]) - self.loadFile(fileName) + split_filename(file_name)[0]) + self.load_file(file_name) - def saveModifiedService(self): + def save_modified_service(self): """ Check to see if a service needs to be saved. """ @@ -402,26 +424,26 @@ class ServiceManager(QtGui.QWidget): 'The current service has been modified. Would you like to save this service?'), QtGui.QMessageBox.Save | QtGui.QMessageBox.Discard | QtGui.QMessageBox.Cancel, QtGui.QMessageBox.Save) - def onRecentServiceClicked(self): + def on_recent_service_clicked(self): """ Load a recent file as the service triggered by mainwindow recent service list. """ sender = self.sender() - self.loadFile(sender.data()) + self.load_file(sender.data()) - def newFile(self): + def new_file(self): """ Create a blank new service file. """ - self.serviceManagerList.clear() - self.serviceItems = [] - self.setFileName(u'') + self.service_manager_list.clear() + self.service_items = [] + self.set_file_name(u'') self.service_id += 1 - self.setModified(False) + self.set_modified(False) Settings().setValue(u'servicemanager/last file', u'') Receiver.send_message(u'servicemanager_new_service') - def saveFile(self): + def save_file(self): """ Save the current service file. @@ -430,17 +452,17 @@ class ServiceManager(QtGui.QWidget): Audio files are also copied into the service manager directory, and then packaged into the zip file. """ - if not self.fileName(): - return self.saveFileAs() + if not self.file_name(): + return self.save_file_as() temp_file, temp_file_name = mkstemp(u'.osz', u'openlp_') # We don't need the file handle. os.close(temp_file) log.debug(temp_file_name) - path_file_name = unicode(self.fileName()) + path_file_name = unicode(self.file_name()) path, file_name = os.path.split(path_file_name) - basename = os.path.splitext(file_name)[0] - service_file_name = '%s.osd' % basename - log.debug(u'ServiceManager.saveFile - %s', path_file_name) + base_name = os.path.splitext(file_name)[0] + service_file_name = '%s.osd' % base_name + log.debug(u'ServiceManager.save_file - %s', path_file_name) Settings().setValue(self.main_window.serviceManagerSettingsSection + u'/last directory', path) service = [] write_list = [] @@ -449,9 +471,9 @@ class ServiceManager(QtGui.QWidget): total_size = 0 Receiver.send_message(u'cursor_busy') # Number of items + 1 to zip it - self.main_window.displayProgressBar(len(self.serviceItems) + 1) + self.main_window.displayProgressBar(len(self.service_items) + 1) # Get list of missing files, and list of files to write - for item in self.serviceItems: + for item in self.service_items: if not item[u'service_item'].uses_file(): continue for frame in item[u'service_item'].get_frames(): @@ -475,37 +497,37 @@ class ServiceManager(QtGui.QWidget): return False Receiver.send_message(u'cursor_busy') # Check if item contains a missing file. - for item in list(self.serviceItems): + for item in list(self.service_items): self.main_window.incrementProgressBar() item[u'service_item'].remove_invalid_frames(missing_list) if item[u'service_item'].missing_frames(): - self.serviceItems.remove(item) + self.service_items.remove(item) else: service_item = item[u'service_item'].get_service_repr(self._saveLite) if service_item[u'header'][u'background_audio']: - for i, filename in enumerate(service_item[u'header'][u'background_audio']): - new_file = os.path.join(u'audio', item[u'service_item'].unique_identifier, filename) - audio_files.append((filename, new_file)) + for i, file_name in enumerate(service_item[u'header'][u'background_audio']): + new_file = os.path.join(u'audio', item[u'service_item'].unique_identifier, file_name) + audio_files.append((file_name, new_file)) service_item[u'header'][u'background_audio'][i] = new_file # Add the service item to the service. service.append({u'serviceitem': service_item}) - self.repaintServiceList(-1, -1) + self.repaint_service_list(-1, -1) for file_item in write_list: file_size = os.path.getsize(file_item) total_size += file_size - log.debug(u'ServiceManager.savefile - ZIP contents size is %i bytes' % total_size) + log.debug(u'ServiceManager.save_file - ZIP contents size is %i bytes' % total_size) service_content = cPickle.dumps(service) # Usual Zip file cannot exceed 2GiB, file with Zip64 cannot be # extracted using unzip in UNIX. allow_zip_64 = (total_size > 2147483648 + len(service_content)) - log.debug(u'ServiceManager.saveFile - allowZip64 is %s' % allow_zip_64) + log.debug(u'ServiceManager.save_file - allowZip64 is %s' % allow_zip_64) zip_file = None success = True self.main_window.incrementProgressBar() try: zip_file = zipfile.ZipFile(temp_file_name, 'w', zipfile.ZIP_STORED, allow_zip_64) # First we add service contents. - # We save ALL filenames into ZIP using UTF-8. + # We save ALL file_names into ZIP using UTF-8. zip_file.writestr(service_file_name.encode(u'utf-8'), service_content) # Finally add all the listed media files. for write_from in write_list: @@ -539,34 +561,34 @@ class ServiceManager(QtGui.QWidget): try: shutil.copy(temp_file_name, path_file_name) except: - return self.saveFileAs() + return self.save_file_as() self.main_window.addRecentFile(path_file_name) - self.setModified(False) + self.set_modified(False) delete_file(temp_file_name) return success - def saveLocalFile(self): + def save_local_file(self): """ Save the current service file but leave all the file references alone to point to the current machine. This format is not transportable as it will not contain any files. """ - if not self.fileName(): - return self.saveFileAs() + if not self.file_name(): + return self.save_file_as() temp_file, temp_file_name = mkstemp(u'.oszl', u'openlp_') # We don't need the file handle. os.close(temp_file) log.debug(temp_file_name) - path_file_name = unicode(self.fileName()) + path_file_name = unicode(self.file_name()) path, file_name = os.path.split(path_file_name) base_name = os.path.splitext(file_name)[0] service_file_name = '%s.osd' % base_name - log.debug(u'ServiceManager.saveFile - %s', path_file_name) + log.debug(u'ServiceManager.save_file - %s', path_file_name) Settings().setValue(self.main_window.serviceManagerSettingsSection + u'/last directory', path) service = [] Receiver.send_message(u'cursor_busy') # Number of items + 1 to zip it - self.main_window.displayProgressBar(len(self.serviceItems) + 1) - for item in self.serviceItems: + self.main_window.displayProgressBar(len(self.service_items) + 1) + for item in self.service_items: self.main_window.incrementProgressBar() service_item = item[u'service_item'].get_service_repr(self._saveLite) #@todo check for file item on save. @@ -597,15 +619,15 @@ class ServiceManager(QtGui.QWidget): try: shutil.copy(temp_file_name, path_file_name) except: - return self.saveFileAs() + return self.save_file_as() self.main_window.addRecentFile(path_file_name) - self.setModified(False) + self.set_modified(False) delete_file(temp_file_name) return success - def saveFileAs(self): + def save_file_as(self): """ - Get a file name and then call :func:`ServiceManager.saveFile` to + Get a file name and then call :func:`ServiceManager.save_file` to save the file. """ default_service_enabled = Settings().value(u'advanced/default service enabled') @@ -623,59 +645,59 @@ class ServiceManager(QtGui.QWidget): time = now + timedelta(days=day_delta) local_time = time.replace(hour=service_hour, minute=service_minute) default_pattern = Settings().value(u'advanced/default service name') - default_filename = format_time(default_pattern, local_time) + default_file_name = format_time(default_pattern, local_time) else: - default_filename = u'' + default_file_name = u'' directory = Settings().value(self.main_window.serviceManagerSettingsSection + u'/last directory') - path = os.path.join(directory, default_filename) + path = os.path.join(directory, default_file_name) # SaveAs from osz to oszl is not valid as the files will be deleted # on exit which is not sensible or usable in the long term. - if self._fileName.endswith(u'oszl') or self.service_has_all_original_files: - fileName = QtGui.QFileDialog.getSaveFileName(self.main_window, UiStrings().SaveService, path, + if self._file_name.endswith(u'oszl') or self.service_has_all_original_files: + file_name = QtGui.QFileDialog.getSavefile_name(self.main_window, UiStrings().SaveService, path, translate('OpenLP.ServiceManager', 'OpenLP Service Files (*.osz);; OpenLP Service Files - lite (*.oszl)')) else: - fileName = QtGui.QFileDialog.getSaveFileName(self.main_window, UiStrings().SaveService, path, + file_name = QtGui.QFileDialog.getSavefile_name(self.main_window, UiStrings().SaveService, path, translate('OpenLP.ServiceManager', 'OpenLP Service Files (*.osz);;')) - if not fileName: + if not file_name: return False - if os.path.splitext(fileName)[1] == u'': - fileName += u'.osz' + if os.path.splitext(file_name)[1] == u'': + file_name += u'.osz' else: - ext = os.path.splitext(fileName)[1] - fileName.replace(ext, u'.osz') - self.setFileName(fileName) - self.decideSaveMethod() + ext = os.path.splitext(file_name)[1] + file_name.replace(ext, u'.osz') + self.set_file_name(file_name) + self.decide_save_method() - def decideSaveMethod(self): + def decide_save_method(self): """ Determine which type of save method to use. """ - if not self.fileName(): - return self.saveFileAs() + if not self.file_name(): + return self.save_file_as() if self._saveLite: - return self.saveLocalFile() + return self.save_local_file() else: - return self.saveFile() + return self.save_file() - def loadFile(self, fileName): + def load_file(self, file_name): """ Load an existing service file """ - if not fileName: + if not file_name: return False - fileName = unicode(fileName) - if not os.path.exists(fileName): + file_name = unicode(file_name) + if not os.path.exists(file_name): return False - zip = None - fileTo = None + zip_file = None + file_to = None try: - zip = zipfile.ZipFile(fileName) - for zipinfo in zip.infolist(): + zip_file = zipfile.ZipFile(file_name) + for zip_info in zip_file.infolist(): try: - ucsfile = zipinfo.filename.decode(u'utf-8') + ucsfile = zip_info.filename.decode(u'utf-8') except UnicodeDecodeError: - log.exception(u'Filename "%s" is not valid UTF-8' % zipinfo.filename.decode(u'utf-8', u'replace')) + log.exception(u'file_name "%s" is not valid UTF-8' % zip_info.file_name.decode(u'utf-8', u'replace')) critical_error_message_box(message=translate('OpenLP.ServiceManager', 'File is not a valid service.\n The content encoding is not UTF-8.')) continue @@ -683,197 +705,200 @@ class ServiceManager(QtGui.QWidget): if not osfile.startswith(u'audio'): osfile = os.path.split(osfile)[1] log.debug(u'Extract file: %s', osfile) - zipinfo.filename = osfile - zip.extract(zipinfo, self.servicePath) + zip_info.filename = osfile + zip_file.extract(zip_info, self.servicePath) if osfile.endswith(u'osd'): p_file = os.path.join(self.servicePath, osfile) if 'p_file' in locals(): Receiver.send_message(u'cursor_busy') - fileTo = open(p_file, u'r') - items = cPickle.load(fileTo) - fileTo.close() - self.newFile() - self.setFileName(fileName) + file_to = open(p_file, u'r') + items = cPickle.load(file_to) + file_to.close() + self.new_file() + self.set_file_name(file_name) self.main_window.displayProgressBar(len(items)) for item in items: self.main_window.incrementProgressBar() - serviceItem = ServiceItem() + service_item = ServiceItem() if self._saveLite: - serviceItem.set_from_service(item) + service_item.set_from_service(item) else: - serviceItem.set_from_service(item, self.servicePath) - serviceItem.validate_item(self.suffixes) + service_item.set_from_service(item, self.servicePath) + service_item.validate_item(self.suffixes) self.load_item_unique_identifier = 0 - if serviceItem.is_capable(ItemCapabilities.OnLoadUpdate): - Receiver.send_message(u'%s_service_load' % serviceItem.name.lower(), serviceItem) + if service_item.is_capable(ItemCapabilities.OnLoadUpdate): + Receiver.send_message(u'%s_service_load' % service_item.name.lower(), service_item) # if the item has been processed - if serviceItem.unique_identifier == self.load_item_unique_identifier: - serviceItem.edit_id = int(self.load_item_edit_id) - serviceItem.temporary_edit = self.load_item_temporary - self.addServiceItem(serviceItem, repaint=False) + if service_item.unique_identifier == self.load_item_unique_identifier: + service_item.edit_id = int(self.load_item_edit_id) + service_item.temporary_edit = self.load_item_temporary + self.add_service_item(service_item, repaint=False) delete_file(p_file) - self.main_window.addRecentFile(fileName) - self.setModified(False) - Settings().setValue('servicemanager/last file', fileName) + self.main_window.addRecentFile(file_name) + self.set_modified(False) + Settings().setValue('servicemanager/last file', file_name) else: critical_error_message_box(message=translate('OpenLP.ServiceManager', 'File is not a valid service.')) log.exception(u'File contains no service data') except (IOError, NameError, zipfile.BadZipfile): - log.exception(u'Problem loading service file %s' % fileName) + log.exception(u'Problem loading service file %s' % file_name) critical_error_message_box(message=translate('OpenLP.ServiceManager', 'File could not be opened because it is corrupt.')) except zipfile.BadZipfile: - if os.path.getsize(fileName) == 0: - log.exception(u'Service file is zero sized: %s' % fileName) + if os.path.getsize(file_name) == 0: + log.exception(u'Service file is zero sized: %s' % file_name) QtGui.QMessageBox.information(self, translate('OpenLP.ServiceManager', 'Empty File'), translate('OpenLP.ServiceManager', 'This service file does not contain any data.')) else: log.exception(u'Service file is cannot be extracted as zip: ' - u'%s' % fileName) + u'%s' % file_name) QtGui.QMessageBox.information(self, translate('OpenLP.ServiceManager', 'Corrupt File'), translate('OpenLP.ServiceManager', 'This file is either corrupt or it is not an OpenLP 2 service file.')) return finally: - if fileTo: - fileTo.close() - if zip: - zip.close() + if file_to: + file_to.close() + if zip_file: + zip_file.close() self.main_window.finishedProgressBar() Receiver.send_message(u'cursor_normal') - self.repaintServiceList(-1, -1) + self.repaint_service_list(-1, -1) - def loadLastFile(self): + def load_Last_file(self): """ Load the last service item from the service manager when the service was last closed. Can be blank if there was no service present. """ - fileName = Settings().value(u'servicemanager/last file') - if fileName: - self.loadFile(fileName) + file_name = Settings().value(u'servicemanager/last file') + if file_name: + self.load_file(file_name) - def contextMenu(self, point): + def context_menu(self, point): """ The Right click context menu from the Serviceitem list """ - item = self.serviceManagerList.itemAt(point) + item = self.service_manager_list.itemAt(point) if item is None: return if item.parent(): pos = item.parent().data(0, QtCore.Qt.UserRole) else: pos = item.data(0, QtCore.Qt.UserRole) - serviceItem = self.serviceItems[pos - 1] - self.editAction.setVisible(False) + service_item = self.service_items[pos - 1] + self.edit_action.setVisible(False) self.create_custom_action.setVisible(False) - self.maintainAction.setVisible(False) - self.notesAction.setVisible(False) - self.timeAction.setVisible(False) - self.autoStartAction.setVisible(False) - if serviceItem[u'service_item'].is_capable(ItemCapabilities.CanEdit) and serviceItem[u'service_item'].edit_id: - self.editAction.setVisible(True) - if serviceItem[u'service_item'].is_capable(ItemCapabilities.CanMaintain): - self.maintainAction.setVisible(True) + self.maintain_action.setVisible(False) + self.notes_action.setVisible(False) + self.time_action.setVisible(False) + self.auto_start_action.setVisible(False) + if service_item[u'service_item'].is_capable(ItemCapabilities.CanEdit) and service_item[u'service_item'].edit_id: + self.edit_action.setVisible(True) + if service_item[u'service_item'].is_capable(ItemCapabilities.CanMaintain): + self.maintain_action.setVisible(True) if item.parent() is None: - self.notesAction.setVisible(True) - if serviceItem[u'service_item'].is_capable(ItemCapabilities.CanLoop) and \ - len(serviceItem[u'service_item'].get_frames()) > 1: - self.autoPlaySlidesGroup.menuAction().setVisible(True) - self.autoPlaySlidesOnce.setChecked(serviceItem[u'service_item'].auto_play_slides_once) - self.autoPlaySlidesLoop.setChecked(serviceItem[u'service_item'].auto_play_slides_loop) - self.timedSlideInterval.setChecked(serviceItem[u'service_item'].timed_slide_interval > 0) - if serviceItem[u'service_item'].timed_slide_interval > 0: - delay_suffix = u' %s s' % unicode(serviceItem[u'service_item'].timed_slide_interval) + self.notes_action.setVisible(True) + if service_item[u'service_item'].is_capable(ItemCapabilities.CanLoop) and \ + len(service_item[u'service_item'].get_frames()) > 1: + self.auto_play_slides_group.menuAction().setVisible(True) + self.auto_play_slides_once.setChecked(service_item[u'service_item'].auto_play_slides_once) + self.auto_play_slides_loop.setChecked(service_item[u'service_item'].auto_play_slides_loop) + self.timed_slide_interval.setChecked(service_item[u'service_item'].timed_slide_interval > 0) + if service_item[u'service_item'].timed_slide_interval > 0: + delay_suffix = u' %s s' % unicode(service_item[u'service_item'].timed_slide_interval) else: delay_suffix = u' ...' - self.timedSlideInterval.setText(translate('OpenLP.ServiceManager', '&Delay between slides') + delay_suffix) + self.timed_slide_interval.setText(translate('OpenLP.ServiceManager', '&Delay between slides') + delay_suffix) # TODO for future: make group explains itself more visually else: - self.autoPlaySlidesGroup.menuAction().setVisible(False) - if serviceItem[u'service_item'].is_capable(ItemCapabilities.HasVariableStartTime): - self.timeAction.setVisible(True) - if serviceItem[u'service_item'].is_capable(ItemCapabilities.CanAutoStartForLive): - self.autoStartAction.setVisible(True) - self.autoStartAction.setIcon(self.inactive) - self.autoStartAction.setText(translate('OpenLP.ServiceManager','&Auto Start - inactive')) - if serviceItem[u'service_item'].will_auto_start: - self.autoStartAction.setText(translate('OpenLP.ServiceManager', '&Auto Start - active')) - self.autoStartAction.setIcon(self.active) - if serviceItem[u'service_item'].is_text(): + self.auto_play_slides_group.menuAction().setVisible(False) + if service_item[u'service_item'].is_capable(ItemCapabilities.HasVariableStartTime): + self.time_action.setVisible(True) + if service_item[u'service_item'].is_capable(ItemCapabilities.CanAutoStartForLive): + self.auto_start_action.setVisible(True) + self.auto_start_action.setIcon(self.inactive) + self.auto_start_action.setText(translate('OpenLP.ServiceManager','&Auto Start - inactive')) + if service_item[u'service_item'].will_auto_start: + self.auto_start_action.setText(translate('OpenLP.ServiceManager', '&Auto Start - active')) + self.auto_start_action.setIcon(self.active) + if service_item[u'service_item'].is_text(): for plugin in self.plugin_manager.plugins: if plugin.name == u'custom' and plugin.status == PluginStatus.Active: self.create_custom_action.setVisible(True) break - self.themeMenu.menuAction().setVisible(False) + self.theme_menu.menuAction().setVisible(False) # Set up the theme menu. - if serviceItem[u'service_item'].is_text() and self.renderer.theme_level == ThemeLevel.Song: - self.themeMenu.menuAction().setVisible(True) + if service_item[u'service_item'].is_text() and self.renderer.theme_level == ThemeLevel.Song: + self.theme_menu.menuAction().setVisible(True) # The service item does not have a theme, check the "Default". - if serviceItem[u'service_item'].theme is None: - themeAction = self.themeMenu.defaultAction() + if service_item[u'service_item'].theme is None: + theme_action = self.theme_menu.defaultAction() else: - themeAction = self.themeMenu.findChild(QtGui.QAction, serviceItem[u'service_item'].theme) - if themeAction is not None: - themeAction.setChecked(True) - self.menu.exec_(self.serviceManagerList.mapToGlobal(point)) + theme_action = self.theme_menu.findChild(QtGui.QAction, service_item[u'service_item'].theme) + if theme_action is not None: + theme_action.setChecked(True) + self.menu.exec_(self.service_manager_list.mapToGlobal(point)) - def onServiceItemNoteForm(self): - item = self.findServiceItem()[0] - self.serviceNoteForm.textEdit.setPlainText( - self.serviceItems[item][u'service_item'].notes) + def on_service_item_note_form(self): + """ + Allow the service note to be edited + """ + item = self.find_service_item()[0] + self.serviceNoteForm.text_edit.setPlainText(self.service_items[item][u'service_item'].notes) if self.serviceNoteForm.exec_(): - self.serviceItems[item][u'service_item'].notes = self.serviceNoteForm.textEdit.toPlainText() - self.repaintServiceList(item, -1) - self.setModified() + self.service_items[item][u'service_item'].notes = self.serviceNoteForm.text_edit.toPlainText() + self.repaint_service_list(item, -1) + self.set_modified() - def onStartTimeForm(self): + def on_start_time_form(self): """ Opens a dialog to type in service item notes. """ - item = self.findServiceItem()[0] - self.startTimeForm.item = self.serviceItems[item] + item = self.find_service_item()[0] + self.startTimeForm.item = self.service_items[item] if self.startTimeForm.exec_(): - self.repaintServiceList(item, -1) + self.repaint_service_list(item, -1) - def toggleAutoPlaySlidesOnce(self): + def toggle_auto_play_slides_once(self): """ Toggle Auto play slide once. Inverts auto play once option for the item """ - item = self.findServiceItem()[0] - service_item = self.serviceItems[item][u'service_item'] + item = self.find_service_item()[0] + service_item = self.service_items[item][u'service_item'] service_item.auto_play_slides_once = not service_item.auto_play_slides_once if service_item.auto_play_slides_once: service_item.auto_play_slides_loop = False - self.autoPlaySlidesLoop.setChecked(False) + self.auto_play_slides_loop.setChecked(False) if service_item.auto_play_slides_once and service_item.timed_slide_interval == 0: service_item.timed_slide_interval = Settings().value( - self.mainwindow.generalSettingsSection + u'/loop delay') - self.setModified() + self.main_window.generalSettingsSection + u'/loop delay') + self.set_modified() - def toggleAutoPlaySlidesLoop(self): + + def toggle_auto_play_slides_loop(self): """ Toggle Auto play slide loop. """ - item = self.findServiceItem()[0] - service_item = self.serviceItems[item][u'service_item'] + item = self.find_service_item()[0] + service_item = self.service_items[item][u'service_item'] service_item.auto_play_slides_loop = not service_item.auto_play_slides_loop if service_item.auto_play_slides_loop: service_item.auto_play_slides_once = False - self.autoPlaySlidesOnce.setChecked(False) + self.auto_play_slides_once.setChecked(False) if service_item.auto_play_slides_loop and service_item.timed_slide_interval == 0: service_item.timed_slide_interval = Settings().value( - self.mainwindow.generalSettingsSection + u'/loop delay') - self.setModified() + self.main_window.generalSettingsSection + u'/loop delay') + self.set_modified() - def onTimedSlideInterval(self): + + def on_timed_slide_interval(self): """ - on set times slide interval. Shows input dialog for enter interval in seconds for delay """ - item = self.findServiceItem()[0] - service_item = self.serviceItems[item][u'service_item'] + item = self.find_service_item()[0] + service_item = self.service_items[item][u'service_item'] if service_item.timed_slide_interval == 0: timed_slide_interval = Settings().value(self.mainwindow.generalSettingsSection + u'/loop delay') else: @@ -889,82 +914,81 @@ class ServiceManager(QtGui.QWidget): elif service_item.timed_slide_interval == 0: service_item.auto_play_slides_loop = False service_item.auto_play_slides_once = False - self.setModified() + self.set_modified() - def onAutoStart(self): + def on_auto_start(self): """ Toggles to Auto Start Setting. """ - item = self.findServiceItem()[0] - self.serviceItems[item][u'service_item'].will_auto_start = \ - not self.serviceItems[item][u'service_item'].will_auto_start + item = self.find_service_item()[0] + self.service_items[item][u'service_item'].will_auto_start = \ + not self.service_items[item][u'service_item'].will_auto_start - def onServiceItemEditForm(self): + def on_service_item_edit_form(self): """ Opens a dialog to edit the service item and update the service display if changes are saved. """ - item = self.findServiceItem()[0] - self.serviceItemEditForm.setServiceItem( - self.serviceItems[item][u'service_item']) + item = self.find_service_item()[0] + self.serviceItemEditForm.set_service_item(self.service_items[item][u'service_item']) if self.serviceItemEditForm.exec_(): - self.addServiceItem(self.serviceItemEditForm.getServiceItem(), - replace=True, expand=self.serviceItems[item][u'expanded']) + self.add_service_item(self.serviceItemEditForm.get_service_item(), + replace=True, expand=self.service_items[item][u'expanded']) - def previewLive(self, message): + def preview_live(self, message): """ Called by the SlideController to request a preview item be made live and allows the next preview to be updated if relevant. """ unique_identifier, row = message.split(u':') - for sitem in self.serviceItems: + for sitem in self.service_items: if sitem[u'service_item'].unique_identifier == unique_identifier: - item = self.serviceManagerList.topLevelItem(sitem[u'order'] - 1) - self.serviceManagerList.setCurrentItem(item) - self.makeLive(int(row)) + item = self.service_manager_list.topLevelItem(sitem[u'order'] - 1) + self.service_manager_list.setCurrentItem(item) + self.make_live(int(row)) return - def nextItem(self): + def next_item(self): """ Called by the SlideController to select the next service item. """ - if not self.serviceManagerList.selectedItems(): + if not self.service_manager_list.selectedItems(): return - selected = self.serviceManagerList.selectedItems()[0] + selected = self.service_manager_list.selectedItems()[0] lookFor = 0 - serviceIterator = QtGui.QTreeWidgetItemIterator(self.serviceManagerList) + serviceIterator = QtGui.QTreeWidgetItemIterator(self.service_manager_list) while serviceIterator.value(): if lookFor == 1 and serviceIterator.value().parent() is None: - self.serviceManagerList.setCurrentItem(serviceIterator.value()) - self.makeLive() + self.service_manager_list.setCurrentItem(serviceIterator.value()) + self.make_live() return if serviceIterator.value() == selected: lookFor = 1 serviceIterator += 1 - def previousItem(self, message): + def previous_item(self, message): """ Called by the SlideController to select the previous service item. """ - if not self.serviceManagerList.selectedItems(): + if not self.service_manager_list.selectedItems(): return - selected = self.serviceManagerList.selectedItems()[0] + selected = self.service_manager_list.selectedItems()[0] prevItem = None prevItemLastSlide = None - serviceIterator = QtGui.QTreeWidgetItemIterator(self.serviceManagerList) + serviceIterator = QtGui.QTreeWidgetItemIterator(self.service_manager_list) while serviceIterator.value(): if serviceIterator.value() == selected: if message == u'last slide' and prevItemLastSlide: pos = prevItem.data(0, QtCore.Qt.UserRole) - check_expanded = self.serviceItems[pos - 1][u'expanded'] - self.serviceManagerList.setCurrentItem(prevItemLastSlide) + check_expanded = self.service_items[pos - 1][u'expanded'] + self.service_manager_list.setCurrentItem(prevItemLastSlide) if not check_expanded: - self.serviceManagerList.collapseItem(prevItem) - self.makeLive() - self.serviceManagerList.setCurrentItem(prevItem) + self.service_manager_list.collapseItem(prevItem) + self.make_live() + self.service_manager_list.setCurrentItem(prevItem) elif prevItem: - self.serviceManagerList.setCurrentItem(prevItem) - self.makeLive() + self.service_manager_list.setCurrentItem(prevItem) + self.make_live() return if serviceIterator.value().parent() is None: prevItem = serviceIterator.value() @@ -972,50 +996,50 @@ class ServiceManager(QtGui.QWidget): prevItemLastSlide = serviceIterator.value() serviceIterator += 1 - def onSetItem(self, message): + def on_set_item(self, message): """ Called by a signal to select a specific item. """ - self.setItem(int(message)) + self.set_item(int(message)) - def setItem(self, index): + def set_item(self, index): """ Makes a specific item in the service live. """ - if index >= 0 and index < self.serviceManagerList.topLevelItemCount: - item = self.serviceManagerList.topLevelItem(index) - self.serviceManagerList.setCurrentItem(item) - self.makeLive() + if index >= 0 and index < self.service_manager_list.topLevelItemCount: + item = self.service_manager_list.topLevelItem(index) + self.service_manager_list.setCurrentItem(item) + self.make_live() - def onMoveSelectionUp(self): + def on_move_selection_up(self): """ Moves the cursor selection up the window. Called by the up arrow. """ - item = self.serviceManagerList.currentItem() - itemBefore = self.serviceManagerList.itemAbove(item) + item = self.service_manager_list.currentItem() + itemBefore = self.service_manager_list.itemAbove(item) if itemBefore is None: return - self.serviceManagerList.setCurrentItem(itemBefore) + self.service_manager_list.setCurrentItem(itemBefore) - def onMoveSelectionDown(self): + def on_move_selection_down(self): """ Moves the cursor selection down the window. Called by the down arrow. """ - item = self.serviceManagerList.currentItem() - itemAfter = self.serviceManagerList.itemBelow(item) + item = self.service_manager_list.currentItem() + itemAfter = self.service_manager_list.itemBelow(item) if itemAfter is None: return - self.serviceManagerList.setCurrentItem(itemAfter) + self.service_manager_list.setCurrentItem(itemAfter) def onCollapseAll(self): """ Collapse all the service items. """ - for item in self.serviceItems: + for item in self.service_items: item[u'expanded'] = False - self.serviceManagerList.collapseAll() + self.service_manager_list.collapseAll() def collapsed(self, item): """ @@ -1023,15 +1047,15 @@ class ServiceManager(QtGui.QWidget): correct state. """ pos = item.data(0, QtCore.Qt.UserRole) - self.serviceItems[pos - 1][u'expanded'] = False + self.service_items[pos - 1][u'expanded'] = False def onExpandAll(self): """ Collapse all the service items. """ - for item in self.serviceItems: + for item in self.service_items: item[u'expanded'] = True - self.serviceManagerList.expandAll() + self.service_manager_list.expandAll() def expanded(self, item): """ @@ -1039,67 +1063,67 @@ class ServiceManager(QtGui.QWidget): correct state. """ pos = item.data(0, QtCore.Qt.UserRole) - self.serviceItems[pos - 1][u'expanded'] = True + self.service_items[pos - 1][u'expanded'] = True def onServiceTop(self): """ Move the current ServiceItem to the top of the list. """ - item, child = self.findServiceItem() - if item < len(self.serviceItems) and item != -1: - temp = self.serviceItems[item] - self.serviceItems.remove(self.serviceItems[item]) - self.serviceItems.insert(0, temp) - self.repaintServiceList(0, child) - self.setModified() + item, child = self.find_service_item() + if item < len(self.service_items) and item != -1: + temp = self.service_items[item] + self.service_items.remove(self.service_items[item]) + self.service_items.insert(0, temp) + self.repaint_service_list(0, child) + self.set_modified() def onServiceUp(self): """ Move the current ServiceItem one position up in the list. """ - item, child = self.findServiceItem() + item, child = self.find_service_item() if item > 0: - temp = self.serviceItems[item] - self.serviceItems.remove(self.serviceItems[item]) - self.serviceItems.insert(item - 1, temp) - self.repaintServiceList(item - 1, child) - self.setModified() + temp = self.service_items[item] + self.service_items.remove(self.service_items[item]) + self.service_items.insert(item - 1, temp) + self.repaint_service_list(item - 1, child) + self.set_modified() def onServiceDown(self): """ Move the current ServiceItem one position down in the list. """ - item, child = self.findServiceItem() - if item < len(self.serviceItems) and item != -1: - temp = self.serviceItems[item] - self.serviceItems.remove(self.serviceItems[item]) - self.serviceItems.insert(item + 1, temp) - self.repaintServiceList(item + 1, child) - self.setModified() + item, child = self.find_service_item() + if item < len(self.service_items) and item != -1: + temp = self.service_items[item] + self.service_items.remove(self.service_items[item]) + self.service_items.insert(item + 1, temp) + self.repaint_service_list(item + 1, child) + self.set_modified() def onServiceEnd(self): """ Move the current ServiceItem to the bottom of the list. """ - item, child = self.findServiceItem() - if item < len(self.serviceItems) and item != -1: - temp = self.serviceItems[item] - self.serviceItems.remove(self.serviceItems[item]) - self.serviceItems.insert(len(self.serviceItems), temp) - self.repaintServiceList(len(self.serviceItems) - 1, child) - self.setModified() + item, child = self.find_service_item() + if item < len(self.service_items) and item != -1: + temp = self.service_items[item] + self.service_items.remove(self.service_items[item]) + self.service_items.insert(len(self.service_items), temp) + self.repaint_service_list(len(self.service_items) - 1, child) + self.set_modified() def onDeleteFromService(self): """ Remove the current ServiceItem from the list. """ - item = self.findServiceItem()[0] + item = self.find_service_item()[0] if item != -1: - self.serviceItems.remove(self.serviceItems[item]) - self.repaintServiceList(item - 1, -1) - self.setModified() + self.service_items.remove(self.service_items[item]) + self.repaint_service_list(item - 1, -1) + self.set_modified() - def repaintServiceList(self, serviceItem, serviceItemChild): + def repaint_service_list(self, serviceItem, serviceItemChild): """ Clear the existing service list and prepaint all the items. This is used when moving items as the move takes place in a supporting list, @@ -1114,16 +1138,16 @@ class ServiceManager(QtGui.QWidget): # Correct order of items in array count = 1 self.service_has_all_original_files = True - for item in self.serviceItems: + for item in self.service_items: item[u'order'] = count count += 1 if not item[u'service_item'].has_original_files: self.service_has_all_original_files = False # Repaint the screen - self.serviceManagerList.clear() - for item_count, item in enumerate(self.serviceItems): + self.service_manager_list.clear() + for item_count, item in enumerate(self.service_items): serviceitem = item[u'service_item'] - treewidgetitem = QtGui.QTreeWidgetItem(self.serviceManagerList) + treewidgetitem = QtGui.QTreeWidgetItem(self.service_manager_list) if serviceitem.is_valid: if serviceitem.notes: icon = QtGui.QImage(serviceitem.icon) @@ -1172,9 +1196,9 @@ class ServiceManager(QtGui.QWidget): child.setData(0, QtCore.Qt.UserRole, count) if serviceItem == item_count: if item[u'expanded'] and serviceItemChild == count: - self.serviceManagerList.setCurrentItem(child) + self.service_manager_list.setCurrentItem(child) elif serviceItemChild == -1: - self.serviceManagerList.setCurrentItem(treewidgetitem) + self.service_manager_list.setCurrentItem(treewidgetitem) treewidgetitem.setExpanded(item[u'expanded']) def cleanUp(self): @@ -1188,15 +1212,15 @@ class ServiceManager(QtGui.QWidget): if os.path.exists(os.path.join(self.servicePath, u'audio')): shutil.rmtree(os.path.join(self.servicePath, u'audio'), True) - def onThemeComboBoxSelected(self, currentIndex): + def on_theme_combo_box_selected(self, currentIndex): """ Set the theme for the current service. """ - log.debug(u'onThemeComboBoxSelected') - self.service_theme = self.themeComboBox.currentText() + log.debug(u'ontheme_combo_box_selected') + self.service_theme = self.theme_combo_box.currentText() self.renderer.set_service_theme(self.service_theme) Settings().setValue(self.main_window.serviceManagerSettingsSection + u'/service theme', self.service_theme) - self.regenerateServiceItems(True) + self.regenerate_service_Items(True) def themeChange(self): """ @@ -1205,22 +1229,22 @@ class ServiceManager(QtGui.QWidget): """ log.debug(u'themeChange') visible = self.renderer.theme_level == ThemeLevel.Global - self.themeLabel.setVisible(visible) - self.themeComboBox.setVisible(visible) + self.theme_label.setVisible(visible) + self.theme_combo_box.setVisible(visible) - def regenerateServiceItems(self, changed=False): + def regenerate_service_Items(self, changed=False): """ Rebuild the service list as things have changed and a repaint is the easiest way to do this. """ Receiver.send_message(u'cursor_busy') - log.debug(u'regenerateServiceItems') + log.debug(u'regenerate_service_Items') # force reset of renderer as theme data has changed self.service_has_all_original_files = True - if self.serviceItems: - for item in self.serviceItems: + if self.service_items: + for item in self.service_items: item[u'selected'] = False - serviceIterator = QtGui.QTreeWidgetItemIterator(self.serviceManagerList) + serviceIterator = QtGui.QTreeWidgetItemIterator(self.service_manager_list) selectedItem = None while serviceIterator.value(): if serviceIterator.value().isSelected(): @@ -1231,20 +1255,20 @@ class ServiceManager(QtGui.QWidget): pos = selectedItem.data(0, QtCore.Qt.UserRole) else: pos = selectedItem.parent().data(0, QtCore.Qt.UserRole) - self.serviceItems[pos - 1][u'selected'] = True - tempServiceItems = self.serviceItems - self.serviceManagerList.clear() - self.serviceItems = [] + self.service_items[pos - 1][u'selected'] = True + tempServiceItems = self.service_items + self.service_manager_list.clear() + self.service_items = [] self.isNew = True for item in tempServiceItems: - self.addServiceItem(item[u'service_item'], False, expand=item[u'expanded'], repaint=False, + self.add_service_item(item[u'service_item'], False, expand=item[u'expanded'], repaint=False, selected=item[u'selected']) # Set to False as items may have changed rendering # does not impact the saved song so True may also be valid if changed: - self.setModified() + self.set_modified() # Repaint it once only at the end - self.repaintServiceList(-1, -1) + self.repaint_service_list(-1, -1) Receiver.send_message(u'cursor_normal') def serviceItemUpdate(self, message): @@ -1256,21 +1280,21 @@ class ServiceManager(QtGui.QWidget): self.load_item_edit_id = int(edit_id) self.load_item_temporary = str_to_bool(temporary) - def replaceServiceItem(self, newItem): + def replace_service_item(self, newItem): """ Using the service item passed replace the one with the same edit id if found. """ - for item_count, item in enumerate(self.serviceItems): + for item_count, item in enumerate(self.service_items): if item[u'service_item'].edit_id == newItem.edit_id and item[u'service_item'].name == newItem.name: newItem.render() newItem.merge(item[u'service_item']) item[u'service_item'] = newItem - self.repaintServiceList(item_count + 1, 0) + self.repaint_service_list(item_count + 1, 0) self.live_controller.replaceServiceManagerItem(newItem) - self.setModified() + self.set_modified() - def addServiceItem(self, item, rebuild=False, expand=None, replace=False, repaint=True, selected=False): + def add_service_item(self, item, rebuild=False, expand=None, replace=False, repaint=True, selected=False): """ Add a Service item to the list @@ -1282,72 +1306,72 @@ class ServiceManager(QtGui.QWidget): """ # if not passed set to config value if expand is None: - expand = self.expandTabs + expand = self.expand_tabs item.from_service = True if replace: - sitem, child = self.findServiceItem() - item.merge(self.serviceItems[sitem][u'service_item']) - self.serviceItems[sitem][u'service_item'] = item - self.repaintServiceList(sitem, child) + sitem, child = self.find_service_item() + item.merge(self.service_items[sitem][u'service_item']) + self.service_items[sitem][u'service_item'] = item + self.repaint_service_list(sitem, child) self.live_controller.replaceServiceManagerItem(item) else: item.render() # nothing selected for dnd - if self.dropPosition == 0: + if self.drop_position == 0: if isinstance(item, list): for inditem in item: - self.serviceItems.append({u'service_item': inditem, - u'order': len(self.serviceItems) + 1, + self.service_items.append({u'service_item': inditem, + u'order': len(self.service_items) + 1, u'expanded': expand, u'selected': selected}) else: - self.serviceItems.append({u'service_item': item, - u'order': len(self.serviceItems) + 1, + self.service_items.append({u'service_item': item, + u'order': len(self.service_items) + 1, u'expanded': expand, u'selected': selected}) if repaint: - self.repaintServiceList(len(self.serviceItems) - 1, -1) + self.repaint_service_list(len(self.service_items) - 1, -1) else: - self.serviceItems.insert(self.dropPosition, - {u'service_item': item, u'order': self.dropPosition, + self.service_items.insert(self.drop_position, + {u'service_item': item, u'order': self.drop_position, u'expanded': expand, u'selected': selected}) - self.repaintServiceList(self.dropPosition, -1) + self.repaint_service_list(self.drop_position, -1) # if rebuilding list make sure live is fixed. if rebuild: self.live_controller.replaceServiceManagerItem(item) - self.dropPosition = 0 - self.setModified() + self.drop_position = 0 + self.set_modified() - def makePreview(self): + def make_preview(self): """ Send the current item to the Preview slide controller """ Receiver.send_message(u'cursor_busy') - item, child = self.findServiceItem() - if self.serviceItems[item][u'service_item'].is_valid: - self.preview_controller.addServiceManagerItem(self.serviceItems[item][u'service_item'], child) + item, child = self.find_service_item() + if self.service_items[item][u'service_item'].is_valid: + self.preview_controller.addServiceManagerItem(self.service_items[item][u'service_item'], child) else: critical_error_message_box(translate('OpenLP.ServiceManager', 'Missing Display Handler'), translate('OpenLP.ServiceManager', 'Your item cannot be displayed as there is no handler to display it')) Receiver.send_message(u'cursor_normal') - def getServiceItem(self): + def get_service_item(self): """ Send the current item to the Preview slide controller """ - item = self.findServiceItem()[0] + item = self.find_service_item()[0] if item == -1: return False else: - return self.serviceItems[item][u'service_item'] + return self.service_items[item][u'service_item'] - def onMakeLive(self): + def on_make_live(self): """ Send the current item to the Live slide controller but triggered by a tablewidget click event. """ - self.makeLive() + self.make_live() - def makeLive(self, row=-1): + def make_live(self, row=-1): """ Send the current item to the Live slide controller @@ -1355,22 +1379,22 @@ class ServiceManager(QtGui.QWidget): Row number to be displayed if from preview. -1 is passed if the value is not set """ - item, child = self.findServiceItem() + item, child = self.find_service_item() # No items in service if item == -1: return if row != -1: child = row Receiver.send_message(u'cursor_busy') - if self.serviceItems[item][u'service_item'].is_valid: - self.live_controller.addServiceManagerItem(self.serviceItems[item][u'service_item'], child) + if self.service_items[item][u'service_item'].is_valid: + self.live_controller.addServiceManagerItem(self.service_items[item][u'service_item'], child) if Settings().value(self.main_window.generalSettingsSection + u'/auto preview'): item += 1 - if self.serviceItems and item < len(self.serviceItems) and \ - self.serviceItems[item][u'service_item'].is_capable(ItemCapabilities.CanPreview): - self.preview_controller.addServiceManagerItem(self.serviceItems[item][u'service_item'], 0) - next_item = self.serviceManagerList.topLevelItem(item) - self.serviceManagerList.setCurrentItem(next_item) + if self.service_items and item < len(self.service_items) and \ + self.service_items[item][u'service_item'].is_capable(ItemCapabilities.CanPreview): + self.preview_controller.addServiceManagerItem(self.service_items[item][u'service_item'], 0) + next_item = self.service_manager_list.topLevelItem(item) + self.service_manager_list.setCurrentItem(next_item) self.live_controller.previewListWidget.setFocus() else: critical_error_message_box(translate('OpenLP.ServiceManager', 'Missing Display Handler'), @@ -1378,23 +1402,25 @@ class ServiceManager(QtGui.QWidget): 'Your item cannot be displayed as the plugin required to display it is missing or inactive')) Receiver.send_message(u'cursor_normal') - def remoteEdit(self): + def remote_edit(self): """ - Posts a remote edit message to a plugin to allow item to be edited. + Triggers a remote edit to a plugin to allow item to be edited. """ - item = self.findServiceItem()[0] - if self.serviceItems[item][u'service_item'].is_capable(ItemCapabilities.CanEdit): - Receiver.send_message(u'%s_edit' % self.serviceItems[item][u'service_item'].name.lower(), - u'L:%s' % self.serviceItems[item][u'service_item'].edit_id) + item, child = self.find_service_item() + if self.service_items[item][u'service_item'].is_capable(ItemCapabilities.CanEdit): + new_item = Registry().get(self.service_items[item][u'service_item'].name). \ + onRemoteEdit(self.service_items[item][u'service_item'].edit_id) + if new_item: + self.add_service_item(new_item, replace=True) def create_custom(self): """ Saves the current text item as a custom slide """ - item = self.findServiceItem()[0] - Receiver.send_message(u'custom_create_from_service', self.serviceItems[item][u'service_item']) + item = self.find_service_item()[0] + Receiver.send_message(u'custom_create_from_service', self.service_items[item][u'service_item']) - def findServiceItem(self): + def find_service_item(self): """ Finds the first selected ServiceItem in the list and returns the position of the serviceitem and its selected child item. For example, @@ -1403,7 +1429,7 @@ class ServiceManager(QtGui.QWidget): (1, 2) """ - items = self.serviceManagerList.selectedItems() + items = self.service_manager_list.selectedItems() serviceItem = -1 serviceItemChild = -1 for item in items: @@ -1419,16 +1445,7 @@ class ServiceManager(QtGui.QWidget): break return serviceItem, serviceItemChild - def dragEnterEvent(self, event): - """ - Accept Drag events - - ``event`` - Handle of the event pint passed - """ - event.accept() - - def dropEvent(self, event): + def drop_event(self, event): """ Receive drop event and trigger an internal event to get the plugins to build and push the correct service item @@ -1442,83 +1459,83 @@ class ServiceManager(QtGui.QWidget): event.setDropAction(QtCore.Qt.CopyAction) event.accept() for url in link.urls(): - filename = url.toLocalFile() - if filename.endswith(u'.osz'): - self.onLoadServiceClicked(filename) - elif filename.endswith(u'.oszl'): + file_name = url.toLocalFile() + if file_name.endswith(u'.osz'): + self.on_load_service_clicked(file_name) + elif file_name.endswith(u'.oszl'): # todo correct - self.onLoadServiceClicked(filename) + self.on_load_service_clicked(file_name) elif link.hasText(): plugin = link.text() - item = self.serviceManagerList.itemAt(event.pos()) + item = self.service_manager_list.itemAt(event.pos()) # ServiceManager started the drag and drop if plugin == u'ServiceManager': - startpos, child = self.findServiceItem() + startpos, child = self.find_service_item() # If no items selected if startpos == -1: return if item is None: - endpos = len(self.serviceItems) + endpos = len(self.service_items) else: endpos = self._get_parent_item_data(item) - 1 - serviceItem = self.serviceItems[startpos] - self.serviceItems.remove(serviceItem) - self.serviceItems.insert(endpos, serviceItem) - self.repaintServiceList(endpos, child) - self.setModified() + serviceItem = self.service_items[startpos] + self.service_items.remove(serviceItem) + self.service_items.insert(endpos, serviceItem) + self.repaint_service_list(endpos, child) + self.set_modified() else: # we are not over anything so drop replace = False if item is None: - self.dropPosition = len(self.serviceItems) + self.drop_position = len(self.service_items) else: # we are over something so lets investigate pos = self._get_parent_item_data(item) - 1 - serviceItem = self.serviceItems[pos] + serviceItem = self.service_items[pos] if (plugin == serviceItem[u'service_item'].name and serviceItem[u'service_item'].is_capable(ItemCapabilities.CanAppend)): action = self.dndMenu.exec_(QtGui.QCursor.pos()) # New action required if action == self.newAction: - self.dropPosition = self._get_parent_item_data(item) + self.drop_position = self._get_parent_item_data(item) # Append to existing action if action == self.addToAction: - self.dropPosition = self._get_parent_item_data(item) + self.drop_position = self._get_parent_item_data(item) item.setSelected(True) replace = True else: - self.dropPosition = self._get_parent_item_data(item) + self.drop_position = self._get_parent_item_data(item) Receiver.send_message(u'%s_add_service_item' % plugin, replace) - def updateThemeList(self, theme_list): + def update_theme_list(self, theme_list): """ Called from ThemeManager when the Themes have changed ``theme_list`` A list of current themes to be displayed """ - self.themeComboBox.clear() - self.themeMenu.clear() - self.themeComboBox.addItem(u'') - themeGroup = QtGui.QActionGroup(self.themeMenu) - themeGroup.setExclusive(True) - themeGroup.setObjectName(u'themeGroup') + self.theme_combo_box.clear() + self.theme_menu.clear() + self.theme_combo_box.addItem(u'') + theme_group = QtGui.QActionGroup(self.theme_menu) + theme_group.setExclusive(True) + theme_group.setObjectName(u'theme_group') # Create a "Default" theme, which allows the user to reset the item's # theme to the service theme or global theme. - defaultTheme = create_widget_action(self.themeMenu, text=UiStrings().Default, checked=False, - triggers=self.onThemeChangeAction) - self.themeMenu.setDefaultAction(defaultTheme) - themeGroup.addAction(defaultTheme) - self.themeMenu.addSeparator() + defaultTheme = create_widget_action(self.theme_menu, text=UiStrings().Default, checked=False, + triggers=self.on_theme_change_action) + self.theme_menu.setDefaultAction(defaultTheme) + theme_group.addAction(defaultTheme) + self.theme_menu.addSeparator() for theme in theme_list: - self.themeComboBox.addItem(theme) - themeGroup.addAction(create_widget_action(self.themeMenu, theme, text=theme, checked=False, - triggers=self.onThemeChangeAction)) - find_and_set_in_combo_box(self.themeComboBox, self.service_theme) + self.theme_combo_box.addItem(theme) + theme_group.addAction(create_widget_action(self.theme_menu, theme, text=theme, checked=False, + triggers=self.on_theme_change_action)) + find_and_set_in_combo_box(self.theme_combo_box, self.service_theme) self.renderer.set_service_theme(self.service_theme) - self.regenerateServiceItems() + self.regenerate_service_Items() - def onThemeChangeAction(self): + def on_theme_change_action(self): """ Handles theme change events """ @@ -1526,9 +1543,9 @@ class ServiceManager(QtGui.QWidget): # No object name means that the "Default" theme is supposed to be used. if not theme: theme = None - item = self.findServiceItem()[0] - self.serviceItems[item][u'service_item'].update_theme(theme) - self.regenerateServiceItems(True) + item = self.find_service_item()[0] + self.service_items[item][u'service_item'].update_theme(theme) + self.regenerate_service_Items(True) def _get_parent_item_data(self, item): """ @@ -1540,11 +1557,11 @@ class ServiceManager(QtGui.QWidget): else: return parent_item.data(0, QtCore.Qt.UserRole) - def printServiceOrder(self): + def print_service_order(self): """ Print a Service Order Sheet. """ - settingDialog = PrintServiceForm(self.main_window, self) + settingDialog = PrintServiceForm() settingDialog.exec_() def _get_renderer(self): diff --git a/openlp/core/ui/servicenoteform.py b/openlp/core/ui/servicenoteform.py index d14675d6a..7e30b18ad 100644 --- a/openlp/core/ui/servicenoteform.py +++ b/openlp/core/ui/servicenoteform.py @@ -29,36 +29,46 @@ from PyQt4 import QtGui -from openlp.core.lib import translate, SpellTextEdit +from openlp.core.lib import translate, SpellTextEdit, Registry from openlp.core.lib.ui import create_button_box class ServiceNoteForm(QtGui.QDialog): """ This is the form that is used to edit the verses of the song. """ - def __init__(self, parent=None): + def __init__(self): """ Constructor """ - QtGui.QDialog.__init__(self, parent) + QtGui.QDialog.__init__(self, self.main_window) self.setupUi() self.retranslateUi() def exec_(self): - self.textEdit.setFocus() + self.text_edit.setFocus() return QtGui.QDialog.exec_(self) def setupUi(self): self.setObjectName(u'serviceNoteEdit') - self.dialogLayout = QtGui.QVBoxLayout(self) - self.dialogLayout.setContentsMargins(8, 8, 8, 8) - self.dialogLayout.setSpacing(8) - self.dialogLayout.setObjectName(u'verticalLayout') - self.textEdit = SpellTextEdit(self, False) - self.textEdit.setObjectName(u'textEdit') - self.dialogLayout.addWidget(self.textEdit) - self.buttonBox = create_button_box(self, u'buttonBox', [u'cancel', u'save']) - self.dialogLayout.addWidget(self.buttonBox) + self.dialog_layout = QtGui.QVBoxLayout(self) + self.dialog_layout.setContentsMargins(8, 8, 8, 8) + self.dialog_layout.setSpacing(8) + self.dialog_layout.setObjectName(u'verticalLayout') + self.text_edit = SpellTextEdit(self, False) + self.text_edit.setObjectName(u'textEdit') + self.dialog_layout.addWidget(self.text_edit) + self.button_box = create_button_box(self, u'button_box', [u'cancel', u'save']) + self.dialog_layout.addWidget(self.button_box) def retranslateUi(self): self.setWindowTitle(translate('OpenLP.ServiceNoteForm', 'Service Item Notes')) + + def _get_main_window(self): + """ + Adds the main window to the class dynamically + """ + if not hasattr(self, u'_main_window'): + self._main_window = Registry().get(u'main_window') + return self._main_window + + main_window = property(_get_main_window) \ No newline at end of file diff --git a/openlp/core/ui/settingsdialog.py b/openlp/core/ui/settingsdialog.py index cd23737e3..f88e6c81e 100644 --- a/openlp/core/ui/settingsdialog.py +++ b/openlp/core/ui/settingsdialog.py @@ -38,7 +38,7 @@ class Ui_SettingsDialog(object): settingsDialog.resize(800, 500) settingsDialog.setWindowIcon(build_icon(u':/system/system_settings.png')) self.dialogLayout = QtGui.QGridLayout(settingsDialog) - self.dialogLayout.setObjectName(u'dialogLayout') + self.dialogLayout.setObjectName(u'dialog_layout') self.dialogLayout.setMargin(8) self.settingListWidget = QtGui.QListWidget(settingsDialog) self.settingListWidget.setUniformItemSizes(True) @@ -49,8 +49,8 @@ class Ui_SettingsDialog(object): self.stackedLayout = QtGui.QStackedLayout() self.stackedLayout.setObjectName(u'stackedLayout') self.dialogLayout.addLayout(self.stackedLayout, 0, 1, 1, 1) - self.buttonBox = create_button_box(settingsDialog, u'buttonBox', [u'cancel', u'ok']) - self.dialogLayout.addWidget(self.buttonBox, 1, 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) self.retranslateUi(settingsDialog) QtCore.QObject.connect(self.settingListWidget, QtCore.SIGNAL(u'currentRowChanged(int)'), self.tabChanged) diff --git a/openlp/core/ui/settingsform.py b/openlp/core/ui/settingsform.py index f54bc8729..992128dc3 100644 --- a/openlp/core/ui/settingsform.py +++ b/openlp/core/ui/settingsform.py @@ -140,7 +140,7 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): per save. """ if self.resetSuffixes: - self.mainWindow.serviceManagerContents.resetSupportedSuffixes() + self.service_manager.reset_supported_suffixes() self.resetSuffixes = False def _get_main_window(self): @@ -151,4 +151,14 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): self._main_window = Registry().get(u'main_window') return self._main_window - main_window = property(_get_main_window) \ No newline at end of file + main_window = property(_get_main_window) + + def _get_service_manager(self): + """ + Adds the plugin manager to the class dynamically + """ + if not hasattr(self, u'_service_manager'): + self._service_manager = Registry().get(u'service_manager') + return self._service_manager + + service_manager = property(_get_service_manager) \ No newline at end of file diff --git a/openlp/core/ui/shortcutlistdialog.py b/openlp/core/ui/shortcutlistdialog.py index c49d1a912..dd72778ef 100644 --- a/openlp/core/ui/shortcutlistdialog.py +++ b/openlp/core/ui/shortcutlistdialog.py @@ -107,9 +107,9 @@ class Ui_ShortcutListDialog(object): self.alternateLabel.setObjectName(u'alternateLabel') self.detailsLayout.addWidget(self.alternateLabel, 0, 2, 1, 1) self.shortcutListLayout.addLayout(self.detailsLayout) - self.buttonBox = create_button_box(shortcutListDialog, u'buttonBox', [u'cancel', u'ok', u'defaults']) - self.buttonBox.setOrientation(QtCore.Qt.Horizontal) - self.shortcutListLayout.addWidget(self.buttonBox) + self.button_box = create_button_box(shortcutListDialog, u'button_box', [u'cancel', u'ok', u'defaults']) + self.button_box.setOrientation(QtCore.Qt.Horizontal) + self.shortcutListLayout.addWidget(self.button_box) self.retranslateUi(shortcutListDialog) def retranslateUi(self, shortcutListDialog): diff --git a/openlp/core/ui/shortcutlistform.py b/openlp/core/ui/shortcutlistform.py index b6753bb7c..5c534ca37 100644 --- a/openlp/core/ui/shortcutlistform.py +++ b/openlp/core/ui/shortcutlistform.py @@ -64,7 +64,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): self.onClearPrimaryButtonClicked) QtCore.QObject.connect(self.clearAlternateButton, QtCore.SIGNAL(u'clicked(bool)'), self.onClearAlternateButtonClicked) - QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(u'clicked(QAbstractButton*)'), + QtCore.QObject.connect(self.button_box, QtCore.SIGNAL(u'clicked(QAbstractButton*)'), self.onRestoreDefaultsClicked) QtCore.QObject.connect(self.defaultRadioButton, QtCore.SIGNAL(u'clicked(bool)'), self.onDefaultRadioButtonClicked) @@ -274,7 +274,7 @@ class ShortcutListForm(QtGui.QDialog, Ui_ShortcutListDialog): """ Restores all default shortcuts. """ - if self.buttonBox.buttonRole(button) != QtGui.QDialogButtonBox.ResetRole: + if self.button_box.buttonRole(button) != QtGui.QDialogButtonBox.ResetRole: return if QtGui.QMessageBox.question(self, translate('OpenLP.ShortcutListDialog', 'Restore Default Shortcuts'), translate('OpenLP.ShortcutListDialog', 'Do you want to restore all ' diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 05151b20e..75028a514 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -297,8 +297,7 @@ class SlideController(DisplayController): sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) - sizePolicy.setHeightForWidth( - self.slidePreview.sizePolicy().hasHeightForWidth()) + sizePolicy.setHeightForWidth(self.slidePreview.sizePolicy().hasHeightForWidth()) self.slidePreview.setSizePolicy(sizePolicy) self.slidePreview.setFrameShape(QtGui.QFrame.Box) self.slidePreview.setFrameShadow(QtGui.QFrame.Plain) @@ -649,12 +648,12 @@ class SlideController(DisplayController): item.render() self._processItem(item, self.selectedRow) - def addServiceItem(self, item): + def add_service_item(self, item): """ Method to install the service item into the controller Called by plugins """ - log.debug(u'addServiceItem live = %s' % self.isLive) + log.debug(u'add_service_item live = %s' % self.isLive) item.render() slideno = 0 if self.songEdit: @@ -1183,14 +1182,16 @@ class SlideController(DisplayController): From the preview display requires the service Item to be editied """ self.songEdit = True - Receiver.send_message(u'%s_edit' % self.serviceItem.name.lower(), u'P:%s' % self.serviceItem.edit_id) + new_item = Registry().get(self.serviceItem.name).onRemoteEdit(self.serviceItem.edit_id, True) + if new_item: + self.add_service_item(new_item) def onPreviewAddToService(self): """ From the preview display request the Item to be added to service """ if self.serviceItem: - self.parent().serviceManagerContents.addServiceItem(self.serviceItem) + self.service_manager.add_service_item(self.serviceItem) def onGoLiveClick(self): """ @@ -1215,7 +1216,7 @@ class SlideController(DisplayController): Receiver.send_message('servicemanager_preview_live', u'%s:%s' % (self.serviceItem.unique_identifier, row)) else: - self.parent().liveController.addServiceManagerItem(self.serviceItem, row) + self.live_controller.addServiceManagerItem(self.serviceItem, row) def onMediaStart(self, item): """ @@ -1309,3 +1310,22 @@ class SlideController(DisplayController): media_controller = property(_get_media_controller) + def _get_service_manager(self): + """ + Adds the service manager to the class dynamically + """ + if not hasattr(self, u'_service_manager'): + self._service_manager = Registry().get(u'service_manager') + return self._service_manager + + service_manager = property(_get_service_manager) + + def _get_live_controller(self): + """ + Adds the live controller to the class dynamically + """ + if not hasattr(self, u'_live_controller'): + self._live_controller = Registry().get(u'live_controller') + return self._live_controller + + live_controller = property(_get_live_controller) \ No newline at end of file diff --git a/openlp/core/ui/starttimedialog.py b/openlp/core/ui/starttimedialog.py index ff8b486bd..0e2f7dc13 100644 --- a/openlp/core/ui/starttimedialog.py +++ b/openlp/core/ui/starttimedialog.py @@ -38,7 +38,7 @@ class Ui_StartTimeDialog(object): StartTimeDialog.setObjectName(u'StartTimeDialog') StartTimeDialog.resize(350, 10) self.dialogLayout = QtGui.QGridLayout(StartTimeDialog) - self.dialogLayout.setObjectName(u'dialogLayout') + self.dialogLayout.setObjectName(u'dialog_layout') self.startLabel = QtGui.QLabel(StartTimeDialog) self.startLabel.setObjectName(u'startLabel') self.startLabel.setAlignment(QtCore.Qt.AlignHCenter) @@ -102,8 +102,8 @@ class Ui_StartTimeDialog(object): self.secondFinishLabel.setAlignment(QtCore.Qt.AlignRight) self.dialogLayout.addWidget(self.secondFinishLabel, 3, 3, 1, 1) self.dialogLayout.addWidget(self.secondSpinBox, 3, 1, 1, 1) - self.buttonBox = create_button_box(StartTimeDialog, u'buttonBox', [u'cancel', u'ok']) - self.dialogLayout.addWidget(self.buttonBox, 5, 2, 1, 2) + self.button_box = create_button_box(StartTimeDialog, u'button_box', [u'cancel', u'ok']) + self.dialogLayout.addWidget(self.button_box, 5, 2, 1, 2) self.retranslateUi(StartTimeDialog) self.setMaximumHeight(self.sizeHint().height()) diff --git a/openlp/core/ui/starttimeform.py b/openlp/core/ui/starttimeform.py index b2577da5b..f53b995b1 100644 --- a/openlp/core/ui/starttimeform.py +++ b/openlp/core/ui/starttimeform.py @@ -31,15 +31,15 @@ from PyQt4 import QtGui from starttimedialog import Ui_StartTimeDialog -from openlp.core.lib import translate, UiStrings +from openlp.core.lib import translate, UiStrings, Registry from openlp.core.lib.ui import critical_error_message_box class StartTimeForm(QtGui.QDialog, Ui_StartTimeDialog): """ The exception dialog """ - def __init__(self, parent): - QtGui.QDialog.__init__(self, parent) + def __init__(self): + QtGui.QDialog.__init__(self, self.main_window) self.setupUi(self) def exec_(self): @@ -84,3 +84,13 @@ class StartTimeForm(QtGui.QDialog, Ui_StartTimeDialog): minutes = seconds / 60 seconds -= 60 * minutes return hours, minutes, seconds + + def _get_main_window(self): + """ + Adds the main window to the class dynamically + """ + if not hasattr(self, u'_main_window'): + self._main_window = Registry().get(u'main_window') + return self._main_window + + main_window = property(_get_main_window) \ No newline at end of file diff --git a/openlp/core/ui/themelayoutdialog.py b/openlp/core/ui/themelayoutdialog.py index fa3a2eb29..123fcbfec 100644 --- a/openlp/core/ui/themelayoutdialog.py +++ b/openlp/core/ui/themelayoutdialog.py @@ -58,8 +58,8 @@ class Ui_ThemeLayoutDialog(object): self.footerColourLabel = QtGui.QLabel(self.previewArea) self.footerColourLabel.setObjectName(u'footerColourLabel') self.previewLayout.addWidget(self.footerColourLabel) - self.buttonBox = create_button_box(themeLayoutDialog, u'buttonBox', [u'ok']) - self.previewLayout.addWidget(self.buttonBox) + self.button_box = create_button_box(themeLayoutDialog, u'button_box', [u'ok']) + self.previewLayout.addWidget(self.button_box) self.retranslateUi(themeLayoutDialog) def retranslateUi(self, themeLayoutDialog): diff --git a/openlp/plugins/alerts/forms/alertdialog.py b/openlp/plugins/alerts/forms/alertdialog.py index dfd895db2..1ca5a1113 100644 --- a/openlp/plugins/alerts/forms/alertdialog.py +++ b/openlp/plugins/alerts/forms/alertdialog.py @@ -77,9 +77,9 @@ class Ui_AlertDialog(object): displayIcon = build_icon(u':/general/general_live.png') self.displayButton = create_button(alertDialog, u'displayButton', icon=displayIcon, enabled=False) self.displayCloseButton = create_button(alertDialog, u'displayCloseButton', icon=displayIcon, enabled=False) - self.buttonBox = create_button_box(alertDialog, u'buttonBox', [u'close'], + self.button_box = create_button_box(alertDialog, u'button_box', [u'close'], [self.displayButton, self.displayCloseButton]) - self.alertDialogLayout.addWidget(self.buttonBox, 2, 0, 1, 2) + self.alertDialogLayout.addWidget(self.button_box, 2, 0, 1, 2) self.retranslateUi(alertDialog) def retranslateUi(self, alertDialog): diff --git a/openlp/plugins/bibles/forms/booknamedialog.py b/openlp/plugins/bibles/forms/booknamedialog.py index c1908a650..df86b4380 100644 --- a/openlp/plugins/bibles/forms/booknamedialog.py +++ b/openlp/plugins/bibles/forms/booknamedialog.py @@ -80,8 +80,8 @@ class Ui_BookNameDialog(object): self.apocryphaCheckBox.setCheckState(QtCore.Qt.Checked) self.optionsLayout.addWidget(self.apocryphaCheckBox) self.bookNameLayout.addWidget(self.optionsGroupBox) - self.buttonBox = create_button_box(bookNameDialog, u'buttonBox', [u'cancel', u'ok']) - self.bookNameLayout.addWidget(self.buttonBox) + self.button_box = create_button_box(bookNameDialog, u'button_box', [u'cancel', u'ok']) + self.bookNameLayout.addWidget(self.button_box) self.retranslateUi(bookNameDialog) diff --git a/openlp/plugins/bibles/forms/editbibledialog.py b/openlp/plugins/bibles/forms/editbibledialog.py index a74baaca5..aecfb7a98 100644 --- a/openlp/plugins/bibles/forms/editbibledialog.py +++ b/openlp/plugins/bibles/forms/editbibledialog.py @@ -44,7 +44,7 @@ class Ui_EditBibleDialog(object): self.dialogLayout = QtGui.QVBoxLayout(editBibleDialog) self.dialogLayout.setSpacing(8) self.dialogLayout.setContentsMargins(8, 8, 8, 8) - self.dialogLayout.setObjectName(u'dialogLayout') + self.dialogLayout.setObjectName(u'dialog_layout') self.bibleTabWidget = QtGui.QTabWidget(editBibleDialog) self.bibleTabWidget.setObjectName(u'BibleTabWidget') # Meta tab @@ -121,8 +121,8 @@ class Ui_EditBibleDialog(object): self.bibleTabWidget.addTab(self.bookNameTab, u'') # Last few bits self.dialogLayout.addWidget(self.bibleTabWidget) - self.buttonBox = create_button_box(editBibleDialog, u'buttonBox', [u'cancel', u'save']) - self.dialogLayout.addWidget(self.buttonBox) + self.button_box = create_button_box(editBibleDialog, u'button_box', [u'cancel', u'save']) + self.dialogLayout.addWidget(self.button_box) self.retranslateUi(editBibleDialog) QtCore.QMetaObject.connectSlotsByName(editBibleDialog) diff --git a/openlp/plugins/bibles/forms/languagedialog.py b/openlp/plugins/bibles/forms/languagedialog.py index 9ed915d34..9ad16bb30 100644 --- a/openlp/plugins/bibles/forms/languagedialog.py +++ b/openlp/plugins/bibles/forms/languagedialog.py @@ -62,8 +62,8 @@ class Ui_LanguageDialog(object): self.languageComboBox.setObjectName(u'languageComboBox') self.languageHBoxLayout.addWidget(self.languageComboBox) self.languageLayout.addLayout(self.languageHBoxLayout) - self.buttonBox = create_button_box(languageDialog, u'buttonBox', [u'cancel', u'ok']) - self.languageLayout.addWidget(self.buttonBox) + self.button_box = create_button_box(languageDialog, u'button_box', [u'cancel', u'ok']) + self.languageLayout.addWidget(self.button_box) self.retranslateUi(languageDialog) diff --git a/openlp/plugins/custom/forms/editcustomdialog.py b/openlp/plugins/custom/forms/editcustomdialog.py index 50534d171..5792e7aae 100644 --- a/openlp/plugins/custom/forms/editcustomdialog.py +++ b/openlp/plugins/custom/forms/editcustomdialog.py @@ -38,7 +38,7 @@ class Ui_CustomEditDialog(object): customEditDialog.resize(450, 350) customEditDialog.setWindowIcon(build_icon(u':/icon/openlp-logo-16x16.png')) self.dialogLayout = QtGui.QVBoxLayout(customEditDialog) - self.dialogLayout.setObjectName(u'dialogLayout') + self.dialogLayout.setObjectName(u'dialog_layout') self.titleLayout = QtGui.QHBoxLayout() self.titleLayout.setObjectName(u'titleLayout') self.titleLabel = QtGui.QLabel(customEditDialog) @@ -97,8 +97,8 @@ class Ui_CustomEditDialog(object): self.bottomFormLayout.addRow(self.creditLabel, self.creditEdit) self.dialogLayout.addLayout(self.bottomFormLayout) self.previewButton = QtGui.QPushButton() - self.buttonBox = create_button_box(customEditDialog, u'buttonBox', [u'cancel', u'save'], [self.previewButton]) - self.dialogLayout.addWidget(self.buttonBox) + self.button_box = create_button_box(customEditDialog, u'button_box', [u'cancel', u'save'], [self.previewButton]) + self.dialogLayout.addWidget(self.button_box) self.retranslateUi(customEditDialog) def retranslateUi(self, customEditDialog): diff --git a/openlp/plugins/custom/forms/editcustomform.py b/openlp/plugins/custom/forms/editcustomform.py index 69058eb0c..8e7c18bdf 100644 --- a/openlp/plugins/custom/forms/editcustomform.py +++ b/openlp/plugins/custom/forms/editcustomform.py @@ -102,10 +102,6 @@ class EditCustomForm(QtGui.QDialog, Ui_CustomEditDialog): # If not preview hide the preview button. self.previewButton.setVisible(preview) - def reject(self): - Receiver.send_message(u'custom_edit_clear') - QtGui.QDialog.reject(self) - def accept(self): log.debug(u'accept') if self.saveCustom(): diff --git a/openlp/plugins/custom/forms/editcustomslidedialog.py b/openlp/plugins/custom/forms/editcustomslidedialog.py index cb16926d0..ee47ba52b 100644 --- a/openlp/plugins/custom/forms/editcustomslidedialog.py +++ b/openlp/plugins/custom/forms/editcustomslidedialog.py @@ -42,9 +42,9 @@ class Ui_CustomSlideEditDialog(object): self.dialogLayout.addWidget(self.slideTextEdit) self.splitButton = create_button(customSlideEditDialog, u'splitButton', icon=u':/general/general_add.png') self.insertButton = create_button(customSlideEditDialog, u'insertButton', icon=u':/general/general_add.png') - self.buttonBox = create_button_box(customSlideEditDialog, u'buttonBox', [u'cancel', u'save'], + self.button_box = create_button_box(customSlideEditDialog, u'button_box', [u'cancel', u'save'], [self.splitButton, self.insertButton]) - self.dialogLayout.addWidget(self.buttonBox) + self.dialogLayout.addWidget(self.button_box) self.retranslateUi(customSlideEditDialog) def retranslateUi(self, customSlideEditDialog): diff --git a/openlp/plugins/custom/lib/mediaitem.py b/openlp/plugins/custom/lib/mediaitem.py index b4938e929..e434f516a 100644 --- a/openlp/plugins/custom/lib/mediaitem.py +++ b/openlp/plugins/custom/lib/mediaitem.py @@ -73,8 +73,6 @@ class CustomMediaItem(MediaManagerItem): QtCore.QObject.connect(self.searchTextEdit, QtCore.SIGNAL(u'cleared()'), self.onClearTextButtonClick) QtCore.QObject.connect(self.searchTextEdit, QtCore.SIGNAL(u'searchTypeChanged(int)'), self.onSearchTextButtonClicked) - QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'custom_edit'), self.onRemoteEdit) - QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'custom_edit_clear'), self.onRemoteEditClear) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'custom_load_list'), self.loadList) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'custom_preview'), self.onPreviewClick) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_updated'), self.config_updated) @@ -115,11 +113,6 @@ class CustomMediaItem(MediaManagerItem): # Called to redisplay the custom list screen edith from a search # or from the exit of the Custom edit dialog. If remote editing is # active trigger it and clean up so it will not update again. - if self.remoteTriggered == u'L': - self.onAddClick() - if self.remoteTriggered == u'P': - self.onPreviewClick() - self.onRemoteEditClear() def onNewClick(self): self.edit_custom_form.loadCustom(0) @@ -127,26 +120,27 @@ class CustomMediaItem(MediaManagerItem): self.onClearTextButtonClick() self.onSelectionChange() - def onRemoteEditClear(self): - self.remoteTriggered = None - self.remoteCustom = -1 - - def onRemoteEdit(self, message): + def onRemoteEdit(self, custom_id, preview=False): """ Called by ServiceManager or SlideController by event passing the custom Id in the payload along with an indicator to say which type of display is required. """ - remote_type, custom_id = message.split(u':') custom_id = int(custom_id) valid = self.manager.get_object(CustomSlide, custom_id) if valid: - self.remoteCustom = custom_id - self.remoteTriggered = remote_type - self.edit_custom_form.loadCustom(custom_id, (remote_type == u'P')) - self.edit_custom_form.exec_() - self.autoSelectId = -1 - self.onSearchTextButtonClicked() + self.edit_custom_form.loadCustom(custom_id, preview) + if self.edit_custom_form.exec_() == QtGui.QDialog.Accepted: + self.remoteTriggered = True + self.remoteCustom = custom_id + self.autoSelectId = -1 + self.onSearchTextButtonClicked() + item = self.buildServiceItem(remote=True) + self.remoteTriggered = None + self.remoteCustom = 1 + if item: + return item + return None def onEditClick(self): """ diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index 092103c86..85024229a 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -189,10 +189,10 @@ class ImageMediaItem(MediaManagerItem): def onResetClick(self): """ - Called to reset the Live backgound with the image selected, + Called to reset the Live background with the image selected, """ self.resetAction.setVisible(False) - self.plugin.liveController.display.resetImage() + self.live_controller.display.resetImage() def liveThemeChanged(self): """ @@ -211,7 +211,7 @@ class ImageMediaItem(MediaManagerItem): bitem = self.listView.item(item.row()) filename = bitem.data(QtCore.Qt.UserRole) if os.path.exists(filename): - if self.plugin.liveController.display.directImage(filename, background): + if self.live_controller.display.directImage(filename, background): self.resetAction.setVisible(True) else: critical_error_message_box(UiStrings().LiveBGError, diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index 443087a09..deca81f77 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -131,7 +131,7 @@ class MediaMediaItem(MediaManagerItem): """ Called to reset the Live background with the media selected, """ - self.live_controller.mediaController.media_reset(self.plugin.liveController) + self.media_controller.media_reset(self.live_controller) self.resetAction.setVisible(False) def videobackgroundReplaced(self): @@ -154,7 +154,7 @@ class MediaMediaItem(MediaManagerItem): service_item.shortname = service_item.title (path, name) = os.path.split(filename) service_item.add_from_command(path, name,CLAPPERBOARD) - if self.live_controller.mediaController.video(DisplayControllerType.Live, service_item, + if self.media_controller.video(DisplayControllerType.Live, service_item, videoBehindText=True): self.resetAction.setVisible(True) else: diff --git a/openlp/plugins/media/lib/mediatab.py b/openlp/plugins/media/lib/mediatab.py index 0b220698c..87a56f238 100644 --- a/openlp/plugins/media/lib/mediatab.py +++ b/openlp/plugins/media/lib/mediatab.py @@ -85,6 +85,6 @@ class MediaTab(SettingsTab): if Settings().value(setting_key) != self.autoStartCheckBox.checkState(): Settings().setValue(setting_key, self.autoStartCheckBox.checkState()) if override_changed: - self.parent.resetSupportedSuffixes() + self.parent.reset_supported_suffixes() Receiver.send_message(u'mediaitem_media_rebuild') Receiver.send_message(u'mediaitem_suffixes') diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index fe533a791..eee1c5801 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -85,7 +85,7 @@ class PresentationMediaItem(MediaManagerItem): for type in types: if fileType.find(type) == -1: fileType += u'*.%s ' % type - self.plugin.serviceManager.supportedSuffixes(type) + self.service_manager.supported_suffixes(type) self.onNewFileMasks = translate('PresentationPlugin.MediaItem', 'Presentations (%s)') % fileType def requiredIcons(self): diff --git a/openlp/plugins/presentations/lib/presentationtab.py b/openlp/plugins/presentations/lib/presentationtab.py index 2c8d3002f..c72676860 100644 --- a/openlp/plugins/presentations/lib/presentationtab.py +++ b/openlp/plugins/presentations/lib/presentationtab.py @@ -129,7 +129,7 @@ class PresentationTab(SettingsTab): Settings().setValue(setting_key, self.OverrideAppCheckBox.checkState()) changed = True if changed: - self.parent.resetSupportedSuffixes() + self.parent.reset_supported_suffixes() Receiver.send_message(u'mediaitem_presentation_rebuild') Receiver.send_message(u'mediaitem_suffixes') diff --git a/openlp/plugins/songs/forms/authorsdialog.py b/openlp/plugins/songs/forms/authorsdialog.py index 1e33886a9..c8f1260c9 100644 --- a/openlp/plugins/songs/forms/authorsdialog.py +++ b/openlp/plugins/songs/forms/authorsdialog.py @@ -37,7 +37,7 @@ class Ui_AuthorsDialog(object): authorsDialog.setObjectName(u'AuthorsDialog') authorsDialog.resize(300, 10) self.dialogLayout = QtGui.QVBoxLayout(authorsDialog) - self.dialogLayout.setObjectName(u'dialogLayout') + self.dialogLayout.setObjectName(u'dialog_layout') self.authorLayout = QtGui.QFormLayout() self.authorLayout.setObjectName(u'authorLayout') self.firstNameLabel = QtGui.QLabel(authorsDialog) @@ -59,8 +59,8 @@ class Ui_AuthorsDialog(object): self.displayLabel.setBuddy(self.displayEdit) self.authorLayout.addRow(self.displayLabel, self.displayEdit) self.dialogLayout.addLayout(self.authorLayout) - self.buttonBox = create_button_box(authorsDialog, u'buttonBox', [u'cancel', u'save']) - self.dialogLayout.addWidget(self.buttonBox) + self.button_box = create_button_box(authorsDialog, u'button_box', [u'cancel', u'save']) + self.dialogLayout.addWidget(self.button_box) self.retranslateUi(authorsDialog) authorsDialog.setMaximumHeight(authorsDialog.sizeHint().height()) diff --git a/openlp/plugins/songs/forms/editsongdialog.py b/openlp/plugins/songs/forms/editsongdialog.py index 79d4b2778..3f6e1e61a 100644 --- a/openlp/plugins/songs/forms/editsongdialog.py +++ b/openlp/plugins/songs/forms/editsongdialog.py @@ -42,7 +42,7 @@ class Ui_EditSongDialog(object): self.dialogLayout = QtGui.QVBoxLayout(editSongDialog) self.dialogLayout.setSpacing(8) self.dialogLayout.setContentsMargins(8, 8, 8, 8) - self.dialogLayout.setObjectName(u'dialogLayout') + self.dialogLayout.setObjectName(u'dialog_layout') self.songTabWidget = QtGui.QTabWidget(editSongDialog) self.songTabWidget.setObjectName(u'songTabWidget') # lyrics tab @@ -272,8 +272,8 @@ class Ui_EditSongDialog(object): self.warningLabel.setObjectName(u'warningLabel') self.warningLabel.setVisible(False) self.bottomLayout.addWidget(self.warningLabel) - self.buttonBox = create_button_box(editSongDialog, u'buttonBox', [u'cancel', u'save']) - self.bottomLayout.addWidget(self.buttonBox) + self.button_box = create_button_box(editSongDialog, u'button_box', [u'cancel', u'save']) + self.bottomLayout.addWidget(self.button_box) self.dialogLayout.addLayout(self.bottomLayout) self.retranslateUi(editSongDialog) diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index 5cfd01643..0c0e5c196 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -101,8 +101,8 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.previewButton = QtGui.QPushButton() self.previewButton.setObjectName(u'previewButton') self.previewButton.setText(UiStrings().SaveAndPreview) - self.buttonBox.addButton(self.previewButton, QtGui.QDialogButtonBox.ActionRole) - QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(u'clicked(QAbstractButton*)'), self.onPreview) + self.button_box.addButton(self.previewButton, QtGui.QDialogButtonBox.ActionRole) + QtCore.QObject.connect(self.button_box, QtCore.SIGNAL(u'clicked(QAbstractButton*)'), self.onPreview) # Create other objects and forms self.manager = manager self.verseForm = EditVerseForm(self) @@ -775,7 +775,6 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): Exit Dialog and do not save """ log.debug (u'SongEditForm.reject') - Receiver.send_message(u'songs_edit_clear') self.clearCaches() QtGui.QDialog.reject(self) diff --git a/openlp/plugins/songs/forms/editversedialog.py b/openlp/plugins/songs/forms/editversedialog.py index 402e1f163..603af2180 100644 --- a/openlp/plugins/songs/forms/editversedialog.py +++ b/openlp/plugins/songs/forms/editversedialog.py @@ -39,7 +39,7 @@ class Ui_EditVerseDialog(object): editVerseDialog.resize(400, 400) editVerseDialog.setModal(True) self.dialogLayout = QtGui.QVBoxLayout(editVerseDialog) - self.dialogLayout.setObjectName(u'dialogLayout') + self.dialogLayout.setObjectName(u'dialog_layout') self.verseTextEdit = SpellTextEdit(editVerseDialog) self.verseTextEdit.setObjectName(u'verseTextEdit') self.dialogLayout.addWidget(self.verseTextEdit) @@ -67,8 +67,8 @@ class Ui_EditVerseDialog(object): self.verseTypeLayout.addWidget(self.insertButton) self.verseTypeLayout.addStretch() self.dialogLayout.addLayout(self.verseTypeLayout) - self.buttonBox = create_button_box(editVerseDialog, u'buttonBox', [u'cancel', u'ok']) - self.dialogLayout.addWidget(self.buttonBox) + 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): diff --git a/openlp/plugins/songs/forms/mediafilesdialog.py b/openlp/plugins/songs/forms/mediafilesdialog.py index bb628aec4..dd2c4b01a 100644 --- a/openlp/plugins/songs/forms/mediafilesdialog.py +++ b/openlp/plugins/songs/forms/mediafilesdialog.py @@ -52,8 +52,8 @@ class Ui_MediaFilesDialog(object): self.fileListWidget.setSelectionMode(QtGui.QAbstractItemView.ExtendedSelection) self.fileListWidget.setObjectName(u'fileListWidget') self.filesVerticalLayout.addWidget(self.fileListWidget) - self.buttonBox = create_button_box(mediaFilesDialog, u'buttonBox', [u'cancel', u'ok']) - self.filesVerticalLayout.addWidget(self.buttonBox) + 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): diff --git a/openlp/plugins/songs/forms/songbookdialog.py b/openlp/plugins/songs/forms/songbookdialog.py index fb378fd6e..7c6bf40aa 100644 --- a/openlp/plugins/songs/forms/songbookdialog.py +++ b/openlp/plugins/songs/forms/songbookdialog.py @@ -37,7 +37,7 @@ class Ui_SongBookDialog(object): songBookDialog.setObjectName(u'songBookDialog') songBookDialog.resize(300, 10) self.dialogLayout = QtGui.QVBoxLayout(songBookDialog) - self.dialogLayout.setObjectName(u'dialogLayout') + self.dialogLayout.setObjectName(u'dialog_layout') self.bookLayout = QtGui.QFormLayout() self.bookLayout.setObjectName(u'bookLayout') self.nameLabel = QtGui.QLabel(songBookDialog) @@ -53,8 +53,8 @@ class Ui_SongBookDialog(object): self.publisherLabel.setBuddy(self.publisherEdit) self.bookLayout.addRow(self.publisherLabel, self.publisherEdit) self.dialogLayout.addLayout(self.bookLayout) - self.buttonBox = create_button_box(songBookDialog, u'buttonBox', [u'cancel', u'save']) - self.dialogLayout.addWidget(self.buttonBox) + 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()) diff --git a/openlp/plugins/songs/forms/songmaintenancedialog.py b/openlp/plugins/songs/forms/songmaintenancedialog.py index a14bfc114..389579284 100644 --- a/openlp/plugins/songs/forms/songmaintenancedialog.py +++ b/openlp/plugins/songs/forms/songmaintenancedialog.py @@ -39,7 +39,7 @@ class Ui_SongMaintenanceDialog(object): songMaintenanceDialog.setWindowModality(QtCore.Qt.ApplicationModal) songMaintenanceDialog.resize(10, 350) self.dialogLayout = QtGui.QGridLayout(songMaintenanceDialog) - self.dialogLayout.setObjectName(u'dialogLayout') + self.dialogLayout.setObjectName(u'dialog_layout') self.typeListWidget = QtGui.QListWidget(songMaintenanceDialog) self.typeListWidget.setIconSize(QtCore.QSize(32, 32)) self.typeListWidget.setUniformItemSizes(True) @@ -130,8 +130,8 @@ class Ui_SongMaintenanceDialog(object): self.stackedLayout.addWidget(self.booksPage) # self.dialogLayout.addLayout(self.stackedLayout, 0, 1) - self.buttonBox = create_button_box(songMaintenanceDialog, u'buttonBox', [u'close']) - self.dialogLayout.addWidget(self.buttonBox, 1, 0, 1, 2) + 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) QtCore.QObject.connect(self.typeListWidget, QtCore.SIGNAL(u'currentRowChanged(int)'), diff --git a/openlp/plugins/songs/forms/topicsdialog.py b/openlp/plugins/songs/forms/topicsdialog.py index c26a92176..9b1a8c11c 100644 --- a/openlp/plugins/songs/forms/topicsdialog.py +++ b/openlp/plugins/songs/forms/topicsdialog.py @@ -37,7 +37,7 @@ class Ui_TopicsDialog(object): topicsDialog.setObjectName(u'topicsDialog') topicsDialog.resize(300, 10) self.dialogLayout = QtGui.QVBoxLayout(topicsDialog) - self.dialogLayout.setObjectName(u'dialogLayout') + self.dialogLayout.setObjectName(u'dialog_layout') self.nameLayout = QtGui.QFormLayout() self.nameLayout.setObjectName(u'nameLayout') self.nameLabel = QtGui.QLabel(topicsDialog) @@ -47,8 +47,8 @@ class Ui_TopicsDialog(object): self.nameLabel.setBuddy(self.nameEdit) self.nameLayout.addRow(self.nameLabel, self.nameEdit) self.dialogLayout.addLayout(self.nameLayout) - self.buttonBox = create_button_box(topicsDialog, u'buttonBox', [u'cancel', u'save']) - self.dialogLayout.addWidget(self.buttonBox) + 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()) diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index cd23ad731..de1ad22ff 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -35,15 +35,12 @@ import shutil from PyQt4 import QtCore, QtGui from sqlalchemy.sql import or_ -from openlp.core.lib import MediaManagerItem, Receiver, ItemCapabilities, \ - translate, check_item_selected, PluginStatus, create_separated_list, \ - check_directory_exists, ServiceItemContext, Settings, UiStrings +from openlp.core.lib import MediaManagerItem, Receiver, ItemCapabilities, translate, check_item_selected, \ + PluginStatus, create_separated_list, check_directory_exists, ServiceItemContext, Settings, UiStrings from openlp.core.lib.ui import create_widget_action from openlp.core.utils import AppLocation -from openlp.plugins.songs.forms import EditSongForm, SongMaintenanceForm, \ - SongImportForm, SongExportForm -from openlp.plugins.songs.lib import OpenLyrics, SongXML, VerseType, \ - clean_string, natcmp +from openlp.plugins.songs.forms import EditSongForm, SongMaintenanceForm, SongImportForm, SongExportForm +from openlp.plugins.songs.lib import OpenLyrics, SongXML, VerseType, clean_string, natcmp from openlp.plugins.songs.lib.db import Author, Song, Book, MediaFile from openlp.plugins.songs.lib.ui import SongStrings @@ -105,8 +102,6 @@ class SongMediaItem(MediaManagerItem): QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'songs_load_list'), self.onSongListLoad) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_updated'), self.configUpdated) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'songs_preview'), self.onPreviewClick) - QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'songs_edit'), self.onRemoteEdit) - QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'songs_edit_clear'), self.onRemoteEditClear) QtCore.QObject.connect(self.searchTextEdit, QtCore.SIGNAL(u'cleared()'), self.onClearTextButtonClick) QtCore.QObject.connect(self.searchTextEdit, QtCore.SIGNAL(u'searchTypeChanged(int)'), self.onSearchTextButtonClicked) @@ -212,15 +207,10 @@ class SongMediaItem(MediaManagerItem): # Called to redisplay the song list screen edit from a search # or from the exit of the Song edit dialog. If remote editing is active # Trigger it and clean up so it will not update again. - if self.remoteTriggered == u'L': - self.onAddClick() - if self.remoteTriggered == u'P': - self.onPreviewClick() # Push edits to the service manager to update items if self.editItem and self.updateServiceOnEdit and not self.remoteTriggered: item = self.buildServiceItem(self.editItem) - self.plugin.serviceManager.replaceServiceItem(item) - self.onRemoteEditClear() + self.service_manager.replace_service_item(item) self.onSearchTextButtonClicked() log.debug(u'onSongListLoad - finished') @@ -321,28 +311,28 @@ class SongMediaItem(MediaManagerItem): def onSongMaintenanceClick(self): self.songMaintenanceForm.exec_() - def onRemoteEditClear(self): - log.debug(u'onRemoteEditClear') - self.remoteTriggered = None - self.remoteSong = -1 - - def onRemoteEdit(self, message): + def onRemoteEdit(self, song_id, preview=False): """ Called by ServiceManager or SlideController by event passing the Song Id in the payload along with an indicator to say which type of display is required. """ - log.debug(u'onRemoteEdit %s' % message) - remote_type, song_id = message.split(u':') + log.debug(u'onRemoteEdit for song %s' % song_id) song_id = int(song_id) valid = self.plugin.manager.get_object(Song, song_id) if valid: - self.remoteSong = song_id - self.remoteTriggered = remote_type - self.editSongForm.loadSong(song_id, remote_type == u'P') - self.editSongForm.exec_() - self.autoSelectId = -1 - self.onSongListLoad() + self.editSongForm.loadSong(song_id, preview) + if self.editSongForm.exec_() == QtGui.QDialog.Accepted: + self.autoSelectId = -1 + self.onSongListLoad() + self.remoteSong = song_id + self.remoteTriggered = True + item = self.buildServiceItem(remote=True) + self.remoteSong = -1 + self.remoteTriggered = None + if item: + return item + return None def onEditClick(self): """ @@ -410,7 +400,7 @@ class SongMediaItem(MediaManagerItem): self.onSongListLoad() def generateSlideData(self, service_item, item=None, xmlVersion=False, - remote=False, context=ServiceItemContext.Service): + remote=False, context=ServiceItemContext.Service): log.debug(u'generateSlideData: %s, %s, %s' % (service_item, item, self.remoteSong)) item_id = self._getIdOfItemToGenerate(item, self.remoteSong) service_item.add_capability(ItemCapabilities.CanEdit) @@ -426,8 +416,7 @@ class SongMediaItem(MediaManagerItem): verse_list = SongXML().get_verses(song.lyrics) # no verse list or only 1 space (in error) verse_tags_translated = False - if VerseType.from_translated_string(unicode( - verse_list[0][0][u'type'])) is not None: + if VerseType.from_translated_string(unicode(verse_list[0][0][u'type'])) is not None: verse_tags_translated = True if not song.verse_order.strip(): for verse in verse_list: diff --git a/openlp/plugins/songusage/forms/songusagedeletedialog.py b/openlp/plugins/songusage/forms/songusagedeletedialog.py index 5ffefa383..349c3258a 100644 --- a/openlp/plugins/songusage/forms/songusagedeletedialog.py +++ b/openlp/plugins/songusage/forms/songusagedeletedialog.py @@ -49,8 +49,8 @@ class Ui_SongUsageDeleteDialog(object): self.deleteCalendar.setVerticalHeaderFormat(QtGui.QCalendarWidget.NoVerticalHeader) self.deleteCalendar.setObjectName(u'deleteCalendar') self.verticalLayout.addWidget(self.deleteCalendar) - self.buttonBox = create_button_box(songUsageDeleteDialog, u'buttonBox', [u'cancel', u'ok']) - self.verticalLayout.addWidget(self.buttonBox) + self.button_box = create_button_box(songUsageDeleteDialog, u'button_box', [u'cancel', u'ok']) + self.verticalLayout.addWidget(self.button_box) self.retranslateUi(songUsageDeleteDialog) def retranslateUi(self, songUsageDeleteDialog): diff --git a/openlp/plugins/songusage/forms/songusagedeleteform.py b/openlp/plugins/songusage/forms/songusagedeleteform.py index e9dd19af3..8174060bd 100644 --- a/openlp/plugins/songusage/forms/songusagedeleteform.py +++ b/openlp/plugins/songusage/forms/songusagedeleteform.py @@ -44,11 +44,11 @@ class SongUsageDeleteForm(QtGui.QDialog, Ui_SongUsageDeleteDialog): self.manager = manager QtGui.QDialog.__init__(self, parent) self.setupUi(self) - QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(u'clicked(QAbstractButton*)'), + QtCore.QObject.connect(self.button_box, QtCore.SIGNAL(u'clicked(QAbstractButton*)'), self.onButtonBoxClicked) def onButtonBoxClicked(self, button): - if self.buttonBox.standardButton(button) == QtGui.QDialogButtonBox.Ok: + if self.button_box.standardButton(button) == QtGui.QDialogButtonBox.Ok: ret = QtGui.QMessageBox.question(self, translate('SongUsagePlugin.SongUsageDeleteForm', 'Delete Selected Song Usage Events?'), translate('SongUsagePlugin.SongUsageDeleteForm', diff --git a/openlp/plugins/songusage/forms/songusagedetaildialog.py b/openlp/plugins/songusage/forms/songusagedetaildialog.py index 0d7d329dc..740771a2b 100644 --- a/openlp/plugins/songusage/forms/songusagedetaildialog.py +++ b/openlp/plugins/songusage/forms/songusagedetaildialog.py @@ -74,8 +74,8 @@ class Ui_SongUsageDetailDialog(object): self.saveFilePushButton.setObjectName(u'saveFilePushButton') self.fileHorizontalLayout.addWidget(self.saveFilePushButton) self.verticalLayout.addWidget(self.fileGroupBox) - self.buttonBox = create_button_box(songUsageDetailDialog, u'buttonBox', [u'cancel', u'ok']) - self.verticalLayout.addWidget(self.buttonBox) + self.button_box = create_button_box(songUsageDetailDialog, u'button_box', [u'cancel', u'ok']) + self.verticalLayout.addWidget(self.button_box) self.retranslateUi(songUsageDetailDialog) QtCore.QObject.connect(self.saveFilePushButton, QtCore.SIGNAL(u'clicked()'), songUsageDetailDialog.defineOutputLocation) diff --git a/tests/functional/openlp_core_lib/test_registry.py b/tests/functional/openlp_core_lib/test_registry.py index 16d0de52a..f27eef3d8 100644 --- a/tests/functional/openlp_core_lib/test_registry.py +++ b/tests/functional/openlp_core_lib/test_registry.py @@ -13,26 +13,36 @@ class TestRegistry(TestCase): def registry_basic_test(self): """ - Test the Service Item basic test + Test the registry creation and its usage """ # GIVEN: A new registry registry = Registry.create() - # WHEN: I add a service it should save it + # WHEN: I add a component it should save it mock_1 = MagicMock() Registry().register(u'test1', mock_1) - # THEN: we should be able retrieve the saved object + # THEN: we should be able retrieve the saved component assert Registry().get(u'test1') == mock_1, u'The saved service can be retrieved and matches' - # WHEN: I add a service for the second time I am mad. - # THEN I will get an exception + # WHEN: I add a component for the second time I am mad. + # THEN and I will get an exception with self.assertRaises(KeyError) as context: Registry().register(u'test1', mock_1) - self.assertEqual(context.exception[0], u'Duplicate service exception test1') + self.assertEqual(context.exception[0], u'Duplicate service exception test1', + u'KeyError exception should have been thrown for duplicate service') - # WHEN I try to get back a non existent service + # WHEN I try to get back a non existent component # THEN I will get an exception with self.assertRaises(KeyError) as context: temp = Registry().get(u'test2') - self.assertEqual(context.exception[0], u'Service test2 not found in list') \ No newline at end of file + self.assertEqual(context.exception[0], u'Service test2 not found in list', + u'KeyError exception should have been thrown for missing service') + + # WHEN I try to replace a component I should be allowed (testing only) + Registry().remove(u'test1') + # THEN I will get an exception + with self.assertRaises(KeyError) as context: + temp = Registry().get(u'test1') + self.assertEqual(context.exception[0], u'Service test1 not found in list', + u'KeyError exception should have been thrown for deleted service') diff --git a/tests/functional/openlp_core_lib/test_serviceitem.py b/tests/functional/openlp_core_lib/test_serviceitem.py index 2b7185370..a50752cce 100644 --- a/tests/functional/openlp_core_lib/test_serviceitem.py +++ b/tests/functional/openlp_core_lib/test_serviceitem.py @@ -29,11 +29,10 @@ class TestServiceItem(TestCase): Set up the Registry """ registry = Registry.create() - mocked_renderer = MagicMock() - mocked_image_manager = MagicMock() + mocked_renderer = MagicMock() mocked_renderer.format_slide.return_value = [VERSE] Registry().register(u'renderer', mocked_renderer) - Registry().register(u'image_manager', mocked_image_manager) + Registry().register(u'image_manager', MagicMock()) def serviceitem_basic_test(self): """ diff --git a/tests/functional/openlp_core_ui/test_servicenotedialog.py b/tests/functional/openlp_core_ui/test_servicenotedialog.py new file mode 100644 index 000000000..e444ff687 --- /dev/null +++ b/tests/functional/openlp_core_ui/test_servicenotedialog.py @@ -0,0 +1,67 @@ +""" + Package to test the openlp.core.ui package. +""" +from unittest import TestCase + +from mock import patch +from openlp.core.lib import Registry +from openlp.core.ui import servicenoteform +from PyQt4 import QtCore, QtGui, QtTest + +class TestStartNoteDialog(TestCase): + + def setUp(self): + """ + Create the UI + """ + registry = Registry.create() + self.app = QtGui.QApplication([]) + self.main_window = QtGui.QMainWindow() + Registry().register(u'main_window', self.main_window) + self.form = servicenoteform.ServiceNoteForm() + + 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 basic_display_test(self): + """ + Test Service Note form functionality + """ + # GIVEN: A dialog with an empty text box + self.form.text_edit.setPlainText(u'') + + # WHEN displaying the UI and pressing enter + with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + self.form.exec_() + okWidget = self.form.button_box.button(self.form.button_box.Save) + QtTest.QTest.mouseClick(okWidget, QtCore.Qt.LeftButton) + + # THEN the following input text is returned + self.assertEqual(self.form.text_edit.toPlainText(), u'', u'The returned text should be empty') + + # WHEN displaying the UI, having set the text and pressing enter + text = u'OpenLP is the best worship software' + self.form.text_edit.setPlainText(text) + with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + self.form.exec_() + okWidget = self.form.button_box.button(self.form.button_box.Save) + QtTest.QTest.mouseClick(okWidget, QtCore.Qt.LeftButton) + + # THEN the following text is returned + self.assertEqual(self.form.text_edit.toPlainText(), text, u'The text originally entered should still be there') + + # WHEN displaying the UI, having set the text and pressing enter + self.form.text_edit.setPlainText(u'') + with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + self.form.exec_() + self.form.text_edit.setPlainText(text) + okWidget = self.form.button_box.button(self.form.button_box.Save) + QtTest.QTest.mouseClick(okWidget, QtCore.Qt.LeftButton) + + # THEN the following text is returned + self.assertEqual(self.form.text_edit.toPlainText(), text, u'The new text should be returned') \ No newline at end of file diff --git a/tests/functional/openlp_core_ui/test_starttimedialog.py b/tests/functional/openlp_core_ui/test_starttimedialog.py index c4b175106..918c6637c 100644 --- a/tests/functional/openlp_core_ui/test_starttimedialog.py +++ b/tests/functional/openlp_core_ui/test_starttimedialog.py @@ -5,8 +5,9 @@ import sys from unittest import TestCase from mock import MagicMock, patch +from openlp.core.lib import Registry from openlp.core.ui import starttimeform -from PyQt4 import QtGui, QtTest +from PyQt4 import QtCore, QtGui, QtTest class TestStartTimeDialog(TestCase): @@ -14,52 +15,81 @@ class TestStartTimeDialog(TestCase): """ Create the UI """ + registry = Registry.create() self.app = QtGui.QApplication([]) - self.window = QtGui.QMainWindow() - self.form = starttimeform.StartTimeForm(self.window) + self.main_window = QtGui.QMainWindow() + Registry().register(u'main_window', self.main_window) + self.form = starttimeform.StartTimeForm() def tearDown(self): """ Delete all the C++ objects at the end so that we don't have a segfault """ del self.form - del self.window + del self.main_window del self.app def ui_defaults_test(self): """ - Test StartTimeDialog defaults + Test StartTimeDialog are defaults correct """ - self.assertEqual(self.form.hourSpinBox.minimum(), 0) - self.assertEqual(self.form.hourSpinBox.maximum(), 4) - self.assertEqual(self.form.minuteSpinBox.minimum(), 0) - self.assertEqual(self.form.minuteSpinBox.maximum(), 59) - self.assertEqual(self.form.secondSpinBox.minimum(), 0) - self.assertEqual(self.form.secondSpinBox.maximum(), 59) - self.assertEqual(self.form.hourFinishSpinBox.minimum(), 0) - self.assertEqual(self.form.hourFinishSpinBox.maximum(), 4) - self.assertEqual(self.form.minuteFinishSpinBox.minimum(), 0) - self.assertEqual(self.form.minuteFinishSpinBox.maximum(), 59) - self.assertEqual(self.form.secondFinishSpinBox.minimum(), 0) - self.assertEqual(self.form.secondFinishSpinBox.maximum(), 59) + self.assertEqual(self.form.hourSpinBox.minimum(), 0, u'The minimum hour should stay the same as the dialog') + self.assertEqual(self.form.hourSpinBox.maximum(), 4, u'The maximum hour should stay the same as the dialog') + self.assertEqual(self.form.minuteSpinBox.minimum(), 0, + u'The minimum minute should stay the same as the dialog') + self.assertEqual(self.form.minuteSpinBox.maximum(), 59, + u'The maximum minute should stay the same as the dialog') + self.assertEqual(self.form.secondSpinBox.minimum(), 0, + u'The minimum second should stay the same as the dialog') + self.assertEqual(self.form.secondSpinBox.maximum(), 59, + u'The maximum second should stay the same as the dialog') + self.assertEqual(self.form.hourFinishSpinBox.minimum(), 0, + u'The minimum finish hour should stay the same as the dialog') + self.assertEqual(self.form.hourFinishSpinBox.maximum(), 4, + u'The maximum finish hour should stay the same as the dialog') + self.assertEqual(self.form.minuteFinishSpinBox.minimum(), 0, + u'The minimum finish minute should stay the same as the dialog') + self.assertEqual(self.form.minuteFinishSpinBox.maximum(), 59, + u'The maximum finish minute should stay the same as the dialog') + self.assertEqual(self.form.secondFinishSpinBox.minimum(), 0, + u'The minimum finish second should stay the same as the dialog') + self.assertEqual(self.form.secondFinishSpinBox.maximum(), 59, + u'The maximum finish second should stay the same as the dialog') def time_display_test(self): """ - Test StartTimeDialog display initialisation + Test StartTimeDialog display functionality """ # GIVEN: A service item with with time mocked_serviceitem = MagicMock() mocked_serviceitem.start_time = 61 mocked_serviceitem.end_time = 3701 + mocked_serviceitem.media_length = 3701 # WHEN displaying the UI and pressing enter - self.form.item = mocked_serviceitem - with patch(u'openlp.core.lib.QtGui.QDialog') as MockedQtGuiQDialog: - MockedQtGuiQDialog.return_value = True - #does not work yet - #self.form.exec_() + self.form.item = {u'service_item': mocked_serviceitem} + with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + self.form.exec_() + okWidget = self.form.button_box.button(self.form.button_box.Ok) + QtTest.QTest.mouseClick(okWidget, QtCore.Qt.LeftButton) + + # THEN the following input values are returned + self.assertEqual(self.form.hourSpinBox.value(), 0) + self.assertEqual(self.form.minuteSpinBox.value(), 1) + self.assertEqual(self.form.secondSpinBox.value(), 1) + self.assertEqual(self.form.item[u'service_item'].start_time, 61, u'The start time should stay the same') + + # WHEN displaying the UI, changing the time to 2min 3secs and pressing enter + self.form.item = {u'service_item': mocked_serviceitem} + with patch(u'PyQt4.QtGui.QDialog') as mocked_exec: + self.form.exec_() + self.form.minuteSpinBox.setValue(2) + self.form.secondSpinBox.setValue(3) + okWidget = self.form.button_box.button(self.form.button_box.Ok) + QtTest.QTest.mouseClick(okWidget, QtCore.Qt.LeftButton) # THEN the following values are returned self.assertEqual(self.form.hourSpinBox.value(), 0) - self.assertEqual(self.form.minuteSpinBox.value(), 0) - self.assertEqual(self.form.secondSpinBox.value(), 0) \ No newline at end of file + self.assertEqual(self.form.minuteSpinBox.value(), 2) + self.assertEqual(self.form.secondSpinBox.value(), 3) + self.assertEqual(self.form.item[u'service_item'].start_time, 123, u'The start time should have changed') \ No newline at end of file