htmlbuilder: code standards

This commit is contained in:
Andreas Preikschat 2013-03-01 11:50:41 +01:00
parent 0086d102bd
commit a6617825ef

View File

@ -269,8 +269,7 @@ def build_html(item, screen, is_live, background, image=None, plugins=None):
def webkit_version(): def webkit_version():
""" """
Return the Webkit version in use. Return the Webkit version in use. Note method added relatively recently, so return 0 if prior to this
Note method added relatively recently, so return 0 if prior to this
""" """
try: try:
webkit_ver = float(QtWebKit.qWebKitVersion()) webkit_ver = float(QtWebKit.qWebKitVersion())
@ -286,7 +285,6 @@ def build_background_css(item, width, height):
``item`` ``item``
Service Item containing theme and location information Service Item containing theme and location information
""" """
width = int(width) / 2 width = int(width) / 2
theme = item.themedata theme = item.themedata
@ -357,21 +355,18 @@ def build_lyrics_css(item, webkit_ver):
if theme and item.main: if theme and item.main:
lyricstable = u'left: %spx; top: %spx;' % (item.main.x(), item.main.y()) lyricstable = u'left: %spx; top: %spx;' % (item.main.x(), item.main.y())
lyrics = build_lyrics_format_css(theme, item.main.width(), item.main.height()) 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, # For performance reasons we want to show as few DIV's as possible, especially when animating/transitions.
# especially when animating/transitions. # However some bugs in older versions of qtwebkit mean we need to perform workarounds and add extra divs. Only
# However some bugs in older versions of qtwebkit mean we need to # do these when needed.
# perform workarounds and add extra divs. Only do these when needed.
# #
# Before 533.3 the webkit-text-fill colour wasn't displayed, only the # Before 533.3 the webkit-text-fill colour wasn't displayed, only the stroke (outline) color. So put stroke
# stroke (outline) color. So put stroke layer underneath the main text. # layer underneath the main text.
# #
# Up to 534.3 the webkit-text-stroke was sometimes out of alignment # Up to 534.3 the webkit-text-stroke was sometimes out of alignment with the fill, or normal text.
# with the fill, or normal text. letter-spacing=1 is workaround # letter-spacing=1 is workaround https://bugs.webkit.org/show_bug.cgi?id=44403
# https://bugs.webkit.org/show_bug.cgi?id=44403
# #
# Up to 534.3 the text-shadow didn't get displayed when # Up to 534.3 the text-shadow didn't get displayed when webkit-text-stroke was used. So use an offset text
# webkit-text-stroke was used. So use an offset text layer underneath. # layer underneath. https://bugs.webkit.org/show_bug.cgi?id=19728
# https://bugs.webkit.org/show_bug.cgi?id=19728
if webkit_ver >= 533.3: if webkit_ver >= 533.3:
lyricsmain += build_lyrics_outline_css(theme) lyricsmain += build_lyrics_outline_css(theme)
else: else:
@ -380,20 +375,18 @@ def build_lyrics_css(item, webkit_ver):
if theme.font_main_outline and webkit_ver <= 534.3: if theme.font_main_outline and webkit_ver <= 534.3:
shadow = u'padding-left: %spx; padding-top: %spx;' % \ shadow = u'padding-left: %spx; padding-top: %spx;' % \
(int(theme.font_main_shadow_size) + (int(theme.font_main_outline_size) * 2), (int(theme.font_main_shadow_size) + (int(theme.font_main_outline_size) * 2),
theme.font_main_shadow_size) theme.font_main_shadow_size)
shadow += build_lyrics_outline_css(theme, True) shadow += build_lyrics_outline_css(theme, True)
else: else:
lyricsmain += u' text-shadow: %s %spx %spx;' % \ lyricsmain += u' text-shadow: %s %spx %spx;' % \
(theme.font_main_shadow_color, theme.font_main_shadow_size, (theme.font_main_shadow_color, theme.font_main_shadow_size, theme.font_main_shadow_size)
theme.font_main_shadow_size)
lyrics_css = style % (lyricstable, lyrics, lyricsmain, outline, shadow) lyrics_css = style % (lyricstable, lyrics, lyricsmain, outline, shadow)
return lyrics_css return lyrics_css
def build_lyrics_outline_css(theme, is_shadow=False): def build_lyrics_outline_css(theme, is_shadow=False):
""" """
Build the css which controls the theme outline Build the css which controls the theme outline. Also used by renderer for splitting verses
Also used by renderer for splitting verses
``theme`` ``theme``
Object containing theme information Object containing theme information
@ -416,8 +409,7 @@ def build_lyrics_outline_css(theme, is_shadow=False):
def build_lyrics_format_css(theme, width, height): def build_lyrics_format_css(theme, width, height):
""" """
Build the css which controls the theme format Build the css which controls the theme format. Also used by renderer for splitting verses
Also used by renderer for splitting verses
``theme`` ``theme``
Object containing theme information Object containing theme information
@ -427,7 +419,6 @@ def build_lyrics_format_css(theme, width, height):
``height`` ``height``
Height of the lyrics block Height of the lyrics block
""" """
align = HorizontalType.Names[theme.display_horizontal_align] align = HorizontalType.Names[theme.display_horizontal_align]
valign = VerticalType.Names[theme.display_vertical_align] valign = VerticalType.Names[theme.display_vertical_align]
@ -469,22 +460,18 @@ def build_lyrics_html(item, webkitvers):
``webkitvers`` ``webkitvers``
The version of qtwebkit we're using The version of qtwebkit we're using
""" """
# Bugs in some versions of QtWebKit mean we sometimes need additional # Bugs in some versions of QtWebKit mean we sometimes need additional divs for outline and shadow, since the CSS
# divs for outline and shadow, since the CSS doesn't work. # doesn't work. To support vertical alignment middle and bottom, nested div's using display:table/display:table-cell
# To support vertical alignment middle and bottom, nested div's using # are required for each lyric block.
# display:table/display:table-cell are required for each lyric block.
lyrics = u'' lyrics = u''
theme = item.themedata theme = item.themedata
if webkitvers <= 534.3 and theme and theme.font_main_outline: if webkitvers <= 534.3 and theme and theme.font_main_outline:
lyrics += u'<div class="lyricstable">' \ lyrics += u'<div class="lyricstable"><div id="lyricsshadow" style="opacity:1" ' \
u'<div id="lyricsshadow" style="opacity:1" ' \
u'class="lyricscell lyricsshadow"></div></div>' u'class="lyricscell lyricsshadow"></div></div>'
if webkitvers < 533.3: if webkitvers < 533.3:
lyrics += u'<div class="lyricstable">' \ lyrics += u'<div class="lyricstable"><div id="lyricsoutline" style="opacity:1" ' \
u'<div id="lyricsoutline" style="opacity:1" ' \
u'class="lyricscell lyricsoutline"></div></div>' u'class="lyricscell lyricsoutline"></div></div>'
lyrics += u'<div class="lyricstable">' \ lyrics += u'<div class="lyricstable"><div id="lyricsmain" style="opacity:1" ' \
u'<div id="lyricsmain" style="opacity:1" ' \
u'class="lyricscell lyricsmain"></div></div>' u'class="lyricscell lyricsmain"></div></div>'
return lyrics return lyrics