From bb8b0cd4351be15bf32454cfbf0e8d1b321cb8eb Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Thu, 13 Oct 2011 06:14:03 +0100 Subject: [PATCH] Move the Alert web code back to the plugin --- openlp/core/lib/htmlbuilder.py | 61 ++++++++++----------------- openlp/core/lib/plugin.py | 18 ++++++++ openlp/core/ui/maindisplay.py | 2 +- openlp/plugins/alerts/alertsplugin.py | 61 +++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 40 deletions(-) diff --git a/openlp/core/lib/htmlbuilder.py b/openlp/core/lib/htmlbuilder.py index 8e31d8950..bc571d04d 100644 --- a/openlp/core/lib/htmlbuilder.py +++ b/openlp/core/lib/htmlbuilder.py @@ -73,13 +73,7 @@ body { #video2 { z-index: 3; } -#alert { - position: absolute; - left: 0px; - top: 0px; - z-index: 10; - %s -} +%s #footer { position: absolute; z-index: 6; @@ -179,7 +173,7 @@ sup { break; } } - + %s function show_image(src){ var img = document.getElementById('image'); img.src = src; @@ -225,34 +219,6 @@ sup { } } - function show_alert(alerttext, position){ - var text = document.getElementById('alert'); - text.innerHTML = alerttext; - if(alerttext == '') { - text.style.visibility = 'hidden'; - return 0; - } - if(position == ''){ - position = getComputedStyle(text, '').verticalAlign; - } - switch(position) - { - case 'top': - text.style.top = '0px'; - break; - case 'middle': - text.style.top = ((window.innerHeight - text.clientHeight) / 2) - + 'px'; - break; - case 'bottom': - text.style.top = (window.innerHeight - text.clientHeight) - + 'px'; - break; - } - text.style.visibility = 'visible'; - return text.clientHeight; - } - function show_footer(footertext){ document.getElementById('footer').innerHTML = footertext; } @@ -316,14 +282,15 @@ sup { %s +%s
- """ -def build_html(item, screen, alert, islive, background, image=None): +def build_html(item, screen, alert, islive, background, image=None, + plugins=None): """ Build the full web paged structure for display @@ -344,6 +311,9 @@ def build_html(item, screen, alert, islive, background, image=None): ``image`` Image media item - bytes + + ``plugins`` + The List of available plugins """ width = screen[u'size'].width() height = screen[u'size'].height() @@ -360,14 +330,27 @@ def build_html(item, screen, alert, islive, background, image=None): image_src = u'src="data:image/png;base64,%s"' % image else: image_src = u'style="display:none;"' + css_additions = u'' + js_additions = u'' + html_additions = u'' + if plugins: + for plugin in plugins: + print plugin + css_additions += plugin.getDisplayCss() + js_additions += plugin.getDisplayJavaScript() + html_additions += plugin.getDisplayHtml() + print js_additions html = HTMLSRC % (build_background_css(item, width, height), width, height, - build_alert_css(alert, width), + css_additions, + #build_alert_css(alert, width), build_footer_css(item, height), build_lyrics_css(item, webkitvers), u'true' if theme and theme.display_slide_transition and islive \ else u'false', + js_additions, bgimage_src, image_src, + html_additions, build_lyrics_html(item, webkitvers)) return html diff --git a/openlp/core/lib/plugin.py b/openlp/core/lib/plugin.py index db7d4845b..358906d58 100644 --- a/openlp/core/lib/plugin.py +++ b/openlp/core/lib/plugin.py @@ -369,3 +369,21 @@ class Plugin(QtCore.QObject): """ self.textStrings[name] = {u'title': title, u'tooltip': tooltip} + def getDisplayCss(self): + """ + Add css style sheets to htmlbuilder + """ + return u'' + + def getDisplayJavaScript(self): + """ + Add javascript functions to htmlbuilder + """ + return u'' + + def getDisplayHtml(self): + """ + Add html code to htmlbuilder + """ + return u'' + diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index f3aed92cb..129b5a827 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -508,7 +508,7 @@ class MainDisplay(QtGui.QGraphicsView): else: image_bytes = None html = build_html(self.serviceItem, self.screen, self.alertTab, - self.isLive, background, image_bytes) + self.isLive, background, image_bytes, self.plugins) log.debug(u'buildHtml - pre setHtml') self.webView.setHtml(html) log.debug(u'buildHtml - post setHtml') diff --git a/openlp/plugins/alerts/alertsplugin.py b/openlp/plugins/alerts/alertsplugin.py index 21db1972a..c9adabca2 100644 --- a/openlp/plugins/alerts/alertsplugin.py +++ b/openlp/plugins/alerts/alertsplugin.py @@ -32,6 +32,7 @@ from PyQt4 import QtCore from openlp.core.lib import Plugin, StringContent, build_icon, translate from openlp.core.lib.db import Manager from openlp.core.lib.ui import icon_action, UiStrings +from openlp.core.lib.theme import VerticalType from openlp.core.utils.actions import ActionList from openlp.plugins.alerts.lib import AlertsManager, AlertsTab from openlp.plugins.alerts.lib.db import init_schema @@ -39,6 +40,54 @@ from openlp.plugins.alerts.forms import AlertForm log = logging.getLogger(__name__) +JAVASCRIPT = """ + function show_alert(alerttext, position){ + var text = document.getElementById('alert'); + text.innerHTML = alerttext; + if(alerttext == '') { + text.style.visibility = 'hidden'; + return 0; + } + if(position == ''){ + position = getComputedStyle(text, '').verticalAlign; + } + switch(position) + { + case 'top': + text.style.top = '0px'; + break; + case 'middle': + text.style.top = ((window.innerHeight - text.clientHeight) / 2) + + 'px'; + break; + case 'bottom': + text.style.top = (window.innerHeight - text.clientHeight) + + 'px'; + break; + } + text.style.visibility = 'visible'; + return text.clientHeight; + } +""" +CSS = """ + #alert { + position: absolute; + left: 0px; + top: 0px; + z-index: 10; + width: 100%%; + vertical-align: %s; + font-family: %s; + font-size: %spt; + color: %s; + background-color: %s; + } +""" + +HTML = """ + +""" + class AlertsPlugin(Plugin): log.info(u'Alerts Plugin loaded') @@ -121,3 +170,15 @@ class AlertsPlugin(Plugin): u'title': translate('AlertsPlugin', 'Alerts', 'container title') } + def getDisplayJavaScript(self): + return JAVASCRIPT + + def getDisplayCss(self): + align = VerticalType.Names[self.settings_tab.location] + alert = CSS % (align, self.settings_tab.font_face, + self.settings_tab.font_size, self.settings_tab.font_color, + self.settings_tab.bg_color) + return alert + + def getDisplayHtml(self): + return HTML