forked from openlp/openlp
More refactoring and improvements
This commit is contained in:
parent
53c6e93d08
commit
443ff3fecd
@ -77,31 +77,32 @@ HTMLSRC = u"""
|
||||
</body>
|
||||
</html>
|
||||
"""
|
||||
def build_html(theme, screen, alert, image):
|
||||
def build_html(item, screen, alert):
|
||||
width = screen[u'size'].width()
|
||||
height = screen[u'size'].height()
|
||||
html = HTMLSRC % (build_video(theme, width, height, alert),
|
||||
build_image(theme, width, height, alert),
|
||||
build_lyrics(theme, width, height, alert),
|
||||
build_alert(theme, width, height, alert),
|
||||
build_image(theme, width, height, alert),
|
||||
build_image_src(theme, width, height, alert, image))
|
||||
html = HTMLSRC % (build_video(width, height),
|
||||
build_image(width, height),
|
||||
build_lyrics(item, width, height),
|
||||
build_alert(width, height, alert),
|
||||
build_image(width, height),
|
||||
build_image_src(item.bg_frame))
|
||||
return html
|
||||
|
||||
def build_video(theme, width, height, alert):
|
||||
def build_video(width, height):
|
||||
video = """
|
||||
#video {
|
||||
position: absolute;
|
||||
left: 0px;
|
||||
top: 0px;
|
||||
width: 640px
|
||||
height: 480px;
|
||||
width: %spx
|
||||
height: %spx;
|
||||
z-index:1;
|
||||
}
|
||||
"""
|
||||
return video
|
||||
return video % (width, height)
|
||||
|
||||
def build_image(theme, width, height, alert):
|
||||
|
||||
def build_image(width, height):
|
||||
image = """
|
||||
#image {
|
||||
position: absolute;
|
||||
@ -114,14 +115,14 @@ def build_image(theme, width, height, alert):
|
||||
"""
|
||||
return image % (width, height)
|
||||
|
||||
def build_image_src(theme, width, height, alert, image):
|
||||
def build_image_src(image):
|
||||
# <img src="" height="480" width="640" />
|
||||
image_src = """
|
||||
<img src="data:image/png;base64,%s">";
|
||||
"""
|
||||
return image_src % image_to_byte(image)
|
||||
|
||||
def build_lyrics(theme, width, height, alert):
|
||||
def build_lyrics(item, width, height):
|
||||
lyrics = """
|
||||
#lyrics {
|
||||
position: absolute;
|
||||
@ -136,6 +137,7 @@ def build_lyrics(theme, width, height, alert):
|
||||
font-size: %spx;
|
||||
}
|
||||
"""
|
||||
theme = item.themedata
|
||||
lyrics_html = u''
|
||||
shadow = u''
|
||||
outline = u''
|
||||
@ -150,10 +152,10 @@ def build_lyrics(theme, width, height, alert):
|
||||
(theme.display_outline_size, theme.display_outline_color)
|
||||
outline = u'text-shadow: -1px 0 white, 0 1px white, 1px 0 white, 0 -1px white'
|
||||
lyrics_html = lyrics % (shadow, outline, theme.font_main_name, theme.font_main_proportion)
|
||||
print lyrics_html
|
||||
print lyrics_html
|
||||
return lyrics_html
|
||||
|
||||
def build_alert(theme, width, height, alert):
|
||||
def build_alert(width, height, alert):
|
||||
alert = """
|
||||
#alert {
|
||||
position: absolute;
|
||||
|
@ -130,7 +130,7 @@ class RenderManager(object):
|
||||
self.renderer.set_theme(self.themedata)
|
||||
self.build_text_rectangle(self.themedata)
|
||||
self.renderer.set_frame_dest(self.width, self.height)
|
||||
return self.renderer.bg_frame
|
||||
return self.renderer._rect, self.renderer._rect_footer
|
||||
|
||||
def build_text_rectangle(self, theme):
|
||||
"""
|
||||
|
@ -92,6 +92,7 @@ class ServiceItem(object):
|
||||
self.is_valid = True
|
||||
self.cache = {}
|
||||
self.icon = None
|
||||
self.themedata = None
|
||||
|
||||
def add_capability(self, capability):
|
||||
"""
|
||||
@ -136,10 +137,12 @@ class ServiceItem(object):
|
||||
self.just_rendered = True
|
||||
if self.service_item_type == ServiceItemType.Text:
|
||||
log.debug(u'Formatting slides')
|
||||
if self.theme is None:
|
||||
self.render_manager.set_override_theme(None)
|
||||
else:
|
||||
self.render_manager.set_override_theme(self.theme)
|
||||
theme = None;
|
||||
if not self.theme:
|
||||
theme = self.theme
|
||||
self.main, self.footer = self.render_manager.set_override_theme(theme)
|
||||
self.bg_frame = self.render_manager.renderer.bg_frame
|
||||
self.themedata = self.render_manager.themedata
|
||||
for slide in self._raw_frames:
|
||||
before = time.time()
|
||||
formated = self.render_manager.format_slide(slide[u'raw_slide'])
|
||||
@ -156,8 +159,6 @@ class ServiceItem(object):
|
||||
if len(self._display_frames) in self.cache.keys():
|
||||
del self.cache[len(self._display_frames)]
|
||||
log.log(15, u'Formatting took %4s' % (time.time() - before))
|
||||
self.bg_frame = self.render_manager.renderer.bg_frame
|
||||
self.themedata = self.render_manager.themedata
|
||||
elif self.service_item_type == ServiceItemType.Image:
|
||||
for slide in self._raw_frames:
|
||||
slide[u'image'] = resize_image(slide[u'image'],
|
||||
@ -182,11 +183,12 @@ class ServiceItem(object):
|
||||
# if self.cache.get(row):
|
||||
# frame = self.cache[row]
|
||||
# else:
|
||||
if raw_html[0]:
|
||||
frame = self.render_manager.generate_slide(raw_html,
|
||||
self.raw_footer)
|
||||
else:
|
||||
frame = self.render_manager.generate_slide(raw_html, u'')
|
||||
# if raw_html[0]:
|
||||
# frame = self.render_manager.generate_slide(raw_html,
|
||||
# self.raw_footer)
|
||||
# else:
|
||||
# frame = self.render_manager.generate_slide(raw_html, u'')
|
||||
frame = None
|
||||
self.cache[row] = frame
|
||||
return frame, raw_html[0]
|
||||
|
||||
|
@ -36,10 +36,12 @@ class HideMode(object):
|
||||
Theme = 2
|
||||
Screen = 3
|
||||
|
||||
from maindisplay import WebViewer
|
||||
from slidecontroller import HideMode
|
||||
from servicenoteform import ServiceNoteForm
|
||||
from serviceitemeditform import ServiceItemEditForm
|
||||
from screen import ScreenList
|
||||
from maindisplay import WebViewer
|
||||
from maindisplay import DisplayManager
|
||||
from amendthemeform import AmendThemeForm
|
||||
from slidecontroller import SlideController
|
||||
|
@ -30,7 +30,7 @@ import time
|
||||
from PyQt4 import QtCore, QtGui, QtWebKit
|
||||
from PyQt4.phonon import Phonon
|
||||
|
||||
from openlp.core.lib import Receiver, resize_image, build_html
|
||||
from openlp.core.lib import Receiver, resize_image, build_html, ServiceItem
|
||||
from openlp.core.ui import HideMode
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@ -59,6 +59,7 @@ HTMLVIDEO = u"""<html>
|
||||
"""
|
||||
|
||||
class DisplayManager(QtGui.QWidget):
|
||||
pass
|
||||
"""
|
||||
Wrapper class to hold the display widgets.
|
||||
I will provide API's in future to access the screens allow for
|
||||
@ -71,24 +72,24 @@ class DisplayManager(QtGui.QWidget):
|
||||
self.screens = screens
|
||||
self.audioPlayer = AudioPlayer(self)
|
||||
# Live display
|
||||
self.mainDisplay = WebViewer(self, screens, True)
|
||||
#self.mainDisplay = WebViewer(self, screens, True)
|
||||
# Display for Preview and Theme previews
|
||||
self.previewDisplay = WebViewer(self, screens, False)
|
||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
QtCore.SIGNAL(u'maindisplay_hide'), self.hideDisplay)
|
||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
QtCore.SIGNAL(u'maindisplay_show'), self.showDisplay)
|
||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
QtCore.SIGNAL(u'videodisplay_start'), self.onStartVideo)
|
||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
QtCore.SIGNAL(u'videodisplay_stop'), self.onStopVideo)
|
||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
QtCore.SIGNAL(u'config_updated'), self.setup)
|
||||
#self.previewDisplay = WebViewer(self, screens, False)
|
||||
# QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
# QtCore.SIGNAL(u'maindisplay_hide'), self.hideDisplay)
|
||||
# QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
# QtCore.SIGNAL(u'maindisplay_show'), self.showDisplay)
|
||||
# QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
# QtCore.SIGNAL(u'videodisplay_start'), self.onStartVideo)
|
||||
# QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
# QtCore.SIGNAL(u'videodisplay_stop'), self.onStopVideo)
|
||||
# QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
# QtCore.SIGNAL(u'config_updated'), self.setup)
|
||||
|
||||
def setup(self):
|
||||
log.debug(u'mainDisplay - setup')
|
||||
# let the render manager have the preview display.
|
||||
self.parent.RenderManager.previewDisplay = self.previewDisplay
|
||||
#self.parent.RenderManager.previewDisplay = self.previewDisplay
|
||||
#Build the initial frame.
|
||||
self.initialFrame = QtGui.QImage(
|
||||
self.screens.current[u'size'].width(),
|
||||
@ -102,77 +103,78 @@ class DisplayManager(QtGui.QWidget):
|
||||
(self.screens.current[u'size'].width() - splash_image.width()) / 2,
|
||||
(self.screens.current[u'size'].height() - splash_image.height()) / 2,
|
||||
splash_image)
|
||||
self.mainDisplay.setup()
|
||||
self.previewDisplay.setup()
|
||||
self.mainDisplay.buildHtml(self.initialFrame)
|
||||
self.mainDisplay.show()
|
||||
# self.mainDisplay.setup()
|
||||
# self.previewDisplay.setup()
|
||||
# if self.isLive
|
||||
# self.mainDisplay.buildHtml(self.initialFrame)
|
||||
# self.mainDisplay.show()
|
||||
|
||||
def hideDisplay(self, message):
|
||||
"""
|
||||
Hide the output displays
|
||||
"""
|
||||
self.mainDisplay.hideDisplay(message)
|
||||
|
||||
def showDisplay(self, message):
|
||||
"""
|
||||
Hide the output displays
|
||||
"""
|
||||
self.mainDisplay.showDisplay(message)
|
||||
|
||||
def addAlert(self, alertMessage, location):
|
||||
"""
|
||||
Handles the addition of an Alert Message to the Displays
|
||||
"""
|
||||
self.mainDisplay.addAlert(alertMessage, location)
|
||||
|
||||
def displayImageWithText(self, frame):
|
||||
"""
|
||||
Handles the addition of a background Image to the displays
|
||||
"""
|
||||
self.mainDisplay.addImageWithText(frame)
|
||||
|
||||
def buildHtml(self, image=None):
|
||||
"""
|
||||
Handles the addition of a background Image to the displays
|
||||
"""
|
||||
self.mainDisplay.buildHtml(image)
|
||||
|
||||
def text(self, text):
|
||||
"""
|
||||
Handles the addition of a background Image to the displays
|
||||
"""
|
||||
self.mainDisplay.text(text)
|
||||
|
||||
def displayImage(self, frame):
|
||||
"""
|
||||
Handles the addition of a background Image to the displays
|
||||
"""
|
||||
self.mainDisplay.displayImage(frame)
|
||||
|
||||
def displayVideo(self, path):
|
||||
"""
|
||||
Handles the addition of a background Video to the displays
|
||||
"""
|
||||
self.mainDisplay.displayVideo(path)
|
||||
|
||||
def onStartVideo(self, item):
|
||||
"""
|
||||
Handles the Starting of a Video and Display Management
|
||||
"""
|
||||
self.mainDisplay.setVisible(False)
|
||||
|
||||
def onStopVideo(self):
|
||||
"""
|
||||
Handles the Stopping of a Video and Display Management
|
||||
"""
|
||||
self.mainDisplay.setVisible(True)
|
||||
|
||||
def close(self):
|
||||
"""
|
||||
Handles the closure of the displays
|
||||
"""
|
||||
|
||||
self.mainDisplay.close()
|
||||
# def hideDisplay(self, message):
|
||||
# """
|
||||
# Hide the output displays
|
||||
# """
|
||||
# self.mainDisplay.hideDisplay(message)
|
||||
#
|
||||
# def showDisplay(self, message):
|
||||
# """
|
||||
# Hide the output displays
|
||||
# """
|
||||
# self.mainDisplay.showDisplay(message)
|
||||
#
|
||||
# def addAlert(self, alertMessage, location):
|
||||
# """
|
||||
# Handles the addition of an Alert Message to the Displays
|
||||
# """
|
||||
# self.mainDisplay.addAlert(alertMessage, location)
|
||||
#
|
||||
# def displayImageWithText(self, frame):
|
||||
# """
|
||||
# Handles the addition of a background Image to the displays
|
||||
# """
|
||||
# self.mainDisplay.addImageWithText(frame)
|
||||
#
|
||||
# def buildHtml(self, image=None):
|
||||
# """
|
||||
# Handles the addition of a background Image to the displays
|
||||
# """
|
||||
# self.mainDisplay.buildHtml(image)
|
||||
#
|
||||
# def text(self, text):
|
||||
# """
|
||||
# Handles the addition of a background Image to the displays
|
||||
# """
|
||||
# self.mainDisplay.text(text)
|
||||
#
|
||||
# def displayImage(self, frame):
|
||||
# """
|
||||
# Handles the addition of a background Image to the displays
|
||||
# """
|
||||
# self.mainDisplay.displayImage(frame)
|
||||
#
|
||||
# def displayVideo(self, path):
|
||||
# """
|
||||
# Handles the addition of a background Video to the displays
|
||||
# """
|
||||
# self.mainDisplay.displayVideo(path)
|
||||
#
|
||||
# def onStartVideo(self, item):
|
||||
# """
|
||||
# Handles the Starting of a Video and Display Management
|
||||
# """
|
||||
# self.mainDisplay.setVisible(False)
|
||||
#
|
||||
# def onStopVideo(self):
|
||||
# """
|
||||
# Handles the Stopping of a Video and Display Management
|
||||
# """
|
||||
# self.mainDisplay.setVisible(True)
|
||||
#
|
||||
# def close(self):
|
||||
# """
|
||||
# Handles the closure of the displays
|
||||
# """
|
||||
#
|
||||
# self.mainDisplay.close()
|
||||
|
||||
class DisplayWidget(QtGui.QGraphicsView):
|
||||
"""
|
||||
@ -230,6 +232,7 @@ class WebViewer(DisplayWidget):
|
||||
DisplayWidget.__init__(self, live, parent=None)
|
||||
self.parent = parent
|
||||
self.screens = screens
|
||||
self.isLive = live
|
||||
self.setWindowTitle(u'OpenLP Display')
|
||||
self.setWindowFlags(QtCore.Qt.FramelessWindowHint |
|
||||
QtCore.Qt.WindowStaysOnTopHint)
|
||||
@ -266,6 +269,7 @@ class WebViewer(DisplayWidget):
|
||||
def text(self, slide):
|
||||
print slide
|
||||
self.frame.findFirstElement('div#lyrics').setInnerXml(slide)
|
||||
return self.preview()
|
||||
|
||||
def alert(self):
|
||||
self.frame.findFirstElement('div#alert').setInnerXml(self.alerttext)
|
||||
@ -304,12 +308,26 @@ class WebViewer(DisplayWidget):
|
||||
QtCore.Qt.ScrollBarAlwaysOff)
|
||||
self.frame.setScrollBarPolicy(QtCore.Qt.Horizontal,
|
||||
QtCore.Qt.ScrollBarAlwaysOff)
|
||||
if self.isLive:
|
||||
#Build the initial frame.
|
||||
initialFrame = QtGui.QImage(
|
||||
self.screens.current[u'size'].width(),
|
||||
self.screens.current[u'size'].height(),
|
||||
QtGui.QImage.Format_ARGB32_Premultiplied)
|
||||
splash_image = QtGui.QImage(u':/graphics/openlp-splash-screen.png')
|
||||
painter_image = QtGui.QPainter()
|
||||
painter_image.begin(initialFrame)
|
||||
painter_image.fillRect(initialFrame.rect(), QtCore.Qt.white)
|
||||
painter_image.drawImage(
|
||||
(self.screens.current[u'size'].width() - splash_image.width()) / 2,
|
||||
(self.screens.current[u'size'].height() - splash_image.height()) / 2,
|
||||
splash_image)
|
||||
item = ServiceItem()
|
||||
item.bg_frame = initialFrame
|
||||
self.webView.setHtml(build_html(item, self.screen, None))
|
||||
self.show()
|
||||
|
||||
def preview(self, image, text, theme):
|
||||
self.setVisible(False)
|
||||
html = build_html(theme, self.screen, None, image)
|
||||
self.webView.setHtml(html)
|
||||
self.frame.findFirstElement('div#lyrics').setInnerXml(text)
|
||||
def preview(self):
|
||||
preview = QtGui.QImage(self.screen[u'size'].width(),
|
||||
self.screen[u'size'].height(),
|
||||
QtGui.QImage.Format_ARGB32_Premultiplied)
|
||||
@ -326,11 +344,13 @@ class WebViewer(DisplayWidget):
|
||||
html = build_html(self.parent.renderManager.themedata, self.screen, None, image)
|
||||
self.webView.setHtml(html)
|
||||
|
||||
def buildHtml(self, image=None):
|
||||
if not image:
|
||||
html = build_html(self.parent.renderManager.themedata, self.screen, None, self.parent.renderManager.renderer.bg_frame)
|
||||
else:
|
||||
html = build_html(self.parent.renderManager.themedata, self.screen, None, image)
|
||||
def buildHtml(self, serviceItem):
|
||||
"""
|
||||
Store the serviceItem and build the new HTML from it. Add the
|
||||
HTML to the display
|
||||
"""
|
||||
self.serviceItem = serviceItem
|
||||
html = build_html(self.serviceItem, self.screen, None)
|
||||
self.webView.setHtml(html)
|
||||
|
||||
#class DisplayWidget(QtGui.QGraphicsView):
|
||||
|
@ -135,8 +135,8 @@ class Ui_MainWindow(object):
|
||||
self.ControlSplitter.setObjectName(u'ControlSplitter')
|
||||
self.MainContentLayout.addWidget(self.ControlSplitter)
|
||||
# Create slide controllers
|
||||
self.PreviewController = SlideController(self, self.settingsmanager)
|
||||
self.LiveController = SlideController(self, self.settingsmanager, True)
|
||||
self.PreviewController = SlideController(self, self.settingsmanager, self.screens)
|
||||
self.LiveController = SlideController(self, self.settingsmanager, self.screens, True)
|
||||
# Create menu
|
||||
self.MenuBar = QtGui.QMenuBar(MainWindow)
|
||||
self.MenuBar.setGeometry(QtCore.QRect(0, 0, 1087, 27))
|
||||
@ -692,10 +692,9 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||
Show the main form, as well as the display form
|
||||
"""
|
||||
QtGui.QWidget.show(self)
|
||||
#screen_number = self.getMonitorNumber()
|
||||
self.displayManager.setup()
|
||||
if self.displayManager.mainDisplay.isVisible():
|
||||
self.displayManager.mainDisplay.setFocus()
|
||||
self.LiveController.display.setup()
|
||||
if self.LiveController.display.isVisible():
|
||||
self.LiveController.display.setFocus()
|
||||
self.activateWindow()
|
||||
if QtCore.QSettings().value(
|
||||
self.generalSettingsSection + u'/auto open',
|
||||
@ -835,8 +834,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||
self.plugin_manager.finalise_plugins()
|
||||
# Save settings
|
||||
self.saveSettings()
|
||||
#Close down the displays
|
||||
self.displayManager.close()
|
||||
#Close down the display
|
||||
self.LiveController.display.close()
|
||||
|
||||
def serviceChanged(self, reset=False, serviceName=None):
|
||||
"""
|
||||
|
@ -30,7 +30,7 @@ import os
|
||||
from PyQt4 import QtCore, QtGui
|
||||
from PyQt4.phonon import Phonon
|
||||
|
||||
from openlp.core.ui import HideMode
|
||||
from openlp.core.ui import HideMode, WebViewer
|
||||
from openlp.core.lib import OpenLPToolbar, Receiver, resize_image, \
|
||||
ItemCapabilities, translate
|
||||
|
||||
@ -96,7 +96,7 @@ class SlideController(QtGui.QWidget):
|
||||
SlideController is the slide controller widget. This widget is what the
|
||||
user uses to control the displaying of verses/slides/etc on the screen.
|
||||
"""
|
||||
def __init__(self, parent, settingsmanager, isLive=False):
|
||||
def __init__(self, parent, settingsmanager, screens, isLive=False):
|
||||
"""
|
||||
Set up the Slide Controller.
|
||||
"""
|
||||
@ -104,8 +104,9 @@ class SlideController(QtGui.QWidget):
|
||||
self.settingsmanager = settingsmanager
|
||||
self.isLive = isLive
|
||||
self.parent = parent
|
||||
self.mainDisplay = self.parent.displayManager.mainDisplay
|
||||
self.displayManager = self.parent.displayManager
|
||||
self.screens = screens
|
||||
self.display = WebViewer(self, screens, isLive)
|
||||
#self.displayManager = self.parent.displayManager
|
||||
self.loopList = [
|
||||
u'Start Loop',
|
||||
u'Loop Separator',
|
||||
@ -599,7 +600,8 @@ class SlideController(QtGui.QWidget):
|
||||
else:
|
||||
self.PreviewListWidget.selectRow(slideno)
|
||||
self.enableToolBar(serviceItem)
|
||||
#Reset the display html
|
||||
# Pass to display for viewing
|
||||
self.display.buildHtml(self.serviceItem)
|
||||
self.onSlideSelected()
|
||||
self.PreviewListWidget.setFocus()
|
||||
Receiver.send_message(u'slidecontroller_%s_started' % self.typePrefix,
|
||||
@ -781,20 +783,17 @@ class SlideController(QtGui.QWidget):
|
||||
before = time.time()
|
||||
if self.serviceItem.just_rendered:
|
||||
self.serviceItem.just_rendered = False
|
||||
if self.isLive:
|
||||
self.displayManager.buildHtml(self.serviceItem.bg_frame)
|
||||
frame, raw_html = self.serviceItem.get_rendered_frame(row)
|
||||
if self.serviceItem.is_text():
|
||||
frame = self.display.text(raw_html)
|
||||
else:
|
||||
self.displayManager.displayImage(frame)
|
||||
if isinstance(frame, QtGui.QImage):
|
||||
self.SlidePreview.setPixmap(QtGui.QPixmap.fromImage(frame))
|
||||
else:
|
||||
self.SlidePreview.setPixmap(QtGui.QPixmap(frame))
|
||||
log.log(
|
||||
15, u'Slide Rendering took %4s' % (time.time() - before))
|
||||
if self.isLive:
|
||||
if self.serviceItem.is_text():
|
||||
self.displayManager.text(raw_html)
|
||||
else:
|
||||
self.displayManager.displayImage(frame)
|
||||
self.selectedRow = row
|
||||
Receiver.send_message(u'slidecontroller_%s_changed' % self.typePrefix,
|
||||
row)
|
||||
|
Loading…
Reference in New Issue
Block a user