Registry takes shape and takes over

This commit is contained in:
Tim Bentley 2013-01-22 21:09:43 +00:00
parent f9e138612c
commit a6de33f177
11 changed files with 163 additions and 79 deletions

View File

@ -32,7 +32,6 @@ import logging
from PyQt4 import QtWebKit from PyQt4 import QtWebKit
from openlp.core.lib.theme import BackgroundType, BackgroundGradientType, VerticalType, HorizontalType from openlp.core.lib.theme import BackgroundType, BackgroundGradientType, VerticalType, HorizontalType
from openlp.core.lib import PluginManager
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -249,8 +248,8 @@ def build_html(item, screen, islive, background, image=None,
css_additions = u'' css_additions = u''
js_additions = u'' js_additions = u''
html_additions = u'' html_additions = u''
if PluginManager.get_instance().plugins: if plugins:
for plugin in PluginManager.get_instance().plugins: for plugin in plugins:
css_additions += plugin.getDisplayCss() css_additions += plugin.getDisplayCss()
js_additions += plugin.getDisplayJavaScript() js_additions += plugin.getDisplayJavaScript()
html_additions += plugin.getDisplayHtml() html_additions += plugin.getDisplayHtml()

View File

@ -39,7 +39,7 @@ import Queue
from PyQt4 import QtCore 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 from openlp.core.ui import ScreenList
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -183,6 +183,7 @@ class ImageManager(QtCore.QObject):
def __init__(self): def __init__(self):
QtCore.QObject.__init__(self) QtCore.QObject.__init__(self)
Registry().register(u'image_manager', self)
currentScreen = ScreenList().current currentScreen = ScreenList().current
self.width = currentScreen[u'size'].width() self.width = currentScreen[u'size'].width()
self.height = currentScreen[u'size'].height() self.height = currentScreen[u'size'].height()

View File

@ -33,7 +33,7 @@ import os
import sys import sys
import logging import logging
from openlp.core.lib import Plugin, PluginStatus from openlp.core.lib import Plugin, PluginStatus, Registry
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -43,13 +43,6 @@ class PluginManager(object):
and executes all the hooks, as and when necessary. and executes all the hooks, as and when necessary.
""" """
log.info(u'Plugin manager loaded') 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): def __init__(self, plugin_dir):
""" """
@ -60,7 +53,7 @@ class PluginManager(object):
The directory to search for plugins. The directory to search for plugins.
""" """
log.info(u'Plugin manager Initialising') log.info(u'Plugin manager Initialising')
PluginManager.__instance__ = self Registry().register(u'plugin_manager', self)
if not plugin_dir in sys.path: if not plugin_dir in sys.path:
log.debug(u'Inserting %s into sys.path', plugin_dir) log.debug(u'Inserting %s into sys.path', plugin_dir)
sys.path.insert(0, plugin_dir) sys.path.insert(0, plugin_dir)

View File

@ -27,18 +27,16 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Temple Place, Suite 330, Boston, MA 02111-1307 USA #
############################################################################### ###############################################################################
""" """
Provide plugin management Provide Registry Services
""" """
import os
import sys
import logging import logging
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class Registry(object): class Registry(object):
""" """
This is the Plugin manager, which loads all the plugins, This is the Component Registry. It is a singleton object and is used to provide a
and executes all the hooks, as and when necessary. look up service for common objects.
""" """
log.info(u'Registry loaded') log.info(u'Registry loaded')
__instance__ = None __instance__ = None
@ -52,16 +50,15 @@ class Registry(object):
@classmethod @classmethod
def create(self): def create(self):
""" """
The constructor for the plugin manager. Passes the controllers on to The constructor for the component registry providing a single registry of objects.
the plugins for them to interact with via their ServiceItems.
``plugin_dir``
The directory to search for plugins.
""" """
log.info(u'Registry Initialising') log.info(u'Registry Initialising')
self.service_list = {} self.service_list = {}
def get(self, key): def get(self, key):
"""
Extracts the registry value from the list based on the key passed in
"""
if key in self.service_list: if key in self.service_list:
return self.service_list[key] return self.service_list[key]
else: else:
@ -69,10 +66,11 @@ class Registry(object):
return None return None
def register(self, key, reference): def register(self, key, reference):
print "register" """
Registers a component against a key.
"""
if key in self.service_list: if key in self.service_list:
log.error(u'Duplicate service exception %s' % key) log.error(u'Duplicate service exception %s' % key)
raise Exception(u'Duplicate service exception %s' % key) raise Exception(u'Duplicate service exception %s' % key)
else: else:
self.service_list[key] = reference self.service_list[key] = reference
print self.service_list

View File

@ -56,7 +56,7 @@ class Renderer(object):
""" """
log.info(u'Renderer Loaded') log.info(u'Renderer Loaded')
def __init__(self, image_manager, theme_manager): def __init__(self):
""" """
Initialise the renderer. Initialise the renderer.
@ -68,8 +68,6 @@ class Renderer(object):
The theme_manager instance, used to get the current theme details. The theme_manager instance, used to get the current theme details.
""" """
log.debug(u'Initialisation started') log.debug(u'Initialisation started')
self.theme_manager = theme_manager
self.image_manager = image_manager
self.screens = ScreenList() self.screens = ScreenList()
Registry().register(u'renderer', self) Registry().register(u'renderer', self)
self.theme_level = ThemeLevel.Global self.theme_level = ThemeLevel.Global
@ -77,7 +75,7 @@ class Renderer(object):
self.service_theme_name = u'' self.service_theme_name = u''
self.item_theme_name = u'' self.item_theme_name = u''
self.force_page = False self.force_page = False
self.display = MainDisplay(None, self.image_manager, False, self) self.display = MainDisplay(None, False, self)
self.display.setup() self.display.setup()
self._theme_dimensions = {} self._theme_dimensions = {}
self._calculate_default() self._calculate_default()
@ -94,7 +92,7 @@ class Renderer(object):
self._calculate_default() self._calculate_default()
if self.display: if self.display:
self.display.close() self.display.close()
self.display = MainDisplay(None, self.image_manager, False, self) self.display = MainDisplay(None, False, self)
self.display.setup() self.display.setup()
self._theme_dimensions = {} self._theme_dimensions = {}
@ -236,7 +234,6 @@ class Renderer(object):
serviceItem.add_from_text(VERSE_FOR_LINE_COUNT) serviceItem.add_from_text(VERSE_FOR_LINE_COUNT)
else: else:
serviceItem.add_from_text(VERSE) serviceItem.add_from_text(VERSE)
serviceItem.renderer = self
serviceItem.raw_footer = FOOTER serviceItem.raw_footer = FOOTER
# if No file do not update cache # if No file do not update cache
if theme_data.background_filename: if theme_data.background_filename:
@ -644,3 +641,23 @@ class Renderer(object):
# this parse we are to be wordy # this parse we are to be wordy
line = line.replace(u'\n', u' ') line = line.replace(u'\n', u' ')
return line.split(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)

View File

@ -148,7 +148,6 @@ class ServiceItem(object):
The plugin that this service item belongs to. The plugin that this service item belongs to.
""" """
if plugin: if plugin:
self.renderer = plugin.renderer
self.name = plugin.name self.name = plugin.name
self.title = u'' self.title = u''
self.shortname = u'' self.shortname = u''
@ -293,7 +292,7 @@ class ServiceItem(object):
self.image_border = background self.image_border = background
self.service_item_type = ServiceItemType.Image self.service_item_type = ServiceItemType.Image
self._raw_frames.append({u'title': title, u'path': path}) 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() self._new_item()
def add_from_text(self, raw_slide, verse_tag=None): def add_from_text(self, raw_slide, verse_tag=None):
@ -646,8 +645,21 @@ class ServiceItem(object):
self.is_valid = False self.is_valid = False
def _get_renderer(self): 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') self._renderer = Registry().get(u'renderer')
return self._renderer return self._renderer
renderer = property(_get_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)

View File

@ -38,8 +38,8 @@ import sys
from PyQt4 import QtCore, QtGui, QtWebKit, QtOpenGL from PyQt4 import QtCore, QtGui, QtWebKit, QtOpenGL
from PyQt4.phonon import Phonon from PyQt4.phonon import Phonon
from openlp.core.lib import Receiver, build_html, ServiceItem, image_to_byte, translate, PluginManager, expand_tags,\ from openlp.core.lib import Receiver, build_html, ServiceItem, image_to_byte, translate, expand_tags,\
Settings, ImageSource Settings, ImageSource, Registry
from openlp.core.lib.theme import BackgroundType from openlp.core.lib.theme import BackgroundType
from openlp.core.ui import HideMode, ScreenList, AlertLocation 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 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) Display.__init__(self, parent, live, controller)
self.imageManager = imageManager
self.screens = ScreenList() self.screens = ScreenList()
self.rebuildCSS = False self.rebuildCSS = False
self.hideMode = None self.hideMode = None
@ -181,8 +180,8 @@ class MainDisplay(Display):
Call the plugins to rebuild the Live display CSS as the screen has Call the plugins to rebuild the Live display CSS as the screen has
not been rebuild on exit of config. not been rebuild on exit of config.
""" """
if self.rebuildCSS and PluginManager.get_instance().plugins: if self.rebuildCSS and self.plugin_manager.plugins:
for plugin in PluginManager.get_instance().plugins: for plugin in self.plugin_manager.plugins:
plugin.refreshCss(self.frame) plugin.refreshCss(self.frame)
self.rebuildCSS = False self.rebuildCSS = False
@ -221,8 +220,8 @@ class MainDisplay(Display):
splash_image) splash_image)
serviceItem = ServiceItem() serviceItem = ServiceItem()
serviceItem.bg_image_bytes = image_to_byte(self.initialFrame) serviceItem.bg_image_bytes = image_to_byte(self.initialFrame)
self.webView.setHtml(build_html(serviceItem, self.screen, self.webView.setHtml(build_html(serviceItem, self.screen, self.isLive, None,
self.isLive, None)) plugins=self.plugin_manager.plugins))
self.__hideMouse() self.__hideMouse()
log.debug(u'Finished MainDisplay setup') log.debug(u'Finished MainDisplay setup')
@ -288,7 +287,7 @@ class MainDisplay(Display):
""" """
API for replacement backgrounds so Images are added directly to cache. 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'): if not hasattr(self, u'serviceItem'):
return False return False
self.override[u'image'] = path self.override[u'image'] = path
@ -310,7 +309,7 @@ class MainDisplay(Display):
re-added to the image manager. re-added to the image manager.
""" """
log.debug(u'image to display') 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.controller.mediaController.media_reset(self.controller)
self.displayImage(image) self.displayImage(image)
@ -391,17 +390,18 @@ class MainDisplay(Display):
self.override = {} self.override = {}
else: else:
# replace the background # 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 == self.setTransparency(self.serviceItem.themedata.background_type ==
BackgroundType.to_string(BackgroundType.Transparent)) BackgroundType.to_string(BackgroundType.Transparent))
if self.serviceItem.themedata.background_filename: 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) self.serviceItem.themedata.background_filename,ImageSource.Theme)
if image_path: if image_path:
image_bytes = self.imageManager.getImageBytes(image_path, ImageSource.ImagePlugin) image_bytes = self.image_manager.getImageBytes(image_path, ImageSource.ImagePlugin)
else: else:
image_bytes = None 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') log.debug(u'buildHtml - pre setHtml')
self.webView.setHtml(html) self.webView.setHtml(html)
log.debug(u'buildHtml - post setHtml') log.debug(u'buildHtml - post setHtml')
@ -476,6 +476,26 @@ class MainDisplay(Display):
self.setCursor(QtCore.Qt.ArrowCursor) self.setCursor(QtCore.Qt.ArrowCursor)
self.frame.evaluateJavaScript('document.body.style.cursor = "auto"') 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): class AudioPlayer(QtCore.QObject):
""" """
@ -599,3 +619,4 @@ class AudioPlayer(QtCore.QObject):
#@todo is this used? #@todo is this used?
def connectSlot(self, signal, slot): def connectSlot(self, signal, slot):
QtCore.QObject.connect(self.mediaObject, signal, slot) QtCore.QObject.connect(self.mediaObject, signal, slot)

View File

@ -542,7 +542,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
# warning cyclic dependency # warning cyclic dependency
# renderer needs to call ThemeManager and # renderer needs to call ThemeManager and
# ThemeManager needs to call Renderer # ThemeManager needs to call Renderer
self.renderer = Renderer(self.imageManager, self.themeManagerContents) self.renderer = Renderer()
# Define the media Dock Manager # Define the media Dock Manager
self.mediaDockManager = MediaDockManager(self.mediaToolBox) self.mediaDockManager = MediaDockManager(self.mediaToolBox)
log.info(u'Load Plugins') log.info(u'Load Plugins')

View File

@ -40,7 +40,7 @@ log = logging.getLogger(__name__)
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.lib import OpenLPToolbar, ServiceItem, Receiver, build_icon, ItemCapabilities, SettingsManager, \ 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.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.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 from openlp.core.ui import ServiceNoteForm, ServiceItemEditForm, StartTimeForm
@ -313,8 +313,7 @@ class ServiceManager(QtGui.QWidget):
Setter for service file. Setter for service file.
""" """
self._fileName = unicode(fileName) self._fileName = unicode(fileName)
self.mainwindow.setServiceModified(self.isModified(), self.mainwindow.setServiceModified(self.isModified(), self.shortFileName())
self.shortFileName())
Settings().setValue(u'servicemanager/last file', fileName) Settings().setValue(u'servicemanager/last file', fileName)
self._saveLite = self._fileName.endswith(u'.oszl') self._saveLite = self._fileName.endswith(u'.oszl')
@ -384,8 +383,8 @@ class ServiceManager(QtGui.QWidget):
if not loadFile: if not loadFile:
fileName = QtGui.QFileDialog.getOpenFileName(self.mainwindow, fileName = QtGui.QFileDialog.getOpenFileName(self.mainwindow,
translate('OpenLP.ServiceManager', 'Open File'), translate('OpenLP.ServiceManager', 'Open File'),
SettingsManager.get_last_dir(self.mainwindow.serviceManagerSettingsSection), SettingsManager.get_last_dir(self.mainwindow.serviceManagerSettingsSection),
translate('OpenLP.ServiceManager', 'OpenLP Service Files (*.osz *.oszl)')) translate('OpenLP.ServiceManager', 'OpenLP Service Files (*.osz *.oszl)'))
if not fileName: if not fileName:
return False return False
else: else:
@ -703,7 +702,6 @@ class ServiceManager(QtGui.QWidget):
for item in items: for item in items:
self.mainwindow.incrementProgressBar() self.mainwindow.incrementProgressBar()
serviceItem = ServiceItem() serviceItem = ServiceItem()
serviceItem.renderer = self.mainwindow.renderer
if self._saveLite: if self._saveLite:
serviceItem.set_from_service(item) serviceItem.set_from_service(item)
else: else:
@ -812,7 +810,7 @@ class ServiceManager(QtGui.QWidget):
break break
self.themeMenu.menuAction().setVisible(False) self.themeMenu.menuAction().setVisible(False)
# Set up the theme menu. # 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) self.themeMenu.menuAction().setVisible(True)
# The service item does not have a theme, check the "Default". # The service item does not have a theme, check the "Default".
if serviceItem[u'service_item'].theme is None: if serviceItem[u'service_item'].theme is None:
@ -1197,7 +1195,7 @@ class ServiceManager(QtGui.QWidget):
""" """
log.debug(u'onThemeComboBoxSelected') log.debug(u'onThemeComboBoxSelected')
self.service_theme = self.themeComboBox.currentText() 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) Settings().setValue(self.mainwindow.serviceManagerSettingsSection + u'/service theme', self.service_theme)
self.regenerateServiceItems(True) self.regenerateServiceItems(True)
@ -1207,7 +1205,7 @@ class ServiceManager(QtGui.QWidget):
sure the theme combo box is in the correct state. sure the theme combo box is in the correct state.
""" """
log.debug(u'themeChange') log.debug(u'themeChange')
visible = self.mainwindow.renderer.theme_level == ThemeLevel.Global visible = self.renderer.theme_level == ThemeLevel.Global
self.themeLabel.setVisible(visible) self.themeLabel.setVisible(visible)
self.themeComboBox.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, themeGroup.addAction(create_widget_action(self.themeMenu, theme, text=theme, checked=False,
triggers=self.onThemeChangeAction)) triggers=self.onThemeChangeAction))
find_and_set_in_combo_box(self.themeComboBox, self.service_theme) 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() self.regenerateServiceItems()
def onThemeChangeAction(self): def onThemeChangeAction(self):
@ -1545,3 +1543,13 @@ class ServiceManager(QtGui.QWidget):
""" """
settingDialog = PrintServiceForm(self.mainwindow, self) settingDialog = PrintServiceForm(self.mainwindow, self)
settingDialog.exec_() 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)

View File

@ -34,14 +34,10 @@ from collections import deque
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.lib import OpenLPToolbar, Receiver, ItemCapabilities, \ from openlp.core.lib import OpenLPToolbar, Receiver, ItemCapabilities, translate, build_icon, build_html, \
translate, build_icon, build_html, PluginManager, ServiceItem, \ ServiceItem, ImageSource, SlideLimits, ServiceItemAction, Settings, Registry
ImageSource, SlideLimits, ServiceItemAction, Settings from openlp.core.ui import HideMode, MainDisplay, Display, ScreenList, DisplayControllerType
from openlp.core.ui import HideMode, MainDisplay, Display, ScreenList
from openlp.core.lib.ui import UiStrings, create_action 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 from openlp.core.utils.actions import ActionList, CategoryOrder
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -510,7 +506,7 @@ class SlideController(DisplayController):
# rebuild display as screen size changed # rebuild display as screen size changed
if self.display: if self.display:
self.display.close() self.display.close()
self.display = MainDisplay(self, self.imageManager, self.isLive, self) self.display = MainDisplay(self, self.isLive, self)
self.display.setup() self.display.setup()
if self.isLive: if self.isLive:
self.__addActionsToWidget(self.display) self.__addActionsToWidget(self.display)
@ -525,7 +521,7 @@ class SlideController(DisplayController):
self.previewDisplay.setup() self.previewDisplay.setup()
serviceItem = ServiceItem() serviceItem = ServiceItem()
self.previewDisplay.webView.setHtml(build_html(serviceItem, self.previewDisplay.screen, None, self.isLive, 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) self.mediaController.setup_display(self.previewDisplay,True)
if self.serviceItem: if self.serviceItem:
self.refreshServiceItem() self.refreshServiceItem()
@ -1283,3 +1279,13 @@ class SlideController(DisplayController):
def onTrackTriggered(self): def onTrackTriggered(self):
action = self.sender() action = self.sender()
self.display.audioPlayer.goTo(action.data()) 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)

View File

@ -37,7 +37,7 @@ from xml.etree.ElementTree import ElementTree, XML
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.lib import OpenLPToolbar, get_text_file_string, build_icon, Receiver, SettingsManager, translate, \ 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.theme import ThemeXML, BackgroundType, VerticalType, BackgroundGradientType
from openlp.core.lib.ui import UiStrings, critical_error_message_box, create_widget_action from openlp.core.lib.ui import UiStrings, critical_error_message_box, create_widget_action
from openlp.core.theme import Theme from openlp.core.theme import Theme
@ -52,6 +52,7 @@ class ThemeManager(QtGui.QWidget):
""" """
def __init__(self, mainwindow, parent=None): def __init__(self, mainwindow, parent=None):
QtGui.QWidget.__init__(self, parent) QtGui.QWidget.__init__(self, parent)
Registry().register(u'theme_manager', self)
self.mainwindow = mainwindow self.mainwindow = mainwindow
self.settingsSection = u'themes' self.settingsSection = u'themes'
self.themeForm = ThemeForm(self) self.themeForm = ThemeForm(self)
@ -261,11 +262,10 @@ class ThemeManager(QtGui.QWidget):
old_theme_data = self.getThemeData(old_theme_name) old_theme_data = self.getThemeData(old_theme_name)
self.cloneThemeData(old_theme_data, new_theme_name) self.cloneThemeData(old_theme_data, new_theme_name)
self.deleteTheme(old_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): if plugin.usesTheme(old_theme_name):
plugin.renameTheme(old_theme_name, new_theme_name) plugin.renameTheme(old_theme_name, new_theme_name)
self.mainwindow.renderer.update_theme( self.renderer.update_theme(new_theme_name, old_theme_name)
new_theme_name, old_theme_name)
self.loadThemes() self.loadThemes()
def onCopyTheme(self): def onCopyTheme(self):
@ -312,7 +312,7 @@ class ThemeManager(QtGui.QWidget):
self.themeForm.theme = theme self.themeForm.theme = theme
self.themeForm.exec_(True) self.themeForm.exec_(True)
self.oldBackgroundImage = None self.oldBackgroundImage = None
self.mainwindow.renderer.update_theme(theme.theme_name) self.renderer.update_theme(theme.theme_name)
self.loadThemes() self.loadThemes()
def onDeleteTheme(self): def onDeleteTheme(self):
@ -327,7 +327,7 @@ class ThemeManager(QtGui.QWidget):
row = self.themeListWidget.row(item) row = self.themeListWidget.row(item)
self.themeListWidget.takeItem(row) self.themeListWidget.takeItem(row)
self.deleteTheme(theme) 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 # As we do not reload the themes, push out the change. Reload the
# list as the internal lists and events need to be triggered. # list as the internal lists and events need to be triggered.
self._pushThemes() self._pushThemes()
@ -631,9 +631,9 @@ class ThemeManager(QtGui.QWidget):
""" """
self._writeTheme(theme, image_from, image_to) self._writeTheme(theme, image_from, image_to)
if theme.background_type == BackgroundType.to_string(BackgroundType.Image): 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)) ImageSource.Theme, QtGui.QColor(theme.background_border_color))
self.mainwindow.imageManager.processUpdates() self.image_manager.processUpdates()
def _writeTheme(self, theme, image_from, image_to): 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. Flag to tell message lines per page need to be generated.
""" """
log.debug(u'generateImage \n%s ', theme_data) 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): def getPreviewImage(self, theme):
""" """
@ -748,7 +748,7 @@ class ThemeManager(QtGui.QWidget):
return False return False
# check for use in the system else where. # check for use in the system else where.
if testPlugin: if testPlugin:
for plugin in self.mainwindow.pluginManager.plugins: for plugin in self.plugin_manager.plugins:
if plugin.usesTheme(theme): if plugin.usesTheme(theme):
critical_error_message_box(translate('OpenLP.ThemeManager', 'Validation Error'), critical_error_message_box(translate('OpenLP.ThemeManager', 'Validation Error'),
translate('OpenLP.ThemeManager', 'Theme %s is used in the %s plugin.') % 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 new_theme.display_vertical_align = vAlignCorrection
return new_theme.extract_xml() 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)