From 93bd032cd92b8bbf2d54bbe0937f9951d2be5e13 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Mon, 1 Jul 2013 08:47:20 +0200 Subject: [PATCH 01/14] html_builder clean up --- openlp/core/lib/htmlbuilder.py | 74 +++------------------------------- openlp/core/ui/maindisplay.py | 2 - 2 files changed, 5 insertions(+), 71 deletions(-) diff --git a/openlp/core/lib/htmlbuilder.py b/openlp/core/lib/htmlbuilder.py index d4e22b0dd..dbfb8537d 100644 --- a/openlp/core/lib/htmlbuilder.py +++ b/openlp/core/lib/htmlbuilder.py @@ -114,12 +114,6 @@ sup { document.getElementById('black').style.display = black; document.getElementById('lyricsmain').style.visibility = lyrics; document.getElementById('image').style.visibility = lyrics; - outline = document.getElementById('lyricsoutline') - if(outline != null) - outline.style.visibility = lyrics; - shadow = document.getElementById('lyricsshadow') - if(shadow != null) - shadow.style.visibility = lyrics; document.getElementById('footer').style.visibility = lyrics; } @@ -138,9 +132,6 @@ sup { */ var txt = document.getElementById('lyricsmain'); if(window.getComputedStyle(txt).textAlign == 'justify'){ - var outline = document.getElementById('lyricsoutline'); - if(outline != null) - txt = outline; if(window.getComputedStyle(txt).webkitTextStrokeWidth != '0px'){ new_text = new_text.replace(/(\s| )+(?![^<]*>)/g, function(match) { @@ -150,8 +141,6 @@ sup { } } text_fade('lyricsmain', new_text); - text_fade('lyricsoutline', new_text); - text_fade('lyricsshadow', new_text.replace(match, '')); } function text_fade(id, new_text){ @@ -190,7 +179,7 @@ sup { %s -%s +
@@ -251,8 +240,7 @@ def build_html(item, screen, is_live, background, image=None, plugins=None): u'true' if theme and theme.display_slide_transition and is_live else u'false', js_additions, bgimage_src, image_src, - html_additions, - build_lyrics_html(item, webkit_ver) + html_additions ) return html @@ -328,40 +316,17 @@ def build_lyrics_css(item, webkit_ver): %s } .lyricsmain { -%s -} -.lyricsoutline { -%s -} -.lyricsshadow { -%s + %s } """ theme = item.themedata lyricstable = u'' lyrics = u'' lyricsmain = u'' - outline = u'' - shadow = u'' if theme and item.main: lyricstable = u'left: %spx; top: %spx;' % (item.main.x(), item.main.y()) lyrics = build_lyrics_format_css(theme, item.main.width(), item.main.height()) - # For performance reasons we want to show as few DIV's as possible, especially when animating/transitions. - # However some bugs in older versions of qtwebkit mean we need to perform workarounds and add extra divs. Only - # do these when needed. - # - # Before 533.3 the webkit-text-fill colour wasn't displayed, only the stroke (outline) color. So put stroke - # layer underneath the main text. - # - # Up to 534.3 the webkit-text-stroke was sometimes out of alignment with the fill, or normal text. - # letter-spacing=1 is workaround https://bugs.webkit.org/show_bug.cgi?id=44403 - # - # Up to 534.3 the text-shadow didn't get displayed when webkit-text-stroke was used. So use an offset text - # layer underneath. https://bugs.webkit.org/show_bug.cgi?id=19728 - if webkit_ver >= 533.3: - lyricsmain += build_lyrics_outline_css(theme) - else: - outline = build_lyrics_outline_css(theme) + lyricsmain += build_lyrics_outline_css(theme) if theme.font_main_shadow: if theme.font_main_outline and webkit_ver <= 534.3: shadow = u'padding-left: %spx; padding-top: %spx;' % \ @@ -371,7 +336,7 @@ def build_lyrics_css(item, webkit_ver): else: lyricsmain += u' text-shadow: %s %spx %spx;' % \ (theme.font_main_shadow_color, theme.font_main_shadow_size, theme.font_main_shadow_size) - lyrics_css = style % (lyricstable, lyrics, lyricsmain, outline, shadow) + lyrics_css = style % (lyricstable, lyrics, lyricsmain) return lyrics_css @@ -431,9 +396,6 @@ def build_lyrics_format_css(theme, width, height): 'padding: 0; padding-bottom: %s; padding-left: %spx; width: %spx; height: %spx; ' % \ (justify, align, valign, theme.font_main_name, theme.font_main_size, theme.font_main_color, 100 + int(theme.font_main_line_adjustment), padding_bottom, left_margin, width, height) - if theme.font_main_outline: - if webkit_version() <= 534.3: - lyrics += u' letter-spacing: 1px;' if theme.font_main_italics: lyrics += u' font-style:italic; ' if theme.font_main_bold: @@ -441,32 +403,6 @@ def build_lyrics_format_css(theme, width, height): return lyrics -def build_lyrics_html(item, webkitvers): - """ - Build the HTML required to show the lyrics - - ``item`` - Service Item containing theme and location information - - ``webkitvers`` - The version of qtwebkit we're using - """ - # Bugs in some versions of QtWebKit mean we sometimes need additional divs for outline and shadow, since the CSS - # doesn't work. To support vertical alignment middle and bottom, nested div's using display:table/display:table-cell - # are required for each lyric block. - lyrics = u'' - theme = item.themedata - if webkitvers <= 534.3 and theme and theme.font_main_outline: - lyrics += u'
' - if webkitvers < 533.3: - lyrics += u'
' - lyrics += u'
' - return lyrics - - def build_footer_css(item, height): """ Build the display of the item footer diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index 7069cb9b7..91cd801e2 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -242,8 +242,6 @@ class MainDisplay(Display): # Windows if there are many items in the service to re-render. # Setting the div elements direct seems to solve the issue self.frame.findFirstElement("#lyricsmain").setInnerXml(slide) - self.frame.findFirstElement("#lyricsoutline").setInnerXml(slide) - self.frame.findFirstElement("#lyricsshadow").setInnerXml(slide) def alert(self, text, location): """ From 8ee3e7265c8c9f5d78fc6701172d23eb6c4d96b4 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Mon, 1 Jul 2013 08:57:13 +0200 Subject: [PATCH 02/14] renames --- openlp/core/lib/htmlbuilder.py | 82 ++++++++++++++-------------------- 1 file changed, 33 insertions(+), 49 deletions(-) diff --git a/openlp/core/lib/htmlbuilder.py b/openlp/core/lib/htmlbuilder.py index dbfb8537d..0606b84d0 100644 --- a/openlp/core/lib/htmlbuilder.py +++ b/openlp/core/lib/htmlbuilder.py @@ -211,8 +211,7 @@ def build_html(item, screen, is_live, background, image=None, plugins=None): """ width = screen[u'size'].width() height = screen[u'size'].height() - theme = item.themedata - webkit_ver = webkit_version() + theme_data = item.themedata # Image generated and poked in if background: bgimage_src = u'src="data:image/png;base64,%s"' % background @@ -236,10 +235,11 @@ def build_html(item, screen, is_live, background, image=None, plugins=None): build_background_css(item, width), css_additions, build_footer_css(item, height), - build_lyrics_css(item, webkit_ver), - u'true' if theme and theme.display_slide_transition and is_live else u'false', + build_lyrics_css(item), + u'true' if theme_data and theme_data.display_slide_transition and is_live else u'false', js_additions, - bgimage_src, image_src, + bgimage_src, + image_src, html_additions ) return html @@ -291,16 +291,13 @@ def build_background_css(item, width): return background -def build_lyrics_css(item, webkit_ver): +def build_lyrics_css(item): """ Build the lyrics display css ``item`` Service Item containing theme and location information - ``webkitvers`` - The version of qtwebkit we're using - """ style = u""" .lyricstable { @@ -319,55 +316,41 @@ def build_lyrics_css(item, webkit_ver): %s } """ - theme = item.themedata + theme_data = item.themedata lyricstable = u'' lyrics = u'' lyricsmain = u'' - if theme and item.main: + if theme_data and item.main: lyricstable = u'left: %spx; top: %spx;' % (item.main.x(), item.main.y()) - lyrics = build_lyrics_format_css(theme, item.main.width(), item.main.height()) - lyricsmain += build_lyrics_outline_css(theme) - if theme.font_main_shadow: - if theme.font_main_outline and webkit_ver <= 534.3: - shadow = u'padding-left: %spx; padding-top: %spx;' % \ - (int(theme.font_main_shadow_size) + (int(theme.font_main_outline_size) * 2), - theme.font_main_shadow_size) - shadow += build_lyrics_outline_css(theme, True) - else: - lyricsmain += u' text-shadow: %s %spx %spx;' % \ - (theme.font_main_shadow_color, theme.font_main_shadow_size, theme.font_main_shadow_size) + lyrics = build_lyrics_format_css(theme_data, item.main.width(), item.main.height()) + lyricsmain += build_lyrics_outline_css(theme_data) + if theme_data.font_main_shadow: + lyricsmain += u' text-shadow: %s %spx %spx;' % \ + (theme_data.font_main_shadow_color, theme_data.font_main_shadow_size, theme_data.font_main_shadow_size) lyrics_css = style % (lyricstable, lyrics, lyricsmain) return lyrics_css -def build_lyrics_outline_css(theme, is_shadow=False): +def build_lyrics_outline_css(theme_data): """ Build the css which controls the theme outline. Also used by renderer for splitting verses - ``theme`` + ``theme_data`` Object containing theme information - - ``is_shadow`` - If true, use the shadow colors instead """ - if theme.font_main_outline: - size = float(theme.font_main_outline_size) / 16 - if is_shadow: - fill_color = theme.font_main_shadow_color - outline_color = theme.font_main_shadow_color - else: - fill_color = theme.font_main_color - outline_color = theme.font_main_outline_color + if theme_data.font_main_outline: + size = float(theme_data.font_main_outline_size) / 16 + fill_color = theme_data.font_main_color + outline_color = theme_data.font_main_outline_color return u' -webkit-text-stroke: %sem %s; -webkit-text-fill-color: %s; ' % (size, outline_color, fill_color) - else: - return u'' + return u'' -def build_lyrics_format_css(theme, width, height): +def build_lyrics_format_css(theme_data, width, height): """ Build the css which controls the theme format. Also used by renderer for splitting verses - ``theme`` + ``theme_data`` Object containing theme information ``width`` @@ -376,17 +359,17 @@ def build_lyrics_format_css(theme, width, height): ``height`` Height of the lyrics block """ - align = HorizontalType.Names[theme.display_horizontal_align] - valign = VerticalType.Names[theme.display_vertical_align] - if theme.font_main_outline: - left_margin = int(theme.font_main_outline_size) * 2 + align = HorizontalType.Names[theme_data.display_horizontal_align] + valign = VerticalType.Names[theme_data.display_vertical_align] + if theme_data.font_main_outline: + left_margin = int(theme_data.font_main_outline_size) * 2 else: left_margin = 0 justify = u'white-space:pre-wrap;' # fix tag incompatibilities - if theme.display_horizontal_align == HorizontalType.Justify: + if theme_data.display_horizontal_align == HorizontalType.Justify: justify = u'' - if theme.display_vertical_align == VerticalType.Bottom: + if theme_data.display_vertical_align == VerticalType.Bottom: padding_bottom = u'0.5em' else: padding_bottom = u'0' @@ -394,11 +377,12 @@ def build_lyrics_format_css(theme, width, height): 'text-align: %s; vertical-align: %s; font-family: %s; ' \ 'font-size: %spt; color: %s; line-height: %d%%; margin: 0;' \ 'padding: 0; padding-bottom: %s; padding-left: %spx; width: %spx; height: %spx; ' % \ - (justify, align, valign, theme.font_main_name, theme.font_main_size, - theme.font_main_color, 100 + int(theme.font_main_line_adjustment), padding_bottom, left_margin, width, height) - if theme.font_main_italics: + (justify, align, valign, theme_data.font_main_name, theme_data.font_main_size, + theme_data.font_main_color, 100 + int(theme_data.font_main_line_adjustment), padding_bottom, + left_margin, width, height) + if theme_data.font_main_italics: lyrics += u' font-style:italic; ' - if theme.font_main_bold: + if theme_data.font_main_bold: lyrics += u' font-weight:bold; ' return lyrics From 6bba69bf880a0956d0efe2ac2eb85a9cf615c57e Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 5 Jul 2013 20:35:27 +0200 Subject: [PATCH 03/14] removed duplicate css --- openlp/core/ui/media/phononplayer.py | 47 ++++++++++------------------ 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/openlp/core/ui/media/phononplayer.py b/openlp/core/ui/media/phononplayer.py index 2a6eb77ba..35de76298 100644 --- a/openlp/core/ui/media/phononplayer.py +++ b/openlp/core/ui/media/phononplayer.py @@ -45,36 +45,22 @@ from openlp.core.ui.media.mediaplayer import MediaPlayer log = logging.getLogger(__name__) ADDITIONAL_EXT = { - u'audio/ac3': [u'.ac3'], - u'audio/flac': [u'.flac'], - u'audio/x-m4a': [u'.m4a'], - u'audio/midi': [u'.mid', u'.midi'], - u'audio/x-mp3': [u'.mp3'], - u'audio/mpeg': [u'.mp3', u'.mp2', u'.mpga', u'.mpega', u'.m4a'], - u'audio/qcelp': [u'.qcp'], - u'audio/x-wma': [u'.wma'], - u'audio/x-ms-wma': [u'.wma'], - u'video/x-flv': [u'.flv'], - u'video/x-matroska': [u'.mpv', u'.mkv'], - u'video/x-wmv': [u'.wmv'], - u'video/x-mpg': [u'.mpg'], - u'video/mpeg': [u'.mp4', u'.mts', u'.mov'], - u'video/x-ms-wmv': [u'.wmv']} - -VIDEO_CSS = u""" -#videobackboard { - z-index:3; - background-color: %(bgcolor)s; + u'audio/ac3': [u'.ac3'], + u'audio/flac': [u'.flac'], + u'audio/x-m4a': [u'.m4a'], + u'audio/midi': [u'.mid', u'.midi'], + u'audio/x-mp3': [u'.mp3'], + u'audio/mpeg': [u'.mp3', u'.mp2', u'.mpga', u'.mpega', u'.m4a'], + u'audio/qcelp': [u'.qcp'], + u'audio/x-wma': [u'.wma'], + u'audio/x-ms-wma': [u'.wma'], + u'video/x-flv': [u'.flv'], + u'video/x-matroska': [u'.mpv', u'.mkv'], + u'video/x-wmv': [u'.wmv'], + u'video/x-mpg': [u'.mpg'], + u'video/mpeg': [u'.mp4', u'.mts', u'.mov'], + u'video/x-ms-wmv': [u'.wmv'] } -#video1 { - background-color: %(bgcolor)s; - z-index:4; -} -#video2 { - background-color: %(bgcolor)s; - z-index:4; -} -""" class PhononPlayer(MediaPlayer): @@ -268,8 +254,7 @@ class PhononPlayer(MediaPlayer): """ Add css style sheets to htmlbuilder """ - background = QtGui.QColor(Settings().value(u'players/background color')).name() - return VIDEO_CSS % {u'bgcolor': background} + return u'' def get_info(self): """ From a5b517fbf0c823992f1fa536b40a316716536268 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Sun, 8 Sep 2013 12:30:14 +0200 Subject: [PATCH 04/14] started to write tests --- .../openlp_core_lib/test_htmlbuilder.py | 76 +++++++++++++++++++ .../openlp_core_lib/test_image_manager.py | 2 +- .../openlp_core_lib/test_serviceitem.py | 3 +- .../openlp_core_lib/test_settings.py | 6 +- 4 files changed, 82 insertions(+), 5 deletions(-) create mode 100644 tests/functional/openlp_core_lib/test_htmlbuilder.py diff --git a/tests/functional/openlp_core_lib/test_htmlbuilder.py b/tests/functional/openlp_core_lib/test_htmlbuilder.py new file mode 100644 index 000000000..0ddf2bd4b --- /dev/null +++ b/tests/functional/openlp_core_lib/test_htmlbuilder.py @@ -0,0 +1,76 @@ +""" +Package to test the openlp.core.lib.htmlbuilder module. +""" + +from unittest import TestCase +from mock import MagicMock + +from PyQt4 import QtCore + +from openlp.core.lib.htmlbuilder import build_footer_css, build_lyrics_outline_css + + +FOOTER_CSS = """ + left: 10px; + bottom: 0px; + width: 1260px; + font-family: Arial; + font-size: 12pt; + color: #FFFFFF; + text-align: left; + white-space: nowrap; + """ +OUTLINE_CSS = ' -webkit-text-stroke: 0.125em #000000; -webkit-text-fill-color: #FFFFFF; ' +LYRICS_CSS = 'white-space:pre-wrap; word-wrap: break-word; text-align: left; vertical-align: top; ' + \ + 'font-family: Arial; font-size: 40pt; color: #FFFFFF; line-height: 100%; margin: 0;padding: 0; ' + \ + 'padding-bottom: 0; padding-left: 0px; width: 1260px; height: 921px; ' + +class Htmbuilder(TestCase): + def build_html(self): + pass + + def build_background_css(self): + pass + + def build_lyrics_css_test(self): + """ + """ + item = MagicMock() + item.main = + item.themedata.font_main_shadow = + item.themedata.font_main_shadow_color = + item.themedata.font_main_shadow_size = + item.themedata.font_main_shadow = + assert LYRICS_CSS = build_lyrics_css(item), 'The lyrics css should be equal.' + + def build_lyrics_outline_css_test(self): + """ + Test the build_lyrics_outline_css() function + """ + theme_data = MagicMock() + theme_data.font_main_outline = True + theme_data.font_main_outline_size = 2 + theme_data.font_main_color = '#FFFFFF' + theme_data.font_main_outline_color = '#000000' + assert OUTLINE_CSS == build_lyrics_outline_css(theme_data), 'The outline css should be equal.' + + + def build_lyrics_format_css(self): + """ + Test the build_lyrics_format_css() function + """ + pass + + def build_footer_css_test(self): + """ + Test the build_footer_css() function + """ + # Create a theme. + item = MagicMock() + item.footer = QtCore.QRect(10, 921, 1260, 103) + item.themedata.font_footer_name = 'Arial' + item.themedata.font_footer_size = 12 + item.themedata.font_footer_color = '#FFFFFF' + height = 1024 + assert FOOTER_CSS == build_footer_css(item, height), 'The footer strings should be equal.' + diff --git a/tests/functional/openlp_core_lib/test_image_manager.py b/tests/functional/openlp_core_lib/test_image_manager.py index a1bc7624a..71adfe4e2 100644 --- a/tests/functional/openlp_core_lib/test_image_manager.py +++ b/tests/functional/openlp_core_lib/test_image_manager.py @@ -3,8 +3,8 @@ """ import os -from unittest import TestCase +from unittest import TestCase from PyQt4 import QtCore, QtGui from openlp.core.lib import Registry, ImageManager, ScreenList diff --git a/tests/functional/openlp_core_lib/test_serviceitem.py b/tests/functional/openlp_core_lib/test_serviceitem.py index c387d83ad..1db175713 100644 --- a/tests/functional/openlp_core_lib/test_serviceitem.py +++ b/tests/functional/openlp_core_lib/test_serviceitem.py @@ -6,11 +6,12 @@ import os import json import tempfile + from unittest import TestCase from mock import MagicMock, patch +from lxml import objectify, etree from openlp.core.lib import ItemCapabilities, ServiceItem, Registry -from lxml import objectify, etree VERSE = 'The Lord said to {r}Noah{/r}: \n'\ 'There\'s gonna be a {su}floody{/su}, {sb}floody{/sb}\n'\ diff --git a/tests/functional/openlp_core_lib/test_settings.py b/tests/functional/openlp_core_lib/test_settings.py index 444b206d6..30e8d960f 100644 --- a/tests/functional/openlp_core_lib/test_settings.py +++ b/tests/functional/openlp_core_lib/test_settings.py @@ -2,13 +2,13 @@ Package to test the openlp.core.lib.settings package. """ import os -from unittest import TestCase from tempfile import mkstemp -from openlp.core.lib import Settings - +from unittest import TestCase from PyQt4 import QtGui +from openlp.core.lib import Settings + class TestSettings(TestCase): """ From 0677e389c1fb151f4ed507bdf5007cf5d7054194 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 11 Sep 2013 15:00:34 +0200 Subject: [PATCH 05/14] doc --- openlp/core/lib/htmlbuilder.py | 366 ++++++++++++++++++ .../openlp_core_lib/test_htmlbuilder.py | 21 +- 2 files changed, 378 insertions(+), 9 deletions(-) diff --git a/openlp/core/lib/htmlbuilder.py b/openlp/core/lib/htmlbuilder.py index 4fbeab335..9cb69579b 100644 --- a/openlp/core/lib/htmlbuilder.py +++ b/openlp/core/lib/htmlbuilder.py @@ -26,7 +26,372 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### +""" +This module is responsible for generating the HTML for :class:`~openlp.core.ui.maindisplay`. The ``build_html`` function +is the function which has to be called from outside. The generated and returned HTML will look similar to this:: + + + + OpenLP Display + + + + + + + + + + + + + + +
+ +
+ + +""" import logging from PyQt4 import QtWebKit @@ -242,6 +607,7 @@ def build_html(item, screen, is_live, background, image=None, plugins=None): image_src, html_additions ) + print(html) return html diff --git a/tests/functional/openlp_core_lib/test_htmlbuilder.py b/tests/functional/openlp_core_lib/test_htmlbuilder.py index 0ddf2bd4b..ae6a96a23 100644 --- a/tests/functional/openlp_core_lib/test_htmlbuilder.py +++ b/tests/functional/openlp_core_lib/test_htmlbuilder.py @@ -3,11 +3,11 @@ Package to test the openlp.core.lib.htmlbuilder module. """ from unittest import TestCase -from mock import MagicMock +from mock import MagicMock, patch from PyQt4 import QtCore -from openlp.core.lib.htmlbuilder import build_footer_css, build_lyrics_outline_css +from openlp.core.lib.htmlbuilder import build_footer_css, build_lyrics_outline_css, build_lyrics_css FOOTER_CSS = """ @@ -35,13 +35,16 @@ class Htmbuilder(TestCase): def build_lyrics_css_test(self): """ """ - item = MagicMock() - item.main = - item.themedata.font_main_shadow = - item.themedata.font_main_shadow_color = - item.themedata.font_main_shadow_size = - item.themedata.font_main_shadow = - assert LYRICS_CSS = build_lyrics_css(item), 'The lyrics css should be equal.' + with patch('openlp.core.lib.htmlbuilder.build_lyrics_format_css') as mocked_method:# + mocked_method.return_value = '' + item = MagicMock() + item.main = + item.themedata.font_main_shadow = + item.themedata.font_main_shadow_color = + item.themedata.font_main_shadow_size = + item.themedata.font_main_shadow = + print(build_lyrics_css(item)) + assert LYRICS_CSS == build_lyrics_css(item), 'The lyrics css should be equal.' def build_lyrics_outline_css_test(self): """ From bf023ee20d79d34d979ed91b97c599db3f05b859 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 11 Sep 2013 15:30:23 +0200 Subject: [PATCH 06/14] more tests --- .../openlp_core_lib/test_htmlbuilder.py | 242 ++++++++++++++++-- 1 file changed, 220 insertions(+), 22 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_htmlbuilder.py b/tests/functional/openlp_core_lib/test_htmlbuilder.py index ae6a96a23..5e2ed0fa8 100644 --- a/tests/functional/openlp_core_lib/test_htmlbuilder.py +++ b/tests/functional/openlp_core_lib/test_htmlbuilder.py @@ -7,9 +7,168 @@ from mock import MagicMock, patch from PyQt4 import QtCore -from openlp.core.lib.htmlbuilder import build_footer_css, build_lyrics_outline_css, build_lyrics_css +from openlp.core.lib.htmlbuilder import build_html, build_background_css, build_lyrics_css, build_lyrics_outline_css, \ + build_lyrics_format_css, build_footer_css +BUILD_HTML = """ + + + +OpenLP Display + + + + + + +plugin HTML +
+ +
+ + +""" +BACKGROUND_CSS = """ +""" +LYRICS_CSS = 'white-space:pre-wrap; word-wrap: break-word; text-align: left; vertical-align: top; ' + \ + 'font-family: Arial; font-size: 40pt; color: #FFFFFF; line-height: 100%; margin: 0;padding: 0; ' + \ + 'padding-bottom: 0; padding-left: 0px; width: 1260px; height: 921px; ' +LYRICS_OUTLINE_CSS = ' -webkit-text-stroke: 0.125em #000000; -webkit-text-fill-color: #FFFFFF; ' +LYRICS_FORMAT_CSS = """ +""" FOOTER_CSS = """ left: 10px; bottom: 0px; @@ -20,45 +179,79 @@ FOOTER_CSS = """ text-align: left; white-space: nowrap; """ -OUTLINE_CSS = ' -webkit-text-stroke: 0.125em #000000; -webkit-text-fill-color: #FFFFFF; ' -LYRICS_CSS = 'white-space:pre-wrap; word-wrap: break-word; text-align: left; vertical-align: top; ' + \ - 'font-family: Arial; font-size: 40pt; color: #FFFFFF; line-height: 100%; margin: 0;padding: 0; ' + \ - 'padding-bottom: 0; padding-left: 0px; width: 1260px; height: 921px; ' + class Htmbuilder(TestCase): - def build_html(self): - pass - - def build_background_css(self): - pass - - def build_lyrics_css_test(self): + def build_html_test(self): """ + Test the build_html() function + """ + # GIVEN: Mocked arguments and function. + with patch('openlp.core.lib.htmlbuilder.build_background_css') as mocked_build_background_css, \ + patch('openlp.core.lib.htmlbuilder.build_footer_css') as mocked_build_footer_css, \ + patch('openlp.core.lib.htmlbuilder.build_lyrics_css') as mocked_build_lyrics_css: + # Mocked function. + mocked_build_background_css.return_value = '' + mocked_build_footer_css.return_value = 'dummy: dummy;' + mocked_build_lyrics_css.return_value = '' + # Mocked arguments. + item = MagicMock() + item.bg_image_bytes = None + screen = MagicMock() + is_live = False + background = None + plugin = MagicMock() + plugin.get_display_css = MagicMock(return_value='plugin CSS') + plugin.get_display_javascript = MagicMock(return_value='plugin JS') + plugin.get_display_html = MagicMock(return_value='plugin HTML') + plugins = [plugin] + + # WHEN: Create the html. + html = build_html(item, screen, is_live, background, plugins=plugins) + + # THEN: The returned html should match. + assert html == BUILD_HTML + + def build_background_css_tes(self): + """ + Test the build_background_css() function + """ + # THEN: The returned html should match. + pass + + def build_lyrics_css_tes(self): + """ + Test the build_lyrics_css() function """ with patch('openlp.core.lib.htmlbuilder.build_lyrics_format_css') as mocked_method:# mocked_method.return_value = '' item = MagicMock() - item.main = - item.themedata.font_main_shadow = - item.themedata.font_main_shadow_color = - item.themedata.font_main_shadow_size = - item.themedata.font_main_shadow = - print(build_lyrics_css(item)) +# item.main = +# item.themedata.font_main_shadow = +# item.themedata.font_main_shadow_color = +# item.themedata.font_main_shadow_size = +# item.themedata.font_main_shadow = + assert LYRICS_CSS == build_lyrics_css(item), 'The lyrics css should be equal.' def build_lyrics_outline_css_test(self): """ Test the build_lyrics_outline_css() function """ + # GIVEN: The mocked theme data. theme_data = MagicMock() theme_data.font_main_outline = True theme_data.font_main_outline_size = 2 theme_data.font_main_color = '#FFFFFF' theme_data.font_main_outline_color = '#000000' - assert OUTLINE_CSS == build_lyrics_outline_css(theme_data), 'The outline css should be equal.' + # WHEN: Create the css. + css = build_lyrics_outline_css(theme_data) - def build_lyrics_format_css(self): + # THEN: The css should be equal. + assert LYRICS_OUTLINE_CSS == css, 'The outline css should be equal.' + + def build_lyrics_format_css_tes(self): """ Test the build_lyrics_format_css() function """ @@ -68,12 +261,17 @@ class Htmbuilder(TestCase): """ Test the build_footer_css() function """ - # Create a theme. + # GIVEN: Create a theme. item = MagicMock() item.footer = QtCore.QRect(10, 921, 1260, 103) item.themedata.font_footer_name = 'Arial' item.themedata.font_footer_size = 12 item.themedata.font_footer_color = '#FFFFFF' height = 1024 - assert FOOTER_CSS == build_footer_css(item, height), 'The footer strings should be equal.' + + # WHEN: create the css. + css = build_footer_css(item, height) + + # THEN: THE css should be the same. + assert FOOTER_CSS == css,'The footer strings should be equal.' From fea4893f406a08d7d115c3072416cf0481e24076 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 11 Sep 2013 15:30:59 +0200 Subject: [PATCH 07/14] removed pritn --- openlp/core/lib/htmlbuilder.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openlp/core/lib/htmlbuilder.py b/openlp/core/lib/htmlbuilder.py index 9cb69579b..89aa8f43c 100644 --- a/openlp/core/lib/htmlbuilder.py +++ b/openlp/core/lib/htmlbuilder.py @@ -607,7 +607,6 @@ def build_html(item, screen, is_live, background, image=None, plugins=None): image_src, html_additions ) - print(html) return html From f24f3a751ffd6ed901b8869bb760b0d3560c544b Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 11 Sep 2013 15:51:49 +0200 Subject: [PATCH 08/14] more tests --- openlp/core/lib/htmlbuilder.py | 2 +- .../openlp_core_lib/test_htmlbuilder.py | 46 +++++++++++++------ 2 files changed, 34 insertions(+), 14 deletions(-) diff --git a/openlp/core/lib/htmlbuilder.py b/openlp/core/lib/htmlbuilder.py index 89aa8f43c..5b998ce92 100644 --- a/openlp/core/lib/htmlbuilder.py +++ b/openlp/core/lib/htmlbuilder.py @@ -680,7 +680,7 @@ def build_lyrics_css(item): .lyricsmain { %s } - """ +""" theme_data = item.themedata lyricstable = '' lyrics = '' diff --git a/tests/functional/openlp_core_lib/test_htmlbuilder.py b/tests/functional/openlp_core_lib/test_htmlbuilder.py index 5e2ed0fa8..f007665ad 100644 --- a/tests/functional/openlp_core_lib/test_htmlbuilder.py +++ b/tests/functional/openlp_core_lib/test_htmlbuilder.py @@ -163,9 +163,23 @@ plugin HTML """ BACKGROUND_CSS = """ """ -LYRICS_CSS = 'white-space:pre-wrap; word-wrap: break-word; text-align: left; vertical-align: top; ' + \ - 'font-family: Arial; font-size: 40pt; color: #FFFFFF; line-height: 100%; margin: 0;padding: 0; ' + \ - 'padding-bottom: 0; padding-left: 0px; width: 1260px; height: 921px; ' +LYRICS_CSS = """ +.lyricstable { + z-index: 5; + position: absolute; + display: table; + left: 10px; top: 20px; +} +.lyricscell { + display: table-cell; + word-wrap: break-word; + -webkit-transition: opacity 0.4s ease; + lyrics_format_css +} +.lyricsmain { + text-shadow: #000000 5px 5px; +} +""" LYRICS_OUTLINE_CSS = ' -webkit-text-stroke: 0.125em #000000; -webkit-text-fill-color: #FFFFFF; ' LYRICS_FORMAT_CSS = """ """ @@ -219,20 +233,26 @@ class Htmbuilder(TestCase): # THEN: The returned html should match. pass - def build_lyrics_css_tes(self): + def build_lyrics_css_test(self): """ Test the build_lyrics_css() function """ - with patch('openlp.core.lib.htmlbuilder.build_lyrics_format_css') as mocked_method:# - mocked_method.return_value = '' + # GIVEN: Mocked method and arguments. + with patch('openlp.core.lib.htmlbuilder.build_lyrics_format_css') as mocked_build_lyrics_format_css, \ + patch('openlp.core.lib.htmlbuilder.build_lyrics_outline_css') as mocked_build_lyrics_outline_css: + mocked_build_lyrics_format_css.return_value = 'lyrics_format_css' + mocked_build_lyrics_outline_css.return_value = '' item = MagicMock() -# item.main = -# item.themedata.font_main_shadow = -# item.themedata.font_main_shadow_color = -# item.themedata.font_main_shadow_size = -# item.themedata.font_main_shadow = + item.main = QtCore.QRect(10, 20, 10, 20) + item.themedata.font_main_shadow = True + item.themedata.font_main_shadow_color = '#000000' + item.themedata.font_main_shadow_size = 5 - assert LYRICS_CSS == build_lyrics_css(item), 'The lyrics css should be equal.' + # WHEN: Create the css. + css = build_lyrics_css(item) + + # THEN: The css should be equal. + assert LYRICS_CSS == css, 'The lyrics css should be equal.' def build_lyrics_outline_css_test(self): """ @@ -273,5 +293,5 @@ class Htmbuilder(TestCase): css = build_footer_css(item, height) # THEN: THE css should be the same. - assert FOOTER_CSS == css,'The footer strings should be equal.' + assert FOOTER_CSS == css, 'The footer strings should be equal.' From 1ca117532fd7823d1add1b95b221e0eeda319dcc Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 11 Sep 2013 16:02:17 +0200 Subject: [PATCH 09/14] more tests --- .../openlp_core_lib/test_htmlbuilder.py | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_htmlbuilder.py b/tests/functional/openlp_core_lib/test_htmlbuilder.py index f007665ad..157bfca86 100644 --- a/tests/functional/openlp_core_lib/test_htmlbuilder.py +++ b/tests/functional/openlp_core_lib/test_htmlbuilder.py @@ -161,8 +161,7 @@ plugin HTML """ -BACKGROUND_CSS = """ -""" +BACKGROUND_CSS_RADIAL = 'background: -webkit-gradient(radial, 5 50%, 100, 5 50%, 5, from(#000000), to(#FFFFFF)) fixed' LYRICS_CSS = """ .lyricstable { z-index: 5; @@ -226,12 +225,21 @@ class Htmbuilder(TestCase): # THEN: The returned html should match. assert html == BUILD_HTML - def build_background_css_tes(self): + def build_background_css_radial_test(self): """ - Test the build_background_css() function + Test the build_background_css() function with a radial background """ - # THEN: The returned html should match. - pass + # GIVEN: Mocked arguments. + item = MagicMock() + item.themedata.background_start_color = '#000000' + item.themedata.background_end_color = '#FFFFFF' + width = 10 + + # WHEN: Create the css. + css = build_background_css(item, width) + + # THEN: The returned css should match. + assert BACKGROUND_CSS_RADIAL == css, 'The background css should be equal.' def build_lyrics_css_test(self): """ From 4999ecb6e6147cc0afb69ea0b2576c444344e9da Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 11 Sep 2013 16:22:28 +0200 Subject: [PATCH 10/14] last test --- openlp/core/lib/htmlbuilder.py | 4 +-- .../openlp_core_lib/test_htmlbuilder.py | 28 ++++++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/openlp/core/lib/htmlbuilder.py b/openlp/core/lib/htmlbuilder.py index 5b998ce92..07a83f336 100644 --- a/openlp/core/lib/htmlbuilder.py +++ b/openlp/core/lib/htmlbuilder.py @@ -746,9 +746,9 @@ def build_lyrics_format_css(theme_data, width, height): theme_data.font_main_color, 100 + int(theme_data.font_main_line_adjustment), padding_bottom, left_margin, width, height) if theme_data.font_main_italics: - lyrics += ' font-style:italic; ' + lyrics += 'font-style:italic; ' if theme_data.font_main_bold: - lyrics += ' font-weight:bold; ' + lyrics += 'font-weight:bold; ' return lyrics diff --git a/tests/functional/openlp_core_lib/test_htmlbuilder.py b/tests/functional/openlp_core_lib/test_htmlbuilder.py index 157bfca86..1cde4d8ba 100644 --- a/tests/functional/openlp_core_lib/test_htmlbuilder.py +++ b/tests/functional/openlp_core_lib/test_htmlbuilder.py @@ -9,6 +9,7 @@ from PyQt4 import QtCore from openlp.core.lib.htmlbuilder import build_html, build_background_css, build_lyrics_css, build_lyrics_outline_css, \ build_lyrics_format_css, build_footer_css +from openlp.core.lib.theme import HorizontalType, VerticalType BUILD_HTML = """ @@ -180,8 +181,10 @@ LYRICS_CSS = """ } """ LYRICS_OUTLINE_CSS = ' -webkit-text-stroke: 0.125em #000000; -webkit-text-fill-color: #FFFFFF; ' -LYRICS_FORMAT_CSS = """ -""" +LYRICS_FORMAT_CSS = ' word-wrap: break-word; text-align: justify; vertical-align: bottom; ' + \ + 'font-family: Arial; font-size: 40pt; color: #FFFFFF; line-height: 108%; margin: 0;padding: 0; ' + \ + 'padding-bottom: 0.5em; padding-left: 2px; width: 1580px; height: 810px; font-style:italic; font-weight:bold; ' + FOOTER_CSS = """ left: 10px; bottom: 0px; @@ -279,11 +282,28 @@ class Htmbuilder(TestCase): # THEN: The css should be equal. assert LYRICS_OUTLINE_CSS == css, 'The outline css should be equal.' - def build_lyrics_format_css_tes(self): + def build_lyrics_format_css_test(self): """ Test the build_lyrics_format_css() function """ - pass + # GIVEN: Mocked arguments. + theme_data = MagicMock() + theme_data.display_horizontal_align = HorizontalType.Justify + theme_data.display_vertical_align = VerticalType.Bottom + theme_data.font_main_name = 'Arial' + theme_data.font_main_size = 40 + theme_data.font_main_color = '#FFFFFF' + theme_data.font_main_italics = True + theme_data.font_main_bold = True + theme_data.font_main_line_adjustment = 8 + width = 1580 + height = 810 + + # WHEN: Get the css. + css = build_lyrics_format_css(theme_data, width, height) + + # THEN: They should be equal. + assert LYRICS_FORMAT_CSS == css, 'The lyrics format css should be equal.' def build_footer_css_test(self): """ From f1009fbc18487268575fdcab35c7cfd4545c5d20 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 11 Sep 2013 16:23:32 +0200 Subject: [PATCH 11/14] blank --- tests/functional/openlp_core_lib/test_htmlbuilder.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/functional/openlp_core_lib/test_htmlbuilder.py b/tests/functional/openlp_core_lib/test_htmlbuilder.py index 1cde4d8ba..3daf36a44 100644 --- a/tests/functional/openlp_core_lib/test_htmlbuilder.py +++ b/tests/functional/openlp_core_lib/test_htmlbuilder.py @@ -184,7 +184,6 @@ LYRICS_OUTLINE_CSS = ' -webkit-text-stroke: 0.125em #000000; -webkit-text-fill-c LYRICS_FORMAT_CSS = ' word-wrap: break-word; text-align: justify; vertical-align: bottom; ' + \ 'font-family: Arial; font-size: 40pt; color: #FFFFFF; line-height: 108%; margin: 0;padding: 0; ' + \ 'padding-bottom: 0.5em; padding-left: 2px; width: 1580px; height: 810px; font-style:italic; font-weight:bold; ' - FOOTER_CSS = """ left: 10px; bottom: 0px; From ffe0ccb625f13ab974634b5ff61837a08af71641 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Wed, 11 Sep 2013 17:08:08 +0200 Subject: [PATCH 12/14] clean up --- tests/functional/openlp_core_lib/test_htmlbuilder.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_htmlbuilder.py b/tests/functional/openlp_core_lib/test_htmlbuilder.py index 3daf36a44..ec8e3a4a3 100644 --- a/tests/functional/openlp_core_lib/test_htmlbuilder.py +++ b/tests/functional/openlp_core_lib/test_htmlbuilder.py @@ -12,7 +12,7 @@ from openlp.core.lib.htmlbuilder import build_html, build_background_css, build_ from openlp.core.lib.theme import HorizontalType, VerticalType -BUILD_HTML = """ +HTML = """ @@ -225,7 +225,7 @@ class Htmbuilder(TestCase): html = build_html(item, screen, is_live, background, plugins=plugins) # THEN: The returned html should match. - assert html == BUILD_HTML + assert html == HTML def build_background_css_radial_test(self): """ From 2b3825eaf0a597fc473a333f31937bb93f93c972 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 11 Oct 2013 12:13:04 +0200 Subject: [PATCH 13/14] missing imports --- tests/functional/openlp_core_lib/test_serviceitem.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/functional/openlp_core_lib/test_serviceitem.py b/tests/functional/openlp_core_lib/test_serviceitem.py index 60698ed88..6893b8ca3 100644 --- a/tests/functional/openlp_core_lib/test_serviceitem.py +++ b/tests/functional/openlp_core_lib/test_serviceitem.py @@ -36,6 +36,8 @@ from unittest import TestCase from tests.functional import MagicMock, patch from tests.utils import assert_length, convert_file_service_item +from openlp.core.lib import ItemCapabilities, ServiceItem, Registry + VERSE = 'The Lord said to {r}Noah{/r}: \n'\ 'There\'s gonna be a {su}floody{/su}, {sb}floody{/sb}\n'\ From 29bdf095d3972e7acd588c21e210375b17c4bc92 Mon Sep 17 00:00:00 2001 From: Andreas Preikschat Date: Fri, 11 Oct 2013 12:15:09 +0200 Subject: [PATCH 14/14] removed import --- tests/functional/openlp_core_lib/test_settings.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/functional/openlp_core_lib/test_settings.py b/tests/functional/openlp_core_lib/test_settings.py index f9c3dd87c..6836ce0e8 100644 --- a/tests/functional/openlp_core_lib/test_settings.py +++ b/tests/functional/openlp_core_lib/test_settings.py @@ -35,8 +35,6 @@ from tempfile import mkstemp from unittest import TestCase from PyQt4 import QtGui -from PyQt4 import QtGui - from openlp.core.lib import Settings