2009-04-28 19:19:20 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
|
|
|
|
2009-09-08 19:58:05 +00:00
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# Copyright (c) 2008-2009 Raoul Snyman #
|
|
|
|
# Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley, Carsten #
|
|
|
|
# Tinggaard, Jon Tibble, Jonathan Corwin, Maikel Stuivenberg, Scott Guerrieri #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
2009-04-28 19:19:20 +00:00
|
|
|
|
2009-08-10 20:10:20 +00:00
|
|
|
import logging
|
2009-07-19 07:40:31 +00:00
|
|
|
from PyQt4 import QtCore, QtGui
|
2009-04-28 19:19:20 +00:00
|
|
|
|
2009-09-25 00:43:42 +00:00
|
|
|
from openlp.core.lib import Receiver
|
2009-04-28 19:19:20 +00:00
|
|
|
|
|
|
|
class MainDisplay(QtGui.QWidget):
|
2009-08-06 13:17:36 +00:00
|
|
|
"""
|
|
|
|
This is the form that is used to display things on the projector.
|
|
|
|
"""
|
2009-08-10 20:10:20 +00:00
|
|
|
global log
|
|
|
|
log=logging.getLogger(u'MainDisplay')
|
|
|
|
log.info(u'MainDisplay Loaded')
|
2009-04-28 19:19:20 +00:00
|
|
|
|
2009-08-06 13:17:36 +00:00
|
|
|
def __init__(self, parent, screens):
|
|
|
|
"""
|
|
|
|
The constructor for the display form.
|
|
|
|
|
|
|
|
``parent``
|
|
|
|
The parent widget.
|
|
|
|
|
|
|
|
``screens``
|
|
|
|
The list of screens.
|
|
|
|
"""
|
2009-08-10 20:10:20 +00:00
|
|
|
log.debug(u'Initilisation started')
|
|
|
|
QtGui.QWidget.__init__(self, None)
|
|
|
|
self.parent = parent
|
2009-05-01 11:50:09 +00:00
|
|
|
self.setWindowTitle(u'OpenLP Display')
|
|
|
|
self.screens = screens
|
2009-06-05 18:53:50 +00:00
|
|
|
self.layout = QtGui.QVBoxLayout(self)
|
|
|
|
self.layout.setSpacing(0)
|
|
|
|
self.layout.setMargin(0)
|
|
|
|
self.layout.setObjectName(u'layout')
|
2009-05-01 11:50:09 +00:00
|
|
|
self.display = QtGui.QLabel(self)
|
2009-05-04 13:48:12 +00:00
|
|
|
self.display.setScaledContents(True)
|
2009-06-05 18:53:50 +00:00
|
|
|
self.layout.addWidget(self.display)
|
2009-05-04 13:48:12 +00:00
|
|
|
self.displayBlank = False
|
2009-08-06 13:17:36 +00:00
|
|
|
self.blankFrame = None
|
2009-06-01 17:50:37 +00:00
|
|
|
self.alertactive = False
|
|
|
|
self.alertTab = None
|
2009-07-19 07:40:31 +00:00
|
|
|
self.timer_id = 0
|
2009-08-24 04:30:04 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
|
|
|
QtCore.SIGNAL(u'live_slide_blank'), self.blankDisplay)
|
2009-08-26 05:00:19 +00:00
|
|
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
|
|
|
QtCore.SIGNAL(u'alert_text'), self.displayAlert)
|
2009-05-01 11:50:09 +00:00
|
|
|
|
|
|
|
def setup(self, screenNumber):
|
|
|
|
"""
|
|
|
|
Sets up the screen on a particular screen.
|
|
|
|
@param (integer) screen This is the screen number.
|
|
|
|
"""
|
|
|
|
screen = self.screens[screenNumber]
|
2009-06-05 18:53:50 +00:00
|
|
|
if screen[u'number'] != screenNumber:
|
2009-05-01 11:50:09 +00:00
|
|
|
# We will most probably never actually hit this bit, but just in
|
|
|
|
# case the index in the list doesn't match the screen number, we
|
|
|
|
# search for it.
|
|
|
|
for scrn in self.screens:
|
2009-06-05 18:53:50 +00:00
|
|
|
if scrn[u'number'] == screenNumber:
|
2009-05-01 11:50:09 +00:00
|
|
|
screen = scrn
|
|
|
|
break
|
2009-06-05 18:53:50 +00:00
|
|
|
self.setGeometry(screen[u'size'])
|
|
|
|
if not screen[u'primary']:
|
2009-04-28 19:40:51 +00:00
|
|
|
self.showFullScreen()
|
2009-05-01 11:50:09 +00:00
|
|
|
else:
|
2009-06-07 19:34:24 +00:00
|
|
|
self.showMinimized()
|
2009-07-21 18:10:14 +00:00
|
|
|
#Build a custom splash screen
|
2009-08-09 12:05:54 +00:00
|
|
|
self.InitialFrame = QtGui.QImage(
|
|
|
|
screen[u'size'].width(), screen[u'size'].height(),
|
|
|
|
QtGui.QImage.Format_ARGB32_Premultiplied)
|
2009-07-21 18:10:14 +00:00
|
|
|
splash_image = QtGui.QImage(u':/graphics/openlp-splash-screen.png')
|
|
|
|
painter_image = QtGui.QPainter()
|
|
|
|
painter_image.begin(self.InitialFrame)
|
|
|
|
painter_image.fillRect(self.InitialFrame.rect(), QtCore.Qt.white)
|
2009-08-09 12:05:54 +00:00
|
|
|
painter_image.drawImage(
|
|
|
|
(screen[u'size'].width() - splash_image.width()) / 2,
|
|
|
|
(screen[u'size'].height() - splash_image.height()) / 2,
|
|
|
|
splash_image)
|
2009-07-21 18:10:14 +00:00
|
|
|
self.frameView(self.InitialFrame)
|
|
|
|
#Build a Black screen
|
2009-06-05 18:53:50 +00:00
|
|
|
painter = QtGui.QPainter()
|
2009-08-09 12:05:54 +00:00
|
|
|
self.blankFrame = QtGui.QImage(
|
|
|
|
screen[u'size'].width(), screen[u'size'].height(),
|
|
|
|
QtGui.QImage.Format_ARGB32_Premultiplied)
|
2009-05-04 13:48:12 +00:00
|
|
|
painter.begin(self.blankFrame)
|
2009-06-10 15:37:33 +00:00
|
|
|
painter.fillRect(self.blankFrame.rect(), QtCore.Qt.black)
|
2009-05-04 13:48:12 +00:00
|
|
|
|
2009-04-28 19:19:20 +00:00
|
|
|
def frameView(self, frame):
|
2009-07-19 07:40:31 +00:00
|
|
|
"""
|
|
|
|
Called from a slide controller to display a frame
|
|
|
|
if the alert is in progress the alert is added on top
|
|
|
|
``frame``
|
|
|
|
Image frame to be rendered
|
|
|
|
"""
|
2009-05-16 19:47:30 +00:00
|
|
|
self.frame = frame
|
2009-07-19 07:40:31 +00:00
|
|
|
if self.timer_id != 0 :
|
2009-06-01 17:50:37 +00:00
|
|
|
self.displayAlert()
|
2009-07-19 07:40:31 +00:00
|
|
|
elif not self.displayBlank:
|
|
|
|
self.display.setPixmap(QtGui.QPixmap.fromImage(frame))
|
2009-05-04 13:48:12 +00:00
|
|
|
|
|
|
|
def blankDisplay(self):
|
2009-06-01 17:50:37 +00:00
|
|
|
if not self.displayBlank:
|
2009-05-04 13:48:12 +00:00
|
|
|
self.displayBlank = True
|
2009-07-03 19:08:21 +00:00
|
|
|
self.display.setPixmap(QtGui.QPixmap.fromImage(self.blankFrame))
|
2009-05-04 13:48:12 +00:00
|
|
|
else:
|
|
|
|
self.displayBlank = False
|
2009-05-04 13:51:56 +00:00
|
|
|
self.frameView(self.frame)
|
2009-06-01 17:50:37 +00:00
|
|
|
|
2009-09-21 17:56:36 +00:00
|
|
|
def displayAlert(self, text=u''):
|
2009-06-01 17:50:37 +00:00
|
|
|
"""
|
2009-07-19 07:40:31 +00:00
|
|
|
Called from the Alert Tab to display an alert
|
|
|
|
|
|
|
|
``text``
|
|
|
|
display text
|
2009-06-01 17:50:37 +00:00
|
|
|
"""
|
2009-08-10 20:10:20 +00:00
|
|
|
alertTab = self.parent.settingsForm.AlertsTab
|
2009-06-16 18:21:24 +00:00
|
|
|
alertframe = QtGui.QPixmap.fromImage(self.frame)
|
2009-06-01 17:50:37 +00:00
|
|
|
painter = QtGui.QPainter(alertframe)
|
|
|
|
top = alertframe.rect().height() * 0.9
|
2009-08-06 14:51:38 +00:00
|
|
|
painter.fillRect(
|
2009-09-21 19:26:10 +00:00
|
|
|
QtCore.QRect(
|
|
|
|
0, top, alertframe.rect().width(),
|
|
|
|
alertframe.rect().height() - top),
|
2009-08-10 20:10:20 +00:00
|
|
|
QtGui.QColor(alertTab.bg_color))
|
2009-06-01 17:50:37 +00:00
|
|
|
font = QtGui.QFont()
|
2009-08-10 20:10:20 +00:00
|
|
|
font.setFamily(alertTab.font_face)
|
2009-06-01 17:50:37 +00:00
|
|
|
font.setBold(True)
|
|
|
|
font.setPointSize(40)
|
|
|
|
painter.setFont(font)
|
2009-08-10 20:10:20 +00:00
|
|
|
painter.setPen(QtGui.QColor(alertTab.font_color))
|
2009-06-01 17:50:37 +00:00
|
|
|
x, y = (0, top)
|
2009-08-06 21:30:14 +00:00
|
|
|
metrics = QtGui.QFontMetrics(font)
|
2009-08-06 14:51:38 +00:00
|
|
|
painter.drawText(
|
2009-08-10 20:10:20 +00:00
|
|
|
x, y + metrics.height() - metrics.descent() - 1, text)
|
2009-06-01 17:50:37 +00:00
|
|
|
painter.end()
|
|
|
|
self.display.setPixmap(alertframe)
|
2009-07-19 07:40:31 +00:00
|
|
|
# check to see if we have a timer running
|
|
|
|
if self.timer_id == 0:
|
2009-08-10 20:10:20 +00:00
|
|
|
self.timer_id = self.startTimer(int(alertTab.timeout) * 1000)
|
2009-07-19 07:40:31 +00:00
|
|
|
|
|
|
|
def timerEvent(self, event):
|
|
|
|
if event.timerId() == self.timer_id:
|
|
|
|
self.display.setPixmap(QtGui.QPixmap.fromImage(self.frame))
|
|
|
|
self.killTimer(self.timer_id)
|
|
|
|
self.timer_id = 0
|