Initial support for transparent backgrounds.

This commit is contained in:
Tomas Groth 2018-10-12 21:51:51 +02:00
parent 2fb0050531
commit bb9aa4a561
5 changed files with 50 additions and 16 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@ -5,7 +5,7 @@
<link href="reveal.css" rel="stylesheet"> <link href="reveal.css" rel="stylesheet">
<style type="text/css"> <style type="text/css">
body { body {
background: #000 !important; background: transparent !important;
color: #fff !important; color: #fff !important;
} }
sup { sup {

View File

@ -26,6 +26,7 @@ import html
import logging import logging
import math import math
import re import re
import time
from PyQt5 import QtWidgets from PyQt5 import QtWidgets
@ -55,7 +56,8 @@ VERSE = 'The Lord said to {r}Noah{/r}: \n' \
'{r}C{/r}{b}h{/b}{bl}i{/bl}{y}l{/y}{g}d{/g}{pk}' \ '{r}C{/r}{b}h{/b}{bl}i{/bl}{y}l{/y}{g}d{/g}{pk}' \
'r{/pk}{o}e{/o}{pp}n{/pp} of the Lord\n' 'r{/pk}{o}e{/o}{pp}n{/pp} of the Lord\n'
VERSE_FOR_LINE_COUNT = '\n'.join(map(str, range(100))) VERSE_FOR_LINE_COUNT = '\n'.join(map(str, range(100)))
FOOTER = ['Arky Arky (Unknown)', 'Public Domain', 'CCLI 123456'] TITLE = 'Arky Arky (Unknown)'
FOOTER = ['Public Domain', 'CCLI 123456']
def remove_tags(text, can_remove_chords=False): def remove_tags(text, can_remove_chords=False):
@ -465,11 +467,26 @@ class Renderer(RegistryBase, LogMixin, RegistryProperties, DisplayWindow):
self.force_page = force_page self.force_page = force_page
if not self.force_page: if not self.force_page:
self.set_theme(theme_data) self.set_theme(theme_data)
self.theme_height = theme_data.font_main_height
slides = self.format_slide(render_tags(VERSE), None)
print(slides)
verses = dict() verses = dict()
verses['v1'] = VERSE verses['title'] = TITLE
self.load_verses(verses) verses['text'] = slides[0]
verses['verse'] = 'V1'
self.load_verses([verses])
self.force_page = False self.force_page = False
return self.save_screenshot() QtWidgets.QApplication.instance().processEvents()
pixmap = self.webview.grab()
QtWidgets.QApplication.instance().processEvents()
pixmap = self.webview.grab()
time.sleep(0.5)
self.show()
QtWidgets.QApplication.instance().processEvents()
pixmap = self.grab()
self.hide()
pixmap.save('/tmp/screen-grab.png', 'png')
return pixmap
self.force_page = False self.force_page = False
return None return None
@ -484,21 +501,21 @@ class Renderer(RegistryBase, LogMixin, RegistryProperties, DisplayWindow):
while not self._is_initialised: while not self._is_initialised:
QtWidgets.QApplication.instance().processEvents() QtWidgets.QApplication.instance().processEvents()
self.log_debug('format slide') self.log_debug('format slide')
theme_name = item.theme if item.theme else Registry().get('theme_manager').global_theme if item:
theme_data = Registry().get('theme_manager').get_theme_data(theme_name) theme_name = item.theme if item.theme else Registry().get('theme_manager').global_theme
self.theme_height = theme_data.font_main_height theme_data = Registry().get('theme_manager').get_theme_data(theme_name)
self.theme_height = theme_data.font_main_height
# Set theme for preview # Set theme for preview
self.set_theme(theme_data) self.set_theme(theme_data)
# Add line endings after each line of text used for bibles. # Add line endings after each line of text used for bibles.
line_end = '<br>' line_end = '<br>'
if item.is_capable(ItemCapabilities.NoLineBreaks): if item and item.is_capable(ItemCapabilities.NoLineBreaks):
line_end = ' ' line_end = ' '
# Bibles # Bibles
if item.is_capable(ItemCapabilities.CanWordSplit): if item and item.is_capable(ItemCapabilities.CanWordSplit):
pages = self._paginate_slide_words(text.split('\n'), line_end) pages = self._paginate_slide_words(text.split('\n'), line_end)
# Songs and Custom # Songs and Custom
elif item.is_capable(ItemCapabilities.CanSoftBreak): elif item is None or item.is_capable(ItemCapabilities.CanSoftBreak):
pages = [] pages = []
if '[---]' in text: if '[---]' in text:
# Remove Overflow split if at start of the text # Remove Overflow split if at start of the text

View File

@ -25,6 +25,7 @@ The :mod:`~openlp.core.display.window` module contains the display window
import json import json
import logging import logging
import os import os
import copy
from PyQt5 import QtCore, QtWebChannel, QtWidgets from PyQt5 import QtCore, QtWebChannel, QtWidgets
@ -33,6 +34,7 @@ from openlp.core.common.path import Path, path_to_str
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
DISPLAY_PATH = Path(__file__).parent / 'html' / 'display.html' DISPLAY_PATH = Path(__file__).parent / 'html' / 'display.html'
CHECKERBOARD_PATH = Path(__file__).parent / 'html' / 'checkerboard.png'
class MediaWatcher(QtCore.QObject): class MediaWatcher(QtCore.QObject):
@ -110,10 +112,14 @@ class DisplayWindow(QtWidgets.QWidget):
self._is_initialised = False self._is_initialised = False
self._fbo = None self._fbo = None
self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.Tool) #| QtCore.Qt.WindowStaysOnTopHint self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.Tool) #| QtCore.Qt.WindowStaysOnTopHint
self.setAttribute(QtCore.Qt.WA_TranslucentBackground);
self.setAutoFillBackground(True);
self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.layout = QtWidgets.QVBoxLayout(self) self.layout = QtWidgets.QVBoxLayout(self)
self.layout.setContentsMargins(0, 0, 0, 0) self.layout.setContentsMargins(0, 0, 0, 0)
self.webview = WebEngineView(self) self.webview = WebEngineView(self)
self.webview.setAttribute(QtCore.Qt.WA_TranslucentBackground);
self.webview.page().setBackgroundColor(QtCore.Qt.transparent);
self.layout.addWidget(self.webview) self.layout.addWidget(self.webview)
self.webview.loadFinished.connect(self.after_loaded) self.webview.loadFinished.connect(self.after_loaded)
self.set_url(QtCore.QUrl.fromLocalFile(path_to_str(DISPLAY_PATH))) self.set_url(QtCore.QUrl.fromLocalFile(path_to_str(DISPLAY_PATH)))
@ -121,8 +127,10 @@ class DisplayWindow(QtWidgets.QWidget):
self.channel = QtWebChannel.QWebChannel(self) self.channel = QtWebChannel.QWebChannel(self)
self.channel.registerObject('mediaWatcher', self.media_watcher) self.channel.registerObject('mediaWatcher', self.media_watcher)
self.webview.page().setWebChannel(self.channel) self.webview.page().setWebChannel(self.channel)
self.is_display = False
if screen and screen.is_display: if screen and screen.is_display:
self.update_from_screen(screen) self.update_from_screen(screen)
self.is_display = True
self.show() self.show()
def update_from_screen(self, screen): def update_from_screen(self, screen):
@ -164,6 +172,7 @@ class DisplayWindow(QtWidgets.QWidget):
:param script: The script to run, a string :param script: The script to run, a string
:param is_sync: Run the script synchronously. Defaults to False :param is_sync: Run the script synchronously. Defaults to False
""" """
log.debug(script)
if not is_sync: if not is_sync:
self.webview.page().runJavaScript(script) self.webview.page().runJavaScript(script)
else: else:
@ -280,7 +289,15 @@ class DisplayWindow(QtWidgets.QWidget):
""" """
Set the theme of the display Set the theme of the display
""" """
self.run_javascript('Display.setTheme({theme});'.format(theme=theme.export_theme())) # If background is transparent and this is not a display, inject checkerboard background image instead
if theme.background_type == 'transparent' and not self.is_display:
theme_copy = copy.deepcopy(theme)
theme_copy.background_type = 'image'
theme_copy.background_filename = CHECKERBOARD_PATH
exported_theme = theme_copy.export_theme()
else:
exported_theme = theme.export_theme()
self.run_javascript('Display.setTheme({theme});'.format(theme=exported_theme))
def get_video_types(self): def get_video_types(self):
""" """

View File

@ -1145,7 +1145,7 @@ class SlideController(QtWidgets.QWidget, LogMixin, RegistryProperties):
else: else:
if start: if start:
for display in self.displays: for display in self.displays:
display.load_images([]) display.load_images(self.service_item.slides)
# self.display.build_html(self.service_item, to_display) # self.display.build_html(self.service_item, to_display)
else: else:
for display in self.displays: for display in self.displays: