openlp/openlp/core/lib/htmlbuilder.py

276 lines
9.1 KiB
Python
Raw Normal View History

2010-07-11 10:58:36 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2010 Raoul Snyman #
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
2010-07-25 09:03:01 +00:00
# Gorven, Scott Guerrieri, Meinert Jordan, Andreas Preikschat, Christian #
# Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon Tibble, #
# Carsten Tinggaard, Frode Woldsund #
2010-07-11 10:58:36 +00:00
# --------------------------------------------------------------------------- #
# 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 #
###############################################################################
from openlp.core.lib import image_to_byte
HTMLSRC = u"""
<html>
<head>
<title>OpenLP Display</title>
<style>
*{
margin: 0;
padding:0
}
%s
%s
%s
%s
%s
2010-07-19 18:03:00 +00:00
%s
2010-07-24 16:55:06 +00:00
%s
2010-07-11 10:58:36 +00:00
</style>
<script language="javascript">
var t = null;
function startfade(newtext){
var text1 = document.getElementById('lyrics');
var text2 = document.getElementById('lyrics2');
if(text2.style.opacity==''||parseFloat(text2.style.opacity) < 0.5){
text2.innerHTML = text1.innerHTML;
text2.style.opacity = text1.style.opacity;
}
text1.style.opacity = 0;
text1.innerHTML = newtext;
if(t!=null)
clearTimeout(t);
t = setTimeout('fade()', 50);
}
function fade(){
var text1 = document.getElementById('lyrics');
var text2 = document.getElementById('lyrics2');
if(parseFloat(text1.style.opacity) < 1)
text1.style.opacity = parseFloat(text1.style.opacity) + 0.02;
if(parseFloat(text2.style.opacity) > 0)
text2.style.opacity = parseFloat(text2.style.opacity) - 0.02;
if((parseFloat(text1.style.opacity) < 1)||(parseFloat(text2.style.opacity) > 0))
t = setTimeout('fade()', 50);
}
</script>
</head>
<body>
<div id="lyrics" class="lyrics"></div>
2010-07-19 18:03:00 +00:00
<div id="footer" class="footer"></div>
2010-07-11 10:58:36 +00:00
<div id="alert"></div>
<video id="video"></video>
2010-07-24 16:55:06 +00:00
<blank id="blank"></blank>
2010-07-11 10:58:36 +00:00
%s
</body>
</html>
"""
2010-07-17 08:59:15 +00:00
def build_html(item, screen, alert):
2010-07-25 08:58:08 +00:00
"""
Build the full web paged structure for display
`item`
Service Item to be displayed
`screen`
Current display information
`alert`
Alert display display information
"""
2010-07-11 10:58:36 +00:00
width = screen[u'size'].width()
height = screen[u'size'].height()
2010-07-17 08:59:15 +00:00
html = HTMLSRC % (build_video(width, height),
build_image(width, height),
2010-07-24 16:55:06 +00:00
build_lyrics(item),
build_footer(item),
build_alert(width, alert),
2010-07-17 08:59:15 +00:00
build_image(width, height),
2010-07-24 16:55:06 +00:00
build_blank(width, height),
2010-07-17 08:59:15 +00:00
build_image_src(item.bg_frame))
2010-07-26 16:42:19 +00:00
print html
2010-07-11 10:58:36 +00:00
return html
2010-07-17 08:59:15 +00:00
def build_video(width, height):
2010-07-25 08:58:08 +00:00
"""
Build the video display div
`width`
Screen width
`height`
Screen height
"""
2010-07-11 10:58:36 +00:00
video = """
2010-07-26 16:42:19 +00:00
#video { position: absolute; left: 0px; top: 0px;
width: %spx; height: %spx; z-index:1; }
2010-07-11 10:58:36 +00:00
"""
2010-07-17 08:59:15 +00:00
return video % (width, height)
2010-07-24 16:55:06 +00:00
def build_blank(width, height):
2010-07-25 08:58:08 +00:00
"""
Build the blank display div
`width`
Screen width
`height`
Screen height
"""
2010-07-24 16:55:06 +00:00
blank = """
#blank {
position: absolute;
left: 0px;
top: 0px;
2010-07-26 16:42:19 +00:00
width: %spx;
2010-07-24 16:55:06 +00:00
height: %spx;
z-index:10;
}
"""
return blank % (width, height)
2010-07-11 10:58:36 +00:00
2010-07-17 08:59:15 +00:00
def build_image(width, height):
2010-07-25 08:58:08 +00:00
"""
Build the image display div
`width`
Screen width
`height`
Screen height
"""
2010-07-11 10:58:36 +00:00
image = """
#image {
position: absolute;
left: 0px;
top: 0px;
width: %spx;
height: %spx;
z-index:2;
}
"""
return image % (width, height)
2010-07-17 08:59:15 +00:00
def build_image_src(image):
2010-07-11 10:58:36 +00:00
# <img src="" height="480" width="640" />
image_src = """
2010-07-26 16:42:19 +00:00
<img src="data:image/png;base64,%s">
2010-07-11 10:58:36 +00:00
"""
2010-07-12 19:36:42 +00:00
return image_src % image_to_byte(image)
2010-07-11 10:58:36 +00:00
2010-07-24 16:55:06 +00:00
def build_lyrics(item):
2010-07-25 08:58:08 +00:00
"""
Build the video display div
`item`
Service Item containing theme and location information
"""
2010-07-11 10:58:36 +00:00
lyrics = """
2010-07-22 18:04:48 +00:00
#lyrics {position: absolute; %s z-index:3; %s; %s %s }
table {border=0;margin=0padding=0;}
2010-07-11 10:58:36 +00:00
"""
2010-07-17 08:59:15 +00:00
theme = item.themedata
2010-07-12 16:49:38 +00:00
lyrics_html = u''
2010-07-18 18:01:35 +00:00
position = u''
2010-07-22 18:04:48 +00:00
fontworks = u''
2010-07-18 18:01:35 +00:00
font = u''
text = u''
2010-07-12 16:49:38 +00:00
if theme:
2010-07-24 16:55:06 +00:00
position = u' left: %spx; top: %spx; width: %spx; height: %spx; ' % \
(item.main.x(), item.main.y(), item.main.width(),
item.main.height())
font = u' font-family %s; font-size: %spx;' % \
2010-07-18 18:01:35 +00:00
(theme.font_main_name, theme.font_main_proportion)
align = u''
if theme.display_horizontalAlign == 2:
align = u'align=center;'
elif theme.display_horizontalAlign == 1:
align = u'align=right;'
if theme.display_verticalAlign == 2:
valign = u'vertical-align=top;'
elif theme.display_verticalAlign == 1:
valign = u'vertical-align=middle;'
else:
valign = u'vertical-align=bottom;'
2010-07-19 18:03:00 +00:00
text = u'color:%s; %s %s' % (theme.font_main_color, align, valign)
2010-07-22 18:04:48 +00:00
if theme.display_shadow and theme.display_outline:
2010-07-24 16:55:06 +00:00
fontworks = u'text-shadow: -%spx 0 %s, 0 %spx %s, %spx 0 %s, 0 ' \
'-%spx %s, %spx %spx %spx %s' % \
2010-07-22 18:04:48 +00:00
(theme.display_outline_size, theme.display_outline_color,
theme.display_outline_size, theme.display_outline_color,
theme.display_outline_size, theme.display_outline_color,
theme.display_outline_size, theme.display_outline_color,
theme.display_shadow_size, theme.display_shadow_size,
theme.display_shadow_size, theme.display_shadow_color)
elif theme.display_shadow:
2010-07-24 16:55:06 +00:00
fontworks = u'text-shadow: %spx %spx %spx %s' % \
2010-07-19 18:03:00 +00:00
(theme.display_shadow_size, theme.display_shadow_size,
theme.display_shadow_size, theme.display_shadow_color)
2010-07-22 18:04:48 +00:00
elif theme.display_outline:
2010-07-24 16:55:06 +00:00
fontworks = u'text-shadow: -%spx 0 %s, 0 %spx %s,' \
' %spx 0 %s, 0 -%spx %s' % \
2010-07-22 18:04:48 +00:00
(theme.display_outline_size, theme.display_outline_color,
theme.display_outline_size, theme.display_outline_color,
theme.display_outline_size, theme.display_outline_color,
theme.display_outline_size, theme.display_outline_color)
lyrics_html = lyrics % (position, fontworks, font, text)
2010-07-19 18:03:00 +00:00
print lyrics_html
return lyrics_html
2010-07-24 16:55:06 +00:00
def build_footer(item):
2010-07-19 18:03:00 +00:00
lyrics = """
2010-07-20 05:01:40 +00:00
#footer {position: absolute; %s z-index:3; %s; %s }
2010-07-19 18:03:00 +00:00
"""
theme = item.themedata
lyrics_html = u''
position = u''
font = u''
text = u''
if theme:
2010-07-24 16:55:06 +00:00
position = u' left: %spx; top: %spx; width: %spx; height: %spx; ' % \
(item.footer.x(), item.footer.y(), item.footer.width(),
item.footer.height())
font = u' font-family %s; font-size: %spx;' % \
2010-07-19 18:03:00 +00:00
(theme.font_footer_name, theme.font_footer_proportion)
align = u''
if theme.display_horizontalAlign == 2:
align = u'align=center;'
elif theme.display_horizontalAlign == 1:
align = u'align=right;'
if theme.display_verticalAlign == 2:
valign = u'vertical-align=top;'
elif theme.display_verticalAlign == 1:
valign = u'vertical-align=middle;'
else:
valign = u'vertical-align=bottom;'
text = u'color:%s; %s %s' % (theme.font_footer_color, align, valign)
2010-07-20 05:01:40 +00:00
lyrics_html = lyrics % (position, font, text)
2010-07-17 08:59:15 +00:00
print lyrics_html
2010-07-12 16:49:38 +00:00
return lyrics_html
2010-07-11 10:58:36 +00:00
2010-07-19 18:03:00 +00:00
2010-07-27 18:42:53 +00:00
def build_alert(width, alertTab):
2010-07-11 10:58:36 +00:00
alert = """
2010-07-26 16:42:19 +00:00
#alert { position: absolute; left: 0px; top: 70px;
2010-07-27 18:42:53 +00:00
width: %spx; height: 10px; z-index:4; font-size: %spx;
2010-07-11 10:58:36 +00:00
}
#alert p {
2010-07-27 18:42:53 +00:00
background-color: %s;
2010-07-11 10:58:36 +00:00
}
"""
2010-07-27 18:42:53 +00:00
alertText = u''
if alertTab:
alertText = alert % (width, alertTab.font_size, alertTab.bg_color)
return alertText