From de6ce1209275d5a2beac53c02ae625cf39d2fab2 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 17 Feb 2013 21:28:45 +0000 Subject: [PATCH 01/15] Mark 1 --- openlp/core/__init__.py | 3 ++- openlp/core/lib/__init__.py | 29 +++++++++++++++++++++++++++++ openlp/core/lib/renderer.py | 1 - openlp/core/ui/mainwindow.py | 30 +++++++++++++++++++++++------- 4 files changed, 54 insertions(+), 9 deletions(-) diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index 3ad0e1348..334fd5003 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -43,7 +43,7 @@ from traceback import format_exception from PyQt4 import QtCore, QtGui -from openlp.core.lib import Settings, ScreenList, UiStrings, Registry, check_directory_exists +from openlp.core.lib import Settings, ScreenList, UiStrings, Registry, check_directory_exists, bootstrap from openlp.core.resources import qInitResources from openlp.core.ui.mainwindow import MainWindow from openlp.core.ui.firsttimelanguageform import FirstTimeLanguageForm @@ -135,6 +135,7 @@ class OpenLP(QtGui.QApplication): # make sure Qt really display the splash screen self.processEvents() # start the main app window + bootstrap() self.main_window = MainWindow() self.main_window.show() if show_splash: diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index a3d9cec4b..ba014ccda 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -386,6 +386,35 @@ def create_separated_list(stringlist): return translate('OpenLP.core.lib', '%s, %s', u'Locale list separator: start') % (stringlist[0], merged) +def bootstrap(): + """ + Bootstrap control function to build all the components and initialise them. + """ + print "bs" + bootstrap_phase_1() + bootstrap_phase_2() + + +def bootstrap_phase_1(): + """ + Bootstrap phase to define all the components so they are registered correctly. + """ + print "ba1" + from openlp.core.lib import ImageManager + ImageManager() + + +def bootstrap_phase_2(): + """ + Bootstrap phase to initialise any components. + """ + print "bs2" + from openlp.core.lib import Settings, PluginManager + from openlp.core.utils import AppLocation + Settings().set_up_default_values() + Settings().remove_obsolete_settings() + PluginManager(AppLocation.get_directory(AppLocation.PluginsDir)) + from registry import Registry from uistrings import UiStrings from screen import ScreenList diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index d3c0b66d5..9fcdd2786 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -662,4 +662,3 @@ class Renderer(object): return self._theme_manager theme_manager = property(_get_theme_manager) - diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 695c4073a..a521c9a27 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -475,8 +475,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.playersSettingsSection = u'players' self.displayTagsSection = u'displayTags' self.headerSection = u'SettingsImport' - Settings().set_up_default_values() - Settings().remove_obsolete_settings() self.serviceNotSaved = False self.aboutForm = AboutForm(self) self.mediaController = MediaController(self) @@ -487,8 +485,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.timer_id = 0 self.timer_version_id = 0 # Set up the path with plugins - self.plugin_manager = PluginManager(AppLocation.get_directory(AppLocation.PluginsDir)) - self.imageManager = ImageManager() # Set up the interface self.setupUi(self) # Register the active media players and suffixes @@ -1015,7 +1011,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): """ log.debug(u'screen_changed') self.application.set_busy_cursor() - self.imageManager.update_display() + self.image_manager.update_display() self.renderer.update_display() self.previewController.screenSizeChanged() self.liveController.screenSizeChanged() @@ -1071,8 +1067,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): ``save_settings`` Switch to prevent saving settings. Defaults to **True**. """ - self.imageManager.stop_manager = True - while self.imageManager.image_thread.isRunning(): + self.image_manager.stop_manager = True + while self.image_manager.image_thread.isRunning(): time.sleep(0.1) # Clean temporary files used by services self.serviceManagerContents.clean_up() @@ -1408,3 +1404,23 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): return self._application application = property(_get_application) + + def _get_plugin_manager(self): + """ + Adds the plugin manager to the class dynamically + """ + if not hasattr(self, u'_plugin_manager'): + self._plugin_manager = Registry().get(u'plugin_manager') + return self._plugin_manager + + plugin_manager = property(_get_plugin_manager) + + def _get_image_manager(self): + """ + Adds the image manager to the class dynamically + """ + if not hasattr(self, u'_image_manager'): + self._image_manager = Registry().get(u'image_manager') + return self._image_manager + + image_manager = property(_get_image_manager) From e8b123925fcfabdc004ac18f3158aca75a20b5f7 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Mon, 18 Feb 2013 19:59:35 +0000 Subject: [PATCH 02/15] Bootstrap cleanup --- openlp/core/__init__.py | 3 +- openlp/core/lib/__init__.py | 29 ----------------- openlp/core/ui/mainwindow.py | 62 +++++++++++++----------------------- 3 files changed, 24 insertions(+), 70 deletions(-) diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index 334fd5003..3ad0e1348 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -43,7 +43,7 @@ from traceback import format_exception from PyQt4 import QtCore, QtGui -from openlp.core.lib import Settings, ScreenList, UiStrings, Registry, check_directory_exists, bootstrap +from openlp.core.lib import Settings, ScreenList, UiStrings, Registry, check_directory_exists from openlp.core.resources import qInitResources from openlp.core.ui.mainwindow import MainWindow from openlp.core.ui.firsttimelanguageform import FirstTimeLanguageForm @@ -135,7 +135,6 @@ class OpenLP(QtGui.QApplication): # make sure Qt really display the splash screen self.processEvents() # start the main app window - bootstrap() self.main_window = MainWindow() self.main_window.show() if show_splash: diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index ba014ccda..a3d9cec4b 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -386,35 +386,6 @@ def create_separated_list(stringlist): return translate('OpenLP.core.lib', '%s, %s', u'Locale list separator: start') % (stringlist[0], merged) -def bootstrap(): - """ - Bootstrap control function to build all the components and initialise them. - """ - print "bs" - bootstrap_phase_1() - bootstrap_phase_2() - - -def bootstrap_phase_1(): - """ - Bootstrap phase to define all the components so they are registered correctly. - """ - print "ba1" - from openlp.core.lib import ImageManager - ImageManager() - - -def bootstrap_phase_2(): - """ - Bootstrap phase to initialise any components. - """ - print "bs2" - from openlp.core.lib import Settings, PluginManager - from openlp.core.utils import AppLocation - Settings().set_up_default_values() - Settings().remove_obsolete_settings() - PluginManager(AppLocation.get_directory(AppLocation.PluginsDir)) - from registry import Registry from uistrings import UiStrings from screen import ScreenList diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index a521c9a27..377e9c67a 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -106,12 +106,12 @@ class Ui_MainWindow(object): self.mainContentLayout.addWidget(self.controlSplitter) # Create slide controllers self.previewController = SlideController(self) - self.liveController = SlideController(self, True) + self.live_controller = SlideController(self, True) previewVisible = Settings().value(u'user interface/preview panel') self.previewController.panel.setVisible(previewVisible) liveVisible = Settings().value(u'user interface/live panel') panelLocked = Settings().value(u'user interface/lock panel') - self.liveController.panel.setVisible(liveVisible) + self.live_controller.panel.setVisible(liveVisible) # Create menu self.menuBar = QtGui.QMenuBar(main_window) self.menuBar.setObjectName(u'menuBar') @@ -475,9 +475,11 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.playersSettingsSection = u'players' self.displayTagsSection = u'displayTags' self.headerSection = u'SettingsImport' + Settings().set_up_default_values() + Settings().remove_obsolete_settings() self.serviceNotSaved = False self.aboutForm = AboutForm(self) - self.mediaController = MediaController(self) + self.media_controller = MediaController(self) self.settingsForm = SettingsForm(self) self.formattingTagForm = FormattingTagForm(self) self.shortcutForm = ShortcutListForm(self) @@ -485,10 +487,12 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.timer_id = 0 self.timer_version_id = 0 # Set up the path with plugins + self.plugin_manager = PluginManager(AppLocation.get_directory(AppLocation.PluginsDir)) + self.image_manager = ImageManager() # Set up the interface self.setupUi(self) # Register the active media players and suffixes - self.mediaController.check_available_media_players() + self.media_controller.check_available_media_players() # Load settings after setupUi so default UI sizes are overwritten self.loadSettings() # Once settings are loaded update the menu with the recent files. @@ -557,7 +561,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.plugin_manager.initialise_plugins() # Create the displays as all necessary components are loaded. self.previewController.screenSizeChanged() - self.liveController.screenSizeChanged() + self.live_controller.screenSizeChanged() log.info(u'Load data from Settings') if Settings().value(u'advanced/save current plugin'): savedPlugin = Settings().value(u'advanced/current media plugin') @@ -601,8 +605,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): Show the main form, as well as the display form """ QtGui.QWidget.show(self) - if self.liveController.display.isVisible(): - self.liveController.display.setFocus() + if self.live_controller.display.isVisible(): + self.live_controller.display.setFocus() self.activateWindow() if self.arguments: args = [] @@ -695,7 +699,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): Check and display message if screen blank on setup. """ settings = Settings() - self.liveController.mainDisplaySetBackground() + self.live_controller.mainDisplaySetBackground() if settings.value(u'%s/screen blank' % self.generalSettingsSection): if settings.value(u'%s/blank warning' % self.generalSettingsSection): QtGui.QMessageBox.question(self, translate('OpenLP.MainWindow', 'OpenLP Main Display Blanked'), @@ -803,7 +807,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): We need to make sure, that the SlidePreview's size is correct. """ self.previewController.previewSizeChanged() - self.liveController.previewSizeChanged() + self.live_controller.previewSizeChanged() def onSettingsShortcutsItemClicked(self): """ @@ -1014,7 +1018,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.image_manager.update_display() self.renderer.update_display() self.previewController.screenSizeChanged() - self.liveController.screenSizeChanged() + self.live_controller.screenSizeChanged() self.setFocus() self.activateWindow() self.application.set_normal_cursor() @@ -1085,9 +1089,9 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): if self.new_data_path: self.changeDataDirectory() # Close down the display - if self.liveController.display: - self.liveController.display.close() - self.liveController.display = None + if self.live_controller.display: + self.live_controller.display.close() + self.live_controller.display = None def serviceChanged(self, reset=False, serviceName=None): """ @@ -1168,7 +1172,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): True - Visible False - Hidden """ - self.previewController.panel.setVisible(visible) + self.preview_controller.panel.setVisible(visible) Settings().setValue(u'user interface/preview panel', visible) self.viewPreviewPanel.setChecked(visible) @@ -1206,7 +1210,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): True - Visible False - Hidden """ - self.liveController.panel.setVisible(visible) + self.live_controller.panel.setVisible(visible) Settings().setValue(u'user interface/live panel', visible) self.viewLivePanel.setChecked(visible) @@ -1226,8 +1230,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.move(settings.value(u'main window position')) self.restoreGeometry(settings.value(u'main window geometry')) self.restoreState(settings.value(u'main window state')) - self.liveController.splitter.restoreState(settings.value(u'live splitter geometry')) - self.previewController.splitter.restoreState(settings.value(u'preview splitter geometry')) + self.live_controller.splitter.restoreState(settings.value(u'live splitter geometry')) + self.preview_controller.splitter.restoreState(settings.value(u'preview splitter geometry')) self.controlSplitter.restoreState(settings.value(u'main window splitter geometry')) settings.endGroup() @@ -1247,8 +1251,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): settings.setValue(u'main window position', self.pos()) settings.setValue(u'main window state', self.saveState()) settings.setValue(u'main window geometry', self.saveGeometry()) - settings.setValue(u'live splitter geometry', self.liveController.splitter.saveState()) - settings.setValue(u'preview splitter geometry', self.previewController.splitter.saveState()) + settings.setValue(u'live splitter geometry', self.live_controller.splitter.saveState()) + settings.setValue(u'preview splitter geometry', self.preview_controller.splitter.saveState()) settings.setValue(u'main window splitter geometry', self.controlSplitter.saveState()) settings.endGroup() @@ -1404,23 +1408,3 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): return self._application application = property(_get_application) - - def _get_plugin_manager(self): - """ - Adds the plugin manager to the class dynamically - """ - if not hasattr(self, u'_plugin_manager'): - self._plugin_manager = Registry().get(u'plugin_manager') - return self._plugin_manager - - plugin_manager = property(_get_plugin_manager) - - def _get_image_manager(self): - """ - Adds the image manager to the class dynamically - """ - if not hasattr(self, u'_image_manager'): - self._image_manager = Registry().get(u'image_manager') - return self._image_manager - - image_manager = property(_get_image_manager) From 7b03764a4ae8e35f598049de024540e8263680ab Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Mon, 18 Feb 2013 20:41:08 +0000 Subject: [PATCH 03/15] code cleanups --- openlp/core/lib/pluginmanager.py | 18 +++++--- openlp/core/ui/mainwindow.py | 76 ++++++++++++++++---------------- openlp/core/ui/settingsform.py | 14 +++++- 3 files changed, 62 insertions(+), 46 deletions(-) diff --git a/openlp/core/lib/pluginmanager.py b/openlp/core/lib/pluginmanager.py index 06f0e36eb..5d03c2b05 100644 --- a/openlp/core/lib/pluginmanager.py +++ b/openlp/core/lib/pluginmanager.py @@ -120,20 +120,16 @@ class PluginManager(object): if plugin.status is not PluginStatus.Disabled: plugin.createMediaManagerItem() - def hook_settings_tabs(self, settings_form=None): + def hook_settings_tabs(self): """ Loop through all the plugins. If a plugin has a valid settings tab item, add it to the settings tab. Tabs are set for all plugins not just Active ones - ``settings_form`` - Defaults to *None*. The settings form to add tabs to. """ for plugin in self.plugins: if plugin.status is not PluginStatus.Disabled: - plugin.createSettingsTab(settings_form) - if settings_form: - settings_form.plugins = self.plugins + plugin.createSettingsTab(self.settings_form) def hook_import_menu(self, import_menu): """ @@ -213,3 +209,13 @@ class PluginManager(object): if plugin.isActive(): plugin.new_service_created() + #def _get_settings_form(self): + # """ + # Adds the plugin manager to the class dynamically + # """ + # if not hasattr(self, u'_settings_form'): + # self._settings_form = Registry().get(u'settings_form') + # return self._settings_form + + #settings_form = property(_get_settings_form) + diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 377e9c67a..288a93fb5 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -105,10 +105,10 @@ class Ui_MainWindow(object): self.controlSplitter.setObjectName(u'controlSplitter') self.mainContentLayout.addWidget(self.controlSplitter) # Create slide controllers - self.previewController = SlideController(self) + self.preview_controller = SlideController(self) self.live_controller = SlideController(self, True) previewVisible = Settings().value(u'user interface/preview panel') - self.previewController.panel.setVisible(previewVisible) + self.preview_controller.panel.setVisible(previewVisible) liveVisible = Settings().value(u'user interface/live panel') panelLocked = Settings().value(u'user interface/lock panel') self.live_controller.panel.setVisible(liveVisible) @@ -475,6 +475,12 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.playersSettingsSection = u'players' self.displayTagsSection = u'displayTags' self.headerSection = u'SettingsImport' + + self.recentFiles = [] + self.timer_id = 0 + self.timer_version_id = 0 + self.new_data_path = None + self.copy_data = False Settings().set_up_default_values() Settings().remove_obsolete_settings() self.serviceNotSaved = False @@ -483,14 +489,14 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.settingsForm = SettingsForm(self) self.formattingTagForm = FormattingTagForm(self) self.shortcutForm = ShortcutListForm(self) - self.recentFiles = [] - self.timer_id = 0 - self.timer_version_id = 0 # Set up the path with plugins self.plugin_manager = PluginManager(AppLocation.get_directory(AppLocation.PluginsDir)) - self.image_manager = ImageManager() # Set up the interface self.setupUi(self) + # Define the media Dock Manager + self.mediaDockManager = MediaDockManager(self.mediaToolBox) + + self.image_manager = ImageManager() # Register the active media players and suffixes self.media_controller.check_available_media_players() # Load settings after setupUi so default UI sizes are overwritten @@ -498,54 +504,48 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): # Once settings are loaded update the menu with the recent files. self.updateRecentFilesMenu() self.pluginForm = PluginForm(self) - self.new_data_path = None - self.copy_data = False + # Set up signals and slots - QtCore.QObject.connect(self.importThemeItem, QtCore.SIGNAL(u'triggered()'), - self.themeManagerContents.on_import_theme) - QtCore.QObject.connect(self.exportThemeItem, QtCore.SIGNAL(u'triggered()'), - self.themeManagerContents.on_export_theme) QtCore.QObject.connect(self.mediaManagerDock, QtCore.SIGNAL(u'visibilityChanged(bool)'), - self.viewMediaManagerItem.setChecked) + self.viewMediaManagerItem.setChecked) QtCore.QObject.connect(self.serviceManagerDock, QtCore.SIGNAL(u'visibilityChanged(bool)'), - self.viewServiceManagerItem.setChecked) + self.viewServiceManagerItem.setChecked) QtCore.QObject.connect(self.themeManagerDock, QtCore.SIGNAL(u'visibilityChanged(bool)'), - self.viewThemeManagerItem.setChecked) - QtCore.QObject.connect(self.webSiteItem, QtCore.SIGNAL(u'triggered()'), self.onHelpWebSiteClicked) - QtCore.QObject.connect(self.toolsOpenDataFolder, QtCore.SIGNAL(u'triggered()'), - self.onToolsOpenDataFolderClicked) - QtCore.QObject.connect(self.toolsFirstTimeWizard, QtCore.SIGNAL(u'triggered()'), self.onFirstTimeWizardClicked) - QtCore.QObject.connect(self.updateThemeImages, QtCore.SIGNAL(u'triggered()'), self.onUpdateThemeImages) - QtCore.QObject.connect(self.formattingTagItem, QtCore.SIGNAL(u'triggered()'), self.onFormattingTagItemClicked) - QtCore.QObject.connect(self.settingsConfigureItem, QtCore.SIGNAL(u'triggered()'), - self.onSettingsConfigureItemClicked) - QtCore.QObject.connect(self.settingsShortcutsItem, QtCore.SIGNAL(u'triggered()'), - self.onSettingsShortcutsItemClicked) - QtCore.QObject.connect(self.settingsImportItem, QtCore.SIGNAL(u'triggered()'), - self.onSettingsImportItemClicked) - QtCore.QObject.connect(self.settingsExportItem, QtCore.SIGNAL(u'triggered()'), self.onSettingsExportItemClicked) + self.viewThemeManagerItem.setChecked) + self.importThemeItem.triggered.connect(self.themeManagerContents.on_import_theme) + self.exportThemeItem.triggered.connect(self.themeManagerContents.on_export_theme) + self.webSiteItem.triggered.connect(self.onHelpWebSiteClicked) + self.toolsOpenDataFolder.triggered.connect(self.onToolsOpenDataFolderClicked) + self.toolsFirstTimeWizard.triggered.connect(self.onFirstTimeWizardClicked) + self.updateThemeImages.triggered.connect(self.onUpdateThemeImages) + self.formattingTagItem.triggered.connect(self.onFormattingTagItemClicked) + self.settingsConfigureItem.triggered.connect(self.onSettingsConfigureItemClicked) + self.settingsShortcutsItem.triggered.connect(self.onSettingsShortcutsItemClicked) + self.settingsImportItem.triggered.connect(self.onSettingsImportItemClicked) + self.settingsExportItem.triggered.connect(self.onSettingsExportItemClicked) # i18n set signals for languages self.languageGroup.triggered.connect(LanguageManager.set_language) - QtCore.QObject.connect(self.modeDefaultItem, QtCore.SIGNAL(u'triggered()'), self.onModeDefaultItemClicked) - QtCore.QObject.connect(self.modeSetupItem, QtCore.SIGNAL(u'triggered()'), self.onModeSetupItemClicked) - QtCore.QObject.connect(self.modeLiveItem, QtCore.SIGNAL(u'triggered()'), self.onModeLiveItemClicked) + self.modeDefaultItem.triggered.connect(self.onModeDefaultItemClicked) + self.modeSetupItem.triggered.connect(self.onModeSetupItemClicked) + self.modeLiveItem.triggered.connect(self.onModeLiveItemClicked) # Media Manager - QtCore.QObject.connect(self.mediaToolBox, QtCore.SIGNAL(u'currentChanged(int)'), self.onMediaToolBoxChanged) + self.mediaToolBox.currentChanged.connect(self.onMediaToolBoxChanged) self.application.set_busy_cursor() + # Simple message boxes Registry().register_function(u'theme_update_global', self.default_theme_changed) Registry().register_function(u'openlp_version_check', self.version_notice) Registry().register_function(u'config_screen_changed', self.screen_changed) + self.renderer = Renderer() - # Define the media Dock Manager - self.mediaDockManager = MediaDockManager(self.mediaToolBox) + log.info(u'Load Plugins') self.plugin_manager.find_plugins() # hook methods have to happen after find_plugins. Find plugins needs # the controllers hence the hooks have moved from setupUI() to here # Find and insert settings tabs log.info(u'hook settings') - self.plugin_manager.hook_settings_tabs(self.settingsForm) + self.plugin_manager.hook_settings_tabs() # Find and insert media manager items log.info(u'hook media') self.plugin_manager.hook_media_manager() @@ -560,7 +560,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): log.info(u'initialise plugins') self.plugin_manager.initialise_plugins() # Create the displays as all necessary components are loaded. - self.previewController.screenSizeChanged() + self.preview_controller.screenSizeChanged() self.live_controller.screenSizeChanged() log.info(u'Load data from Settings') if Settings().value(u'advanced/save current plugin'): @@ -806,7 +806,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): """ We need to make sure, that the SlidePreview's size is correct. """ - self.previewController.previewSizeChanged() + self.preview_controller.previewSizeChanged() self.live_controller.previewSizeChanged() def onSettingsShortcutsItemClicked(self): @@ -1017,7 +1017,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.application.set_busy_cursor() self.image_manager.update_display() self.renderer.update_display() - self.previewController.screenSizeChanged() + self.preview_controller.screenSizeChanged() self.live_controller.screenSizeChanged() self.setFocus() self.activateWindow() diff --git a/openlp/core/ui/settingsform.py b/openlp/core/ui/settingsform.py index 1b000f16b..7d38711ef 100644 --- a/openlp/core/ui/settingsform.py +++ b/openlp/core/ui/settingsform.py @@ -75,7 +75,7 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): self.insertTab(self.advancedTab, 2, PluginStatus.Active) self.insertTab(self.playerTab, 3, PluginStatus.Active) count = 4 - for plugin in self.plugins: + for plugin in self.plugin_manager.plugins: if plugin.settingsTab: self.insertTab(plugin.settingsTab, count, plugin.status) count += 1 @@ -126,7 +126,7 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): self.themesTab.postSetUp() self.advancedTab.postSetUp() self.playerTab.postSetUp() - for plugin in self.plugins: + for plugin in self.plugin_manager.plugins: if plugin.settingsTab: plugin.settingsTab.postSetUp() @@ -166,3 +166,13 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): return self._service_manager service_manager = property(_get_service_manager) + + def _get_plugin_manager(self): + """ + Adds the plugin manager to the class dynamically + """ + if not hasattr(self, u'_plugin_manager'): + self._plugin_manager = Registry().get(u'plugin_manager') + return self._plugin_manager + + plugin_manager = property(_get_plugin_manager) From 4b30d6cd29227419a45d36a229f7b43fa617951e Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Mon, 18 Feb 2013 21:36:36 +0000 Subject: [PATCH 04/15] Openup servicemanager again --- openlp/core/__init__.py | 1 + openlp/core/lib/pluginmanager.py | 26 +++++++++++++++++++ openlp/core/ui/mainwindow.py | 23 ++-------------- .../openlp_core_ui/test_servicemanager.py | 13 +++++----- 4 files changed, 35 insertions(+), 28 deletions(-) diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index 3ad0e1348..781c19627 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -136,6 +136,7 @@ class OpenLP(QtGui.QApplication): self.processEvents() # start the main app window self.main_window = MainWindow() + Registry().execute(u'bootstrap') self.main_window.show() if show_splash: # now kill the splashscreen diff --git a/openlp/core/lib/pluginmanager.py b/openlp/core/lib/pluginmanager.py index 7ae00a4d0..98bca2529 100644 --- a/openlp/core/lib/pluginmanager.py +++ b/openlp/core/lib/pluginmanager.py @@ -54,11 +54,37 @@ class PluginManager(object): """ log.info(u'Plugin manager Initialising') Registry().register(u'plugin_manager', self) + Registry().register_function(u'bootstrap', self.bootstrap) self.base_path = os.path.abspath(AppLocation.get_directory(AppLocation.PluginsDir)) log.debug(u'Base path %s ', self.base_path) self.plugins = [] log.info(u'Plugin manager Initialised') + def bootstrap(self): + """ + Bootstrap all the plugin manager functions + """ + log.info(u'Bootstrap') + self.find_plugins() + # hook methods have to happen after find_plugins. Find plugins needs + # the controllers hence the hooks have moved from setupUI() to here + # Find and insert settings tabs + log.info(u'hook settings') + self.hook_settings_tabs() + # Find and insert media manager items + log.info(u'hook media') + self.hook_media_manager() + # Call the hook method to pull in import menus. + log.info(u'hook menus') + self.hook_import_menu() + # Call the hook method to pull in export menus. + self.hook_export_menu() + # Call the hook method to pull in tools menus. + self.hook_tools_menu() + # Call the initialise method to setup plugins. + log.info(u'initialise plugins') + self.initialise_plugins() + def find_plugins(self): """ Scan a directory for objects inheriting from the ``Plugin`` class. diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index c0384aa6b..1202228fa 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -492,7 +492,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): # Set up the path with plugins self.plugin_manager = PluginManager() - self.imageManager = ImageManager() + self.image_manager = ImageManager() # Set up the interface self.setupUi(self) @@ -541,26 +541,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.renderer = Renderer() - log.info(u'Load Plugins') - self.plugin_manager.find_plugins() - # hook methods have to happen after find_plugins. Find plugins needs - # the controllers hence the hooks have moved from setupUI() to here - # Find and insert settings tabs - log.info(u'hook settings') - self.plugin_manager.hook_settings_tabs() - # Find and insert media manager items - log.info(u'hook media') - self.plugin_manager.hook_media_manager() - # Call the hook method to pull in import menus. - log.info(u'hook menus') - self.plugin_manager.hook_import_menu() - # Call the hook method to pull in export menus. - self.plugin_manager.hook_export_menu() - # Call the hook method to pull in tools menus. - self.plugin_manager.hook_tools_menu() - # Call the initialise method to setup plugins. - log.info(u'initialise plugins') - self.plugin_manager.initialise_plugins() + # Create the displays as all necessary components are loaded. self.preview_controller.screenSizeChanged() self.live_controller.screenSizeChanged() diff --git a/tests/interfaces/openlp_core_ui/test_servicemanager.py b/tests/interfaces/openlp_core_ui/test_servicemanager.py index 97212f326..db161022b 100644 --- a/tests/interfaces/openlp_core_ui/test_servicemanager.py +++ b/tests/interfaces/openlp_core_ui/test_servicemanager.py @@ -21,15 +21,15 @@ class TestServiceManager(TestCase): self.app = QtGui.QApplication.instance() ScreenList.create(self.app.desktop()) Registry().register(u'application', MagicMock()) - #with patch(u'openlp.core.lib.PluginManager'): - # self.main_window = MainWindow() - #self.service_manager = Registry().get(u'service_manager') + with patch(u'openlp.core.lib.PluginManager'): + self.main_window = MainWindow() + self.service_manager = Registry().get(u'service_manager') def tearDown(self): """ Delete all the C++ objects at the end so that we don't have a segfault """ - #del self.main_window + del self.main_window del self.app def basic_service_manager_test(self): @@ -40,6 +40,5 @@ class TestServiceManager(TestCase): # WHEN I have an empty display # THEN the count of items should be zero - #self.assertEqual(self.service_manager.service_manager_list.topLevelItemCount(), 0, - # u'The service manager list should be empty ') - pass + self.assertEqual(self.service_manager.service_manager_list.topLevelItemCount(), 0, + u'The service manager list should be empty ') From 6d732cf3ba69dbd5664009b1e77580f6fbc59cb4 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 19 Feb 2013 19:50:14 +0000 Subject: [PATCH 05/15] Cleanups --- openlp/core/__init__.py | 3 +- openlp/core/lib/pluginmanager.py | 4 +- openlp/core/lib/settingstab.py | 2 +- openlp/core/ui/generaltab.py | 4 +- openlp/core/ui/mainwindow.py | 15 ------ openlp/core/ui/media/mediacontroller.py | 1 + openlp/core/ui/media/playertab.py | 2 +- openlp/core/ui/settingsform.py | 13 ++--- openlp/core/ui/thememanager.py | 53 +++++++++---------- openlp/core/ui/themestab.py | 2 +- .../openlp_core_lib/test_pluginmanager.py | 30 ++++++----- 11 files changed, 59 insertions(+), 70 deletions(-) diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index 781c19627..4916928d2 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -136,7 +136,8 @@ class OpenLP(QtGui.QApplication): self.processEvents() # start the main app window self.main_window = MainWindow() - Registry().execute(u'bootstrap') + Registry().execute(u'bootstrap_stage_1') + Registry().execute(u'bootstrap_stage_2') self.main_window.show() if show_splash: # now kill the splashscreen diff --git a/openlp/core/lib/pluginmanager.py b/openlp/core/lib/pluginmanager.py index 98bca2529..0390874b9 100644 --- a/openlp/core/lib/pluginmanager.py +++ b/openlp/core/lib/pluginmanager.py @@ -54,13 +54,13 @@ class PluginManager(object): """ log.info(u'Plugin manager Initialising') Registry().register(u'plugin_manager', self) - Registry().register_function(u'bootstrap', self.bootstrap) + Registry().register_function(u'bootstrap_stage_1', self.bootstrap_stage_1) self.base_path = os.path.abspath(AppLocation.get_directory(AppLocation.PluginsDir)) log.debug(u'Base path %s ', self.base_path) self.plugins = [] log.info(u'Plugin manager Initialised') - def bootstrap(self): + def bootstrap_stage_1(self): """ Bootstrap all the plugin manager functions """ diff --git a/openlp/core/lib/settingstab.py b/openlp/core/lib/settingstab.py index f8839ce64..5b8a01fc6 100644 --- a/openlp/core/lib/settingstab.py +++ b/openlp/core/lib/settingstab.py @@ -123,7 +123,7 @@ class SettingsTab(QtGui.QWidget): """ self.load() - def postSetUp(self, postUpdate=False): + def post_set_up(self, postUpdate=False): """ Changes which need to be made after setup of application diff --git a/openlp/core/ui/generaltab.py b/openlp/core/ui/generaltab.py index a20206f9b..90e7da702 100644 --- a/openlp/core/ui/generaltab.py +++ b/openlp/core/ui/generaltab.py @@ -308,9 +308,9 @@ class GeneralTab(SettingsTab): settings.setValue(u'audio repeat list', self.repeatListCheckBox.isChecked()) settings.endGroup() # On save update the screens as well - self.postSetUp(True) + self.post_set_up(True) - def postSetUp(self, postUpdate=False): + def post_set_up(self, postUpdate=False): """ Apply settings after settings tab has loaded and most of the system so must be delayed diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 1202228fa..b37202b44 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -475,7 +475,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.playersSettingsSection = u'players' self.displayTagsSection = u'displayTags' self.headerSection = u'SettingsImport' - self.recentFiles = [] self.timer_id = 0 self.timer_version_id = 0 @@ -490,23 +489,17 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.formattingTagForm = FormattingTagForm(self) self.shortcutForm = ShortcutListForm(self) # Set up the path with plugins - self.plugin_manager = PluginManager() self.image_manager = ImageManager() - # Set up the interface self.setupUi(self) # Define the media Dock Manager self.mediaDockManager = MediaDockManager(self.mediaToolBox) - - # Register the active media players and suffixes - self.media_controller.check_available_media_players() # Load settings after setupUi so default UI sizes are overwritten self.loadSettings() # Once settings are loaded update the menu with the recent files. self.updateRecentFilesMenu() self.pluginForm = PluginForm(self) - # Set up signals and slots QtCore.QObject.connect(self.mediaManagerDock, QtCore.SIGNAL(u'visibilityChanged(bool)'), self.viewMediaManagerItem.setChecked) @@ -533,15 +526,11 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): # Media Manager self.mediaToolBox.currentChanged.connect(self.onMediaToolBoxChanged) self.application.set_busy_cursor() - # Simple message boxes Registry().register_function(u'theme_update_global', self.default_theme_changed) Registry().register_function(u'openlp_version_check', self.version_notice) Registry().register_function(u'config_screen_changed', self.screen_changed) - self.renderer = Renderer() - - # Create the displays as all necessary components are loaded. self.preview_controller.screenSizeChanged() self.live_controller.screenSizeChanged() @@ -550,10 +539,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): savedPlugin = Settings().value(u'advanced/current media plugin') if savedPlugin != -1: self.mediaToolBox.setCurrentIndex(savedPlugin) - self.settingsForm.postSetUp() - # Once all components are initialised load the Themes - log.info(u'Load Themes') - self.themeManagerContents.load_themes(True) # Reset the cursor self.application.set_normal_cursor() diff --git a/openlp/core/ui/media/mediacontroller.py b/openlp/core/ui/media/mediacontroller.py index 048fb5f4d..b055f249e 100644 --- a/openlp/core/ui/media/mediacontroller.py +++ b/openlp/core/ui/media/mediacontroller.py @@ -99,6 +99,7 @@ class MediaController(object): """ self.mainWindow = parent Registry().register(u'media_controller', self) + Registry().register_function(u'bootstrap_stage_1', self.check_available_media_players) self.mediaPlayers = {} self.displayControllers = {} self.currentMediaPlayer = {} diff --git a/openlp/core/ui/media/playertab.py b/openlp/core/ui/media/playertab.py index d8b896864..920aef376 100644 --- a/openlp/core/ui/media/playertab.py +++ b/openlp/core/ui/media/playertab.py @@ -232,7 +232,7 @@ class PlayerTab(SettingsTab): Registry().execute(u'mediaitem_media_rebuild') Registry().execute(u'config_screen_changed') - def postSetUp(self, postUpdate=False): + def post_set_up(self): """ Late setup for players as the MediaController has to be initialised first. diff --git a/openlp/core/ui/settingsform.py b/openlp/core/ui/settingsform.py index 7d38711ef..80ee7eb29 100644 --- a/openlp/core/ui/settingsform.py +++ b/openlp/core/ui/settingsform.py @@ -50,6 +50,7 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): Initialise the settings form """ Registry().register(u'settings_form', self) + Registry().register_function(u'bootstrap_stage_2', self.post_set_up) QtGui.QDialog.__init__(self, parent) self.setupUi(self) # General tab @@ -118,17 +119,17 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): self.stackedLayout.widget(tabIndex).cancel() return QtGui.QDialog.reject(self) - def postSetUp(self): + def post_set_up(self): """ Run any post-setup code for the tabs on the form """ - self.generalTab.postSetUp() - self.themesTab.postSetUp() - self.advancedTab.postSetUp() - self.playerTab.postSetUp() + self.generalTab.post_set_up() + self.themesTab.post_set_up() + self.advancedTab.post_set_up() + self.playerTab.post_set_up() for plugin in self.plugin_manager.plugins: if plugin.settingsTab: - plugin.settingsTab.postSetUp() + plugin.settingsTab.post_set_up() def tabChanged(self, tabIndex): """ diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 3e5ce56d4..88907f945 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -60,6 +60,7 @@ class ThemeManager(QtGui.QWidget): """ QtGui.QWidget.__init__(self, parent) Registry().register(u'theme_manager', self) + Registry().register_function(u'bootstrap_stage_1', self.load_first_time_themes) self.settingsSection = u'themes' self.themeForm = ThemeForm(self) self.fileRenameForm = FileRenameForm() @@ -148,19 +149,6 @@ class ThemeManager(QtGui.QWidget): # Last little bits of setting up self.config_updated() - def first_time(self): - """ - Import new themes downloaded by the first time wizard - """ - self.application.set_busy_cursor() - files = SettingsManager.get_files(self.settingsSection, u'.otz') - for theme_file in files: - theme_file = os.path.join(self.path, theme_file) - self.unzip_theme(theme_file, self.path) - delete_file(theme_file) - self.application.set_normal_cursor() - - def config_updated(self): """ Triggered when Config dialog is updated. @@ -414,9 +402,31 @@ class ThemeManager(QtGui.QWidget): self.load_themes() self.application.set_normal_cursor() - def load_themes(self, first_time=False): + def load_first_time_themes(self): """ - Loads the theme lists and triggers updates accross the whole system + Imports any themes on start up and makes sure there is at least one theme + """ + self.application.set_busy_cursor() + files = SettingsManager.get_files(self.settingsSection, u'.otz') + for theme_file in files: + theme_file = os.path.join(self.path, theme_file) + self.unzip_theme(theme_file, self.path) + delete_file(theme_file) + files = SettingsManager.get_files(self.settingsSection, u'.png') + # No themes have been found so create one + if not files: + theme = ThemeXML() + theme.theme_name = UiStrings().Default + self._write_theme(theme, None, None) + Settings().setValue(self.settingsSection + u'/global theme', theme.theme_name) + self.config_updated() + files = SettingsManager.get_files(self.settingsSection, u'.png') + self.application.set_normal_cursor() + self.load_themes() + + def load_themes(self): + """ + Loads the theme lists and triggers updates across the whole system using direct calls or core functions and events for the plugins. The plugins will call back in to get the real list if they want it. """ @@ -424,18 +434,7 @@ class ThemeManager(QtGui.QWidget): self.theme_list = [] self.theme_list_widget.clear() files = SettingsManager.get_files(self.settingsSection, u'.png') - if first_time: - self.first_time() - files = SettingsManager.get_files(self.settingsSection, u'.png') - # No themes have been found so create one - if not files: - theme = ThemeXML() - theme.theme_name = UiStrings().Default - self._write_theme(theme, None, None) - Settings().setValue(self.settingsSection + u'/global theme', theme.theme_name) - self.config_updated() - files = SettingsManager.get_files(self.settingsSection, u'.png') - # Sort the themes by its name considering language specific + # Sort the themes by its name considering language specific files.sort(key=lambda file_name: unicode(file_name), cmp=locale_compare) # now process the file list of png files for name in files: diff --git a/openlp/core/ui/themestab.py b/openlp/core/ui/themestab.py index 1442ff4e9..2ae3d7cc7 100644 --- a/openlp/core/ui/themestab.py +++ b/openlp/core/ui/themestab.py @@ -155,7 +155,7 @@ class ThemesTab(SettingsTab): self.renderer.set_theme_level(self.theme_level) Registry().execute(u'theme_update_global', self.global_theme) - def postSetUp(self): + def post_set_up(self): """ After setting things up... """ diff --git a/tests/functional/openlp_core_lib/test_pluginmanager.py b/tests/functional/openlp_core_lib/test_pluginmanager.py index fef9b54d6..28f1bd525 100644 --- a/tests/functional/openlp_core_lib/test_pluginmanager.py +++ b/tests/functional/openlp_core_lib/test_pluginmanager.py @@ -18,8 +18,14 @@ class TestPluginManager(TestCase): """ Some pre-test setup required. """ + mocked_main_window = MagicMock() + mocked_main_window.file_import_menu.return_value = True + mocked_main_window.file_export_menu.return_value = True + mocked_main_window.tools_menu.return_value = True Registry.create() Registry().register(u'service_list', MagicMock()) + Registry().register(u'main_window', mocked_main_window) + Registry().register(u'settings_form', MagicMock()) def hook_media_manager_with_disabled_plugin_test(self): """ @@ -83,7 +89,7 @@ class TestPluginManager(TestCase): plugin_manager.plugins = [mocked_plugin] # WHEN: We run hook_settings_tabs() - plugin_manager.hook_settings_tabs(mocked_settings_form) + plugin_manager.hook_settings_tabs() # THEN: The createSettingsTab() method should not have been called, but the plugins lists should be the same assert mocked_plugin.createSettingsTab.call_count == 0, \ @@ -119,7 +125,7 @@ class TestPluginManager(TestCase): plugin_manager.plugins = [mocked_plugin] # WHEN: We run hook_settings_tabs() - plugin_manager.hook_settings_tabs(mocked_settings_form) + plugin_manager.hook_settings_tabs() # THEN: The createMediaManagerItem() method should have been called with the mocked settings form mocked_plugin.createSettingsTab.assert_called_with(mocked_settings_form) @@ -138,7 +144,7 @@ class TestPluginManager(TestCase): plugin_manager.plugins = [mocked_plugin] # WHEN: We run hook_import_menu() - plugin_manager.hook_import_menu(mocked_import_menu) + plugin_manager.hook_import_menu() # THEN: The createMediaManagerItem() method should have been called assert mocked_plugin.addImportMenuItem.call_count == 0, \ @@ -156,7 +162,7 @@ class TestPluginManager(TestCase): plugin_manager.plugins = [mocked_plugin] # WHEN: We run hook_import_menu() - plugin_manager.hook_import_menu(mocked_import_menu) + plugin_manager.hook_import_menu() # THEN: The addImportMenuItem() method should have been called mocked_plugin.addImportMenuItem.assert_called_with(mocked_import_menu) @@ -168,12 +174,11 @@ class TestPluginManager(TestCase): # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled mocked_plugin = MagicMock() mocked_plugin.status = PluginStatus.Disabled - mocked_export_menu = MagicMock() plugin_manager = PluginManager() plugin_manager.plugins = [mocked_plugin] # WHEN: We run hook_export_menu() - plugin_manager.hook_export_menu(mocked_export_menu) + plugin_manager.hook_export_menu() # THEN: The addExportMenuItem() method should have been called assert mocked_plugin.addExportMenuItem.call_count == 0, \ @@ -186,15 +191,14 @@ class TestPluginManager(TestCase): # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active mocked_plugin = MagicMock() mocked_plugin.status = PluginStatus.Active - mocked_export_menu = MagicMock() plugin_manager = PluginManager() plugin_manager.plugins = [mocked_plugin] # WHEN: We run hook_export_menu() - plugin_manager.hook_export_menu(mocked_export_menu) + plugin_manager.hook_export_menu() # THEN: The addExportMenuItem() method should have been called - mocked_plugin.addExportMenuItem.assert_called_with(mocked_export_menu) + mocked_plugin.addExportMenuItem.assert_called_with() def hook_tools_menu_with_disabled_plugin_test(self): """ @@ -203,12 +207,11 @@ class TestPluginManager(TestCase): # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled mocked_plugin = MagicMock() mocked_plugin.status = PluginStatus.Disabled - mocked_tools_menu = MagicMock() plugin_manager = PluginManager() plugin_manager.plugins = [mocked_plugin] # WHEN: We run hook_tools_menu() - plugin_manager.hook_tools_menu(mocked_tools_menu) + plugin_manager.hook_tools_menu() # THEN: The addToolsMenuItem() method should have been called assert mocked_plugin.addToolsMenuItem.call_count == 0, \ @@ -221,15 +224,14 @@ class TestPluginManager(TestCase): # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active mocked_plugin = MagicMock() mocked_plugin.status = PluginStatus.Active - mocked_tools_menu = MagicMock() plugin_manager = PluginManager() plugin_manager.plugins = [mocked_plugin] # WHEN: We run hook_tools_menu() - plugin_manager.hook_tools_menu(mocked_tools_menu) + plugin_manager.hook_tools_menu() # THEN: The addToolsMenuItem() method should have been called - mocked_plugin.addToolsMenuItem.assert_called_with(mocked_tools_menu) + mocked_plugin.addToolsMenuItem.assert_called_with() def initialise_plugins_with_disabled_plugin_test(self): """ From d6274d817aa8fe2c9569c8c16a296971791b5114 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Thu, 21 Feb 2013 14:23:33 +0000 Subject: [PATCH 06/15] fix tests --- .../openlp_core_lib/test_pluginmanager.py | 35 +++++++++---------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_pluginmanager.py b/tests/functional/openlp_core_lib/test_pluginmanager.py index 28f1bd525..eee418b07 100644 --- a/tests/functional/openlp_core_lib/test_pluginmanager.py +++ b/tests/functional/openlp_core_lib/test_pluginmanager.py @@ -18,14 +18,15 @@ class TestPluginManager(TestCase): """ Some pre-test setup required. """ - mocked_main_window = MagicMock() - mocked_main_window.file_import_menu.return_value = True - mocked_main_window.file_export_menu.return_value = True - mocked_main_window.tools_menu.return_value = True + self.mocked_main_window = MagicMock() + self.mocked_main_window.file_import_menu.return_value = True + self.mocked_main_window.file_export_menu.return_value = True + self.mocked_main_window.file_export_menu.return_value = True + self.mocked_settings_form = MagicMock() Registry.create() Registry().register(u'service_list', MagicMock()) - Registry().register(u'main_window', mocked_main_window) - Registry().register(u'settings_form', MagicMock()) + Registry().register(u'main_window', self.mocked_main_window) + Registry().register(u'settings_form', self.mocked_settings_form) def hook_media_manager_with_disabled_plugin_test(self): """ @@ -84,7 +85,6 @@ class TestPluginManager(TestCase): # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled mocked_plugin = MagicMock() mocked_plugin.status = PluginStatus.Disabled - mocked_settings_form = MagicMock() plugin_manager = PluginManager() plugin_manager.plugins = [mocked_plugin] @@ -94,8 +94,8 @@ class TestPluginManager(TestCase): # THEN: The createSettingsTab() method should not have been called, but the plugins lists should be the same assert mocked_plugin.createSettingsTab.call_count == 0, \ u'The createMediaManagerItem() method should not have been called.' - self.assertEqual(mocked_settings_form.plugins, plugin_manager.plugins, - u'The plugins on the settings form should be the same as the plugins in the plugin manager') + #self.assertEqual(self.mocked_settings_form.plugin_manager.plugins, plugin_manager.plugins, + # u'The plugins on the settings form should be the same as the plugins in the plugin manager') def hook_settings_tabs_with_active_plugin_and_no_form_test(self): """ @@ -111,7 +111,7 @@ class TestPluginManager(TestCase): plugin_manager.hook_settings_tabs() # THEN: The createSettingsTab() method should have been called - mocked_plugin.createSettingsTab.assert_called_with(None) + mocked_plugin.createSettingsTab.assert_called_with(self.mocked_settings_form) def hook_settings_tabs_with_active_plugin_and_mocked_form_test(self): """ @@ -120,7 +120,6 @@ class TestPluginManager(TestCase): # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active mocked_plugin = MagicMock() mocked_plugin.status = PluginStatus.Active - mocked_settings_form = MagicMock() plugin_manager = PluginManager() plugin_manager.plugins = [mocked_plugin] @@ -128,9 +127,9 @@ class TestPluginManager(TestCase): plugin_manager.hook_settings_tabs() # THEN: The createMediaManagerItem() method should have been called with the mocked settings form - mocked_plugin.createSettingsTab.assert_called_with(mocked_settings_form) - self.assertEqual(mocked_settings_form.plugins, plugin_manager.plugins, - u'The plugins on the settings form should be the same as the plugins in the plugin manager') + mocked_plugin.createSettingsTab.assert_called_with(self.mocked_settings_form) + #self.assertEqual(self.mocked_settings_form.plugins, plugin_manager.plugins, + # u'The plugins on the settings form should be the same as the plugins in the plugin manager') def hook_import_menu_with_disabled_plugin_test(self): """ @@ -139,7 +138,6 @@ class TestPluginManager(TestCase): # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled mocked_plugin = MagicMock() mocked_plugin.status = PluginStatus.Disabled - mocked_import_menu = MagicMock() plugin_manager = PluginManager() plugin_manager.plugins = [mocked_plugin] @@ -157,7 +155,6 @@ class TestPluginManager(TestCase): # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active mocked_plugin = MagicMock() mocked_plugin.status = PluginStatus.Active - mocked_import_menu = MagicMock() plugin_manager = PluginManager() plugin_manager.plugins = [mocked_plugin] @@ -165,7 +162,7 @@ class TestPluginManager(TestCase): plugin_manager.hook_import_menu() # THEN: The addImportMenuItem() method should have been called - mocked_plugin.addImportMenuItem.assert_called_with(mocked_import_menu) + mocked_plugin.addImportMenuItem.assert_called_with(self.mocked_main_window.file_import_menu) def hook_export_menu_with_disabled_plugin_test(self): """ @@ -198,7 +195,7 @@ class TestPluginManager(TestCase): plugin_manager.hook_export_menu() # THEN: The addExportMenuItem() method should have been called - mocked_plugin.addExportMenuItem.assert_called_with() + mocked_plugin.addExportMenuItem.assert_called_with(self.mocked_main_window.file_export_menu) def hook_tools_menu_with_disabled_plugin_test(self): """ @@ -231,7 +228,7 @@ class TestPluginManager(TestCase): plugin_manager.hook_tools_menu() # THEN: The addToolsMenuItem() method should have been called - mocked_plugin.addToolsMenuItem.assert_called_with() + mocked_plugin.addToolsMenuItem.assert_called_with(self.mocked_main_window.tools_menu) def initialise_plugins_with_disabled_plugin_test(self): """ From 4bc2c301e20bd4007797f9fb8f56df804611f936 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Thu, 21 Feb 2013 21:18:26 +0000 Subject: [PATCH 07/15] Stage renames --- openlp/core/__init__.py | 4 ++-- openlp/core/lib/pluginmanager.py | 4 ++-- openlp/core/ui/media/mediacontroller.py | 2 +- openlp/core/ui/settingsform.py | 2 +- openlp/core/ui/thememanager.py | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index 4916928d2..74dd7b24d 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -136,8 +136,8 @@ class OpenLP(QtGui.QApplication): self.processEvents() # start the main app window self.main_window = MainWindow() - Registry().execute(u'bootstrap_stage_1') - Registry().execute(u'bootstrap_stage_2') + Registry().execute(u'bootstrap_initialise') + Registry().execute(u'bootstrap_post_set_up') self.main_window.show() if show_splash: # now kill the splashscreen diff --git a/openlp/core/lib/pluginmanager.py b/openlp/core/lib/pluginmanager.py index 0390874b9..42f2d715a 100644 --- a/openlp/core/lib/pluginmanager.py +++ b/openlp/core/lib/pluginmanager.py @@ -54,13 +54,13 @@ class PluginManager(object): """ log.info(u'Plugin manager Initialising') Registry().register(u'plugin_manager', self) - Registry().register_function(u'bootstrap_stage_1', self.bootstrap_stage_1) + Registry().register_function(u'bootstrap_initialise', self.bootstrap_initialise) self.base_path = os.path.abspath(AppLocation.get_directory(AppLocation.PluginsDir)) log.debug(u'Base path %s ', self.base_path) self.plugins = [] log.info(u'Plugin manager Initialised') - def bootstrap_stage_1(self): + def bootstrap_initialise(self): """ Bootstrap all the plugin manager functions """ diff --git a/openlp/core/ui/media/mediacontroller.py b/openlp/core/ui/media/mediacontroller.py index b055f249e..301e48f1a 100644 --- a/openlp/core/ui/media/mediacontroller.py +++ b/openlp/core/ui/media/mediacontroller.py @@ -99,7 +99,7 @@ class MediaController(object): """ self.mainWindow = parent Registry().register(u'media_controller', self) - Registry().register_function(u'bootstrap_stage_1', self.check_available_media_players) + Registry().register_function(u'bootstrap_initialise', self.check_available_media_players) self.mediaPlayers = {} self.displayControllers = {} self.currentMediaPlayer = {} diff --git a/openlp/core/ui/settingsform.py b/openlp/core/ui/settingsform.py index 80ee7eb29..166f7908a 100644 --- a/openlp/core/ui/settingsform.py +++ b/openlp/core/ui/settingsform.py @@ -50,7 +50,7 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): Initialise the settings form """ Registry().register(u'settings_form', self) - Registry().register_function(u'bootstrap_stage_2', self.post_set_up) + Registry().register_function(u'bootstrap_post_set_up', self.post_set_up) QtGui.QDialog.__init__(self, parent) self.setupUi(self) # General tab diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 88907f945..3f179331a 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -60,7 +60,7 @@ class ThemeManager(QtGui.QWidget): """ QtGui.QWidget.__init__(self, parent) Registry().register(u'theme_manager', self) - Registry().register_function(u'bootstrap_stage_1', self.load_first_time_themes) + Registry().register_function(u'bootstrap_initialise', self.load_first_time_themes) self.settingsSection = u'themes' self.themeForm = ThemeForm(self) self.fileRenameForm = FileRenameForm() From 8c29f8d4e518caf9d153c9e2ad2e053bd0af5dfd Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 22 Feb 2013 07:15:07 +0000 Subject: [PATCH 08/15] minor changes --- openlp/core/lib/pluginmanager.py | 2 +- openlp/core/ui/thememanager.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/openlp/core/lib/pluginmanager.py b/openlp/core/lib/pluginmanager.py index 42f2d715a..e918d743a 100644 --- a/openlp/core/lib/pluginmanager.py +++ b/openlp/core/lib/pluginmanager.py @@ -64,7 +64,7 @@ class PluginManager(object): """ Bootstrap all the plugin manager functions """ - log.info(u'Bootstrap') + log.info(u'bootstrap_initialise') self.find_plugins() # hook methods have to happen after find_plugins. Find plugins needs # the controllers hence the hooks have moved from setupUI() to here diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 27bdf6bd3..2ca72e9a1 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -417,7 +417,6 @@ class ThemeManager(QtGui.QWidget): self._write_theme(theme, None, None) Settings().setValue(self.settingsSection + u'/global theme', theme.theme_name) self.config_updated() - files = SettingsManager.get_files(self.settingsSection, u'.png') self.application.set_normal_cursor() self.load_themes() From b96304253ecd18b98d575c495ec6e18a3588eeec Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 27 Feb 2013 21:11:43 +0000 Subject: [PATCH 09/15] Fix merge comments --- .../openlp_core_lib/test_pluginmanager.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_pluginmanager.py b/tests/functional/openlp_core_lib/test_pluginmanager.py index eee418b07..94b3776f1 100644 --- a/tests/functional/openlp_core_lib/test_pluginmanager.py +++ b/tests/functional/openlp_core_lib/test_pluginmanager.py @@ -19,9 +19,9 @@ class TestPluginManager(TestCase): Some pre-test setup required. """ self.mocked_main_window = MagicMock() - self.mocked_main_window.file_import_menu.return_value = True - self.mocked_main_window.file_export_menu.return_value = True - self.mocked_main_window.file_export_menu.return_value = True + self.mocked_main_window.file_import_menu.return_value = None + self.mocked_main_window.file_export_menu.return_value = None + self.mocked_main_window.file_export_menu.return_value = None self.mocked_settings_form = MagicMock() Registry.create() Registry().register(u'service_list', MagicMock()) @@ -91,12 +91,6 @@ class TestPluginManager(TestCase): # WHEN: We run hook_settings_tabs() plugin_manager.hook_settings_tabs() - # THEN: The createSettingsTab() method should not have been called, but the plugins lists should be the same - assert mocked_plugin.createSettingsTab.call_count == 0, \ - u'The createMediaManagerItem() method should not have been called.' - #self.assertEqual(self.mocked_settings_form.plugin_manager.plugins, plugin_manager.plugins, - # u'The plugins on the settings form should be the same as the plugins in the plugin manager') - def hook_settings_tabs_with_active_plugin_and_no_form_test(self): """ Test running the hook_settings_tabs() method with an active plugin and no settings form @@ -126,11 +120,6 @@ class TestPluginManager(TestCase): # WHEN: We run hook_settings_tabs() plugin_manager.hook_settings_tabs() - # THEN: The createMediaManagerItem() method should have been called with the mocked settings form - mocked_plugin.createSettingsTab.assert_called_with(self.mocked_settings_form) - #self.assertEqual(self.mocked_settings_form.plugins, plugin_manager.plugins, - # u'The plugins on the settings form should be the same as the plugins in the plugin manager') - def hook_import_menu_with_disabled_plugin_test(self): """ Test running the hook_import_menu() method with a disabled plugin From e5c371feb571281abbc39a1bd23414c68e5cada4 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 27 Feb 2013 21:23:46 +0000 Subject: [PATCH 10/15] Fix merge comments --- .../openlp_core_lib/test_pluginmanager.py | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_pluginmanager.py b/tests/functional/openlp_core_lib/test_pluginmanager.py index 94b3776f1..5682ca669 100644 --- a/tests/functional/openlp_core_lib/test_pluginmanager.py +++ b/tests/functional/openlp_core_lib/test_pluginmanager.py @@ -91,22 +91,6 @@ class TestPluginManager(TestCase): # WHEN: We run hook_settings_tabs() plugin_manager.hook_settings_tabs() - def hook_settings_tabs_with_active_plugin_and_no_form_test(self): - """ - Test running the hook_settings_tabs() method with an active plugin and no settings form - """ - # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active - mocked_plugin = MagicMock() - mocked_plugin.status = PluginStatus.Active - plugin_manager = PluginManager() - plugin_manager.plugins = [mocked_plugin] - - # WHEN: We run hook_settings_tabs() - plugin_manager.hook_settings_tabs() - - # THEN: The createSettingsTab() method should have been called - mocked_plugin.createSettingsTab.assert_called_with(self.mocked_settings_form) - def hook_settings_tabs_with_active_plugin_and_mocked_form_test(self): """ Test running the hook_settings_tabs() method with an active plugin and a mocked settings form From c564b05f362ae9edcc4fe6cb249e3791a59b4394 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 27 Feb 2013 21:27:32 +0000 Subject: [PATCH 11/15] Fix merge comments --- .../functional/openlp_core_lib/test_pluginmanager.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_pluginmanager.py b/tests/functional/openlp_core_lib/test_pluginmanager.py index 5682ca669..b2281c2d9 100644 --- a/tests/functional/openlp_core_lib/test_pluginmanager.py +++ b/tests/functional/openlp_core_lib/test_pluginmanager.py @@ -78,19 +78,22 @@ class TestPluginManager(TestCase): assert mocked_plugin.createMediaManagerItem.call_count == 0, \ u'The createMediaManagerItem() method should not have been called.' - def hook_settings_tabs_with_disabled_plugin_and_mocked_form_test(self): + def hook_settings_tabs_with_active_plugin_and_no_form_test(self): """ - Test running the hook_settings_tabs() method with a disabled plugin and a mocked form + Test running the hook_settings_tabs() method with an active plugin and no settings form """ - # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled + # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active mocked_plugin = MagicMock() - mocked_plugin.status = PluginStatus.Disabled + mocked_plugin.status = PluginStatus.Active plugin_manager = PluginManager() plugin_manager.plugins = [mocked_plugin] # WHEN: We run hook_settings_tabs() plugin_manager.hook_settings_tabs() + # THEN: The createSettingsTab() method should have been called + mocked_plugin.createSettingsTab.assert_called_with(self.mocked_settings_form) + def hook_settings_tabs_with_active_plugin_and_mocked_form_test(self): """ Test running the hook_settings_tabs() method with an active plugin and a mocked settings form From 73aafdb62ccb51d03539e9f57e77b17548ca38cb Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 27 Feb 2013 21:42:21 +0000 Subject: [PATCH 12/15] failing tests --- .../openlp_core_lib/test_pluginmanager.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/functional/openlp_core_lib/test_pluginmanager.py b/tests/functional/openlp_core_lib/test_pluginmanager.py index b2281c2d9..4e2803168 100644 --- a/tests/functional/openlp_core_lib/test_pluginmanager.py +++ b/tests/functional/openlp_core_lib/test_pluginmanager.py @@ -78,6 +78,25 @@ class TestPluginManager(TestCase): assert mocked_plugin.createMediaManagerItem.call_count == 0, \ u'The createMediaManagerItem() method should not have been called.' + def hook_settings_tabs_with_disabled_plugin_and_mocked_form_test(self): + """ + Test running the hook_settings_tabs() method with a disabled plugin and a mocked form + """ + # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Disabled + mocked_plugin = MagicMock() + mocked_plugin.status = PluginStatus.Disabled + plugin_manager = PluginManager() + plugin_manager.plugins = [mocked_plugin] + + # WHEN: We run hook_settings_tabs() + plugin_manager.hook_settings_tabs() + + # THEN: The createSettingsTab() method should not have been called, but the plugins lists should be the same + assert mocked_plugin.createSettingsTab.call_count == 0, \ + u'The createMediaManagerItem() method should not have been called.' + self.assertEqual(self.mocked_settings_form.plugins, plugin_manager.plugins, + u'The plugins on the settings form should be the same as the plugins in the plugin manager') + def hook_settings_tabs_with_active_plugin_and_no_form_test(self): """ Test running the hook_settings_tabs() method with an active plugin and no settings form @@ -107,6 +126,11 @@ class TestPluginManager(TestCase): # WHEN: We run hook_settings_tabs() plugin_manager.hook_settings_tabs() + # THEN: The createMediaManagerItem() method should have been called with the mocked settings form + mocked_plugin.createSettingsTab.assert_called_with(self.mocked_settings_form) + self.assertEqual(self.mocked_settings_form.plugins, plugin_manager.plugins, + u'The plugins on the settings form should be the same as the plugins in the plugin manager') + def hook_import_menu_with_disabled_plugin_test(self): """ Test running the hook_import_menu() method with a disabled plugin From 8ddfd194c34182bb326f0dde1046d8e089aa647d Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Thu, 28 Feb 2013 05:45:34 +0000 Subject: [PATCH 13/15] Remove unneeded tests --- .../openlp_core_lib/test_pluginmanager.py | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_pluginmanager.py b/tests/functional/openlp_core_lib/test_pluginmanager.py index 4e2803168..d156884e0 100644 --- a/tests/functional/openlp_core_lib/test_pluginmanager.py +++ b/tests/functional/openlp_core_lib/test_pluginmanager.py @@ -94,8 +94,6 @@ class TestPluginManager(TestCase): # THEN: The createSettingsTab() method should not have been called, but the plugins lists should be the same assert mocked_plugin.createSettingsTab.call_count == 0, \ u'The createMediaManagerItem() method should not have been called.' - self.assertEqual(self.mocked_settings_form.plugins, plugin_manager.plugins, - u'The plugins on the settings form should be the same as the plugins in the plugin manager') def hook_settings_tabs_with_active_plugin_and_no_form_test(self): """ @@ -113,24 +111,6 @@ class TestPluginManager(TestCase): # THEN: The createSettingsTab() method should have been called mocked_plugin.createSettingsTab.assert_called_with(self.mocked_settings_form) - def hook_settings_tabs_with_active_plugin_and_mocked_form_test(self): - """ - Test running the hook_settings_tabs() method with an active plugin and a mocked settings form - """ - # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active - mocked_plugin = MagicMock() - mocked_plugin.status = PluginStatus.Active - plugin_manager = PluginManager() - plugin_manager.plugins = [mocked_plugin] - - # WHEN: We run hook_settings_tabs() - plugin_manager.hook_settings_tabs() - - # THEN: The createMediaManagerItem() method should have been called with the mocked settings form - mocked_plugin.createSettingsTab.assert_called_with(self.mocked_settings_form) - self.assertEqual(self.mocked_settings_form.plugins, plugin_manager.plugins, - u'The plugins on the settings form should be the same as the plugins in the plugin manager') - def hook_import_menu_with_disabled_plugin_test(self): """ Test running the hook_import_menu() method with a disabled plugin From 43874d00909ebdce432911380dbdca6fc1ee402c Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Thu, 28 Feb 2013 20:55:33 +0100 Subject: [PATCH 14/15] fixed bug #902964 (Libreoffice deprecated commandline args) Fixes: https://launchpad.net/bugs/902964 --- openlp/core/utils/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 6706750b5..d32729699 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -335,11 +335,11 @@ def get_uno_command(): Returns the UNO command to launch an openoffice.org instance. """ COMMAND = u'soffice' - OPTIONS = u'-nologo -norestore -minimized -nodefault -nofirststartwizard' + OPTIONS = u'--nologo --norestore --minimized --nodefault --nofirststartwizard' if UNO_CONNECTION_TYPE == u'pipe': - CONNECTION = u'"-accept=pipe,name=openlp_pipe;urp;"' + CONNECTION = u'"--accept=pipe,name=openlp_pipe;urp;"' else: - CONNECTION = u'"-accept=socket,host=localhost,port=2002;urp;"' + CONNECTION = u'"--accept=socket,host=localhost,port=2002;urp;"' return u'%s %s %s' % (COMMAND, OPTIONS, CONNECTION) From 5da93e1f153b7be26606e92b6b2079eba5aaf1f3 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Thu, 28 Feb 2013 21:19:01 +0000 Subject: [PATCH 15/15] Fix tests to work --- .../openlp_core_lib/test_pluginmanager.py | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/tests/functional/openlp_core_lib/test_pluginmanager.py b/tests/functional/openlp_core_lib/test_pluginmanager.py index d156884e0..7b2a0ba31 100644 --- a/tests/functional/openlp_core_lib/test_pluginmanager.py +++ b/tests/functional/openlp_core_lib/test_pluginmanager.py @@ -87,13 +87,40 @@ class TestPluginManager(TestCase): mocked_plugin.status = PluginStatus.Disabled plugin_manager = PluginManager() plugin_manager.plugins = [mocked_plugin] + mocked_settings_form = MagicMock() + # Replace the autoloaded plugin with the version for testing in real code this would error + mocked_settings_form.plugin_manager = plugin_manager # WHEN: We run hook_settings_tabs() plugin_manager.hook_settings_tabs() # THEN: The createSettingsTab() method should not have been called, but the plugins lists should be the same assert mocked_plugin.createSettingsTab.call_count == 0, \ - u'The createMediaManagerItem() method should not have been called.' + u'The createMediaManagerItem() method should not have been called.' + self.assertEqual(mocked_settings_form.plugin_manager.plugins, plugin_manager.plugins, + u'The plugins on the settings form should be the same as the plugins in the plugin manager') + + def hook_settings_tabs_with_active_plugin_and_mocked_form_test(self): + """ + Test running the hook_settings_tabs() method with an active plugin and a mocked settings form + """ + # GIVEN: A PluginManager instance and a list with a mocked up plugin whose status is set to Active + mocked_plugin = MagicMock() + mocked_plugin.status = PluginStatus.Active + plugin_manager = PluginManager() + plugin_manager.plugins = [mocked_plugin] + mocked_settings_form = MagicMock() + # Replace the autoloaded plugin with the version for testing in real code this would error + mocked_settings_form.plugin_manager = plugin_manager + + # WHEN: We run hook_settings_tabs() + plugin_manager.hook_settings_tabs() + + # THEN: The createMediaManagerItem() method should have been called with the mocked settings form + assert mocked_plugin.createSettingsTab.call_count == 1, \ + u'The createMediaManagerItem() method should have been called once.' + self.assertEqual(mocked_settings_form.plugin_manager.plugins, plugin_manager.plugins, + u'The plugins on the settings form should be the same as the plugins in the plugin manager') def hook_settings_tabs_with_active_plugin_and_no_form_test(self): """