From 59bb9efdf3722c5bb59c7918751ed3a9f7ff5f96 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Mon, 21 Jan 2013 20:56:27 +0000 Subject: [PATCH 01/16] demo of singleton --- openlp/core/lib/htmlbuilder.py | 5 +++-- openlp/core/ui/maindisplay.py | 9 ++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/openlp/core/lib/htmlbuilder.py b/openlp/core/lib/htmlbuilder.py index 3f2b4dfad..9b3c97164 100644 --- a/openlp/core/lib/htmlbuilder.py +++ b/openlp/core/lib/htmlbuilder.py @@ -32,6 +32,7 @@ import logging from PyQt4 import QtWebKit from openlp.core.lib.theme import BackgroundType, BackgroundGradientType, VerticalType, HorizontalType +from openlp.core.lib import PluginManager log = logging.getLogger(__name__) @@ -248,8 +249,8 @@ def build_html(item, screen, islive, background, image=None, css_additions = u'' js_additions = u'' html_additions = u'' - if plugins: - for plugin in plugins: + if PluginManager.get_instance().plugins: + for plugin in PluginManager.get_instance().plugins: css_additions += plugin.getDisplayCss() js_additions += plugin.getDisplayJavaScript() html_additions += plugin.getDisplayHtml() diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index ce4f3efe4..084c1d36b 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -65,7 +65,6 @@ class Display(QtGui.QGraphicsView): self.isLive = live self.controller = controller self.screen = {} - self.plugins = PluginManager.get_instance().plugins # FIXME: On Mac OS X (tested on 10.7) the display screen is corrupt with # OpenGL. Only white blank screen is shown on the 2nd monitor all the # time. We need to investigate more how to use OpenGL properly on Mac OS @@ -182,8 +181,8 @@ class MainDisplay(Display): Call the plugins to rebuild the Live display CSS as the screen has not been rebuild on exit of config. """ - if self.rebuildCSS and self.plugins: - for plugin in self.plugins: + if self.rebuildCSS and PluginManager.get_instance().plugins: + for plugin in PluginManager.get_instance().plugins: plugin.refreshCss(self.frame) self.rebuildCSS = False @@ -223,7 +222,7 @@ class MainDisplay(Display): serviceItem = ServiceItem() serviceItem.bg_image_bytes = image_to_byte(self.initialFrame) self.webView.setHtml(build_html(serviceItem, self.screen, - self.isLive, None, plugins=self.plugins)) + self.isLive, None)) self.__hideMouse() log.debug(u'Finished MainDisplay setup') @@ -402,7 +401,7 @@ class MainDisplay(Display): image_bytes = self.imageManager.getImageBytes(image_path, ImageSource.ImagePlugin) else: image_bytes = None - html = build_html(self.serviceItem, self.screen, self.isLive, background, image_bytes, self.plugins) + html = build_html(self.serviceItem, self.screen, self.isLive, background, image_bytes) log.debug(u'buildHtml - pre setHtml') self.webView.setHtml(html) log.debug(u'buildHtml - post setHtml') From 502a7c2c2ea0274ac466193363f0537305309ead Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 22 Jan 2013 18:54:59 +0000 Subject: [PATCH 02/16] Kernel start --- openlp/core/__init__.py | 3 ++- openlp/core/lib/__init__.py | 4 ++-- openlp/core/lib/renderer.py | 3 ++- openlp/core/lib/serviceitem.py | 10 ++++++---- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index d5556d16e..5dbb629e7 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 Receiver, Settings, check_directory_exists +from openlp.core.lib import Receiver, Settings, check_directory_exists, Kernel from openlp.core.lib.ui import UiStrings from openlp.core.resources import qInitResources from openlp.core.ui.mainwindow import MainWindow @@ -288,6 +288,7 @@ def main(args=None): portable_settings.sync() else: app.setApplicationName(u'OpenLP') + kernel = Kernel.create() app.setApplicationVersion(get_application_version()[u'version']) # Instance check if not options.testing: diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index d0a5e9880..4016cbc2a 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -112,8 +112,7 @@ class Settings(QtCore.QSettings): Settings.__filePath__ = iniFile def __init__(self, *args): - if not args and Settings.__filePath__ and \ - Settings.defaultFormat() == Settings.IniFormat: + if not args and Settings.__filePath__ and Settings.defaultFormat() == Settings.IniFormat: QtCore.QSettings.__init__(self, Settings.__filePath__, Settings.IniFormat) else: QtCore.QSettings.__init__(self, *args) @@ -459,6 +458,7 @@ def create_separated_list(stringlist): u'Locale list separator: start') % (stringlist[0], merged) +from kernel import Kernel from eventreceiver import Receiver from listwidgetwithdnd import ListWidgetWithDnD from formattingtags import FormattingTags diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 235d7d269..0c6869461 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -32,7 +32,7 @@ import logging from PyQt4 import QtGui, QtCore, QtWebKit from openlp.core.lib import ServiceItem, expand_tags, build_lyrics_format_css, build_lyrics_outline_css, Receiver, \ - ItemCapabilities, FormattingTags, ImageSource + ItemCapabilities, FormattingTags, ImageSource, Kernel from openlp.core.lib.theme import ThemeLevel from openlp.core.ui import MainDisplay, ScreenList @@ -71,6 +71,7 @@ class Renderer(object): self.theme_manager = theme_manager self.image_manager = image_manager self.screens = ScreenList() + Kernel().register(u'renderer', self) self.theme_level = ThemeLevel.Global self.global_theme_name = u'' self.service_theme_name = u'' diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index ddfbe7f9b..c7180be46 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -39,7 +39,7 @@ import uuid from PyQt4 import QtGui -from openlp.core.lib import build_icon, clean_tags, expand_tags, translate, ImageSource, Settings +from openlp.core.lib import build_icon, clean_tags, expand_tags, translate, ImageSource, Settings, Kernel log = logging.getLogger(__name__) @@ -240,11 +240,13 @@ class ServiceItem(object): for the theme manager. """ log.debug(u'Render called') + renderer = Kernel().get(u'renderer') + print renderer self._display_frames = [] self.bg_image_bytes = None if not provides_own_theme_data: - self.renderer.set_item_theme(self.theme) - self.themedata, self.main, self.footer = self.renderer.pre_render() + renderer.set_item_theme(self.theme) + self.themedata, self.main, self.footer = renderer.pre_render() if self.service_item_type == ServiceItemType.Text: log.debug(u'Formatting slides: %s' % self.title) # Save rendered pages to this dict. In the case that a slide is used @@ -256,7 +258,7 @@ class ServiceItem(object): if verse_tag in previous_pages and previous_pages[verse_tag][0] == slide[u'raw_slide']: pages = previous_pages[verse_tag][1] else: - pages = self.renderer.format_slide(slide[u'raw_slide'], self) + pages = renderer.format_slide(slide[u'raw_slide'], self) previous_pages[verse_tag] = (slide[u'raw_slide'], pages) for page in pages: page = page.replace(u'
', u'{br}') From 5051b9a17742481c4ab742ca42c80a67da27eb23 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 22 Jan 2013 18:56:38 +0000 Subject: [PATCH 03/16] Forgot the new file --- openlp/core/lib/kernel.py | 78 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 openlp/core/lib/kernel.py diff --git a/openlp/core/lib/kernel.py b/openlp/core/lib/kernel.py new file mode 100644 index 000000000..202d6efad --- /dev/null +++ b/openlp/core/lib/kernel.py @@ -0,0 +1,78 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2013 Raoul Snyman # +# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### +""" +Provide plugin management +""" +import os +import sys +import logging + +log = logging.getLogger(__name__) + +class Kernel(object): + """ + This is the Plugin manager, which loads all the plugins, + and executes all the hooks, as and when necessary. + """ + log.info(u'Kernel loaded') + __instance__ = None + + + def __new__(cls): + if not cls.__instance__: + cls.__instance__ = object.__new__(cls) + return cls.__instance__ + + @classmethod + def create(self): + """ + The constructor for the plugin manager. Passes the controllers on to + the plugins for them to interact with via their ServiceItems. + + ``plugin_dir`` + The directory to search for plugins. + """ + log.info(u'Kernel Initialising') + self.service_list = {} + + def get(self, key): + if key in self.service_list: + return self.service_list[key] + else: + log.error(u'Service %s not found in list' % key) + return None + + def register(self, key, reference): + print "register" + if key in self.service_list: + log.error(u'Duplicate service exception %s' % key) + raise Exception(u'Duplicate service exception %s' % key) + else: + self.service_list[key] = reference + print self.service_list From f7591916141d0f367e6073d1d58cab7acb43909d Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 22 Jan 2013 19:34:15 +0000 Subject: [PATCH 04/16] Move to properties --- openlp/core/__init__.py | 4 +- openlp/core/lib/__init__.py | 2 +- openlp/core/lib/kernel.py | 78 ---------------------------------- openlp/core/lib/renderer.py | 4 +- openlp/core/lib/serviceitem.py | 17 +++++--- 5 files changed, 16 insertions(+), 89 deletions(-) delete mode 100644 openlp/core/lib/kernel.py diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index 5dbb629e7..256e162d9 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 Receiver, Settings, check_directory_exists, Kernel +from openlp.core.lib import Receiver, Settings, check_directory_exists, Registry from openlp.core.lib.ui import UiStrings from openlp.core.resources import qInitResources from openlp.core.ui.mainwindow import MainWindow @@ -288,7 +288,7 @@ def main(args=None): portable_settings.sync() else: app.setApplicationName(u'OpenLP') - kernel = Kernel.create() + registry = Registry.create() app.setApplicationVersion(get_application_version()[u'version']) # Instance check if not options.testing: diff --git a/openlp/core/lib/__init__.py b/openlp/core/lib/__init__.py index 4016cbc2a..387c86e06 100644 --- a/openlp/core/lib/__init__.py +++ b/openlp/core/lib/__init__.py @@ -458,7 +458,7 @@ def create_separated_list(stringlist): u'Locale list separator: start') % (stringlist[0], merged) -from kernel import Kernel +from registry import Registry from eventreceiver import Receiver from listwidgetwithdnd import ListWidgetWithDnD from formattingtags import FormattingTags diff --git a/openlp/core/lib/kernel.py b/openlp/core/lib/kernel.py deleted file mode 100644 index 202d6efad..000000000 --- a/openlp/core/lib/kernel.py +++ /dev/null @@ -1,78 +0,0 @@ -# -*- coding: utf-8 -*- -# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 - -############################################################################### -# OpenLP - Open Source Lyrics Projection # -# --------------------------------------------------------------------------- # -# Copyright (c) 2008-2013 Raoul Snyman # -# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan # -# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # -# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # -# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # -# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # -# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # -# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # -# --------------------------------------------------------------------------- # -# This program is free software; you can redistribute it and/or modify it # -# under the terms of the GNU General Public License as published by the Free # -# Software Foundation; version 2 of the License. # -# # -# This program is distributed in the hope that it will be useful, but WITHOUT # -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # -# more details. # -# # -# You should have received a copy of the GNU General Public License along # -# with this program; if not, write to the Free Software Foundation, Inc., 59 # -# Temple Place, Suite 330, Boston, MA 02111-1307 USA # -############################################################################### -""" -Provide plugin management -""" -import os -import sys -import logging - -log = logging.getLogger(__name__) - -class Kernel(object): - """ - This is the Plugin manager, which loads all the plugins, - and executes all the hooks, as and when necessary. - """ - log.info(u'Kernel loaded') - __instance__ = None - - - def __new__(cls): - if not cls.__instance__: - cls.__instance__ = object.__new__(cls) - return cls.__instance__ - - @classmethod - def create(self): - """ - The constructor for the plugin manager. Passes the controllers on to - the plugins for them to interact with via their ServiceItems. - - ``plugin_dir`` - The directory to search for plugins. - """ - log.info(u'Kernel Initialising') - self.service_list = {} - - def get(self, key): - if key in self.service_list: - return self.service_list[key] - else: - log.error(u'Service %s not found in list' % key) - return None - - def register(self, key, reference): - print "register" - if key in self.service_list: - log.error(u'Duplicate service exception %s' % key) - raise Exception(u'Duplicate service exception %s' % key) - else: - self.service_list[key] = reference - print self.service_list diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 0c6869461..6f572e726 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -32,7 +32,7 @@ import logging from PyQt4 import QtGui, QtCore, QtWebKit from openlp.core.lib import ServiceItem, expand_tags, build_lyrics_format_css, build_lyrics_outline_css, Receiver, \ - ItemCapabilities, FormattingTags, ImageSource, Kernel + ItemCapabilities, FormattingTags, ImageSource, Registry from openlp.core.lib.theme import ThemeLevel from openlp.core.ui import MainDisplay, ScreenList @@ -71,7 +71,7 @@ class Renderer(object): self.theme_manager = theme_manager self.image_manager = image_manager self.screens = ScreenList() - Kernel().register(u'renderer', self) + Registry().register(u'renderer', self) self.theme_level = ThemeLevel.Global self.global_theme_name = u'' self.service_theme_name = u'' diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index c7180be46..8a257fbfa 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -39,7 +39,7 @@ import uuid from PyQt4 import QtGui -from openlp.core.lib import build_icon, clean_tags, expand_tags, translate, ImageSource, Settings, Kernel +from openlp.core.lib import build_icon, clean_tags, expand_tags, translate, ImageSource, Settings, Registry log = logging.getLogger(__name__) @@ -240,13 +240,11 @@ class ServiceItem(object): for the theme manager. """ log.debug(u'Render called') - renderer = Kernel().get(u'renderer') - print renderer self._display_frames = [] self.bg_image_bytes = None if not provides_own_theme_data: - renderer.set_item_theme(self.theme) - self.themedata, self.main, self.footer = renderer.pre_render() + self.renderer.set_item_theme(self.theme) + self.themedata, self.main, self.footer = self.renderer.pre_render() if self.service_item_type == ServiceItemType.Text: log.debug(u'Formatting slides: %s' % self.title) # Save rendered pages to this dict. In the case that a slide is used @@ -258,7 +256,7 @@ class ServiceItem(object): if verse_tag in previous_pages and previous_pages[verse_tag][0] == slide[u'raw_slide']: pages = previous_pages[verse_tag][1] else: - pages = renderer.format_slide(slide[u'raw_slide'], self) + pages = self.renderer.format_slide(slide[u'raw_slide'], self) previous_pages[verse_tag] = (slide[u'raw_slide'], pages) for page in pages: page = page.replace(u'
', u'{br}') @@ -646,3 +644,10 @@ class ServiceItem(object): type = frame[u'title'].split(u'.')[-1] if type.lower() not in suffix_list: self.is_valid = False + + def _get_renderer(self): + if not self._renderer: + self._renderer = Registry().get(u'renderer') + return self._renderer + + renderer = property(_get_renderer) \ No newline at end of file From f9e138612c1d30185c1da656df2ee032f8f32c7f Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 22 Jan 2013 19:35:29 +0000 Subject: [PATCH 05/16] missed file --- openlp/core/lib/registry.py | 78 +++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 openlp/core/lib/registry.py diff --git a/openlp/core/lib/registry.py b/openlp/core/lib/registry.py new file mode 100644 index 000000000..67c317587 --- /dev/null +++ b/openlp/core/lib/registry.py @@ -0,0 +1,78 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2013 Raoul Snyman # +# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan # +# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, # +# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. # +# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, # +# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, # +# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, # +# Frode Woldsund, Martin Zibricky, Patrick Zimmermann # +# --------------------------------------------------------------------------- # +# This program is free software; you can redistribute it and/or modify it # +# under the terms of the GNU General Public License as published by the Free # +# Software Foundation; version 2 of the License. # +# # +# This program is distributed in the hope that it will be useful, but WITHOUT # +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or # +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for # +# more details. # +# # +# You should have received a copy of the GNU General Public License along # +# with this program; if not, write to the Free Software Foundation, Inc., 59 # +# Temple Place, Suite 330, Boston, MA 02111-1307 USA # +############################################################################### +""" +Provide plugin management +""" +import os +import sys +import logging + +log = logging.getLogger(__name__) + +class Registry(object): + """ + This is the Plugin manager, which loads all the plugins, + and executes all the hooks, as and when necessary. + """ + log.info(u'Registry loaded') + __instance__ = None + + + def __new__(cls): + if not cls.__instance__: + cls.__instance__ = object.__new__(cls) + return cls.__instance__ + + @classmethod + def create(self): + """ + The constructor for the plugin manager. Passes the controllers on to + the plugins for them to interact with via their ServiceItems. + + ``plugin_dir`` + The directory to search for plugins. + """ + log.info(u'Registry Initialising') + self.service_list = {} + + def get(self, key): + if key in self.service_list: + return self.service_list[key] + else: + log.error(u'Service %s not found in list' % key) + return None + + def register(self, key, reference): + print "register" + if key in self.service_list: + log.error(u'Duplicate service exception %s' % key) + raise Exception(u'Duplicate service exception %s' % key) + else: + self.service_list[key] = reference + print self.service_list From a6de33f17736ee2b73c89d42527b0cbbfe7aa7dd Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 22 Jan 2013 21:09:43 +0000 Subject: [PATCH 06/16] Registry takes shape and takes over --- openlp/core/lib/htmlbuilder.py | 5 ++-- openlp/core/lib/imagemanager.py | 3 +- openlp/core/lib/pluginmanager.py | 11 ++----- openlp/core/lib/registry.py | 22 +++++++------- openlp/core/lib/renderer.py | 29 ++++++++++++++---- openlp/core/lib/serviceitem.py | 20 ++++++++++--- openlp/core/ui/maindisplay.py | 49 ++++++++++++++++++++++--------- openlp/core/ui/mainwindow.py | 2 +- openlp/core/ui/servicemanager.py | 28 +++++++++++------- openlp/core/ui/slidecontroller.py | 24 +++++++++------ openlp/core/ui/thememanager.py | 49 ++++++++++++++++++++++++------- 11 files changed, 163 insertions(+), 79 deletions(-) diff --git a/openlp/core/lib/htmlbuilder.py b/openlp/core/lib/htmlbuilder.py index 9b3c97164..3f2b4dfad 100644 --- a/openlp/core/lib/htmlbuilder.py +++ b/openlp/core/lib/htmlbuilder.py @@ -32,7 +32,6 @@ import logging from PyQt4 import QtWebKit from openlp.core.lib.theme import BackgroundType, BackgroundGradientType, VerticalType, HorizontalType -from openlp.core.lib import PluginManager log = logging.getLogger(__name__) @@ -249,8 +248,8 @@ def build_html(item, screen, islive, background, image=None, css_additions = u'' js_additions = u'' html_additions = u'' - if PluginManager.get_instance().plugins: - for plugin in PluginManager.get_instance().plugins: + if plugins: + for plugin in plugins: css_additions += plugin.getDisplayCss() js_additions += plugin.getDisplayJavaScript() html_additions += plugin.getDisplayHtml() diff --git a/openlp/core/lib/imagemanager.py b/openlp/core/lib/imagemanager.py index 941818295..62a06335c 100644 --- a/openlp/core/lib/imagemanager.py +++ b/openlp/core/lib/imagemanager.py @@ -39,7 +39,7 @@ import Queue from PyQt4 import QtCore -from openlp.core.lib import resize_image, image_to_byte, Receiver +from openlp.core.lib import resize_image, image_to_byte, Receiver, Registry from openlp.core.ui import ScreenList log = logging.getLogger(__name__) @@ -183,6 +183,7 @@ class ImageManager(QtCore.QObject): def __init__(self): QtCore.QObject.__init__(self) + Registry().register(u'image_manager', self) currentScreen = ScreenList().current self.width = currentScreen[u'size'].width() self.height = currentScreen[u'size'].height() diff --git a/openlp/core/lib/pluginmanager.py b/openlp/core/lib/pluginmanager.py index 7fbe7ba9e..021cdf256 100644 --- a/openlp/core/lib/pluginmanager.py +++ b/openlp/core/lib/pluginmanager.py @@ -33,7 +33,7 @@ import os import sys import logging -from openlp.core.lib import Plugin, PluginStatus +from openlp.core.lib import Plugin, PluginStatus, Registry log = logging.getLogger(__name__) @@ -43,13 +43,6 @@ class PluginManager(object): and executes all the hooks, as and when necessary. """ log.info(u'Plugin manager loaded') - __instance__ = None - @staticmethod - def get_instance(): - """ - Obtain a single instance of class. - """ - return PluginManager.__instance__ def __init__(self, plugin_dir): """ @@ -60,7 +53,7 @@ class PluginManager(object): The directory to search for plugins. """ log.info(u'Plugin manager Initialising') - PluginManager.__instance__ = self + Registry().register(u'plugin_manager', self) if not plugin_dir in sys.path: log.debug(u'Inserting %s into sys.path', plugin_dir) sys.path.insert(0, plugin_dir) diff --git a/openlp/core/lib/registry.py b/openlp/core/lib/registry.py index 67c317587..8ea0fc056 100644 --- a/openlp/core/lib/registry.py +++ b/openlp/core/lib/registry.py @@ -27,18 +27,16 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### """ -Provide plugin management +Provide Registry Services """ -import os -import sys import logging log = logging.getLogger(__name__) class Registry(object): """ - This is the Plugin manager, which loads all the plugins, - and executes all the hooks, as and when necessary. + This is the Component Registry. It is a singleton object and is used to provide a + look up service for common objects. """ log.info(u'Registry loaded') __instance__ = None @@ -52,16 +50,15 @@ class Registry(object): @classmethod def create(self): """ - The constructor for the plugin manager. Passes the controllers on to - the plugins for them to interact with via their ServiceItems. - - ``plugin_dir`` - The directory to search for plugins. + The constructor for the component registry providing a single registry of objects. """ log.info(u'Registry Initialising') self.service_list = {} def get(self, key): + """ + Extracts the registry value from the list based on the key passed in + """ if key in self.service_list: return self.service_list[key] else: @@ -69,10 +66,11 @@ class Registry(object): return None def register(self, key, reference): - print "register" + """ + Registers a component against a key. + """ if key in self.service_list: log.error(u'Duplicate service exception %s' % key) raise Exception(u'Duplicate service exception %s' % key) else: self.service_list[key] = reference - print self.service_list diff --git a/openlp/core/lib/renderer.py b/openlp/core/lib/renderer.py index 6f572e726..57bacb4bf 100644 --- a/openlp/core/lib/renderer.py +++ b/openlp/core/lib/renderer.py @@ -56,7 +56,7 @@ class Renderer(object): """ log.info(u'Renderer Loaded') - def __init__(self, image_manager, theme_manager): + def __init__(self): """ Initialise the renderer. @@ -68,8 +68,6 @@ class Renderer(object): The theme_manager instance, used to get the current theme details. """ log.debug(u'Initialisation started') - self.theme_manager = theme_manager - self.image_manager = image_manager self.screens = ScreenList() Registry().register(u'renderer', self) self.theme_level = ThemeLevel.Global @@ -77,7 +75,7 @@ class Renderer(object): self.service_theme_name = u'' self.item_theme_name = u'' self.force_page = False - self.display = MainDisplay(None, self.image_manager, False, self) + self.display = MainDisplay(None, False, self) self.display.setup() self._theme_dimensions = {} self._calculate_default() @@ -94,7 +92,7 @@ class Renderer(object): self._calculate_default() if self.display: self.display.close() - self.display = MainDisplay(None, self.image_manager, False, self) + self.display = MainDisplay(None, False, self) self.display.setup() self._theme_dimensions = {} @@ -236,7 +234,6 @@ class Renderer(object): serviceItem.add_from_text(VERSE_FOR_LINE_COUNT) else: serviceItem.add_from_text(VERSE) - serviceItem.renderer = self serviceItem.raw_footer = FOOTER # if No file do not update cache if theme_data.background_filename: @@ -644,3 +641,23 @@ class Renderer(object): # this parse we are to be wordy line = line.replace(u'\n', u' ') return line.split(u' ') + + 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) + + def _get_theme_manager(self): + """ + Adds the theme manager to the class dynamically + """ + if not hasattr(self, u'_theme_manager'): + self._theme_manager = Registry().get(u'theme_manager') + return self._theme_manager + + theme_manager = property(_get_theme_manager) \ No newline at end of file diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index 8a257fbfa..a1e9ed2a3 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -148,7 +148,6 @@ class ServiceItem(object): The plugin that this service item belongs to. """ if plugin: - self.renderer = plugin.renderer self.name = plugin.name self.title = u'' self.shortname = u'' @@ -293,7 +292,7 @@ class ServiceItem(object): self.image_border = background self.service_item_type = ServiceItemType.Image self._raw_frames.append({u'title': title, u'path': path}) - self.renderer.image_manager.addImage(path, ImageSource.ImagePlugin, self.image_border) + self.image_manager.addImage(path, ImageSource.ImagePlugin, self.image_border) self._new_item() def add_from_text(self, raw_slide, verse_tag=None): @@ -646,8 +645,21 @@ class ServiceItem(object): self.is_valid = False def _get_renderer(self): - if not self._renderer: + """ + Adds the Renderer to the class dynamically + """ + if not hasattr(self, u'_renderer'): self._renderer = Registry().get(u'renderer') return self._renderer - renderer = property(_get_renderer) \ No newline at end of file + renderer = property(_get_renderer) + + 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) \ No newline at end of file diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index 084c1d36b..8dd9dcddc 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -38,8 +38,8 @@ import sys from PyQt4 import QtCore, QtGui, QtWebKit, QtOpenGL from PyQt4.phonon import Phonon -from openlp.core.lib import Receiver, build_html, ServiceItem, image_to_byte, translate, PluginManager, expand_tags,\ - Settings, ImageSource +from openlp.core.lib import Receiver, build_html, ServiceItem, image_to_byte, translate, expand_tags,\ + Settings, ImageSource, Registry from openlp.core.lib.theme import BackgroundType from openlp.core.ui import HideMode, ScreenList, AlertLocation @@ -114,9 +114,8 @@ class MainDisplay(Display): """ This is the display screen as a specialized class from the Display class """ - def __init__(self, parent, imageManager, live, controller): + def __init__(self, parent, live, controller): Display.__init__(self, parent, live, controller) - self.imageManager = imageManager self.screens = ScreenList() self.rebuildCSS = False self.hideMode = None @@ -181,8 +180,8 @@ class MainDisplay(Display): Call the plugins to rebuild the Live display CSS as the screen has not been rebuild on exit of config. """ - if self.rebuildCSS and PluginManager.get_instance().plugins: - for plugin in PluginManager.get_instance().plugins: + if self.rebuildCSS and self.plugin_manager.plugins: + for plugin in self.plugin_manager.plugins: plugin.refreshCss(self.frame) self.rebuildCSS = False @@ -221,8 +220,8 @@ class MainDisplay(Display): splash_image) serviceItem = ServiceItem() serviceItem.bg_image_bytes = image_to_byte(self.initialFrame) - self.webView.setHtml(build_html(serviceItem, self.screen, - self.isLive, None)) + self.webView.setHtml(build_html(serviceItem, self.screen, self.isLive, None, + plugins=self.plugin_manager.plugins)) self.__hideMouse() log.debug(u'Finished MainDisplay setup') @@ -288,7 +287,7 @@ class MainDisplay(Display): """ API for replacement backgrounds so Images are added directly to cache. """ - self.imageManager.addImage(path, ImageSource.ImagePlugin, background) + self.image_manager.addImage(path, ImageSource.ImagePlugin, background) if not hasattr(self, u'serviceItem'): return False self.override[u'image'] = path @@ -310,7 +309,7 @@ class MainDisplay(Display): re-added to the image manager. """ log.debug(u'image to display') - image = self.imageManager.getImageBytes(path, ImageSource.ImagePlugin) + image = self.image_manager.getImageBytes(path, ImageSource.ImagePlugin) self.controller.mediaController.media_reset(self.controller) self.displayImage(image) @@ -391,17 +390,18 @@ class MainDisplay(Display): self.override = {} else: # replace the background - background = self.imageManager.getImageBytes(self.override[u'image'], ImageSource.ImagePlugin) + background = self.image_manager.getImageBytes(self.override[u'image'], ImageSource.ImagePlugin) self.setTransparency(self.serviceItem.themedata.background_type == BackgroundType.to_string(BackgroundType.Transparent)) if self.serviceItem.themedata.background_filename: - self.serviceItem.bg_image_bytes = self.imageManager.getImageBytes( + self.serviceItem.bg_image_bytes = self.image_manager.getImageBytes( self.serviceItem.themedata.background_filename,ImageSource.Theme) if image_path: - image_bytes = self.imageManager.getImageBytes(image_path, ImageSource.ImagePlugin) + image_bytes = self.image_manager.getImageBytes(image_path, ImageSource.ImagePlugin) else: image_bytes = None - html = build_html(self.serviceItem, self.screen, self.isLive, background, image_bytes) + html = build_html(self.serviceItem, self.screen, self.isLive, background, image_bytes, + plugins=self.plugin_manager.plugins) log.debug(u'buildHtml - pre setHtml') self.webView.setHtml(html) log.debug(u'buildHtml - post setHtml') @@ -476,6 +476,26 @@ class MainDisplay(Display): self.setCursor(QtCore.Qt.ArrowCursor) self.frame.evaluateJavaScript('document.body.style.cursor = "auto"') + def _get_plugin_manager(self): + """ + Adds the Renderer 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) + class AudioPlayer(QtCore.QObject): """ @@ -599,3 +619,4 @@ class AudioPlayer(QtCore.QObject): #@todo is this used? def connectSlot(self, signal, slot): QtCore.QObject.connect(self.mediaObject, signal, slot) + diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 6ba7a4d6d..99c38d486 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -542,7 +542,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): # warning cyclic dependency # renderer needs to call ThemeManager and # ThemeManager needs to call Renderer - self.renderer = Renderer(self.imageManager, self.themeManagerContents) + self.renderer = Renderer() # Define the media Dock Manager self.mediaDockManager = MediaDockManager(self.mediaToolBox) log.info(u'Load Plugins') diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 8a9b01d04..5414c18d8 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -40,7 +40,7 @@ log = logging.getLogger(__name__) from PyQt4 import QtCore, QtGui from openlp.core.lib import OpenLPToolbar, ServiceItem, Receiver, build_icon, ItemCapabilities, SettingsManager, \ - translate, str_to_bool, check_directory_exists, Settings, PluginStatus + translate, str_to_bool, check_directory_exists, Settings, PluginStatus, Registry from openlp.core.lib.theme import ThemeLevel from openlp.core.lib.ui import UiStrings, critical_error_message_box, create_widget_action, find_and_set_in_combo_box from openlp.core.ui import ServiceNoteForm, ServiceItemEditForm, StartTimeForm @@ -313,8 +313,7 @@ class ServiceManager(QtGui.QWidget): Setter for service file. """ self._fileName = unicode(fileName) - self.mainwindow.setServiceModified(self.isModified(), - self.shortFileName()) + self.mainwindow.setServiceModified(self.isModified(), self.shortFileName()) Settings().setValue(u'servicemanager/last file', fileName) self._saveLite = self._fileName.endswith(u'.oszl') @@ -384,8 +383,8 @@ class ServiceManager(QtGui.QWidget): if not loadFile: fileName = QtGui.QFileDialog.getOpenFileName(self.mainwindow, translate('OpenLP.ServiceManager', 'Open File'), - SettingsManager.get_last_dir(self.mainwindow.serviceManagerSettingsSection), - translate('OpenLP.ServiceManager', 'OpenLP Service Files (*.osz *.oszl)')) + SettingsManager.get_last_dir(self.mainwindow.serviceManagerSettingsSection), + translate('OpenLP.ServiceManager', 'OpenLP Service Files (*.osz *.oszl)')) if not fileName: return False else: @@ -703,7 +702,6 @@ class ServiceManager(QtGui.QWidget): for item in items: self.mainwindow.incrementProgressBar() serviceItem = ServiceItem() - serviceItem.renderer = self.mainwindow.renderer if self._saveLite: serviceItem.set_from_service(item) else: @@ -812,7 +810,7 @@ class ServiceManager(QtGui.QWidget): break self.themeMenu.menuAction().setVisible(False) # Set up the theme menu. - if serviceItem[u'service_item'].is_text() and self.mainwindow.renderer.theme_level == ThemeLevel.Song: + if serviceItem[u'service_item'].is_text() and self.renderer.theme_level == ThemeLevel.Song: self.themeMenu.menuAction().setVisible(True) # The service item does not have a theme, check the "Default". if serviceItem[u'service_item'].theme is None: @@ -1197,7 +1195,7 @@ class ServiceManager(QtGui.QWidget): """ log.debug(u'onThemeComboBoxSelected') self.service_theme = self.themeComboBox.currentText() - self.mainwindow.renderer.set_service_theme(self.service_theme) + self.renderer.set_service_theme(self.service_theme) Settings().setValue(self.mainwindow.serviceManagerSettingsSection + u'/service theme', self.service_theme) self.regenerateServiceItems(True) @@ -1207,7 +1205,7 @@ class ServiceManager(QtGui.QWidget): sure the theme combo box is in the correct state. """ log.debug(u'themeChange') - visible = self.mainwindow.renderer.theme_level == ThemeLevel.Global + visible = self.renderer.theme_level == ThemeLevel.Global self.themeLabel.setVisible(visible) self.themeComboBox.setVisible(visible) @@ -1520,7 +1518,7 @@ class ServiceManager(QtGui.QWidget): 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.mainwindow.renderer.set_service_theme(self.service_theme) + self.renderer.set_service_theme(self.service_theme) self.regenerateServiceItems() def onThemeChangeAction(self): @@ -1545,3 +1543,13 @@ class ServiceManager(QtGui.QWidget): """ settingDialog = PrintServiceForm(self.mainwindow, self) settingDialog.exec_() + + def _get_renderer(self): + """ + Adds the Renderer to the class dynamically + """ + if not hasattr(self, u'_renderer'): + self._renderer = Registry().get(u'renderer') + return self._renderer + + renderer = property(_get_renderer) \ No newline at end of file diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 7e6879bdf..7562c590f 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -34,14 +34,10 @@ from collections import deque from PyQt4 import QtCore, QtGui -from openlp.core.lib import OpenLPToolbar, Receiver, ItemCapabilities, \ - translate, build_icon, build_html, PluginManager, ServiceItem, \ - ImageSource, SlideLimits, ServiceItemAction, Settings -from openlp.core.ui import HideMode, MainDisplay, Display, ScreenList +from openlp.core.lib import OpenLPToolbar, Receiver, ItemCapabilities, translate, build_icon, build_html, \ + ServiceItem, ImageSource, SlideLimits, ServiceItemAction, Settings, Registry +from openlp.core.ui import HideMode, MainDisplay, Display, ScreenList, DisplayControllerType from openlp.core.lib.ui import UiStrings, create_action -from openlp.core.lib import SlideLimits, ServiceItemAction -from openlp.core.ui import HideMode, MainDisplay, Display, ScreenList, \ - DisplayControllerType from openlp.core.utils.actions import ActionList, CategoryOrder log = logging.getLogger(__name__) @@ -510,7 +506,7 @@ class SlideController(DisplayController): # rebuild display as screen size changed if self.display: self.display.close() - self.display = MainDisplay(self, self.imageManager, self.isLive, self) + self.display = MainDisplay(self, self.isLive, self) self.display.setup() if self.isLive: self.__addActionsToWidget(self.display) @@ -525,7 +521,7 @@ class SlideController(DisplayController): self.previewDisplay.setup() serviceItem = ServiceItem() self.previewDisplay.webView.setHtml(build_html(serviceItem, self.previewDisplay.screen, None, self.isLive, - plugins=PluginManager.get_instance().plugins)) + plugins=self.plugin_manager.plugins)) self.mediaController.setup_display(self.previewDisplay,True) if self.serviceItem: self.refreshServiceItem() @@ -1283,3 +1279,13 @@ class SlideController(DisplayController): def onTrackTriggered(self): action = self.sender() self.display.audioPlayer.goTo(action.data()) + + 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) \ No newline at end of file diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 8a3bbc28c..319e22494 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -37,7 +37,7 @@ from xml.etree.ElementTree import ElementTree, XML from PyQt4 import QtCore, QtGui from openlp.core.lib import OpenLPToolbar, get_text_file_string, build_icon, Receiver, SettingsManager, translate, \ - check_item_selected, check_directory_exists, create_thumb, validate_thumb, ImageSource, Settings + check_item_selected, check_directory_exists, create_thumb, validate_thumb, ImageSource, Settings, Registry from openlp.core.lib.theme import ThemeXML, BackgroundType, VerticalType, BackgroundGradientType from openlp.core.lib.ui import UiStrings, critical_error_message_box, create_widget_action from openlp.core.theme import Theme @@ -52,6 +52,7 @@ class ThemeManager(QtGui.QWidget): """ def __init__(self, mainwindow, parent=None): QtGui.QWidget.__init__(self, parent) + Registry().register(u'theme_manager', self) self.mainwindow = mainwindow self.settingsSection = u'themes' self.themeForm = ThemeForm(self) @@ -261,11 +262,10 @@ class ThemeManager(QtGui.QWidget): old_theme_data = self.getThemeData(old_theme_name) self.cloneThemeData(old_theme_data, new_theme_name) self.deleteTheme(old_theme_name) - for plugin in self.mainwindow.pluginManager.plugins: + for plugin in self.plugin_manager.plugins: if plugin.usesTheme(old_theme_name): plugin.renameTheme(old_theme_name, new_theme_name) - self.mainwindow.renderer.update_theme( - new_theme_name, old_theme_name) + self.renderer.update_theme(new_theme_name, old_theme_name) self.loadThemes() def onCopyTheme(self): @@ -312,7 +312,7 @@ class ThemeManager(QtGui.QWidget): self.themeForm.theme = theme self.themeForm.exec_(True) self.oldBackgroundImage = None - self.mainwindow.renderer.update_theme(theme.theme_name) + self.renderer.update_theme(theme.theme_name) self.loadThemes() def onDeleteTheme(self): @@ -327,7 +327,7 @@ class ThemeManager(QtGui.QWidget): row = self.themeListWidget.row(item) self.themeListWidget.takeItem(row) self.deleteTheme(theme) - self.mainwindow.renderer.update_theme(theme, only_delete=True) + self.renderer.update_theme(theme, only_delete=True) # As we do not reload the themes, push out the change. Reload the # list as the internal lists and events need to be triggered. self._pushThemes() @@ -631,9 +631,9 @@ class ThemeManager(QtGui.QWidget): """ self._writeTheme(theme, image_from, image_to) if theme.background_type == BackgroundType.to_string(BackgroundType.Image): - self.mainwindow.imageManager.updateImageBorder(theme.background_filename, + self.image_manager.updateImageBorder(theme.background_filename, ImageSource.Theme, QtGui.QColor(theme.background_border_color)) - self.mainwindow.imageManager.processUpdates() + self.image_manager.processUpdates() def _writeTheme(self, theme, image_from, image_to): """ @@ -698,7 +698,7 @@ class ThemeManager(QtGui.QWidget): Flag to tell message lines per page need to be generated. """ log.debug(u'generateImage \n%s ', theme_data) - return self.mainwindow.renderer.generate_preview(theme_data, forcePage) + return self.renderer.generate_preview(theme_data, forcePage) def getPreviewImage(self, theme): """ @@ -748,7 +748,7 @@ class ThemeManager(QtGui.QWidget): return False # check for use in the system else where. if testPlugin: - for plugin in self.mainwindow.pluginManager.plugins: + for plugin in self.plugin_manager.plugins: if plugin.usesTheme(theme): critical_error_message_box(translate('OpenLP.ThemeManager', 'Validation Error'), translate('OpenLP.ThemeManager', 'Theme %s is used in the %s plugin.') % @@ -806,3 +806,32 @@ class ThemeManager(QtGui.QWidget): new_theme.display_vertical_align = vAlignCorrection return new_theme.extract_xml() + def _get_renderer(self): + """ + Adds the Renderer to the class dynamically + """ + if not hasattr(self, u'_renderer'): + self._renderer = Registry().get(u'renderer') + return self._renderer + + renderer = property(_get_renderer) + + 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) + + def _get_plugin_manager(self): + """ + Adds the Renderer 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) \ No newline at end of file From 064ca583cae7b4001e755804c605355117dca86a Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 22 Jan 2013 21:25:16 +0000 Subject: [PATCH 07/16] Live and Preview Moved --- openlp/core/ui/servicemanager.py | 50 ++++++++++++++++++++++++------- openlp/core/ui/slidecontroller.py | 2 ++ 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 5414c18d8..ef6c88e7d 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -804,7 +804,7 @@ class ServiceManager(QtGui.QWidget): self.autoStartAction.setText(translate('OpenLP.ServiceManager', '&Auto Start - active')) self.autoStartAction.setIcon(self.active) if serviceItem[u'service_item'].is_text(): - for plugin in self.mainwindow.pluginManager.plugins: + for plugin in self.plugin_manager.plugins: if plugin.name == u'custom' and plugin.status == PluginStatus.Active: self.create_custom_action.setVisible(True) break @@ -1268,7 +1268,7 @@ class ServiceManager(QtGui.QWidget): newItem.merge(item[u'service_item']) item[u'service_item'] = newItem self.repaintServiceList(itemcount + 1, 0) - self.mainwindow.liveController.replaceServiceManagerItem(newItem) + self.live_controller.replaceServiceManagerItem(newItem) self.setModified() def addServiceItem(self, item, rebuild=False, expand=None, replace=False, repaint=True, selected=False): @@ -1290,7 +1290,7 @@ class ServiceManager(QtGui.QWidget): item.merge(self.serviceItems[sitem][u'service_item']) self.serviceItems[sitem][u'service_item'] = item self.repaintServiceList(sitem, child) - self.mainwindow.liveController.replaceServiceManagerItem(item) + self.live_controller.replaceServiceManagerItem(item) else: item.render() # nothing selected for dnd @@ -1313,7 +1313,7 @@ class ServiceManager(QtGui.QWidget): self.repaintServiceList(self.dropPosition, -1) # if rebuilding list make sure live is fixed. if rebuild: - self.mainwindow.liveController.replaceServiceManagerItem(item) + self.live_controller.replaceServiceManagerItem(item) self.dropPosition = 0 self.setModified() @@ -1324,8 +1324,7 @@ class ServiceManager(QtGui.QWidget): Receiver.send_message(u'cursor_busy') item, child = self.findServiceItem() if self.serviceItems[item][u'service_item'].is_valid: - self.mainwindow.previewController.addServiceManagerItem( - self.serviceItems[item][u'service_item'], child) + self.preview_controller.addServiceManagerItem(self.serviceItems[item][u'service_item'], child) else: critical_error_message_box(translate('OpenLP.ServiceManager', 'Missing Display Handler'), translate('OpenLP.ServiceManager', @@ -1365,16 +1364,15 @@ class ServiceManager(QtGui.QWidget): child = row Receiver.send_message(u'cursor_busy') if self.serviceItems[item][u'service_item'].is_valid: - self.mainwindow.liveController.addServiceManagerItem( - self.serviceItems[item][u'service_item'], child) + self.live_controller.addServiceManagerItem(self.serviceItems[item][u'service_item'], child) if Settings().value(self.mainwindow.generalSettingsSection + u'/auto preview', False): item += 1 if self.serviceItems and item < len(self.serviceItems) and \ self.serviceItems[item][u'service_item'].is_capable(ItemCapabilities.CanPreview): - self.mainwindow.previewController.addServiceManagerItem(self.serviceItems[item][u'service_item'], 0) + self.preview_controller.addServiceManagerItem(self.serviceItems[item][u'service_item'], 0) next_item = self.serviceManagerList.topLevelItem(item) self.serviceManagerList.setCurrentItem(next_item) - self.mainwindow.liveController.previewListWidget.setFocus() + self.live_controller.previewListWidget.setFocus() else: critical_error_message_box(translate('OpenLP.ServiceManager', 'Missing Display Handler'), translate('OpenLP.ServiceManager', @@ -1552,4 +1550,34 @@ class ServiceManager(QtGui.QWidget): self._renderer = Registry().get(u'renderer') return self._renderer - renderer = property(_get_renderer) \ No newline at end of file + renderer = property(_get_renderer) + + 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) + + def _get_preview_controller(self): + """ + Adds the preview controller to the class dynamically + """ + if not hasattr(self, u'_preview_controller'): + self._preview_controller = Registry().get(u'preview_controller') + return self._preview_controller + + preview_controller = property(_get_preview_controller) + + 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) \ No newline at end of file diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index 7562c590f..e2e3b7598 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -109,6 +109,7 @@ class SlideController(DisplayController): # Type label for the top of the slide controller self.typeLabel = QtGui.QLabel(self.panel) if self.isLive: + Registry().register(u'live_controller', self) self.typeLabel.setText(UiStrings().Live) self.split = 1 self.typePrefix = u'live' @@ -117,6 +118,7 @@ class SlideController(DisplayController): self.category = UiStrings().LiveToolbar ActionList.get_instance().add_category(unicode(self.category), CategoryOrder.standardToolbar) else: + Registry().register(u'preview_controller', self) self.typeLabel.setText(UiStrings().Preview) self.split = 0 self.typePrefix = u'preview' From 9067b16e0e4ac6ce90ed252264f108ac0e46168d Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 22 Jan 2013 21:59:45 +0000 Subject: [PATCH 08/16] fix up some tests --- openlp/core/lib/registry.py | 1 - .../openlp_core_lib/test_registry.py | 33 +++++++++++++++++++ .../openlp_core_lib/test_serviceitem.py | 22 +++++++------ 3 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 tests/functional/openlp_core_lib/test_registry.py diff --git a/openlp/core/lib/registry.py b/openlp/core/lib/registry.py index 8ea0fc056..f5029828a 100644 --- a/openlp/core/lib/registry.py +++ b/openlp/core/lib/registry.py @@ -41,7 +41,6 @@ class Registry(object): log.info(u'Registry loaded') __instance__ = None - def __new__(cls): if not cls.__instance__: cls.__instance__ = object.__new__(cls) diff --git a/tests/functional/openlp_core_lib/test_registry.py b/tests/functional/openlp_core_lib/test_registry.py new file mode 100644 index 000000000..44515ae98 --- /dev/null +++ b/tests/functional/openlp_core_lib/test_registry.py @@ -0,0 +1,33 @@ +""" + Package to test the openlp.core.lib package. +""" +import os + +from unittest import TestCase +from mock import MagicMock +from openlp.core.lib import ServiceItem, Registry + +TESTPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..', u'resources')) + +class TestServiceItem(TestCase): + + def registry_basic_test(self): + """ + Test the Service Item basic test + """ + # GIVEN: A new registry + registry = Registry.create() + + # WHEN:A service item is created (without a plugin) + mock_1 = MagicMock() + Registry().register(u'test1', mock_1) + + # THEN: we should be able retrieve the saved object + assert Registry().get(u'test1') == mock_1, u'The saved object can be retrieved' + #assert service_item.missing_frames() is True, u'There should not be any frames in the service item' + + # THEN: We should get back a valid service item + try: + assert Registry().get(u'test2') == mock_1, u'This should not be fired' + except Exception, e: + pass \ No newline at end of file diff --git a/tests/functional/openlp_core_lib/test_serviceitem.py b/tests/functional/openlp_core_lib/test_serviceitem.py index c2b9aacb1..43f05ed25 100644 --- a/tests/functional/openlp_core_lib/test_serviceitem.py +++ b/tests/functional/openlp_core_lib/test_serviceitem.py @@ -5,7 +5,7 @@ import os from unittest import TestCase from mock import MagicMock -from openlp.core.lib import ServiceItem +from openlp.core.lib import ServiceItem, Registry VERSE = u'The Lord said to {r}Noah{/r}: \n'\ 'There\'s gonna be a {su}floody{/su}, {sb}floody{/sb}\n'\ @@ -20,6 +20,17 @@ TESTPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..', class TestServiceItem(TestCase): + def setUp(self): + """ + Set up the Registry + """ + registry = Registry.create() + mocked_renderer = MagicMock() + mocked_image_manager = MagicMock() + mocked_renderer.format_slide.return_value = [VERSE] + Registry().register(u'renderer', mocked_renderer) + Registry().register(u'image_manager', mocked_image_manager) + def serviceitem_basic_test(self): """ Test the Service Item basic test @@ -48,11 +59,6 @@ class TestServiceItem(TestCase): assert service_item.is_valid is True, u'The new service item should be valid' assert service_item.missing_frames() is False, u'check frames loaded ' - # GIVEN: A service item with text - mocked_renderer = MagicMock() - mocked_renderer.format_slide.return_value = [VERSE] - service_item.renderer = mocked_renderer - # WHEN: Render called assert len(service_item._display_frames) == 0, u'A blank Service Item with no display frames' service_item.render(True) @@ -68,8 +74,6 @@ class TestServiceItem(TestCase): # GIVEN: A new service item and a mocked renderer service_item = ServiceItem(None) service_item.name = u'test' - mocked_renderer = MagicMock() - service_item.renderer = mocked_renderer # WHEN: adding image to a service item test_image = os.path.join(TESTPATH, u'church.jpg') @@ -125,8 +129,6 @@ class TestServiceItem(TestCase): # GIVEN: A new service item and a mocked renderer service_item = ServiceItem(None) service_item.name = u'test' - mocked_renderer = MagicMock() - service_item.renderer = mocked_renderer # WHEN: adding image to a service item test_file = os.path.join(TESTPATH, u'church.jpg') From 3378e32da345ac2b37ed58845baa43ddd908070d Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 23 Jan 2013 19:28:47 +0000 Subject: [PATCH 09/16] More cleanups and removal of plugin_helpers --- openlp/core/lib/mediamanageritem.py | 73 ++++++++++++++++++- openlp/core/lib/plugin.py | 21 ++++-- openlp/core/lib/registry.py | 6 +- openlp/core/ui/mainwindow.py | 3 +- openlp/core/ui/media/mediacontroller.py | 17 ++++- openlp/core/ui/servicemanager.py | 1 + openlp/core/ui/slidecontroller.py | 44 +++++++---- openlp/plugins/alerts/forms/alertform.py | 2 +- openlp/plugins/bibles/bibleplugin.py | 4 +- openlp/plugins/bibles/lib/mediaitem.py | 2 +- openlp/plugins/custom/lib/mediaitem.py | 2 +- openlp/plugins/images/lib/mediaitem.py | 12 +-- openlp/plugins/media/lib/mediaitem.py | 26 +++---- openlp/plugins/media/mediaplugin.py | 25 +++++-- openlp/plugins/presentations/lib/mediaitem.py | 12 +-- .../presentations/presentationplugin.py | 2 +- openlp/plugins/songs/forms/songimportform.py | 2 +- openlp/plugins/songs/lib/mediaitem.py | 9 +-- openlp/plugins/songs/songsplugin.py | 4 +- openlp/plugins/songusage/songusageplugin.py | 8 +- 20 files changed, 197 insertions(+), 78 deletions(-) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 55e1bb84b..b8da7d1a8 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -36,7 +36,7 @@ import re from PyQt4 import QtCore, QtGui from openlp.core.lib import SettingsManager, OpenLPToolbar, ServiceItem, StringContent, build_icon, translate, \ - Receiver, ListWidgetWithDnD, ServiceItemContext, Settings + Receiver, ListWidgetWithDnD, ServiceItemContext, Settings, Registry from openlp.core.lib.searchedit import SearchEdit from openlp.core.lib.ui import UiStrings, create_widget_action, critical_error_message_box @@ -98,6 +98,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) self.settingsSection = self.plugin.name self.icon = None if icon: @@ -618,3 +619,73 @@ class MediaManagerItem(QtGui.QWidget): Performs a plugin specific search for items containing ``string`` """ raise NotImplementedError(u'Plugin.search needs to be defined by the plugin') + + 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) + + def _get_renderer(self): + """ + Adds the Renderer to the class dynamically + """ + if not hasattr(self, u'_renderer'): + self._renderer = Registry().get(u'renderer') + return self._renderer + + renderer = property(_get_renderer) + + 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) + + def _get_preview_controller(self): + """ + Adds the preview controller to the class dynamically + """ + if not hasattr(self, u'_preview_controller'): + self._preview_controller = Registry().get(u'preview_controller') + return self._preview_controller + + preview_controller = property(_get_preview_controller) + + 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_media_controller(self): + """ + Adds the media controller to the class dynamically + """ + if not hasattr(self, u'_media_controller'): + self._media_controller = Registry().get(u'media_controller') + return self._media_controller + + media_controller = property(_get_media_controller) + + 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/lib/plugin.py b/openlp/core/lib/plugin.py index 1a127a83e..ee085875e 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -33,7 +33,7 @@ import logging from PyQt4 import QtCore -from openlp.core.lib import Receiver, Settings +from openlp.core.lib import Receiver, Settings, Registry from openlp.core.lib.ui import UiStrings from openlp.core.utils import get_application_version @@ -168,10 +168,7 @@ class Plugin(QtCore.QObject): self.renderer = plugin_helpers[u'renderer'] self.serviceManager = plugin_helpers[u'service'] self.settingsForm = plugin_helpers[u'settings form'] - self.mediaDock = plugin_helpers[u'toolbox'] self.pluginManager = plugin_helpers[u'pluginmanager'] - self.formParent = plugin_helpers[u'formparent'] - self.mediaController = plugin_helpers[u'mediacontroller'] QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'%s_add_service_item' % self.name), self.processAddServiceEvent) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'%s_config_updated' % self.name), @@ -217,7 +214,7 @@ class Plugin(QtCore.QObject): you need, and return it for integration into OpenLP. """ if self.mediaItemClass: - self.mediaItem = self.mediaItemClass(self.mediaDock.media_dock, self, self.icon) + self.mediaItem = self.mediaItemClass(self.main_window.mediaDockManager.media_dock, self, self.icon) def addImportMenuItem(self, importMenu): """ @@ -287,14 +284,14 @@ class Plugin(QtCore.QObject): """ if self.mediaItem: self.mediaItem.initialise() - self.mediaDock.insert_dock(self.mediaItem, self.icon, self.weight) + self.main_window.mediaDockManager.insert_dock(self.mediaItem, self.icon, self.weight) def finalise(self): """ Called by the plugin Manager to cleanup things. """ if self.mediaItem: - self.mediaDock.remove_dock(self.mediaItem) + self.main_window.mediaDockManager.remove_dock(self.mediaItem) def appStartup(self): """ @@ -389,3 +386,13 @@ class Plugin(QtCore.QObject): The plugin's config has changed """ pass + + 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/lib/registry.py b/openlp/core/lib/registry.py index f5029828a..f69eeb3a6 100644 --- a/openlp/core/lib/registry.py +++ b/openlp/core/lib/registry.py @@ -47,12 +47,14 @@ class Registry(object): return cls.__instance__ @classmethod - def create(self): + def create(cls): """ The constructor for the component registry providing a single registry of objects. """ log.info(u'Registry Initialising') - self.service_list = {} + registry = cls() + registry.service_list = {} + return registry def get(self, key): """ diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 99c38d486..3dff36937 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -40,7 +40,7 @@ from datetime import datetime from PyQt4 import QtCore, QtGui from openlp.core.lib import Renderer, build_icon, OpenLPDockWidget, PluginManager, Receiver, translate, ImageManager, \ - PluginStatus + PluginStatus, Registry from openlp.core.lib.ui import UiStrings, create_action from openlp.core.lib import SlideLimits, Settings from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, ThemeManager, SlideController, PluginForm, \ @@ -456,6 +456,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): plugins. """ QtGui.QMainWindow.__init__(self) + Registry().register(u'main_window', self) self.application = application self.clipboard = self.application.clipboard() self.arguments = self.application.args diff --git a/openlp/core/ui/media/mediacontroller.py b/openlp/core/ui/media/mediacontroller.py index f371610f0..b3496628f 100644 --- a/openlp/core/ui/media/mediacontroller.py +++ b/openlp/core/ui/media/mediacontroller.py @@ -32,7 +32,7 @@ import os import datetime from PyQt4 import QtCore, QtGui -from openlp.core.lib import OpenLPToolbar, Receiver, translate, Settings +from openlp.core.lib import OpenLPToolbar, Receiver, translate, Settings, Registry from openlp.core.lib.ui import UiStrings, critical_error_message_box from openlp.core.ui.media import MediaState, MediaInfo, MediaType, get_media_players, set_media_players from openlp.core.ui.media.mediaplayer import MediaPlayer @@ -88,6 +88,7 @@ class MediaController(object): """ def __init__(self, parent): self.mainWindow = parent + Registry().register(u'media_controller', self) self.mediaPlayers = {} self.displayControllers = {} self.currentMediaPlayer = {} @@ -130,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.mainWindow.serviceManagerContents.supportedSuffixes(item[2:]) + self.service_manager.supportedSuffixes(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.mainWindow.serviceManagerContents.supportedSuffixes(item[2:]) + self.service_manager.supportedSuffixes(item[2:]) def register_players(self, player): """ @@ -729,3 +730,13 @@ class MediaController(object): if controller.isLive: return controller.display return controller.previewDisplay + + 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/servicemanager.py b/openlp/core/ui/servicemanager.py index ef6c88e7d..96ba8eaf2 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -105,6 +105,7 @@ class ServiceManager(QtGui.QWidget): QtGui.QWidget.__init__(self, parent) 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.mainwindow = mainwindow self.serviceItems = [] self.suffixes = [] diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index e2e3b7598..1e1a706ad 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -82,8 +82,6 @@ class SlideController(DisplayController): self.ratio = float(self.screens.current[u'size'].width()) / float(self.screens.current[u'size'].height()) except ZeroDivisionError: self.ratio = 1 - self.imageManager = self.parent().imageManager - self.mediaController = self.parent().mediaController self.loopList = [ u'playSlidesMenu', u'loopSeparator', @@ -232,7 +230,7 @@ class SlideController(DisplayController): tooltip=translate('OpenLP.SlideController', 'Edit and reload song preview.'), triggers=self.onEditSong) self.controllerLayout.addWidget(self.toolbar) # Build the Media Toolbar - self.mediaController.register_controller(self) + self.media_controller.register_controller(self) if self.isLive: # Build the Song Toolbar self.songMenu = QtGui.QToolButton(self.toolbar) @@ -355,8 +353,7 @@ class SlideController(DisplayController): self.setLiveHotkeys(self) self.__addActionsToWidget(self.previewListWidget) else: - self.previewListWidget.addActions( - [self.nextItem, self.previousItem]) + self.previewListWidget.addActions([self.nextItem, self.previousItem]) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'slidecontroller_%s_stop_loop' % self.typePrefix), self.onStopLoop) QtCore.QObject.connect(Receiver.get_receiver(), @@ -451,7 +448,7 @@ class SlideController(DisplayController): def liveEscape(self): self.display.setVisible(False) - self.mediaController.media_stop(self) + self.media_controller.media_stop(self) def toggleDisplay(self, action): """ @@ -518,13 +515,13 @@ class SlideController(DisplayController): self.ratio = float(self.screens.current[u'size'].width()) / float(self.screens.current[u'size'].height()) except ZeroDivisionError: self.ratio = 1 - self.mediaController.setup_display(self.display, False) + self.media_controller.setup_display(self.display, False) self.previewSizeChanged() self.previewDisplay.setup() serviceItem = ServiceItem() self.previewDisplay.webView.setHtml(build_html(serviceItem, self.previewDisplay.screen, None, self.isLive, plugins=self.plugin_manager.plugins)) - self.mediaController.setup_display(self.previewDisplay,True) + self.media_controller.setup_display(self.previewDisplay,True) if self.serviceItem: self.refreshServiceItem() @@ -774,9 +771,9 @@ class SlideController(DisplayController): else: # If current slide set background to image if framenumber == slideno: - self.serviceItem.bg_image_bytes = self.imageManager.getImageBytes(frame[u'path'], + self.serviceItem.bg_image_bytes = self.image_manager.getImageBytes(frame[u'path'], ImageSource.ImagePlugin) - image = self.imageManager.getImage(frame[u'path'], ImageSource.ImagePlugin) + image = self.image_manager.getImage(frame[u'path'], ImageSource.ImagePlugin) label.setPixmap(QtGui.QPixmap.fromImage(image)) self.previewListWidget.setCellWidget(framenumber, 0, label) slideHeight = width * (1 / self.ratio) @@ -1225,7 +1222,7 @@ class SlideController(DisplayController): Respond to the arrival of a media service item """ log.debug(u'SlideController onMediaStart') - self.mediaController.video(self.controllerType, item, self.hideMode()) + self.media_controller.video(self.controllerType, item, self.hideMode()) if not self.isLive: self.previewDisplay.show() self.slidePreview.hide() @@ -1235,7 +1232,7 @@ class SlideController(DisplayController): Respond to a request to close the Video """ log.debug(u'SlideController onMediaClose') - self.mediaController.media_reset(self) + self.media_controller.media_reset(self) self.previewDisplay.hide() self.slidePreview.show() @@ -1290,4 +1287,25 @@ class SlideController(DisplayController): self._plugin_manager = Registry().get(u'plugin_manager') return self._plugin_manager - plugin_manager = property(_get_plugin_manager) \ No newline at end of file + 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) + + def _get_media_controller(self): + """ + Adds the media controller to the class dynamically + """ + if not hasattr(self, u'_media_controller'): + self._media_controller = Registry().get(u'media_controller') + return self._media_controller + + media_controller = property(_get_media_controller) + diff --git a/openlp/plugins/alerts/forms/alertform.py b/openlp/plugins/alerts/forms/alertform.py index 8af7b3e21..cedb7acfc 100644 --- a/openlp/plugins/alerts/forms/alertform.py +++ b/openlp/plugins/alerts/forms/alertform.py @@ -45,7 +45,7 @@ class AlertForm(QtGui.QDialog, Ui_AlertDialog): self.manager = plugin.manager self.plugin = plugin self.item_id = None - QtGui.QDialog.__init__(self, plugin.formParent) + QtGui.QDialog.__init__(self, self.plugin.main_window) self.setupUi(self) QtCore.QObject.connect(self.displayButton, QtCore.SIGNAL(u'clicked()'), self.onDisplayClicked) QtCore.QObject.connect(self.displayCloseButton, QtCore.SIGNAL(u'clicked()'), self.onDisplayCloseClicked) diff --git a/openlp/plugins/bibles/bibleplugin.py b/openlp/plugins/bibles/bibleplugin.py index f22fc8bf8..fa0fdb4ec 100644 --- a/openlp/plugins/bibles/bibleplugin.py +++ b/openlp/plugins/bibles/bibleplugin.py @@ -81,7 +81,7 @@ class BiblePlugin(Plugin): Perform tasks on application startup """ if self.manager.old_bible_databases: - if QtGui.QMessageBox.information(self.formParent, + if QtGui.QMessageBox.information(self.main_window, translate('OpenLP', 'Information'), translate('OpenLP', 'Bible format has changed.\nYou have to upgrade your existing Bibles.\n' 'Should OpenLP upgrade now?'), @@ -128,7 +128,7 @@ class BiblePlugin(Plugin): Upgrade older bible databases. """ if not hasattr(self, u'upgrade_wizard'): - self.upgrade_wizard = BibleUpgradeForm(self.formParent, self.manager, self) + self.upgrade_wizard = BibleUpgradeForm(self.main_window, self.manager, self) # If the import was not cancelled then reload. if self.upgrade_wizard.exec_(): self.mediaItem.reloadBibles() diff --git a/openlp/plugins/bibles/lib/mediaitem.py b/openlp/plugins/bibles/lib/mediaitem.py index b4a1ec470..9cbe4539b 100644 --- a/openlp/plugins/bibles/lib/mediaitem.py +++ b/openlp/plugins/bibles/lib/mediaitem.py @@ -480,7 +480,7 @@ class BibleMediaItem(MediaManagerItem): elif self.advancedTab.isVisible(): bible = self.advancedVersionComboBox.currentText() if bible: - self.editBibleForm = EditBibleForm(self, self.plugin.formParent, self.plugin.manager) + self.editBibleForm = EditBibleForm(self, self.main_window, self.plugin.manager) self.editBibleForm.loadBible(bible) if self.editBibleForm.exec_(): self.reloadBibles() diff --git a/openlp/plugins/custom/lib/mediaitem.py b/openlp/plugins/custom/lib/mediaitem.py index f9478d6ff..72597b1c2 100644 --- a/openlp/plugins/custom/lib/mediaitem.py +++ b/openlp/plugins/custom/lib/mediaitem.py @@ -58,7 +58,7 @@ class CustomMediaItem(MediaManagerItem): def __init__(self, parent, plugin, icon): self.IconPath = u'custom/custom' MediaManagerItem.__init__(self, parent, plugin, icon) - self.edit_custom_form = EditCustomForm(self, self.plugin.formParent, self.plugin.manager) + self.edit_custom_form = EditCustomForm(self, self.main_window, self.plugin.manager) self.singleServiceItem = False self.quickPreviewAllowed = True self.hasSearch = True diff --git a/openlp/plugins/images/lib/mediaitem.py b/openlp/plugins/images/lib/mediaitem.py index c6fb3881a..f4feb378a 100644 --- a/openlp/plugins/images/lib/mediaitem.py +++ b/openlp/plugins/images/lib/mediaitem.py @@ -99,22 +99,22 @@ class ImageMediaItem(MediaManagerItem): row_list = [item.row() for item in self.listView.selectedIndexes()] row_list.sort(reverse=True) Receiver.send_message(u'cursor_busy') - self.plugin.formParent.displayProgressBar(len(row_list)) + self.main_window.displayProgressBar(len(row_list)) for row in row_list: text = self.listView.item(row) if text: delete_file(os.path.join(self.servicePath, text.text())) self.listView.takeItem(row) - self.plugin.formParent.incrementProgressBar() + self.main_window.incrementProgressBar() SettingsManager.set_list(self.settingsSection, u'images', self.getFileList()) - self.plugin.formParent.finishedProgressBar() + self.main_window.finishedProgressBar() Receiver.send_message(u'cursor_normal') self.listView.blockSignals(False) def loadList(self, images, initialLoad=False): if not initialLoad: Receiver.send_message(u'cursor_busy') - self.plugin.formParent.displayProgressBar(len(images)) + self.main_window.displayProgressBar(len(images)) # Sort the images by its filename considering language specific # characters. images.sort(cmp=locale_compare, key=lambda filename: os.path.split(unicode(filename))[1]) @@ -134,9 +134,9 @@ class ImageMediaItem(MediaManagerItem): item_name.setData(QtCore.Qt.UserRole, imageFile) self.listView.addItem(item_name) if not initialLoad: - self.plugin.formParent.incrementProgressBar() + self.main_window.incrementProgressBar() if not initialLoad: - self.plugin.formParent.finishedProgressBar() + self.main_window.finishedProgressBar() Receiver.send_message(u'cursor_normal') def generateSlideData(self, service_item, item=None, xmlVersion=False, diff --git a/openlp/plugins/media/lib/mediaitem.py b/openlp/plugins/media/lib/mediaitem.py index 1c44a4cda..517f88cff 100644 --- a/openlp/plugins/media/lib/mediaitem.py +++ b/openlp/plugins/media/lib/mediaitem.py @@ -63,14 +63,14 @@ class MediaMediaItem(MediaManagerItem): self.mediaObject = None self.displayController = DisplayController(parent) self.displayController.controllerLayout = QtGui.QVBoxLayout() - self.plugin.mediaController.register_controller(self.displayController) - self.plugin.mediaController.set_controls_visible(self.displayController, False) + self.media_controller.register_controller(self.displayController) + self.media_controller.set_controls_visible(self.displayController, False) self.displayController.previewDisplay = Display(self.displayController, False, self.displayController) self.displayController.previewDisplay.hide() self.displayController.previewDisplay.setGeometry(QtCore.QRect(0, 0, 300, 300)) self.displayController.previewDisplay.screen = {u'size':self.displayController.previewDisplay.geometry()} self.displayController.previewDisplay.setup() - self.plugin.mediaController.setup_display(self.displayController.previewDisplay, False) + self.media_controller.setup_display(self.displayController.previewDisplay, False) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'video_background_replaced'), self.videobackgroundReplaced) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'mediaitem_media_rebuild'), self.rebuild_players) @@ -130,7 +130,7 @@ class MediaMediaItem(MediaManagerItem): """ Called to reset the Live background with the media selected, """ - self.plugin.liveController.mediaController.media_reset(self.plugin.liveController) + self.live_controller.mediaController.media_reset(self.plugin.liveController) self.resetAction.setVisible(False) def videobackgroundReplaced(self): @@ -153,7 +153,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.plugin.liveController.mediaController.video(DisplayControllerType.Live, service_item, + if self.live_controller.mediaController.video(DisplayControllerType.Live, service_item, videoBehindText=True): self.resetAction.setVisible(True) else: @@ -185,7 +185,7 @@ class MediaMediaItem(MediaManagerItem): # Only get start and end times if going to a service if context == ServiceItemContext.Service: # Start media and obtain the length - if not self.plugin.mediaController.media_length(service_item): + if not self.media_controller.media_length(service_item): return False service_item.add_capability(ItemCapabilities.CanAutoStartForLive) service_item.add_capability(ItemCapabilities.RequiresMedia) @@ -211,11 +211,11 @@ class MediaMediaItem(MediaManagerItem): """ self.populateDisplayTypes() self.onNewFileMasks = translate('MediaPlugin.MediaItem', 'Videos (%s);;Audio (%s);;%s (*)') % ( - u' '.join(self.plugin.mediaController.video_extensions_list), - u' '.join(self.plugin.mediaController.audio_extensions_list), UiStrings().AllFiles) + u' '.join(self.media_controller.video_extensions_list), + u' '.join(self.media_controller.audio_extensions_list), UiStrings().AllFiles) def displaySetup(self): - self.plugin.mediaController.setup_display(self.displayController.previewDisplay, False) + self.media_controller.setup_display(self.displayController.previewDisplay, False) def populateDisplayTypes(self): """ @@ -227,7 +227,7 @@ class MediaMediaItem(MediaManagerItem): self.displayTypeComboBox.blockSignals(True) self.displayTypeComboBox.clear() usedPlayers, overridePlayer = get_media_players() - mediaPlayers = self.plugin.mediaController.mediaPlayers + mediaPlayers = self.media_controller.mediaPlayers currentIndex = 0 for player in usedPlayers: # load the drop down selection @@ -269,7 +269,7 @@ class MediaMediaItem(MediaManagerItem): elif track_info.isFile(): filename = os.path.split(unicode(track))[1] item_name = QtGui.QListWidgetItem(filename) - if u'*.%s' % (filename.split(u'.')[-1].lower()) in self.plugin.mediaController.audio_extensions_list: + if u'*.%s' % (filename.split(u'.')[-1].lower()) in self.media_controller.audio_extensions_list: item_name.setIcon(AUDIO) else: item_name.setIcon(VIDEO) @@ -287,9 +287,9 @@ class MediaMediaItem(MediaManagerItem): media.sort(cmp=locale_compare, key=lambda filename: os.path.split(unicode(filename))[1]) ext = [] if type == MediaType.Audio: - ext = self.plugin.mediaController.audio_extensions_list + ext = self.media_controller.audio_extensions_list else: - ext = self.plugin.mediaController.video_extensions_list + ext = self.media_controller.video_extensions_list ext = map(lambda x: x[1:], ext) media = filter(lambda x: os.path.splitext(x)[1] in ext, media) return media diff --git a/openlp/plugins/media/mediaplugin.py b/openlp/plugins/media/mediaplugin.py index 9a67af766..cfb4b3b88 100644 --- a/openlp/plugins/media/mediaplugin.py +++ b/openlp/plugins/media/mediaplugin.py @@ -31,8 +31,7 @@ import logging from PyQt4 import QtCore -from openlp.core.lib import Plugin, StringContent, build_icon, translate, \ - Settings +from openlp.core.lib import Plugin, StringContent, build_icon, translate, Settings, Registry from openlp.plugins.media.lib import MediaMediaItem, MediaTab log = logging.getLogger(__name__) @@ -91,26 +90,26 @@ class MediaPlugin(Plugin): Time to tidy up on exit """ log.info(u'Media Finalising') - self.mediaController.finalise() + self.media_controller.finalise() Plugin.finalise(self) def getDisplayCss(self): """ Add css style sheets to htmlbuilder """ - return self.mediaController.get_media_display_css() + return self.media_controller.get_media_display_css() def getDisplayJavaScript(self): """ Add javascript functions to htmlbuilder """ - return self.mediaController.get_media_display_javascript() + return self.media_controller.get_media_display_javascript() def getDisplayHtml(self): """ Add html code to htmlbuilder """ - return self.mediaController.get_media_display_html() + return self.media_controller.get_media_display_html() def appStartup(self): """ @@ -122,7 +121,7 @@ class MediaPlugin(Plugin): settings.beginGroup(self.settingsSection) if settings.contains(u'use phonon'): log.info(u'Found old Phonon setting') - players = self.mediaController.mediaPlayers.keys() + players = self.media_controller.mediaPlayers.keys() has_phonon = u'phonon' in players if settings.value(u'use phonon') and has_phonon: log.debug(u'Converting old setting to new setting') @@ -130,8 +129,18 @@ class MediaPlugin(Plugin): if players: new_players = [player for player in players if player != u'phonon'] new_players.insert(0, u'phonon') - self.mediaController.mediaPlayers[u'phonon'].isActive = True + self.media_controller.mediaPlayers[u'phonon'].isActive = True settings.setValue(u'players', u','.join(new_players)) self.settingsTab.load() settings.remove(u'use phonon') settings.endGroup() + + def _get_media_controller(self): + """ + Adds the media controller to the class dynamically + """ + if not hasattr(self, u'_media_controller'): + self._media_controller = Registry().get(u'media_controller') + return self._media_controller + + media_controller = property(_get_media_controller) diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index c34a17562..521abf932 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -154,13 +154,13 @@ class PresentationMediaItem(MediaManagerItem): Receiver.send_message(u'cursor_busy') if not initialLoad: Receiver.send_message(u'cursor_busy') - self.plugin.formParent.displayProgressBar(len(files)) + self.main_window.displayProgressBar(len(files)) # Sort the presentations by its filename considering language specific characters. files.sort(cmp=locale_compare, key=lambda filename: os.path.split(unicode(filename))[1]) for file in files: if not initialLoad: - self.plugin.formParent.incrementProgressBar() + self.main_window.incrementProgressBar() if currlist.count(file) > 0: continue filename = os.path.split(unicode(file))[1] @@ -209,7 +209,7 @@ class PresentationMediaItem(MediaManagerItem): self.listView.addItem(item_name) Receiver.send_message(u'cursor_normal') if not initialLoad: - self.plugin.formParent.finishedProgressBar() + self.main_window.finishedProgressBar() Receiver.send_message(u'cursor_normal') def onDeleteClick(self): @@ -221,15 +221,15 @@ class PresentationMediaItem(MediaManagerItem): row_list = [item.row() for item in items] row_list.sort(reverse=True) Receiver.send_message(u'cursor_busy') - self.plugin.formParent.displayProgressBar(len(row_list)) + self.main_window.displayProgressBar(len(row_list)) for item in items: filepath = unicode(item.data(QtCore.Qt.UserRole)) for cidx in self.controllers: doc = self.controllers[cidx].add_document(filepath) doc.presentation_deleted() doc.close_presentation() - self.plugin.formParent.incrementProgressBar() - self.plugin.formParent.finishedProgressBar() + self.main_window.incrementProgressBar() + self.main_window.finishedProgressBar() Receiver.send_message(u'cursor_normal') for row in row_list: self.listView.takeItem(row) diff --git a/openlp/plugins/presentations/presentationplugin.py b/openlp/plugins/presentations/presentationplugin.py index 937b78641..6e6645366 100644 --- a/openlp/plugins/presentations/presentationplugin.py +++ b/openlp/plugins/presentations/presentationplugin.py @@ -100,7 +100,7 @@ class PresentationPlugin(Plugin): Create the Media Manager List """ self.mediaItem = PresentationMediaItem( - self.mediaDock.media_dock, self, self.icon, self.controllers) + self.main_window.mediaDockManager.media_dock, self, self.icon, self.controllers) def registerControllers(self, controller): """ diff --git a/openlp/plugins/songs/forms/songimportform.py b/openlp/plugins/songs/forms/songimportform.py index d9045e163..680f215f1 100644 --- a/openlp/plugins/songs/forms/songimportform.py +++ b/openlp/plugins/songs/forms/songimportform.py @@ -59,7 +59,7 @@ class SongImportForm(OpenLPWizard): ``plugin`` The songs plugin. """ - self.clipboard = plugin.formParent.clipboard + self.clipboard = self.main_window.clipboard OpenLPWizard.__init__(self, parent, plugin, u'songImportWizard', u':/wizards/wizard_importsong.bmp') def setupUi(self, image): diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py index 8351c2dd5..3d07ba99c 100644 --- a/openlp/plugins/songs/lib/mediaitem.py +++ b/openlp/plugins/songs/lib/mediaitem.py @@ -71,8 +71,7 @@ class SongMediaItem(MediaManagerItem): def __init__(self, parent, plugin, icon): self.IconPath = u'songs/song' MediaManagerItem.__init__(self, parent, plugin, icon) - self.editSongForm = EditSongForm(self, self.plugin.formParent, - self.plugin.manager) + self.editSongForm = EditSongForm(self, self.main_window, self.plugin.manager) self.openLyrics = OpenLyrics(self.plugin.manager) self.singleServiceItem = False self.songMaintenanceForm = SongMaintenanceForm(self.plugin.manager, self) @@ -374,7 +373,7 @@ class SongMediaItem(MediaManagerItem): QtGui.QMessageBox.Yes) == QtGui.QMessageBox.No: return Receiver.send_message(u'cursor_busy') - self.plugin.formParent.displayProgressBar(len(items)) + self.main_window.displayProgressBar(len(items)) for item in items: item_id = item.data(QtCore.Qt.UserRole) media_files = self.plugin.manager.get_all_objects(MediaFile, MediaFile.song_id == item_id) @@ -390,8 +389,8 @@ class SongMediaItem(MediaManagerItem): except OSError: log.exception(u'Could not remove directory: %s', save_path) self.plugin.manager.delete_object(Song, item_id) - self.plugin.formParent.incrementProgressBar() - self.plugin.formParent.finishedProgressBar() + self.main_window.incrementProgressBar() + self.main_window.finishedProgressBar() Receiver.send_message(u'cursor_normal') self.onSearchTextButtonClicked() diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index b29291369..075810d99 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -144,7 +144,7 @@ class SongsPlugin(Plugin): if maxSongs == 0: return progressDialog = QtGui.QProgressDialog(translate('SongsPlugin', 'Reindexing songs...'), UiStrings().Cancel, - 0, maxSongs, self.formParent) + 0, maxSongs, self.main_window) progressDialog.setWindowTitle(translate('SongsPlugin', 'Reindexing songs')) progressDialog.setWindowModality(QtCore.Qt.WindowModal) songs = self.manager.get_all_objects(Song) @@ -248,7 +248,7 @@ class SongsPlugin(Plugin): if not song_dbs: return Receiver.send_message(u'openlp_process_events') - progress = QtGui.QProgressDialog(self.formParent) + progress = QtGui.QProgressDialog(self.main_window) progress.setWindowModality(QtCore.Qt.WindowModal) progress.setWindowTitle(translate('OpenLP.Ui', 'Importing Songs')) progress.setLabelText(translate('OpenLP.Ui', 'Starting import...')) diff --git a/openlp/plugins/songusage/songusageplugin.py b/openlp/plugins/songusage/songusageplugin.py index 980ef3190..3850f81e6 100644 --- a/openlp/plugins/songusage/songusageplugin.py +++ b/openlp/plugins/songusage/songusageplugin.py @@ -92,12 +92,12 @@ class SongUsagePlugin(Plugin): self.songUsageMenu.addSeparator() self.songUsageMenu.addAction(self.songUsageReport) self.songUsageMenu.addAction(self.songUsageDelete) - self.songUsageActiveButton = QtGui.QToolButton(self.formParent.statusBar) + self.songUsageActiveButton = QtGui.QToolButton(self.main_window.statusBar) self.songUsageActiveButton.setCheckable(True) self.songUsageActiveButton.setAutoRaise(True) self.songUsageActiveButton.setStatusTip(translate('SongUsagePlugin', 'Toggle the tracking of song usage.')) self.songUsageActiveButton.setObjectName(u'songUsageActiveButton') - self.formParent.statusBar.insertPermanentWidget(1, self.songUsageActiveButton) + self.main_window.statusBar.insertPermanentWidget(1, self.songUsageActiveButton) self.songUsageActiveButton.hide() # Signals and slots QtCore.QObject.connect(self.songUsageStatus, QtCore.SIGNAL(u'visibilityChanged(bool)'), @@ -119,8 +119,8 @@ class SongUsagePlugin(Plugin): action_list.add_action(self.songUsageStatus, translate('SongUsagePlugin', 'Song Usage')) action_list.add_action(self.songUsageDelete, translate('SongUsagePlugin', 'Song Usage')) action_list.add_action(self.songUsageReport, translate('SongUsagePlugin', 'Song Usage')) - self.songUsageDeleteForm = SongUsageDeleteForm(self.manager, self.formParent) - self.songUsageDetailForm = SongUsageDetailForm(self, self.formParent) + self.songUsageDeleteForm = SongUsageDeleteForm(self.manager, self.main_window) + self.songUsageDetailForm = SongUsageDetailForm(self, self.main_window) self.songUsageMenu.menuAction().setVisible(True) self.songUsageActiveButton.show() From 76d259264dd2a95a68721fe230542d954d11e52c Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 23 Jan 2013 19:53:40 +0000 Subject: [PATCH 10/16] More cleanups --- openlp/core/lib/plugin.py | 7 ++----- openlp/core/ui/mainwindow.py | 2 +- openlp/core/ui/settingsform.py | 20 +++++++++++++++----- openlp/plugins/alerts/alertsplugin.py | 2 +- openlp/plugins/songs/forms/editsongform.py | 15 ++++++++++++--- openlp/plugins/songs/songsplugin.py | 3 +-- 6 files changed, 32 insertions(+), 17 deletions(-) diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index ee085875e..b5bfd7e0f 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -165,10 +165,6 @@ class Plugin(QtCore.QObject): self.status = PluginStatus.Inactive self.previewController = plugin_helpers[u'preview'] self.liveController = plugin_helpers[u'live'] - self.renderer = plugin_helpers[u'renderer'] - self.serviceManager = plugin_helpers[u'service'] - self.settingsForm = plugin_helpers[u'settings form'] - self.pluginManager = plugin_helpers[u'pluginmanager'] QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'%s_add_service_item' % self.name), self.processAddServiceEvent) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'%s_config_updated' % self.name), @@ -395,4 +391,5 @@ class Plugin(QtCore.QObject): 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) + diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 3dff36937..aa8cd0cca 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -475,7 +475,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): self.serviceNotSaved = False self.aboutForm = AboutForm(self) self.mediaController = MediaController(self) - self.settingsForm = SettingsForm(self, self) + self.settingsForm = SettingsForm(self) self.formattingTagForm = FormattingTagForm(self) self.shortcutForm = ShortcutListForm(self) self.recentFiles = [] diff --git a/openlp/core/ui/settingsform.py b/openlp/core/ui/settingsform.py index 2807f215a..f54bc8729 100644 --- a/openlp/core/ui/settingsform.py +++ b/openlp/core/ui/settingsform.py @@ -33,7 +33,7 @@ import logging from PyQt4 import QtGui -from openlp.core.lib import Receiver, build_icon, PluginStatus +from openlp.core.lib import Receiver, build_icon, PluginStatus, Registry from openlp.core.ui import AdvancedTab, GeneralTab, ThemesTab from openlp.core.ui.media import PlayerTab from settingsdialog import Ui_SettingsDialog @@ -44,21 +44,21 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): """ Provide the form to manipulate the settings for OpenLP """ - def __init__(self, mainWindow, parent=None): + def __init__(self, parent=None): """ Initialise the settings form """ - self.mainWindow = mainWindow + Registry().register(u'settings_form', self) QtGui.QDialog.__init__(self, parent) self.setupUi(self) # General tab self.generalTab = GeneralTab(self) # Themes tab - self.themesTab = ThemesTab(self, mainWindow) + self.themesTab = ThemesTab(self, self.main_window) # Advanced tab self.advancedTab = AdvancedTab(self) # Advanced tab - self.playerTab = PlayerTab(self, mainWindow) + self.playerTab = PlayerTab(self, self.main_window) def exec_(self): # load all the settings @@ -142,3 +142,13 @@ class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): if self.resetSuffixes: self.mainWindow.serviceManagerContents.resetSupportedSuffixes() self.resetSuffixes = False + + 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/plugins/alerts/alertsplugin.py b/openlp/plugins/alerts/alertsplugin.py index e81c53d67..1bac08cec 100644 --- a/openlp/plugins/alerts/alertsplugin.py +++ b/openlp/plugins/alerts/alertsplugin.py @@ -139,7 +139,7 @@ class AlertsPlugin(Plugin): text=translate('AlertsPlugin', '&Alert'), icon=u':/plugins/plugin_alerts.png', statustip=translate('AlertsPlugin', 'Show an alert message.'), visible=False, shortcuts=[u'F7'], triggers=self.onAlertsTrigger) - self.serviceManager.mainwindow.toolsMenu.addAction(self.toolsAlertItem) + self.main_window.toolsMenu.addAction(self.toolsAlertItem) def initialise(self): log.info(u'Alerts Initialising') diff --git a/openlp/plugins/songs/forms/editsongform.py b/openlp/plugins/songs/forms/editsongform.py index e22937cd1..7de317334 100644 --- a/openlp/plugins/songs/forms/editsongform.py +++ b/openlp/plugins/songs/forms/editsongform.py @@ -38,7 +38,8 @@ import shutil from PyQt4 import QtCore, QtGui -from openlp.core.lib import PluginStatus, Receiver, MediaType, translate, create_separated_list, check_directory_exists +from openlp.core.lib import PluginStatus, Receiver, MediaType, translate, create_separated_list, \ + check_directory_exists, Registry from openlp.core.lib.ui import UiStrings, set_case_insensitive_completer, critical_error_message_box, \ find_and_set_in_combo_box from openlp.core.utils import AppLocation @@ -87,8 +88,7 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): self.onVerseListViewClicked) QtCore.QObject.connect(self.verseOrderEdit, QtCore.SIGNAL(u'textChanged(QString)'), self.onVerseOrderTextChanged) - QtCore.QObject.connect(self.themeAddButton, QtCore.SIGNAL(u'clicked()'), - self.mediaitem.plugin.renderer.theme_manager.onAddTheme) + QtCore.QObject.connect(self.themeAddButton, QtCore.SIGNAL(u'clicked()'), self.theme_manager.onAddTheme) QtCore.QObject.connect(self.maintenanceButton, QtCore.SIGNAL(u'clicked()'), self.onMaintenanceButtonClicked) QtCore.QObject.connect(self.audioAddFromFileButton, QtCore.SIGNAL(u'clicked()'), self.onAudioAddFromFileButtonClicked) @@ -908,3 +908,12 @@ class EditSongForm(QtGui.QDialog, Ui_EditSongDialog): except: log.exception(u'Problem processing song Lyrics \n%s', sxml.dump_xml()) + def _get_theme_manager(self): + """ + Adds the theme manager to the class dynamically + """ + if not hasattr(self, u'_theme_manager'): + self._theme_manager = Registry().get(u'theme_manager') + return self._theme_manager + + theme_manager = property(_get_theme_manager) \ No newline at end of file diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index 075810d99..e5541960f 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -187,8 +187,7 @@ class SongsPlugin(Plugin): ``newTheme`` The new name the plugin should now use. """ - songsUsingTheme = self.manager.get_all_objects(Song, - Song.theme_name == oldTheme) + songsUsingTheme = self.manager.get_all_objects(Song, Song.theme_name == oldTheme) for song in songsUsingTheme: song.theme_name = newTheme self.manager.save_object(song) From be6977a1a3b1d99e4b607a0bc417392037225b98 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 23 Jan 2013 21:05:25 +0000 Subject: [PATCH 11/16] remove plugin helpers --- openlp/core/lib/imagemanager.py | 3 +-- openlp/core/lib/mediamanageritem.py | 10 +++++----- openlp/core/lib/plugin.py | 8 +------- openlp/core/lib/pluginmanager.py | 7 ++----- openlp/core/ui/maindisplay.py | 2 +- openlp/core/ui/mainwindow.py | 13 +------------ openlp/core/ui/slidecontroller.py | 6 +++--- openlp/plugins/alerts/alertsplugin.py | 4 ++-- openlp/plugins/bibles/bibleplugin.py | 4 ++-- openlp/plugins/custom/customplugin.py | 4 ++-- openlp/plugins/images/imageplugin.py | 4 ++-- openlp/plugins/media/mediaplugin.py | 4 ++-- openlp/plugins/presentations/presentationplugin.py | 4 ++-- openlp/plugins/remotes/remoteplugin.py | 4 ++-- openlp/plugins/songs/songsplugin.py | 4 ++-- openlp/plugins/songusage/songusageplugin.py | 4 ++-- 16 files changed, 32 insertions(+), 53 deletions(-) diff --git a/openlp/core/lib/imagemanager.py b/openlp/core/lib/imagemanager.py index 62a06335c..72389066b 100644 --- a/openlp/core/lib/imagemanager.py +++ b/openlp/core/lib/imagemanager.py @@ -39,8 +39,7 @@ import Queue from PyQt4 import QtCore -from openlp.core.lib import resize_image, image_to_byte, Receiver, Registry -from openlp.core.ui import ScreenList +from openlp.core.lib import resize_image, image_to_byte, Receiver, Registry, ScreenList log = logging.getLogger(__name__) diff --git a/openlp/core/lib/mediamanageritem.py b/openlp/core/lib/mediamanageritem.py index 70080a30d..100f248c0 100644 --- a/openlp/core/lib/mediamanageritem.py +++ b/openlp/core/lib/mediamanageritem.py @@ -470,7 +470,7 @@ class MediaManagerItem(QtGui.QWidget): serviceItem = self.buildServiceItem() if serviceItem: serviceItem.from_plugin = True - self.plugin.previewController.addServiceItem(serviceItem) + self.preview_controller.addServiceItem(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.plugin.liveController.addServiceItem(serviceItem) + self.live_controller.addServiceItem(serviceItem) def createItemFromId(self, item_id): item = QtGui.QListWidgetItem() @@ -511,7 +511,7 @@ class MediaManagerItem(QtGui.QWidget): QtGui.QMessageBox.information(self, UiStrings().NISp, translate('OpenLP.MediaManagerItem', 'You must select one or more items to add.')) else: - # Is it posssible to process multiple list items to generate + # Is it possible to process multiple list items to generate # multiple service items? if self.singleServiceItem or self.remoteTriggered: log.debug(u'%s Add requested', self.plugin.name) @@ -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.plugin.serviceManager.addServiceItem(serviceItem, replace=replace) + self.service_manager.addServiceItem(serviceItem, replace=replace) def onAddEditClick(self): """ @@ -542,7 +542,7 @@ class MediaManagerItem(QtGui.QWidget): translate('OpenLP.MediaManagerItem', 'You must select an existing service item to add to.')) elif self.plugin.name == serviceItem.name: self.generateSlideData(serviceItem) - self.plugin.serviceManager.addServiceItem(serviceItem, replace=True) + self.service_manager.addServiceItem(serviceItem, replace=True) else: # Turn off the remote edit update message indicator QtGui.QMessageBox.information(self, translate('OpenLP.MediaManagerItem', 'Invalid Service Item'), diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index 8d0347b38..49a08e32a 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -118,8 +118,7 @@ class Plugin(QtCore.QObject): """ log.info(u'loaded') - def __init__(self, name, default_settings, plugin_helpers=None, media_item_class=None, - settings_tab_class=None, version=None): + def __init__(self, name, default_settings, media_item_class=None, settings_tab_class=None, version=None): """ This is the constructor for the plugin object. This provides an easy way for descendent plugins to populate common data. This method *must* @@ -135,9 +134,6 @@ class Plugin(QtCore.QObject): ``default_settings`` A dict containing the plugin's settings. The value to each key is the default value to be used. - ``plugin_helpers`` - Defaults to *None*. A list of helper objects. - ``media_item_class`` The class name of the plugin's media item. @@ -165,8 +161,6 @@ class Plugin(QtCore.QObject): self.mediaItem = None self.weight = 0 self.status = PluginStatus.Inactive - self.previewController = plugin_helpers[u'preview'] - self.liveController = plugin_helpers[u'live'] # Add the default status to the default settings. default_settings[name + u'/status'] = PluginStatus.Inactive default_settings[name + u'/last directory'] = u'' diff --git a/openlp/core/lib/pluginmanager.py b/openlp/core/lib/pluginmanager.py index 021cdf256..ae1d9f984 100644 --- a/openlp/core/lib/pluginmanager.py +++ b/openlp/core/lib/pluginmanager.py @@ -62,7 +62,7 @@ class PluginManager(object): self.plugins = [] log.info(u'Plugin manager Initialised') - def find_plugins(self, plugin_dir, plugin_helpers): + def find_plugins(self, plugin_dir): """ Scan the directory ``plugin_dir`` for objects inheriting from the ``Plugin`` class. @@ -70,9 +70,6 @@ class PluginManager(object): ``plugin_dir`` The directory to scan. - ``plugin_helpers`` - A list of helper objects to pass to the plugins. - """ log.info(u'Finding plugins') startdepth = len(os.path.abspath(plugin_dir).split(os.sep)) @@ -110,7 +107,7 @@ class PluginManager(object): plugin_objects = [] for p in plugin_classes: try: - plugin = p(plugin_helpers) + plugin = p() log.debug(u'Loaded plugin %s', unicode(p)) plugin_objects.append(plugin) except TypeError: diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index 6e08f3d78..3fed96ec4 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -301,7 +301,7 @@ class MainDisplay(Display): """ log.debug(u'image to display') image = self.image_manager.getImageBytes(path, ImageSource.ImagePlugin) - self.controller.mediaController.media_reset(self.controller) + self.controller.media_controller.media_reset(self.controller) self.displayImage(image) def displayImage(self, image): diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 2566ce911..9504327ff 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -482,7 +482,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): # Set up the path with plugins plugin_path = AppLocation.get_directory(AppLocation.PluginsDir) self.pluginManager = PluginManager(plugin_path) - self.pluginHelpers = {} self.imageManager = ImageManager() # Set up the interface self.setupUi(self) @@ -547,17 +546,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): # Define the media Dock Manager self.mediaDockManager = MediaDockManager(self.mediaToolBox) log.info(u'Load Plugins') - # make the controllers available to the plugins - self.pluginHelpers[u'preview'] = self.previewController - self.pluginHelpers[u'live'] = self.liveController - self.pluginHelpers[u'renderer'] = self.renderer - self.pluginHelpers[u'service'] = self.serviceManagerContents - self.pluginHelpers[u'settings form'] = self.settingsForm - self.pluginHelpers[u'toolbox'] = self.mediaDockManager - self.pluginHelpers[u'pluginmanager'] = self.pluginManager - self.pluginHelpers[u'formparent'] = self - self.pluginHelpers[u'mediacontroller'] = self.mediaController - self.pluginManager.find_plugins(plugin_path, self.pluginHelpers) + self.pluginManager.find_plugins(plugin_path) # 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 diff --git a/openlp/core/ui/slidecontroller.py b/openlp/core/ui/slidecontroller.py index e22c96b6a..e60bf992a 100644 --- a/openlp/core/ui/slidecontroller.py +++ b/openlp/core/ui/slidecontroller.py @@ -35,9 +35,9 @@ from collections import deque from PyQt4 import QtCore, QtGui from openlp.core.lib import OpenLPToolbar, Receiver, ItemCapabilities, translate, build_icon, build_html, \ - ServiceItem, ImageSource, SlideLimits, ServiceItemAction, Settings, Registry, UiStrings -from openlp.core.ui import HideMode, MainDisplay, Display, ScreenList, DisplayControllerType -from openlp.core.lib.ui import UiStrings, create_action + ServiceItem, ImageSource, SlideLimits, ServiceItemAction, Settings, Registry, UiStrings, ScreenList +from openlp.core.ui import HideMode, MainDisplay, Display, DisplayControllerType +from openlp.core.lib.ui import create_action from openlp.core.utils.actions import ActionList, CategoryOrder log = logging.getLogger(__name__) diff --git a/openlp/plugins/alerts/alertsplugin.py b/openlp/plugins/alerts/alertsplugin.py index c0cc94ee9..29727b79d 100644 --- a/openlp/plugins/alerts/alertsplugin.py +++ b/openlp/plugins/alerts/alertsplugin.py @@ -128,8 +128,8 @@ __default_settings__ = { class AlertsPlugin(Plugin): log.info(u'Alerts Plugin loaded') - def __init__(self, plugin_helpers): - Plugin.__init__(self, u'alerts', __default_settings__, plugin_helpers, settings_tab_class=AlertsTab) + def __init__(self): + Plugin.__init__(self, u'alerts', __default_settings__, settings_tab_class=AlertsTab) self.weight = -3 self.iconPath = u':/plugins/plugin_alerts.png' self.icon = build_icon(self.iconPath) diff --git a/openlp/plugins/bibles/bibleplugin.py b/openlp/plugins/bibles/bibleplugin.py index 02526406a..d24858db5 100644 --- a/openlp/plugins/bibles/bibleplugin.py +++ b/openlp/plugins/bibles/bibleplugin.py @@ -68,8 +68,8 @@ __default_settings__ = { class BiblePlugin(Plugin): log.info(u'Bible Plugin loaded') - def __init__(self, plugin_helpers): - Plugin.__init__(self, u'bibles', __default_settings__, plugin_helpers, BibleMediaItem, BiblesTab) + def __init__(self): + Plugin.__init__(self, u'bibles', __default_settings__, BibleMediaItem, BiblesTab) self.weight = -9 self.iconPath = u':/plugins/plugin_bibles.png' self.icon = build_icon(self.iconPath) diff --git a/openlp/plugins/custom/customplugin.py b/openlp/plugins/custom/customplugin.py index 116c6454a..d80b8929d 100644 --- a/openlp/plugins/custom/customplugin.py +++ b/openlp/plugins/custom/customplugin.py @@ -60,8 +60,8 @@ class CustomPlugin(Plugin): """ log.info(u'Custom Plugin loaded') - def __init__(self, plugin_helpers): - Plugin.__init__(self, u'custom', __default_settings__, plugin_helpers, CustomMediaItem, CustomTab) + def __init__(self): + Plugin.__init__(self, u'custom', __default_settings__, CustomMediaItem, CustomTab) self.weight = -5 self.manager = Manager(u'custom', init_schema) self.iconPath = u':/plugins/plugin_custom.png' diff --git a/openlp/plugins/images/imageplugin.py b/openlp/plugins/images/imageplugin.py index d46fabb9d..11e542e60 100644 --- a/openlp/plugins/images/imageplugin.py +++ b/openlp/plugins/images/imageplugin.py @@ -45,8 +45,8 @@ __default_settings__ = { class ImagePlugin(Plugin): log.info(u'Image Plugin loaded') - def __init__(self, plugin_helpers): - Plugin.__init__(self, u'images', __default_settings__, plugin_helpers, ImageMediaItem, ImageTab) + def __init__(self): + Plugin.__init__(self, u'images', __default_settings__, ImageMediaItem, ImageTab) self.weight = -7 self.iconPath = u':/plugins/plugin_images.png' self.icon = build_icon(self.iconPath) diff --git a/openlp/plugins/media/mediaplugin.py b/openlp/plugins/media/mediaplugin.py index b79b9ab9f..d93f120ec 100644 --- a/openlp/plugins/media/mediaplugin.py +++ b/openlp/plugins/media/mediaplugin.py @@ -46,8 +46,8 @@ __default_settings__ = { class MediaPlugin(Plugin): log.info(u'%s MediaPlugin loaded', __name__) - def __init__(self, plugin_helpers): - Plugin.__init__(self, u'media', __default_settings__, plugin_helpers, MediaMediaItem) + def __init__(self): + Plugin.__init__(self, u'media', __default_settings__, MediaMediaItem) self.weight = -6 self.iconPath = u':/plugins/plugin_media.png' self.icon = build_icon(self.iconPath) diff --git a/openlp/plugins/presentations/presentationplugin.py b/openlp/plugins/presentations/presentationplugin.py index 68a0bbdd9..883bb4bb8 100644 --- a/openlp/plugins/presentations/presentationplugin.py +++ b/openlp/plugins/presentations/presentationplugin.py @@ -59,13 +59,13 @@ class PresentationPlugin(Plugin): """ log = logging.getLogger(u'PresentationPlugin') - def __init__(self, plugin_helpers): + def __init__(self): """ PluginPresentation constructor. """ log.debug(u'Initialised') self.controllers = {} - Plugin.__init__(self, u'presentations', __default_settings__, plugin_helpers, __default_settings__) + Plugin.__init__(self, u'presentations', __default_settings__, __default_settings__) self.weight = -8 self.iconPath = u':/plugins/plugin_presentations.png' self.icon = build_icon(self.iconPath) diff --git a/openlp/plugins/remotes/remoteplugin.py b/openlp/plugins/remotes/remoteplugin.py index 5e71ba5b4..160b7d542 100644 --- a/openlp/plugins/remotes/remoteplugin.py +++ b/openlp/plugins/remotes/remoteplugin.py @@ -44,11 +44,11 @@ __default_settings__ = { class RemotesPlugin(Plugin): log.info(u'Remote Plugin loaded') - def __init__(self, plugin_helpers): + def __init__(self): """ remotes constructor """ - Plugin.__init__(self, u'remotes', __default_settings__, plugin_helpers, settings_tab_class=RemoteTab) + Plugin.__init__(self, u'remotes', __default_settings__, settings_tab_class=RemoteTab) self.iconPath = u':/plugins/plugin_remote.png' self.icon = build_icon(self.iconPath) self.weight = -1 diff --git a/openlp/plugins/songs/songsplugin.py b/openlp/plugins/songs/songsplugin.py index 4f3007a1a..4f57d3e21 100644 --- a/openlp/plugins/songs/songsplugin.py +++ b/openlp/plugins/songs/songsplugin.py @@ -73,11 +73,11 @@ class SongsPlugin(Plugin): """ log.info(u'Song Plugin loaded') - def __init__(self, plugin_helpers): + def __init__(self): """ Create and set up the Songs plugin. """ - Plugin.__init__(self, u'songs', __default_settings__, plugin_helpers, SongMediaItem, SongsTab) + Plugin.__init__(self, u'songs', __default_settings__, SongMediaItem, SongsTab) self.manager = Manager(u'songs', init_schema, upgrade_mod=upgrade) self.weight = -10 self.iconPath = u':/plugins/plugin_songs.png' diff --git a/openlp/plugins/songusage/songusageplugin.py b/openlp/plugins/songusage/songusageplugin.py index d4c43bd54..398997715 100644 --- a/openlp/plugins/songusage/songusageplugin.py +++ b/openlp/plugins/songusage/songusageplugin.py @@ -60,8 +60,8 @@ __default_settings__ = { class SongUsagePlugin(Plugin): log.info(u'SongUsage Plugin loaded') - def __init__(self, plugin_helpers): - Plugin.__init__(self, u'songusage', __default_settings__, plugin_helpers) + def __init__(self): + Plugin.__init__(self, u'songusage', __default_settings__) self.manager = Manager(u'songusage', init_schema, upgrade_mod=upgrade) self.weight = -4 self.icon = build_icon(u':/plugins/plugin_songusage.png') From e519e1b435b0a9a7d653c895f83687968cdc84f4 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 23 Jan 2013 21:47:23 +0000 Subject: [PATCH 12/16] remove main window code in service manager --- openlp/core/__init__.py | 3 +- openlp/core/ui/mainwindow.py | 2 +- openlp/core/ui/servicemanager.py | 93 ++++++++++++++++++-------------- 3 files changed, 54 insertions(+), 44 deletions(-) diff --git a/openlp/core/__init__.py b/openlp/core/__init__.py index 1798e30d9..04badb454 100644 --- a/openlp/core/__init__.py +++ b/openlp/core/__init__.py @@ -50,8 +50,7 @@ from openlp.core.ui.firsttimelanguageform import FirstTimeLanguageForm from openlp.core.ui.firsttimeform import FirstTimeForm from openlp.core.ui.exceptionform import ExceptionForm from openlp.core.ui import SplashScreen -from openlp.core.utils import AppLocation, LanguageManager, VersionThread, \ - get_application_version +from openlp.core.utils import AppLocation, LanguageManager, VersionThread, get_application_version __all__ = [u'OpenLP', u'main'] diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 9504327ff..701a35ed6 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -158,7 +158,7 @@ class Ui_MainWindow(object): # Create the service manager self.serviceManagerDock = OpenLPDockWidget(mainWindow, u'serviceManagerDock', u':/system/system_servicemanager.png') - self.serviceManagerContents = ServiceManager(mainWindow, self.serviceManagerDock) + self.serviceManagerContents = ServiceManager(self.serviceManagerDock) self.serviceManagerDock.setWidget(self.serviceManagerContents) mainWindow.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.serviceManagerDock) # Create the theme manager diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 9ab236515..73c3920a1 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -48,6 +48,9 @@ from openlp.core.ui.printserviceform import PrintServiceForm from openlp.core.utils import AppLocation, delete_file, split_filename, format_time from openlp.core.utils.actions import ActionList, CategoryOrder +ACTIVE = build_icon(QtGui.QImage(u':/media/auto-start_active.png')) +INACTIVE = build_icon(QtGui.QImage(u':/media/auto-start_inactive.png')) + class ServiceManagerList(QtGui.QTreeWidget): """ Set up key bindings and mouse behaviour for the service list @@ -98,15 +101,12 @@ class ServiceManager(QtGui.QWidget): the resources used into one OSZ or oszl file for use on any OpenLP v2 installation. Also handles the UI tasks of moving things up and down etc. """ - def __init__(self, mainwindow, parent=None): + def __init__(self, parent=None): """ Sets up the service manager, toolbars, list view, et al. """ QtGui.QWidget.__init__(self, parent) - 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.mainwindow = mainwindow self.serviceItems = [] self.suffixes = [] self.dropPosition = 0 @@ -116,9 +116,9 @@ class ServiceManager(QtGui.QWidget): self._modified = False self._fileName = u'' self.service_has_all_original_files = True - self.serviceNoteForm = ServiceNoteForm(self.mainwindow) - self.serviceItemEditForm = ServiceItemEditForm(self.mainwindow) - self.startTimeForm = StartTimeForm(self.mainwindow) + self.serviceNoteForm = ServiceNoteForm(self.main_window) + self.serviceItemEditForm = ServiceItemEditForm(self.main_window) + self.startTimeForm = StartTimeForm(self.main_window) # start with the layout self.layout = QtGui.QVBoxLayout(self) self.layout.setSpacing(0) @@ -232,7 +232,7 @@ class ServiceManager(QtGui.QWidget): 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.mainwindow.serviceManagerSettingsSection + u'/service theme') + 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() @@ -301,7 +301,7 @@ class ServiceManager(QtGui.QWidget): self.serviceId += 1 self._modified = modified serviceFile = self.shortFileName() or translate('OpenLP.ServiceManager', 'Untitled Service') - self.mainwindow.setServiceModified(modified, serviceFile) + self.main_window.setServiceModified(modified, serviceFile) def isModified(self): """ @@ -314,7 +314,7 @@ class ServiceManager(QtGui.QWidget): Setter for service file. """ self._fileName = unicode(fileName) - self.mainwindow.setServiceModified(self.isModified(), self.shortFileName()) + self.main_window.setServiceModified(self.isModified(), self.shortFileName()) Settings().setValue(u'servicemanager/last file', fileName) self._saveLite = self._fileName.endswith(u'.oszl') @@ -382,19 +382,20 @@ class ServiceManager(QtGui.QWidget): elif result == QtGui.QMessageBox.Save: self.decideSaveMethod() if not loadFile: - fileName = QtGui.QFileDialog.getOpenFileName(self.mainwindow, + fileName = QtGui.QFileDialog.getOpenFileName(self.main_window, translate('OpenLP.ServiceManager', 'Open File'), - SettingsManager.get_last_dir(self.mainwindow.serviceManagerSettingsSection), + SettingsManager.get_last_dir(self.main_window.serviceManagerSettingsSection), translate('OpenLP.ServiceManager', 'OpenLP Service Files (*.osz *.oszl)')) if not fileName: return False else: fileName = loadFile - Settings().setValue(self.mainwindow.serviceManagerSettingsSection + u'/last directory', split_filename(fileName)[0]) + Settings().setValue(self.main_window.serviceManagerSettingsSection + u'/last directory', + split_filename(fileName)[0]) self.loadFile(fileName) def saveModifiedService(self): - return QtGui.QMessageBox.question(self.mainwindow, + return QtGui.QMessageBox.question(self.main_window, translate('OpenLP.ServiceManager', 'Modified Service'), translate('OpenLP.ServiceManager', 'The current service has been modified. Would you like to save this service?'), @@ -436,7 +437,7 @@ class ServiceManager(QtGui.QWidget): basename = os.path.splitext(file_name)[0] service_file_name = '%s.osd' % basename log.debug(u'ServiceManager.saveFile - %s', path_file_name) - Settings().setValue(self.mainwindow.serviceManagerSettingsSection + u'/last directory', path) + Settings().setValue(self.main_window.serviceManagerSettingsSection + u'/last directory', path) service = [] write_list = [] missing_list = [] @@ -444,7 +445,7 @@ class ServiceManager(QtGui.QWidget): total_size = 0 Receiver.send_message(u'cursor_busy') # Number of items + 1 to zip it - self.mainwindow.displayProgressBar(len(self.serviceItems) + 1) + self.main_window.displayProgressBar(len(self.serviceItems) + 1) # Get list of missing files, and list of files to write for item in self.serviceItems: if not item[u'service_item'].uses_file(): @@ -466,12 +467,12 @@ class ServiceManager(QtGui.QWidget): answer = QtGui.QMessageBox.critical(self, title, message, QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel)) if answer == QtGui.QMessageBox.Cancel: - self.mainwindow.finishedProgressBar() + self.main_window.finishedProgressBar() return False Receiver.send_message(u'cursor_busy') # Check if item contains a missing file. for item in list(self.serviceItems): - self.mainwindow.incrementProgressBar() + self.main_window.incrementProgressBar() item[u'service_item'].remove_invalid_frames(missing_list) if item[u'service_item'].missing_frames(): self.serviceItems.remove(item) @@ -498,7 +499,7 @@ class ServiceManager(QtGui.QWidget): log.debug(u'ServiceManager.saveFile - allowZip64 is %s' % allow_zip_64) zip = None success = True - self.mainwindow.incrementProgressBar() + self.main_window.incrementProgressBar() try: zip = zipfile.ZipFile(temp_file_name, 'w', zipfile.ZIP_STORED, allow_zip_64) # First we add service contents. @@ -530,14 +531,14 @@ class ServiceManager(QtGui.QWidget): finally: if zip: zip.close() - self.mainwindow.finishedProgressBar() + self.main_window.finishedProgressBar() Receiver.send_message(u'cursor_normal') if success: try: shutil.copy(temp_file_name, path_file_name) except: return self.saveFileAs() - self.mainwindow.addRecentFile(path_file_name) + self.main_window.addRecentFile(path_file_name) self.setModified(False) delete_file(temp_file_name) return success @@ -562,21 +563,21 @@ class ServiceManager(QtGui.QWidget): basename = os.path.splitext(file_name)[0] service_file_name = '%s.osd' % basename log.debug(u'ServiceManager.saveFile - %s', path_file_name) - Settings().setValue(self.mainwindow.serviceManagerSettingsSection + u'/last directory', path) + 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.mainwindow.displayProgressBar(len(self.serviceItems) + 1) + self.main_window.displayProgressBar(len(self.serviceItems) + 1) for item in self.serviceItems: - self.mainwindow.incrementProgressBar() + self.main_window.incrementProgressBar() service_item = item[u'service_item'].get_service_repr(self._saveLite) #@todo check for file item on save. service.append({u'serviceitem': service_item}) - self.mainwindow.incrementProgressBar() + self.main_window.incrementProgressBar() service_content = cPickle.dumps(service) zip = None success = True - self.mainwindow.incrementProgressBar() + self.main_window.incrementProgressBar() try: zip = zipfile.ZipFile(temp_file_name, 'w', zipfile.ZIP_STORED, True) @@ -592,14 +593,14 @@ class ServiceManager(QtGui.QWidget): finally: if zip: zip.close() - self.mainwindow.finishedProgressBar() + self.main_window.finishedProgressBar() Receiver.send_message(u'cursor_normal') if success: try: shutil.copy(temp_file_name, path_file_name) except: return self.saveFileAs() - self.mainwindow.addRecentFile(path_file_name) + self.main_window.addRecentFile(path_file_name) self.setModified(False) delete_file(temp_file_name) return success @@ -627,16 +628,16 @@ class ServiceManager(QtGui.QWidget): default_filename = format_time(default_pattern, local_time) else: default_filename = u'' - directory = Settings().value(self.mainwindow.serviceManagerSettingsSection + u'/last directory') + directory = Settings().value(self.main_window.serviceManagerSettingsSection + u'/last directory') path = os.path.join(directory, default_filename) # 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.mainwindow, UiStrings().SaveService, path, + fileName = QtGui.QFileDialog.getSaveFileName(self.main_window, UiStrings().SaveService, path, translate('OpenLP.ServiceManager', 'OpenLP Service Files (*.osz);; OpenLP Service Files - lite (*.oszl)')) else: - fileName = QtGui.QFileDialog.getSaveFileName(self.mainwindow, UiStrings().SaveService, path, + fileName = QtGui.QFileDialog.getSaveFileName(self.main_window, UiStrings().SaveService, path, translate('OpenLP.ServiceManager', 'OpenLP Service Files (*.osz);;')) if not fileName: return False @@ -695,9 +696,9 @@ class ServiceManager(QtGui.QWidget): fileTo.close() self.newFile() self.setFileName(fileName) - self.mainwindow.displayProgressBar(len(items)) + self.main_window.displayProgressBar(len(items)) for item in items: - self.mainwindow.incrementProgressBar() + self.main_window.incrementProgressBar() serviceItem = ServiceItem() if self._saveLite: serviceItem.set_from_service(item) @@ -713,7 +714,7 @@ class ServiceManager(QtGui.QWidget): serviceItem.temporary_edit = self.load_item_temporary self.addServiceItem(serviceItem, repaint=False) delete_file(p_file) - self.mainwindow.addRecentFile(fileName) + self.main_window.addRecentFile(fileName) self.setModified(False) Settings().setValue('servicemanager/last file', fileName) else: @@ -740,7 +741,7 @@ class ServiceManager(QtGui.QWidget): fileTo.close() if zip: zip.close() - self.mainwindow.finishedProgressBar() + self.main_window.finishedProgressBar() Receiver.send_message(u'cursor_normal') self.repaintServiceList(-1, -1) @@ -795,11 +796,11 @@ class ServiceManager(QtGui.QWidget): self.timeAction.setVisible(True) if serviceItem[u'service_item'].is_capable(ItemCapabilities.CanAutoStartForLive): self.autoStartAction.setVisible(True) - self.autoStartAction.setIcon(self.inactive) + self.autoStartAction.setIcon(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) + self.autoStartAction.setIcon(ACTIVE) if serviceItem[u'service_item'].is_text(): for plugin in self.plugin_manager.plugins: if plugin.name == u'custom' and plugin.status == PluginStatus.Active: @@ -1193,7 +1194,7 @@ class ServiceManager(QtGui.QWidget): log.debug(u'onThemeComboBoxSelected') self.service_theme = self.themeComboBox.currentText() self.renderer.set_service_theme(self.service_theme) - Settings().setValue(self.mainwindow.serviceManagerSettingsSection + u'/service theme', self.service_theme) + Settings().setValue(self.main_window.serviceManagerSettingsSection + u'/service theme', self.service_theme) self.regenerateServiceItems(True) def themeChange(self): @@ -1362,7 +1363,7 @@ class ServiceManager(QtGui.QWidget): 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 Settings().value(self.mainwindow.generalSettingsSection + u'/auto preview'): + 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): @@ -1536,7 +1537,7 @@ class ServiceManager(QtGui.QWidget): """ Print a Service Order Sheet. """ - settingDialog = PrintServiceForm(self.mainwindow, self) + settingDialog = PrintServiceForm(self.main_window, self) settingDialog.exec_() def _get_renderer(self): @@ -1577,4 +1578,14 @@ class ServiceManager(QtGui.QWidget): self._plugin_manager = Registry().get(u'plugin_manager') return self._plugin_manager - plugin_manager = property(_get_plugin_manager) \ No newline at end of file + plugin_manager = property(_get_plugin_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 From c801e45668f55e9294e5efc84360142e90364173 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Wed, 23 Jan 2013 21:51:45 +0000 Subject: [PATCH 13/16] remove unused --- tests/functional/openlp_core_lib/test_registry.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/functional/openlp_core_lib/test_registry.py b/tests/functional/openlp_core_lib/test_registry.py index 44515ae98..ee5cf794d 100644 --- a/tests/functional/openlp_core_lib/test_registry.py +++ b/tests/functional/openlp_core_lib/test_registry.py @@ -5,7 +5,7 @@ import os from unittest import TestCase from mock import MagicMock -from openlp.core.lib import ServiceItem, Registry +from openlp.core.lib import Registry TESTPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..', u'resources')) From 1e3590a1528f1a351791db4256b99405c8bd9883 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Thu, 24 Jan 2013 06:00:51 +0000 Subject: [PATCH 14/16] Clean up complete for now --- openlp/core/ui/mainwindow.py | 3 ++- openlp/core/ui/servicemanager.py | 9 ++++---- openlp/core/ui/thememanager.py | 21 +++++++++++++------ .../openlp_core_lib/test_registry.py | 16 ++++++++++---- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 701a35ed6..b5f069854 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -163,7 +163,7 @@ class Ui_MainWindow(object): mainWindow.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.serviceManagerDock) # Create the theme manager self.themeManagerDock = OpenLPDockWidget(mainWindow, u'themeManagerDock', u':/system/system_thememanager.png') - self.themeManagerContents = ThemeManager(mainWindow, self.themeManagerDock) + self.themeManagerContents = ThemeManager(self.themeManagerDock) self.themeManagerContents.setObjectName(u'themeManagerContents') self.themeManagerDock.setWidget(self.themeManagerContents) mainWindow.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.themeManagerDock) @@ -1330,3 +1330,4 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow): # Check if the new data path is our default. if self.newDataPath == AppLocation.get_directory(AppLocation.DataDir): settings.remove(u'advanced/data path') + diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 73c3920a1..1880bf41f 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -48,9 +48,6 @@ from openlp.core.ui.printserviceform import PrintServiceForm from openlp.core.utils import AppLocation, delete_file, split_filename, format_time from openlp.core.utils.actions import ActionList, CategoryOrder -ACTIVE = build_icon(QtGui.QImage(u':/media/auto-start_active.png')) -INACTIVE = build_icon(QtGui.QImage(u':/media/auto-start_inactive.png')) - class ServiceManagerList(QtGui.QTreeWidget): """ Set up key bindings and mouse behaviour for the service list @@ -106,6 +103,8 @@ class ServiceManager(QtGui.QWidget): Sets up the service manager, toolbars, list view, et al. """ QtGui.QWidget.__init__(self, parent) + 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.suffixes = [] @@ -796,11 +795,11 @@ class ServiceManager(QtGui.QWidget): self.timeAction.setVisible(True) if serviceItem[u'service_item'].is_capable(ItemCapabilities.CanAutoStartForLive): self.autoStartAction.setVisible(True) - self.autoStartAction.setIcon(INACTIVE) + 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(ACTIVE) + self.autoStartAction.setIcon(self.active) if serviceItem[u'service_item'].is_text(): for plugin in self.plugin_manager.plugins: if plugin.name == u'custom' and plugin.status == PluginStatus.Active: diff --git a/openlp/core/ui/thememanager.py b/openlp/core/ui/thememanager.py index 15399474f..2a837631e 100644 --- a/openlp/core/ui/thememanager.py +++ b/openlp/core/ui/thememanager.py @@ -51,10 +51,9 @@ class ThemeManager(QtGui.QWidget): """ Manages the orders of Theme. """ - def __init__(self, mainwindow, parent=None): + def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) Registry().register(u'theme_manager', self) - self.mainwindow = mainwindow self.settingsSection = u'themes' self.themeForm = ThemeForm(self) self.fileRenameForm = FileRenameForm(self) @@ -681,11 +680,11 @@ class ThemeManager(QtGui.QWidget): """ Called to update the themes' preview images. """ - self.mainwindow.displayProgressBar(len(self.themeList)) + self.main_window.displayProgressBar(len(self.themeList)) for theme in self.themeList: - self.mainwindow.incrementProgressBar() + self.main_window.incrementProgressBar() self.generateAndSaveImage(self.path, theme, self.getThemeData(theme)) - self.mainwindow.finishedProgressBar() + self.main_window.finishedProgressBar() self.loadThemes() def generateImage(self, theme_data, forcePage=False): @@ -834,4 +833,14 @@ class ThemeManager(QtGui.QWidget): self._plugin_manager = Registry().get(u'plugin_manager') return self._plugin_manager - plugin_manager = property(_get_plugin_manager) \ No newline at end of file + plugin_manager = property(_get_plugin_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) diff --git a/tests/functional/openlp_core_lib/test_registry.py b/tests/functional/openlp_core_lib/test_registry.py index ee5cf794d..b9729ace1 100644 --- a/tests/functional/openlp_core_lib/test_registry.py +++ b/tests/functional/openlp_core_lib/test_registry.py @@ -18,15 +18,23 @@ class TestServiceItem(TestCase): # GIVEN: A new registry registry = Registry.create() - # WHEN:A service item is created (without a plugin) + # WHEN: I add a service it should save it mock_1 = MagicMock() Registry().register(u'test1', mock_1) # THEN: we should be able retrieve the saved object - assert Registry().get(u'test1') == mock_1, u'The saved object can be retrieved' - #assert service_item.missing_frames() is True, u'There should not be any frames in the service item' + assert Registry().get(u'test1') == mock_1, u'The saved service can be retrieved and matches' - # THEN: We should get back a valid service item + # WHEN: I add a service it should save it a second time + # THEN I will get an exception + try: + Registry().register(u'test1', mock_1) + except Exception, e: + pass + + + # WHEN I try to get back a non existent service + # THEN I will get an exception try: assert Registry().get(u'test2') == mock_1, u'This should not be fired' except Exception, e: From 0e6b7c705df0110880c863474e0b7bad6fe067d0 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Thu, 24 Jan 2013 20:04:18 +0000 Subject: [PATCH 15/16] fix up testing bugs --- openlp/core/lib/registry.py | 4 ++-- .../functional/openlp_core_lib/test_registry.py | 17 +++++++---------- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/openlp/core/lib/registry.py b/openlp/core/lib/registry.py index f69eeb3a6..a30ed4ba3 100644 --- a/openlp/core/lib/registry.py +++ b/openlp/core/lib/registry.py @@ -64,7 +64,7 @@ class Registry(object): return self.service_list[key] else: log.error(u'Service %s not found in list' % key) - return None + raise KeyError(u'Service %s not found in list' % key) def register(self, key, reference): """ @@ -72,6 +72,6 @@ class Registry(object): """ if key in self.service_list: log.error(u'Duplicate service exception %s' % key) - raise Exception(u'Duplicate service exception %s' % key) + raise KeyError(u'Duplicate service exception %s' % key) else: self.service_list[key] = reference diff --git a/tests/functional/openlp_core_lib/test_registry.py b/tests/functional/openlp_core_lib/test_registry.py index b9729ace1..16d0de52a 100644 --- a/tests/functional/openlp_core_lib/test_registry.py +++ b/tests/functional/openlp_core_lib/test_registry.py @@ -9,7 +9,7 @@ from openlp.core.lib import Registry TESTPATH = os.path.abspath(os.path.join(os.path.dirname(__file__), u'..', u'..', u'resources')) -class TestServiceItem(TestCase): +class TestRegistry(TestCase): def registry_basic_test(self): """ @@ -25,17 +25,14 @@ class TestServiceItem(TestCase): # THEN: we should be able retrieve the saved object assert Registry().get(u'test1') == mock_1, u'The saved service can be retrieved and matches' - # WHEN: I add a service it should save it a second time + # WHEN: I add a service for the second time I am mad. # THEN I will get an exception - try: + with self.assertRaises(KeyError) as context: Registry().register(u'test1', mock_1) - except Exception, e: - pass - + self.assertEqual(context.exception[0], u'Duplicate service exception test1') # WHEN I try to get back a non existent service # THEN I will get an exception - try: - assert Registry().get(u'test2') == mock_1, u'This should not be fired' - except Exception, e: - pass \ No newline at end of file + 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 From 88119d58ab4b2111fcceedc55b473e0ee8ed9077 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Thu, 24 Jan 2013 20:14:30 +0000 Subject: [PATCH 16/16] fix tests to run --- tests/functional/openlp_core_lib/test_serviceitem.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_serviceitem.py b/tests/functional/openlp_core_lib/test_serviceitem.py index c75c3e961..2b7185370 100644 --- a/tests/functional/openlp_core_lib/test_serviceitem.py +++ b/tests/functional/openlp_core_lib/test_serviceitem.py @@ -177,9 +177,6 @@ class TestServiceItem(TestCase): mocked_add_icon = MagicMock() service_item.add_icon = mocked_add_icon - mocked_renderer = MagicMock() - service_item.renderer = mocked_renderer - # WHEN: adding a custom from a saved Service line = self.convert_file_service_item(u'serviceitem_custom1.osd') service_item.set_from_service(line) @@ -199,8 +196,6 @@ class TestServiceItem(TestCase): service_item = ServiceItem(None) mocked_add_icon = MagicMock() service_item.add_icon = mocked_add_icon - mocked_renderer = MagicMock() - service_item.renderer = mocked_renderer # WHEN: adding a custom from a saved Service