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): """