openlp/openlp/core/ui/maindisplay.py

114 lines
4.1 KiB
Python
Raw Normal View History

2009-04-28 19:19:20 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
"""
OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman
Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley,
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
"""
from PyQt4 import QtCore, QtGui, QtTest
2009-04-28 19:19:20 +00:00
from time import sleep
2009-05-20 20:17:20 +00:00
from openlp.core.lib import translate
2009-04-28 19:19:20 +00:00
class MainDisplay(QtGui.QWidget):
def __init__(self, parent , screens):
2009-05-01 11:50:09 +00:00
QtGui.QWidget.__init__(self, parent)
self.setWindowTitle(u'OpenLP Display')
self.screens = screens
self.display = QtGui.QLabel(self)
self.display.setScaledContents(True)
self.displayBlank = False
self.blankFrame= None
self.alertactive = False
self.alerttext = u''
self.alertTab = None
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]
if screen['number'] != screenNumber:
# 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:
if scrn['number'] == screenNumber:
screen = scrn
break
self.setGeometry(screen['size'])
self.display.setGeometry(screen['size'])
2009-05-01 11:50:09 +00:00
if not screen['primary']:
2009-04-28 19:40:51 +00:00
self.showFullScreen()
2009-05-01 11:50:09 +00:00
else:
self.showMinimized()
2009-04-28 19:19:20 +00:00
painter=QtGui.QPainter()
self.blankFrame = QtGui.QPixmap(screen['size'].width(), screen['size'].height())
painter.begin(self.blankFrame)
painter.fillRect(self.blankFrame.rect(), QtGui.QColor(u'#000000'))
self.frameView(self.blankFrame)
2009-04-28 19:19:20 +00:00
def frameView(self, frame):
self.frame = frame
if not self.displayBlank:
self.display.setPixmap(frame)
elif self.alertactive:
self.displayAlert()
def blankDisplay(self):
if not self.displayBlank:
self.displayBlank = True
self.display.setPixmap(self.blankFrame)
else:
self.displayBlank = False
2009-05-04 13:51:56 +00:00
self.frameView(self.frame)
def alert(self, alertTab, text):
"""
Called from the Alert Tab
alertTab = details from AlertTab
text = display text
screen = screen number to be displayed on.
"""
self.alerttext = text
self.alertTab = alertTab
if len(text) > 0:
self.alertactive = True
self.displayAlert()
self.alertactive = False
def displayAlert(self):
alertframe = QtGui.QPixmap(self.frame)
painter = QtGui.QPainter(alertframe)
top = alertframe.rect().height() * 0.9
painter.fillRect(QtCore.QRect(0, top , alertframe.rect().width(), alertframe.rect().height() - top), QtGui.QColor(self.alertTab.bg_color))
font = QtGui.QFont()
font.setFamily(self.alertTab.font_face)
font.setBold(True)
font.setPointSize(40)
painter.setFont(font)
painter.setPen(QtGui.QColor(self.alertTab.font_color))
x, y = (0, top)
metrics=QtGui.QFontMetrics(font)
painter.drawText(x, y+metrics.height()-metrics.descent()-1, self.alerttext)
painter.end()
self.display.setPixmap(alertframe)
QtTest.QTest.qWait(self.alertTab.timeout*1000)
self.display.setPixmap(self.frame)