Alerts move to top and bottom

This commit is contained in:
Tim Bentley 2010-02-13 07:30:00 +00:00
parent 47a61a6581
commit 973d5e3dd8
2 changed files with 36 additions and 15 deletions

View File

@ -190,6 +190,7 @@ class MainDisplay(DisplayWidget):
else: else:
self.setVisible(False) self.setVisible(False)
self.primary = True self.primary = True
Receiver.send_message(u'screen_changed')
def resetDisplay(self): def resetDisplay(self):
if self.primary: if self.primary:
@ -214,6 +215,11 @@ class MainDisplay(DisplayWidget):
self.screen[u'size'].height() ) self.screen[u'size'].height() )
self.display_image.setPixmap(QtGui.QPixmap.fromImage(frame)) self.display_image.setPixmap(QtGui.QPixmap.fromImage(frame))
def setAlertSize(self, top, height):
self.display_alert.setGeometry(
QtCore.QRect(0, top,
self.screen[u'size'].width(), height))
def addAlertImage(self, frame, blank=False): def addAlertImage(self, frame, blank=False):
if blank: if blank:
self.display_alert.setPixmap(self.transparent) self.display_alert.setPixmap(self.transparent)

View File

@ -21,6 +21,27 @@ class AlertsManager(QtCore.QObject):
self.alertList = [] self.alertList = []
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'alert_text'), self.displayAlert) QtCore.SIGNAL(u'alert_text'), self.displayAlert)
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'screen_changed'), self.screenChanged)
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'config_updated'), self.screenChanged)
def screenChanged(self):
log.debug(u'screen changed')
self.screen = self.parent.maindisplay.screen
self.alertTab = self.parent.alertsTab
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 displayAlert(self, text=u''): def displayAlert(self, text=u''):
""" """
@ -30,11 +51,10 @@ class AlertsManager(QtCore.QObject):
display text display text
""" """
log.debug(u'display alert called %s' % text) log.debug(u'display alert called %s' % text)
self.screen = self.parent.maindisplay.screen
self.parent.maindisplay.parent.StatusBar.showMessage(self.trUtf8(u'')) self.parent.maindisplay.parent.StatusBar.showMessage(self.trUtf8(u''))
self.alertList.append(text) self.alertList.append(text)
if self.timer_id != 0 or self.parent.maindisplay.mediaLoaded: if self.timer_id != 0 or self.parent.maindisplay.mediaLoaded:
self.parent.StatusBar.showMessage(\ self.parent.maindisplay.parent.StatusBar.showMessage(\
self.trUtf8(u'Alert message created and delayed')) self.trUtf8(u'Alert message created and delayed'))
return return
self.generateAlert() self.generateAlert()
@ -46,7 +66,7 @@ class AlertsManager(QtCore.QObject):
text = self.alertList.pop(0) text = self.alertList.pop(0)
alertTab = self.parent.alertsTab alertTab = self.parent.alertsTab
alertframe = \ alertframe = \
QtGui.QPixmap(self.screen[u'size'].width(), self.parent.maindisplay.alertHeight) QtGui.QPixmap(self.screen[u'size'].width(), self.alertHeight)
alertframe.fill(QtCore.Qt.transparent) alertframe.fill(QtCore.Qt.transparent)
painter = QtGui.QPainter(alertframe) painter = QtGui.QPainter(alertframe)
painter.fillRect(alertframe.rect(), QtCore.Qt.transparent) painter.fillRect(alertframe.rect(), QtCore.Qt.transparent)
@ -55,26 +75,21 @@ class AlertsManager(QtCore.QObject):
QtCore.QRect( QtCore.QRect(
0, 0, alertframe.rect().width(), 0, 0, alertframe.rect().width(),
alertframe.rect().height()), alertframe.rect().height()),
QtGui.QColor(alertTab.bg_color)) QtGui.QColor(self.alertTab.bg_color))
font = QtGui.QFont() painter.setFont(self.font)
font.setFamily(alertTab.font_face) painter.setPen(QtGui.QColor(self.alertTab.font_color))
font.setBold(True) x, y = (0, 2)
font.setPointSize(alertTab.font_size)
painter.setFont(font)
painter.setPen(QtGui.QColor(alertTab.font_color))
x, y = (0, 0)
metrics = QtGui.QFontMetrics(font)
painter.drawText( painter.drawText(
x, y + metrics.height() - metrics.descent() - 1, text) x, y + self.metrics.height() - self.metrics.descent() - 1, text)
painter.end() painter.end()
self.parent.maindisplay.display_alert.setPixmap(alertframe) self.parent.maindisplay.addAlertImage(alertframe)
# check to see if we have a timer running # check to see if we have a timer running
if self.timer_id == 0: if self.timer_id == 0:
self.timer_id = self.startTimer(int(alertTab.timeout) * 1000) self.timer_id = self.startTimer(int(alertTab.timeout) * 1000)
def timerEvent(self, event): def timerEvent(self, event):
if event.timerId() == self.timer_id: if event.timerId() == self.timer_id:
self.parent.maindisplay.display_alert.setPixmap(self.parent.maindisplay.transparent) self.parent.maindisplay.addAlertImage(None, True)
self.killTimer(self.timer_id) self.killTimer(self.timer_id)
self.timer_id = 0 self.timer_id = 0
self.generateAlert() self.generateAlert()