From 51f35dc9ce625c017731cc339110e0ed6da9ea0e Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Mon, 9 Aug 2010 22:21:04 +0100 Subject: [PATCH] Alerts over presentations + tidyups --- openlp/core/lib/htmlbuilder.py | 320 +++++++++++++++------------------ openlp/core/ui/maindisplay.py | 66 ++++--- 2 files changed, 178 insertions(+), 208 deletions(-) diff --git a/openlp/core/lib/htmlbuilder.py b/openlp/core/lib/htmlbuilder.py index b763b7b2d..a182edaf6 100644 --- a/openlp/core/lib/htmlbuilder.py +++ b/openlp/core/lib/htmlbuilder.py @@ -33,33 +33,60 @@ HTMLSRC = u""" +
@@ -239,18 +280,11 @@ body {
- - -
-%s + +
+ """ @@ -269,79 +303,17 @@ def build_html(item, screen, alert): width = screen[u'size'].width() height = screen[u'size'].height() theme = item.themedata - html = HTMLSRC % (build_video(width, height), - build_image(width, height), - build_lyrics(item), - build_footer(item), - build_alert(width, height, alert), - build_image(width, height), - build_black(width, height), - "true" if theme and - theme.display_slideTransition else "false", - build_image_src(item.bg_frame)) - return html - -def build_video(width, height): - """ - Build the video display div - - `width` - Screen width - `height` - Screen height - """ - video = """ - #video { position: absolute; left: 0px; top: 0px; - width: %spx; height: %spx; z-index:2; } - """ - return video % (width, height) - -def build_black(width, height): - """ - Build the black display div - - `width` - Screen width - `height` - Screen height - """ - black = """ - #black { position: absolute; left: 0px; top: 0px; - width: %spx; height: %spx; z-index:8; - background-color: black; display: none; - } - """ - return black % (width, height) - -def build_image(width, height): - """ - Build the image display div - - `width` - Screen width - `height` - Screen height - """ - image = """ - #image { position: absolute; left: 0px; top: 0px; - width: %spx; height: %spx; z-index:1; - } - """ - return image % (width, height) - -def build_image_src(image): - """ - Build display for the backgroung image - - `image` - Image to be displayed - """ - if image: - return '' % \ - image_to_byte(image) + if item.bg_frame: + image = u'data:image/png;base64,%s' % image_to_byte(item.bg_frame) else: - return '' - + image = u'' + html = HTMLSRC % (width, height, + build_alert(alert, width), + build_footer(item), + build_lyrics(item), + u'true' if theme and theme.display_slideTransition else u'false', + image) + return html def build_lyrics(item): """ @@ -358,7 +330,6 @@ def build_lyrics(item): .lyrics { %s } .lyricsoutline { %s } .lyricsshadow { %s } - table {border=0; margin=0; padding=0; } """ theme = item.themedata lyricscommon = u'' @@ -408,7 +379,6 @@ def build_lyrics(item): shadow = u'color: %s;' % (theme.display_shadow_color) lyrics_html = style % (lyricscommon, lyricstable, outlinetable, shadowtable, lyrics, outline, shadow) - print lyrics_html return lyrics_html def build_footer(item): @@ -418,64 +388,54 @@ def build_footer(item): `item` Service Item to be processed. """ - lyrics = """ - #footer {position: absolute; %s z-index:5; %s; %s } + style = """ + left: %spx; + top: %spx; + width: %spx; + height: %spx; + font-family: %s; + font-size: %spx; + color: %s; + align: %s; """ theme = item.themedata - lyrics_html = u'' - position = u'' - font = u'' - text = u'' - if theme: - 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;' % \ - (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;' - text = u'color:%s; %s ' % (theme.font_footer_color, align) - lyrics_html = lyrics % (position, font, text) + if not theme: + return u'' + if theme.display_horizontalAlign == 2: + align = u'center' + elif theme.display_horizontalAlign == 1: + align = u'right' + else: + align = u'left' + lyrics_html = style % (item.footer.x(), item.footer.y(), + item.footer.width(), item.footer.height(), theme.font_footer_name, + theme.font_footer_proportion, theme.font_footer_color, align) return lyrics_html -def build_alert(width, height, alertTab): +def build_alert(alertTab, width): """ Build the display of the footer - `width` - Screen Width - `height` - Screen height `alertTab` Details from the Alert tab for fonts etc """ style = """ - .alerttable { position: absolute; z-index:10; left 0px; top 0px; %s } - .alertcell { %s } - .alert { %s } - """ - style2 = """ - #alert {position: absolute; z-index:10; left 0px; top 0px; width: %spx; %s %s} + width: %s; + vertical-align: %s; + font-family %s; + font-size: %spx; + color: %s; + background-color: %s; """ - alerttable = u'' - alertcell = u'' - alert = u'' - if alertTab: - if alertTab.location == 2: - alertcell = u'vertical-align:bottom;' - elif alertTab.location == 1: - alertcell = u'vertical-align:middle;' - else: - alertcell = u'vertical-align:top;' - alerttable = u'width: %spx; height: %spx; ' % (width, height) - alert = u'font-family %s; font-size: %spx; color: %s; ' \ - u'background-color: %s' % \ - (alertTab.font_face, alertTab.font_size, alertTab.font_color, - alertTab.bg_color) - #alert_html = style % (alerttable, alertcell, alert) - alert_html = style2 % (width, alertcell, alert) - print alert_html - return alert_html + if not alertTab: + return u'' + align = u'' + if alertTab.location == 2: + align = u'bottom' + elif alertTab.location == 1: + align = u'middle' + else: + align = u'top' + alert = style % (width, align, alertTab.font_face, alertTab.font_size, + alertTab.font_color, alertTab.bg_color) + return alert diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index 9ab9c9cdb..c548ff179 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -113,7 +113,7 @@ class MainDisplay(DisplayWidget): self.page = self.webView.page() self.frame = self.page.mainFrame() QtCore.QObject.connect(self.webView, - QtCore.SIGNAL(u'loadFinished(bool)'), self.loaded) + QtCore.SIGNAL(u'loadFinished(bool)'), self.isLoaded) self.frame.setScrollBarPolicy(QtCore.Qt.Vertical, QtCore.Qt.ScrollBarAlwaysOff) self.frame.setScrollBarPolicy(QtCore.Qt.Horizontal, @@ -162,11 +162,11 @@ class MainDisplay(DisplayWidget): The slide text to be displayed """ log.debug(u'text') - self.frame.evaluateJavaScript("startfade('" + - slide.replace("\\", "\\\\").replace("\'", "\\\'") + "')") + self.frame.evaluateJavaScript(u'show_text("%s")' % \ + slide.replace(u'\\', u'\\\\').replace(u'\"', u'\\\"')) return self.preview() - def alert(self, text, shrink=False): + def alert(self, text): """ Add the alert text @@ -174,15 +174,22 @@ class MainDisplay(DisplayWidget): The slide text to be displayed """ log.debug(u'alert') - js = "displayAlert('" + \ - text.replace("\\", "\\\\").replace("\'", "\\\'") + "', %s)" % \ - ('true' if shrink else 'false') + if self.height() != self.screen[u'size'].height() \ + or not self.isVisible(): + shrink = True + else: + shrink = False + js = u'show_alert("%s", "%s")' % ( + text.replace(u'\\', u'\\\\').replace(u'\"', u'\\\"'), + u'top' if shrink else u'') height = self.frame.evaluateJavaScript(js) if shrink: if text: self.resize(self.width(), int(height.toString())) + self.setVisible(True) else: self.setGeometry(self.screen[u'size']) + self.setVisible(False) def image(self, image): """ @@ -203,10 +210,10 @@ class MainDisplay(DisplayWidget): Display an image, as is. """ if image: - js = "setImage('" + \ - u'data:image/png;base64,%s' % image_to_byte(image) + "');" + js = u'show_image("data:image/png;base64,%s");' % \ + image_to_byte(image) else: - js = "setImage('');" + js = u'show_image("");' self.frame.evaluateJavaScript(js) def resetImage(self): @@ -222,35 +229,35 @@ class MainDisplay(DisplayWidget): Used after Video plugin has changed the background """ log.debug(u'resetVideo') - self.frame.evaluateJavaScript('video("close");') + self.frame.evaluateJavaScript(u'show_video("close");') def videoPlay(self): """ Responds to the request to play a loaded video """ log.debug(u'videoPlay') - self.frame.evaluateJavaScript('video("play");') + self.frame.evaluateJavaScript(u'show_video("play");') def videoPause(self): """ Responds to the request to pause a loaded video """ log.debug(u'videoPause') - self.frame.evaluateJavaScript('video("pause");') + self.frame.evaluateJavaScript(u'show_video("pause");') def videoStop(self): """ Responds to the request to stop a loaded video """ log.debug(u'videoStop') - self.frame.evaluateJavaScript('video("stop");') + self.frame.evaluateJavaScript(u'show_video("stop");') def videoVolume(self, volume): """ Changes the volume of a running video """ log.debug(u'videoVolume %d' % volume) - self.frame.evaluateJavaScript('video(null,null,%s);' % + self.frame.evaluateJavaScript(u'show_video(null, null, %s);' % str(float(volume)/float(10))) def video(self, videoPath, volume): @@ -259,13 +266,12 @@ class MainDisplay(DisplayWidget): """ log.debug(u'video') self.loaded = True - js = 'video("play","%s",%s,true);' % \ - (videoPath.replace("\\", "\\\\"), str(float(volume)/float(10))) + js = u'show_video("play", "%s", %s, true);' % \ + (videoPath.replace(u'\\', u'\\\\'), str(float(volume)/float(10))) self.frame.evaluateJavaScript(js) - print js return self.preview() - def loaded(self): + def isLoaded(self): """ Called by webView event to show display is fully loaded """ @@ -280,7 +286,7 @@ class MainDisplay(DisplayWidget): # Wait for the fade to finish before geting the preview. # Important otherwise preview will have incorrect text if at all ! if self.serviceItem.themedata.display_slideTransition: - while self.frame.evaluateJavaScript("fadeFinished()").toString() == u'false': + while self.frame.evaluateJavaScript(u'show_text_complete()').toString() == u'false': Receiver.send_message(u'openlp_process_events') # Wait for the webview to update before geting the preview. # Important otherwise first preview will miss the background ! @@ -295,7 +301,7 @@ class MainDisplay(DisplayWidget): painter.end() # save preview for debugging if log.isEnabledFor(logging.DEBUG): - preview.save("temp.png", "png") + preview.save(u'temp.png', u'png') return preview def buildHtml(self, serviceItem): @@ -310,7 +316,13 @@ class MainDisplay(DisplayWidget): html = build_html(self.serviceItem, self.screen, self.parent.alertTab) self.webView.setHtml(html) if serviceItem.footer and serviceItem.foot_text: - self.frame.findFirstElement('div#footer').setInnerXml(serviceItem.foot_text) + self.footer(serviceItem.foot_text) + + def footer(self, text): + log.debug(u'footer') + js = "show_footer('" + \ + text.replace("\\", "\\\\").replace("\'", "\\\'") + "')" + self.frame.evaluateJavaScript(js) def hideDisplay(self, mode=HideMode.Screen): """ @@ -318,15 +330,13 @@ class MainDisplay(DisplayWidget): Store the images so they can be replaced when required """ log.debug(u'hideDisplay mode = %d', mode) - self.frame.evaluateJavaScript( - "document.getElementById('blank').style.visibility = 'visible'") if mode == HideMode.Screen: - self.frame.evaluateJavaScript('blankState("desktop");') + self.frame.evaluateJavaScript(u'show_blank("desktop");') self.setVisible(False) elif mode == HideMode.Blank or self.initialFrame: - self.frame.evaluateJavaScript('blankState("black");') + self.frame.evaluateJavaScript(u'show_blank("black");') else: - self.frame.evaluateJavaScript('blankState("theme");') + self.frame.evaluateJavaScript(u'show_blank("theme");') if mode != HideMode.Screen and self.isHidden(): self.setVisible(True) @@ -337,7 +347,7 @@ class MainDisplay(DisplayWidget): Make the stored images None to release memory. """ log.debug(u'showDisplay') - self.frame.evaluateJavaScript('blankState("show");') + self.frame.evaluateJavaScript('show_blank("show");') if self.isHidden(): self.setVisible(True) # Trigger actions when display is active again