head again, perhaps I should have waited

This commit is contained in:
Jonathan Corwin 2010-05-01 10:02:47 +01:00
commit 6c52ad359f
2 changed files with 70 additions and 38 deletions

View File

@ -48,8 +48,8 @@ class Renderer(object):
self.theme_name = None self.theme_name = None
self._theme = None self._theme = None
self._bg_image_filename = None self._bg_image_filename = None
self._frame = None self.frame = None
self._frameOp = None self.frame_opaque = None
self.bg_frame = None self.bg_frame = None
self.bg_image = None self.bg_image = None
@ -89,10 +89,10 @@ class Renderer(object):
""" """
log.debug(u'set bg image %s', filename) log.debug(u'set bg image %s', filename)
self._bg_image_filename = unicode(filename) self._bg_image_filename = unicode(filename)
if self._frame: if self.frame:
self.bg_image = resize_image(self._bg_image_filename, self.bg_image = resize_image(self._bg_image_filename,
self._frame.width(), self.frame.width(),
self._frame.height()) self.frame.height())
def set_frame_dest(self, frame_width, frame_height, preview=False): def set_frame_dest(self, frame_width, frame_height, preview=False):
""" """
@ -111,13 +111,13 @@ class Renderer(object):
self.bg_frame = None self.bg_frame = None
log.debug(u'set frame dest (frame) w %d h %d', frame_width, log.debug(u'set frame dest (frame) w %d h %d', frame_width,
frame_height) frame_height)
self._frame = QtGui.QImage(frame_width, frame_height, self.frame = QtGui.QImage(frame_width, frame_height,
QtGui.QImage.Format_ARGB32_Premultiplied) QtGui.QImage.Format_ARGB32_Premultiplied)
self._frameOp = QtGui.QImage(frame_width, frame_height, self.frame_opaque = QtGui.QImage(frame_width, frame_height,
QtGui.QImage.Format_ARGB32_Premultiplied) QtGui.QImage.Format_ARGB32_Premultiplied)
if self._bg_image_filename and not self.bg_image: if self._bg_image_filename and not self.bg_image:
self.bg_image = resize_image(self._bg_image_filename, self.bg_image = resize_image(self._bg_image_filename,
self._frame.width(), self._frame.height()) self.frame.width(), self.frame.height())
if self.bg_frame is None: if self.bg_frame is None:
self._generate_background_frame() self._generate_background_frame()
@ -242,9 +242,9 @@ class Renderer(object):
if footer_lines: if footer_lines:
bbox1 = self._render_lines_unaligned(footer_lines, True) bbox1 = self._render_lines_unaligned(footer_lines, True)
# reset the frame. first time do not worry about what you paint on. # reset the frame. first time do not worry about what you paint on.
self._frame = QtGui.QImage(self.bg_frame) self.frame = QtGui.QImage(self.bg_frame)
if self._theme.display_slideTransition: if self._theme.display_slideTransition:
self._frameOp = QtGui.QImage(self.bg_frame) self.frame_opaque = QtGui.QImage(self.bg_frame)
x, y = self._correctAlignment(self._rect, bbox) x, y = self._correctAlignment(self._rect, bbox)
bbox = self._render_lines_unaligned(lines, False, (x, y), True) bbox = self._render_lines_unaligned(lines, False, (x, y), True)
if footer_lines: if footer_lines:
@ -252,9 +252,9 @@ class Renderer(object):
(self._rect_footer.left(), self._rect_footer.top()), True) (self._rect_footer.left(), self._rect_footer.top()), True)
log.debug(u'generate_frame_from_lines - Finish') log.debug(u'generate_frame_from_lines - Finish')
if self._theme.display_slideTransition: if self._theme.display_slideTransition:
return {u'main':self._frame, u'trans':self._frameOp} return {u'main':self.frame, u'trans':self.frame_opaque}
else: else:
return {u'main':self._frame, u'trans':None} return {u'main':self.frame, u'trans':None}
def _generate_background_frame(self): def _generate_background_frame(self):
""" """
@ -264,36 +264,36 @@ class Renderer(object):
assert(self._theme) assert(self._theme)
if self._theme.background_mode == u'transparent': if self._theme.background_mode == u'transparent':
self.bg_frame = \ self.bg_frame = \
QtGui.QPixmap(self._frame.width(), self._frame.height()) QtGui.QPixmap(self.frame.width(), self.frame.height())
self.bg_frame.fill(QtCore.Qt.transparent) self.bg_frame.fill(QtCore.Qt.transparent)
else: else:
self.bg_frame = QtGui.QImage(self._frame.width(), self.bg_frame = QtGui.QImage(self.frame.width(),
self._frame.height(), QtGui.QImage.Format_ARGB32_Premultiplied) self.frame.height(), QtGui.QImage.Format_ARGB32_Premultiplied)
log.debug(u'render background %s start', self._theme.background_type) log.debug(u'render background %s start', self._theme.background_type)
painter = QtGui.QPainter() painter = QtGui.QPainter()
painter.begin(self.bg_frame) painter.begin(self.bg_frame)
if self._theme.background_mode == u'transparent': if self._theme.background_mode == u'transparent':
painter.fillRect(self._frame.rect(), QtCore.Qt.transparent) painter.fillRect(self.frame.rect(), QtCore.Qt.transparent)
else: else:
if self._theme.background_type == u'solid': if self._theme.background_type == u'solid':
painter.fillRect(self._frame.rect(), painter.fillRect(self.frame.rect(),
QtGui.QColor(self._theme.background_color)) QtGui.QColor(self._theme.background_color))
elif self._theme.background_type == u'gradient': elif self._theme.background_type == u'gradient':
# gradient # gradient
gradient = None gradient = None
if self._theme.background_direction == u'horizontal': if self._theme.background_direction == u'horizontal':
w = int(self._frame.width()) / 2 w = int(self.frame.width()) / 2
# vertical # vertical
gradient = QtGui.QLinearGradient(w, 0, w, gradient = QtGui.QLinearGradient(w, 0, w,
self._frame.height()) self.frame.height())
elif self._theme.background_direction == u'vertical': elif self._theme.background_direction == u'vertical':
h = int(self._frame.height()) / 2 h = int(self.frame.height()) / 2
# Horizontal # Horizontal
gradient = QtGui.QLinearGradient(0, h, self._frame.width(), gradient = QtGui.QLinearGradient(0, h, self.frame.width(),
h) h)
else: else:
w = int(self._frame.width()) / 2 w = int(self.frame.width()) / 2
h = int(self._frame.height()) / 2 h = int(self.frame.height()) / 2
# Circular # Circular
gradient = QtGui.QRadialGradient(w, h, w) gradient = QtGui.QRadialGradient(w, h, w)
gradient.setColorAt(0, gradient.setColorAt(0,
@ -302,8 +302,8 @@ class Renderer(object):
QtGui.QColor(self._theme.background_endColor)) QtGui.QColor(self._theme.background_endColor))
painter.setBrush(QtGui.QBrush(gradient)) painter.setBrush(QtGui.QBrush(gradient))
rectPath = QtGui.QPainterPath() rectPath = QtGui.QPainterPath()
max_x = self._frame.width() max_x = self.frame.width()
max_y = self._frame.height() max_y = self.frame.height()
rectPath.moveTo(0, 0) rectPath.moveTo(0, 0)
rectPath.lineTo(0, max_y) rectPath.lineTo(0, max_y)
rectPath.lineTo(max_x, max_y) rectPath.lineTo(max_x, max_y)
@ -312,7 +312,7 @@ class Renderer(object):
painter.drawPath(rectPath) painter.drawPath(rectPath)
elif self._theme.background_type == u'image': elif self._theme.background_type == u'image':
# image # image
painter.fillRect(self._frame.rect(), QtCore.Qt.black) painter.fillRect(self.frame.rect(), QtCore.Qt.black)
if self.bg_image: if self.bg_image:
painter.drawImage(0, 0, self.bg_image) painter.drawImage(0, 0, self.bg_image)
painter.end() painter.end()
@ -378,7 +378,7 @@ class Renderer(object):
retval = QtCore.QRect(x, y, brx - x, bry - y) retval = QtCore.QRect(x, y, brx - x, bry - y)
if self._debug: if self._debug:
painter = QtGui.QPainter() painter = QtGui.QPainter()
painter.begin(self._frame) painter.begin(self.frame)
painter.setPen(QtGui.QPen(QtGui.QColor(0, 0, 255))) painter.setPen(QtGui.QPen(QtGui.QColor(0, 0, 255)))
painter.drawRect(retval) painter.drawRect(retval)
painter.end() painter.end()
@ -414,11 +414,11 @@ class Renderer(object):
starty = y starty = y
rightextent = None rightextent = None
self.painter = QtGui.QPainter() self.painter = QtGui.QPainter()
self.painter.begin(self._frame) self.painter.begin(self.frame)
self.painter.setRenderHint(QtGui.QPainter.Antialiasing) self.painter.setRenderHint(QtGui.QPainter.Antialiasing)
if self._theme.display_slideTransition: if self._theme.display_slideTransition:
self.painter2 = QtGui.QPainter() self.painter2 = QtGui.QPainter()
self.painter2.begin(self._frameOp) self.painter2.begin(self.frame_opaque)
self.painter2.setRenderHint(QtGui.QPainter.Antialiasing) self.painter2.setRenderHint(QtGui.QPainter.Antialiasing)
self.painter2.setOpacity(0.7) self.painter2.setOpacity(0.7)
# dont allow alignment messing with footers # dont allow alignment messing with footers
@ -581,4 +581,4 @@ class Renderer(object):
""" """
image.save(u'renderer.png', u'png') image.save(u'renderer.png', u'png')
if image2: if image2:
image2.save(u'renderer2.png', u'png') image2.save(u'renderer2.png', u'png')

View File

@ -334,7 +334,7 @@ class VideoDisplay(Phonon.VideoWidget):
self.parent = parent self.parent = parent
self.screens = screens self.screens = screens
self.hidden = False self.hidden = False
self.background = False self.message = None
self.mediaObject = Phonon.MediaObject() self.mediaObject = Phonon.MediaObject()
self.setAspectRatio(aspect) self.setAspectRatio(aspect)
self.audioObject = Phonon.AudioOutput(Phonon.VideoCategory) self.audioObject = Phonon.AudioOutput(Phonon.VideoCategory)
@ -389,16 +389,27 @@ class VideoDisplay(Phonon.VideoWidget):
self.setVisible(False) self.setVisible(False)
self.primary = True self.primary = True
def onMediaBackground(self, message): def onMediaBackground(self, message=None):
"""
Play a video triggered from the video plugin with the
file name passed in on the event.
Also triggered from the Finish event so the video will loop
if it is triggered from the plugin
"""
log.debug(u'VideoDisplay Queue new media message %s' % message)
#If not file take the stored one
if not message: if not message:
message = self.message message = self.message
log.debug(u'VideoDisplay Queue new media message %s' % message) # still no file name then stop as it was a normal video stopping
self.mediaObject.setCurrentSource(Phonon.MediaSource(message)) if message:
self.message = message self.mediaObject.setCurrentSource(Phonon.MediaSource(message))
self.background = True self.message = message
self._play() self._play()
def onMediaQueue(self, message): def onMediaQueue(self, message):
"""
Set up a video to play from the serviceitem.
"""
log.debug(u'VideoDisplay Queue new media message %s' % message) log.debug(u'VideoDisplay Queue new media message %s' % message)
file = os.path.join(message[0].get_frame_path(), file = os.path.join(message[0].get_frame_path(),
message[0].get_frame_title()) message[0].get_frame_title())
@ -406,39 +417,60 @@ class VideoDisplay(Phonon.VideoWidget):
self._play() self._play()
def onMediaPlay(self): def onMediaPlay(self):
"""
Respond to the Play button on the slide controller unless the display
has been hidden by the slidecontroller
"""
if not self.hidden: if not self.hidden:
log.debug(u'VideoDisplay Play the new media, Live ') log.debug(u'VideoDisplay Play the new media, Live ')
self._play() self._play()
def _play(self): def _play(self):
"""
We want to play the video so start it and display the screen
"""
log.debug(u'VideoDisplay _play called') log.debug(u'VideoDisplay _play called')
self.mediaObject.play() self.mediaObject.play()
self.setVisible(True) self.setVisible(True)
self.showFullScreen() self.showFullScreen()
def onMediaPause(self): def onMediaPause(self):
"""
Pause the video and refresh the screen
"""
log.debug(u'VideoDisplay Media paused by user') log.debug(u'VideoDisplay Media paused by user')
self.mediaObject.pause() self.mediaObject.pause()
self.show() self.show()
def onMediaStop(self): def onMediaStop(self):
"""
Stop the video and clean up
"""
log.debug(u'VideoDisplay Media stopped by user') log.debug(u'VideoDisplay Media stopped by user')
self.background = False
self.message = None self.message = None
self.mediaObject.stop() self.mediaObject.stop()
self.onMediaFinish() self.onMediaFinish()
def onMediaFinish(self): def onMediaFinish(self):
"""
Clean up the Object queue
"""
log.debug(u'VideoDisplay Reached end of media playlist') log.debug(u'VideoDisplay Reached end of media playlist')
self.mediaObject.clearQueue() self.mediaObject.clearQueue()
self.setVisible(False) self.setVisible(False)
def mediaHide(self): def mediaHide(self):
"""
Hide the video display
"""
self.mediaObject.pause() self.mediaObject.pause()
self.hidden = True self.hidden = True
self.setVisible(False) self.setVisible(False)
def mediaShow(self): def mediaShow(self):
"""
Show the video disaply if it was already hidden
"""
if self.hidden: if self.hidden:
self.hidden = False self.hidden = False
self._play() self._play()