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">
<style type="text/css">
body {
background: #000 !important;
background: transparent !important;
color: #fff !important;
}
sup {

View File

@ -26,6 +26,7 @@ import html
import logging
import math
import re
import time
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{/pk}{o}e{/o}{pp}n{/pp} of the Lord\n'
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):
@ -465,11 +467,26 @@ class Renderer(RegistryBase, LogMixin, RegistryProperties, DisplayWindow):
self.force_page = force_page
if not self.force_page:
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['v1'] = VERSE
self.load_verses(verses)
verses['title'] = TITLE
verses['text'] = slides[0]
verses['verse'] = 'V1'
self.load_verses([verses])
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
return None
@ -484,21 +501,21 @@ class Renderer(RegistryBase, LogMixin, RegistryProperties, DisplayWindow):
while not self._is_initialised:
QtWidgets.QApplication.instance().processEvents()
self.log_debug('format slide')
if item:
theme_name = item.theme if item.theme else Registry().get('theme_manager').global_theme
theme_data = Registry().get('theme_manager').get_theme_data(theme_name)
self.theme_height = theme_data.font_main_height
# Set theme for preview
self.set_theme(theme_data)
# Add line endings after each line of text used for bibles.
line_end = '<br>'
if item.is_capable(ItemCapabilities.NoLineBreaks):
if item and item.is_capable(ItemCapabilities.NoLineBreaks):
line_end = ' '
# 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)
# Songs and Custom
elif item.is_capable(ItemCapabilities.CanSoftBreak):
elif item is None or item.is_capable(ItemCapabilities.CanSoftBreak):
pages = []
if '[---]' in 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 logging
import os
import copy
from PyQt5 import QtCore, QtWebChannel, QtWidgets
@ -33,6 +34,7 @@ from openlp.core.common.path import Path, path_to_str
log = logging.getLogger(__name__)
DISPLAY_PATH = Path(__file__).parent / 'html' / 'display.html'
CHECKERBOARD_PATH = Path(__file__).parent / 'html' / 'checkerboard.png'
class MediaWatcher(QtCore.QObject):
@ -110,10 +112,14 @@ class DisplayWindow(QtWidgets.QWidget):
self._is_initialised = False
self._fbo = None
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.layout = QtWidgets.QVBoxLayout(self)
self.layout.setContentsMargins(0, 0, 0, 0)
self.webview = WebEngineView(self)
self.webview.setAttribute(QtCore.Qt.WA_TranslucentBackground);
self.webview.page().setBackgroundColor(QtCore.Qt.transparent);
self.layout.addWidget(self.webview)
self.webview.loadFinished.connect(self.after_loaded)
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.registerObject('mediaWatcher', self.media_watcher)
self.webview.page().setWebChannel(self.channel)
self.is_display = False
if screen and screen.is_display:
self.update_from_screen(screen)
self.is_display = True
self.show()
def update_from_screen(self, screen):
@ -164,6 +172,7 @@ class DisplayWindow(QtWidgets.QWidget):
:param script: The script to run, a string
:param is_sync: Run the script synchronously. Defaults to False
"""
log.debug(script)
if not is_sync:
self.webview.page().runJavaScript(script)
else:
@ -280,7 +289,15 @@ class DisplayWindow(QtWidgets.QWidget):
"""
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):
"""

View File

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