Refactor Alert code for Html

This commit is contained in:
Tim Bentley 2010-06-26 09:09:09 +01:00
parent b59b2bdafa
commit d82f94e326
3 changed files with 39 additions and 65 deletions

View File

@ -52,7 +52,16 @@ class DisplayManager(QtGui.QWidget):
self.videoDisplay.setup()
self.mainDisplay.setup()
def addAlert(self, alertMessage, location):
"""
Handles the add Alert Message to the Displays
"""
self.mainDisplay.addAlert(alertMessage, location)
def close(self):
"""
Handles the closure of the displays
"""
self.videoDisplay.close()
self.audioPlayer.close()
self.mainDisplay.close()
@ -184,7 +193,6 @@ class MainDisplay(DisplayWidget):
self.transparent = QtGui.QPixmap(
self.screen[u'size'].width(), self.screen[u'size'].height())
self.transparent.fill(QtCore.Qt.transparent)
# self.display_alert.setPixmap(self.transparent)
# self.display_text.setPixmap(self.transparent)
#self.frameView(self.transparent)
# To display or not to display?
@ -195,7 +203,6 @@ class MainDisplay(DisplayWidget):
self.setVisible(False)
self.primary = True
def setupScene(self):
self.scene = QtGui.QGraphicsScene(self)
self.scene.setSceneRect(0,0,self.size().width(), self.size().height())
@ -209,15 +216,13 @@ class MainDisplay(DisplayWidget):
def setupText(self):
#self.display_text = QtGui.QGraphicsTextItem()
self.display_text = QtGui.QGraphicsPixmapItem()
#self.display_text.setPos(0,self.size().height()/2)
#self.display_text.setPos(0,0)
#self.display_text.setTextWidth(self.size().width())
self.display_text.setZValue(4)
self.scene.addItem(self.display_text)
def setupAlert(self):
self.alertText = QtGui.QGraphicsTextItem()
self.alertText.setPos(0,self.size().height()/2)
self.alertText.setPos(0,self.size().height() - 76)
self.alertText.setTextWidth(self.size().width())
self.alertText.setZValue(8)
self.scene.addItem(self.alertText)
@ -234,7 +239,6 @@ class MainDisplay(DisplayWidget):
self.setVisible(False)
else:
self.setVisible(True)
#self.showFullScreen()
def hideDisplayForVideo(self):
"""
@ -250,7 +254,6 @@ class MainDisplay(DisplayWidget):
log.debug(u'hideDisplay mode = %d', mode)
self.storeImage = QtGui.QPixmap(self.display_image.pixmap())
self.storeText = QtGui.QPixmap(self.display_text.pixmap())
#self.display_alert.setPixmap(self.transparent)
#self.display_text.setPixmap(self.transparent)
if mode == HideMode.Screen:
#self.display_image.setPixmap(self.transparent)
@ -277,7 +280,6 @@ class MainDisplay(DisplayWidget):
self.display_image.setPixmap(self.storeImage)
if self.storeText:
self.display_text.setPixmap(self.storeText)
#self.display_alert.setPixmap(self.transparent)
self.storeImage = None
self.store = None
Receiver.send_message(u'maindisplay_active')
@ -288,18 +290,18 @@ class MainDisplay(DisplayWidget):
frame, self.screen[u'size'].width(), self.screen[u'size'].height())
self.display_image.setPixmap(QtGui.QPixmap.fromImage(frame))
def setAlertSize(self, top, height):
log.debug(u'setAlertSize')
# self.display_alert.setGeometry(
# QtCore.QRect(0, top,
# self.screen[u'size'].width(), height))
def addAlertImage(self, frame, blank=False):
def addAlert(self, message, location):
"""
Places the Alert text on the display at the correct location
"""
log.debug(u'addAlertImage')
if blank:
self.display_alert.setPixmap(self.transparent)
if location == 0:
self.alertText.setPos(0, 0)
elif location == 1:
self.alertText.setPos(0,self.size().height()/2)
else:
self.display_alert.setPixmap(frame)
self.alertText.setPos(0,self.size().height() - 76)
self.alertText.setHtml(message)
def frameView(self, frame, transition=False, display=True):
"""
@ -333,7 +335,6 @@ class MainDisplay(DisplayWidget):
self.display_frame = frame
if not self.isVisible() and self.screens.display:
self.setVisible(True)
#self.showFullScreen()
else:
self.storeText = QtGui.QPixmap.fromImage(frame[u'main'])

View File

@ -31,6 +31,15 @@ from openlp.core.lib import Receiver, translate
log = logging.getLogger(__name__)
HTMLCODE = u"""
<p style=\"color:%s;
background-color:%s;
font-family:%s;
font-size: %spt; \">
%s
</p>
"""
class AlertsManager(QtCore.QObject):
"""
AlertsTab is the Alerts settings tab in the settings dialog.
@ -47,28 +56,6 @@ class AlertsManager(QtCore.QObject):
QtCore.SIGNAL(u'maindisplay_active'), self.generateAlert)
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'alerts_text'), self.onAlertText)
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'config_screen_changed'), self.screenChanged)
def screenChanged(self):
log.debug(u'screen changed')
self.alertTab = self.parent.alertsTab
self.screen = self.parent.maindisplay.screens.current
self.font = QtGui.QFont()
self.font.setFamily(self.alertTab.font_face)
self.font.setBold(True)
self.font.setPointSize(self.alertTab.font_size)
self.metrics = QtGui.QFontMetrics(self.font)
self.alertHeight = self.metrics.height() + 4
if self.alertTab.location == 0:
self.alertScreenPosition = 0
else:
self.alertScreenPosition = self.screen[u'size'].height() \
- self.alertHeight
self.alertHeight = self.screen[u'size'].height() \
- self.alertScreenPosition
self.parent.maindisplay.setAlertSize(self.alertScreenPosition,
self.alertHeight)
def onAlertText(self, message):
"""
@ -88,8 +75,6 @@ class AlertsManager(QtCore.QObject):
display text
"""
log.debug(u'display alert called %s' % text)
if not self.screen:
self.screenChanged()
self.alertList.append(text)
if self.timer_id != 0:
Receiver.send_message(u'maindisplay_status_text',
@ -105,24 +90,9 @@ class AlertsManager(QtCore.QObject):
return
text = self.alertList.pop(0)
alertTab = self.parent.alertsTab
alertframe = \
QtGui.QPixmap(self.screen[u'size'].width(), self.alertHeight)
alertframe.fill(QtCore.Qt.transparent)
painter = QtGui.QPainter(alertframe)
painter.fillRect(alertframe.rect(), QtCore.Qt.transparent)
painter.setRenderHint(QtGui.QPainter.Antialiasing)
painter.fillRect(
QtCore.QRect(
0, 0, alertframe.rect().width(),
alertframe.rect().height()),
QtGui.QColor(self.alertTab.bg_color))
painter.setFont(self.font)
painter.setPen(QtGui.QColor(self.alertTab.font_color))
x, y = (0, 2)
painter.drawText(
x, y + self.metrics.height() - self.metrics.descent() - 1, text)
painter.end()
self.parent.maindisplay.addAlertImage(alertframe)
text = HTMLCODE % (alertTab.font_color, alertTab.bg_color,
alertTab.font_face, alertTab.font_size, text)
self.parent.preview_controller.parent.displayManager.addAlert(text, alertTab.location)
# check to see if we have a timer running
if self.timer_id == 0:
self.timer_id = self.startTimer(int(alertTab.timeout) * 1000)
@ -130,7 +100,7 @@ class AlertsManager(QtCore.QObject):
def timerEvent(self, event):
log.debug(u'timer event')
if event.timerId() == self.timer_id:
self.parent.maindisplay.addAlertImage(None, True)
self.parent.preview_controller.parent.displayManager.addAlert(u'', self.alertTab.location)
self.killTimer(self.timer_id)
self.timer_id = 0
self.generateAlert()

View File

@ -128,6 +128,7 @@ class AlertsTab(SettingsTab):
self.LocationComboBox = QtGui.QComboBox(self.LocationWidget)
self.LocationComboBox.addItem(QtCore.QString())
self.LocationComboBox.addItem(QtCore.QString())
self.LocationComboBox.addItem(QtCore.QString())
self.LocationComboBox.setObjectName(u'LocationComboBox')
self.LocationLayout.addWidget(self.LocationComboBox)
self.LocationSpacer = QtGui.QSpacerItem(147, 20,
@ -208,9 +209,11 @@ class AlertsTab(SettingsTab):
translate('AlertsPlugin.AlertsTab', 'Preview'))
self.FontPreview.setText(
translate('AlertsPlugin.AlertsTab', 'openlp.org'))
self.LocationComboBox.setItemText(0,
self.LocationComboBox.setItemText(0,
translate('AlertsPlugin.AlertsTab', 'Top'))
self.LocationComboBox.setItemText(1,
self.LocationComboBox.setItemText(1,
translate('AlertsPlugin.AlertsTab', 'Middle'))
self.LocationComboBox.setItemText(2,
translate('AlertsPlugin.AlertsTab', 'Bottom'))
def onBackgroundColorButtonClicked(self):
@ -295,4 +298,4 @@ class AlertsTab(SettingsTab):
font.setPointSize(self.font_size)
self.FontPreview.setFont(font)
self.FontPreview.setStyleSheet(u'background-color: %s; color: %s' %
(self.bg_color, self.font_color))
(self.bg_color, self.font_color))