forked from openlp/openlp
Hack to get theme screenshot working
This commit is contained in:
parent
4c103e4305
commit
dfa10b42bb
@ -28,7 +28,7 @@ import math
|
|||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from PyQt5 import QtWidgets
|
from PyQt5 import QtWidgets, QtGui
|
||||||
|
|
||||||
from openlp.core.lib.formattingtags import FormattingTags
|
from openlp.core.lib.formattingtags import FormattingTags
|
||||||
from openlp.core.common.registry import Registry, RegistryBase
|
from openlp.core.common.registry import Registry, RegistryBase
|
||||||
@ -469,24 +469,13 @@ class Renderer(RegistryBase, LogMixin, RegistryProperties, DisplayWindow):
|
|||||||
self.set_theme(theme_data)
|
self.set_theme(theme_data)
|
||||||
self.theme_height = theme_data.font_main_height
|
self.theme_height = theme_data.font_main_height
|
||||||
slides = self.format_slide(render_tags(VERSE), None)
|
slides = self.format_slide(render_tags(VERSE), None)
|
||||||
print(slides)
|
|
||||||
verses = dict()
|
verses = dict()
|
||||||
verses['title'] = TITLE
|
verses['title'] = TITLE
|
||||||
verses['text'] = slides[0]
|
verses['text'] = slides[0]
|
||||||
verses['verse'] = 'V1'
|
verses['verse'] = 'V1'
|
||||||
self.load_verses([verses])
|
self.load_verses([verses])
|
||||||
self.force_page = False
|
self.force_page = False
|
||||||
QtWidgets.QApplication.instance().processEvents()
|
return self.save_screenshot()
|
||||||
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
|
||||||
|
|
||||||
@ -724,3 +713,23 @@ class Renderer(RegistryBase, LogMixin, RegistryProperties, DisplayWindow):
|
|||||||
self.run_javascript('Display.addTextSlide("v1", "{text}");'.format(text=text), is_sync=True)
|
self.run_javascript('Display.addTextSlide("v1", "{text}");'.format(text=text), is_sync=True)
|
||||||
does_text_fits = self.run_javascript('Display.doesContentFit();', is_sync=True)
|
does_text_fits = self.run_javascript('Display.doesContentFit();', is_sync=True)
|
||||||
return does_text_fits
|
return does_text_fits
|
||||||
|
|
||||||
|
def save_screenshot(self, fname=None):
|
||||||
|
"""
|
||||||
|
Save a screenshot, either returning it or saving it to file. Do some extra work to actually get a picture.
|
||||||
|
"""
|
||||||
|
self.setVisible(True)
|
||||||
|
pixmap = self.grab()
|
||||||
|
for i in range(0, 4):
|
||||||
|
QtWidgets.QApplication.instance().processEvents()
|
||||||
|
time.sleep(0.05)
|
||||||
|
QtWidgets.QApplication.instance().processEvents()
|
||||||
|
pixmap = self.grab()
|
||||||
|
self.setVisible(False)
|
||||||
|
pixmap = QtGui.QPixmap(self.webview.size())
|
||||||
|
self.webview.render(pixmap)
|
||||||
|
if fname:
|
||||||
|
ext = os.path.splitext(fname)[-1][1:]
|
||||||
|
pixmap.save(fname, ext)
|
||||||
|
else:
|
||||||
|
return pixmap
|
||||||
|
@ -53,9 +53,10 @@ class WebEnginePage(QtWebEngineWidgets.QWebEnginePage):
|
|||||||
|
|
||||||
class WebEngineView(QtWebEngineWidgets.QWebEngineView):
|
class WebEngineView(QtWebEngineWidgets.QWebEngineView):
|
||||||
"""
|
"""
|
||||||
A sub-classed QWebEngineView to handle paint events of OpenGL
|
A sub-classed QWebEngineView to handle paint events of OpenGL (does not seem to work)
|
||||||
|
and set some attributtes.
|
||||||
"""
|
"""
|
||||||
_child = None # QtWidgets.QOpenGLWidget
|
_child = None # QtWidgets.QOpenGLWidget or QWidget?
|
||||||
delegatePaint = QtCore.pyqtSignal()
|
delegatePaint = QtCore.pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
@ -84,9 +85,9 @@ class WebEngineView(QtWebEngineWidgets.QWebEngineView):
|
|||||||
Handle events
|
Handle events
|
||||||
"""
|
"""
|
||||||
if ev.type() == QtCore.QEvent.ChildAdded:
|
if ev.type() == QtCore.QEvent.ChildAdded:
|
||||||
# Only use QOpenGLWidget child
|
# Only use QWidget child (used to be QOpenGLWidget)
|
||||||
w = ev.child()
|
w = ev.child()
|
||||||
if w and isinstance(w, QtWidgets.QOpenGLWidget):
|
if w and isinstance(w, QtWidgets.QWidget):
|
||||||
self._child = w
|
self._child = w
|
||||||
w.installEventFilter(self)
|
w.installEventFilter(self)
|
||||||
return super(WebEngineView, self).event(ev)
|
return super(WebEngineView, self).event(ev)
|
||||||
|
@ -188,7 +188,7 @@ class ThemesTab(SettingsTab):
|
|||||||
Set the global default theme
|
Set the global default theme
|
||||||
"""
|
"""
|
||||||
self.global_theme = self.default_combo_box.currentText()
|
self.global_theme = self.default_combo_box.currentText()
|
||||||
self.renderer.set_global_theme()
|
# self.renderer.set_global_theme()
|
||||||
self._preview_global_theme()
|
self._preview_global_theme()
|
||||||
|
|
||||||
def update_theme_list(self, theme_list):
|
def update_theme_list(self, theme_list):
|
||||||
|
Loading…
Reference in New Issue
Block a user