Move the Alert web code back to the plugin

This commit is contained in:
Tim Bentley 2011-10-13 06:14:03 +01:00
parent e87b4658d8
commit bb8b0cd435
4 changed files with 102 additions and 40 deletions

View File

@ -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 {
<video id="video2" class="size" style="visibility:hidden" autobuffer preload>
</video>
%s
%s
<div id="footer" class="footer"></div>
<div id="black" class="size"></div>
<div id="alert" style="visibility:hidden"></div>
</body>
</html>
"""
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

View File

@ -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''

View File

@ -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')

View File

@ -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 = """
<div id="alert" style="visibility:hidden"></div>
"""
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