From de6ce1209275d5a2beac53c02ae625cf39d2fab2 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Sun, 17 Feb 2013 21:28:45 +0000 Subject: [PATCH] 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)