Video cleanups

This commit is contained in:
Tim Bentley 2010-08-04 20:09:43 +01:00
parent 821911503e
commit 6d352df382
4 changed files with 63 additions and 63 deletions

View File

@ -293,59 +293,59 @@ class Renderer(object):
Results are cached for performance reasons.
"""
assert(self._theme)
if self._theme.background_mode == u'transparent':
self.bg_frame = \
QtGui.QPixmap(self.frame.width(), self.frame.height())
self.bg_frame.fill(QtCore.Qt.transparent)
else:
self.bg_frame = QtGui.QImage(self.frame.width(),
self.frame.height(), QtGui.QImage.Format_ARGB32_Premultiplied)
# if self._theme.background_mode == u'transparent':
# self.bg_frame = \
# QtGui.QPixmap(self.frame.width(), self.frame.height())
# self.bg_frame.fill(QtCore.Qt.transparent)
# else:
self.bg_frame = QtGui.QImage(self.frame.width(),
self.frame.height(), QtGui.QImage.Format_ARGB32_Premultiplied)
log.debug(u'render background %s start', self._theme.background_type)
painter = QtGui.QPainter()
painter.begin(self.bg_frame)
if self._theme.background_mode == u'transparent':
painter.fillRect(self.frame.rect(), QtCore.Qt.transparent)
else:
if self._theme.background_type == u'solid':
painter.fillRect(self.frame.rect(),
QtGui.QColor(self._theme.background_color))
elif self._theme.background_type == u'gradient':
# gradient
gradient = None
if self._theme.background_direction == u'horizontal':
w = int(self.frame.width()) / 2
# vertical
gradient = QtGui.QLinearGradient(w, 0, w,
self.frame.height())
elif self._theme.background_direction == u'vertical':
h = int(self.frame.height()) / 2
# Horizontal
gradient = QtGui.QLinearGradient(0, h, self.frame.width(),
h)
else:
w = int(self.frame.width()) / 2
h = int(self.frame.height()) / 2
# Circular
gradient = QtGui.QRadialGradient(w, h, w)
gradient.setColorAt(0,
QtGui.QColor(self._theme.background_startColor))
gradient.setColorAt(1,
QtGui.QColor(self._theme.background_endColor))
painter.setBrush(QtGui.QBrush(gradient))
rect_path = QtGui.QPainterPath()
max_x = self.frame.width()
max_y = self.frame.height()
rect_path.moveTo(0, 0)
rect_path.lineTo(0, max_y)
rect_path.lineTo(max_x, max_y)
rect_path.lineTo(max_x, 0)
rect_path.closeSubpath()
painter.drawPath(rect_path)
elif self._theme.background_type == u'image':
# image
painter.fillRect(self.frame.rect(), QtCore.Qt.black)
if self.bg_image:
painter.drawImage(0, 0, self.bg_image)
# if self._theme.background_mode == u'transparent':
# painter.fillRect(self.frame.rect(), QtCore.Qt.transparent)
# else:
if self._theme.background_type == u'solid':
painter.fillRect(self.frame.rect(),
QtGui.QColor(self._theme.background_color))
elif self._theme.background_type == u'gradient':
# gradient
gradient = None
if self._theme.background_direction == u'horizontal':
w = int(self.frame.width()) / 2
# vertical
gradient = QtGui.QLinearGradient(w, 0, w,
self.frame.height())
elif self._theme.background_direction == u'vertical':
h = int(self.frame.height()) / 2
# Horizontal
gradient = QtGui.QLinearGradient(0, h, self.frame.width(),
h)
else:
w = int(self.frame.width()) / 2
h = int(self.frame.height()) / 2
# Circular
gradient = QtGui.QRadialGradient(w, h, w)
gradient.setColorAt(0,
QtGui.QColor(self._theme.background_startColor))
gradient.setColorAt(1,
QtGui.QColor(self._theme.background_endColor))
painter.setBrush(QtGui.QBrush(gradient))
rect_path = QtGui.QPainterPath()
max_x = self.frame.width()
max_y = self.frame.height()
rect_path.moveTo(0, 0)
rect_path.lineTo(0, max_y)
rect_path.lineTo(max_x, max_y)
rect_path.lineTo(max_x, 0)
rect_path.closeSubpath()
painter.drawPath(rect_path)
elif self._theme.background_type == u'image':
# image
painter.fillRect(self.frame.rect(), QtCore.Qt.black)
if self.bg_image:
painter.drawImage(0, 0, self.bg_image)
painter.end()
log.debug(u'render background End')

View File

@ -175,10 +175,8 @@ class MainDisplay(DisplayWidget):
The slide text to be displayed
"""
log.debug(u'alert')
js = "displayAlert('" + \
text.replace("\\", "\\\\").replace("\'", "\\\'") + "')"
print js
self.frame.evaluateJavaScript(js)
self.frame.evaluateJavaScript( "displayAlert('" + \
text.replace("\\", "\\\\").replace("\'", "\\\'") + "')")
def image(self, image):
"""
@ -240,14 +238,16 @@ class MainDisplay(DisplayWidget):
self.frame.evaluateJavaScript(
"document.getElementById('image').style.visibility = 'visible'")
def videoVolume(self, amount):
def videoVolume(self, volume):
"""
Changes the volume of a running video
"""
log.debug(u'videoVolume')
self.frame.evaluateJavaScript("document.getElementById('video').volume = 0")
log.debug(u'videoVolume %d' % volume)
self.frame.evaluateJavaScript(
"document.getElementById('video').volume = %s" %
str(float(volume)/float(10)))
def video(self, videoPath, noSound=False):
def video(self, videoPath, volume):
"""
Loads and starts a video to run with the option of sound
"""
@ -258,8 +258,7 @@ class MainDisplay(DisplayWidget):
self.frame.evaluateJavaScript(
"document.getElementById('image').style.visibility = 'hidden'")
self.videoPlay()
if noSound:
self.videoVolume(0)
self.videoVolume(volume)
def loaded(self):
"""

View File

@ -672,7 +672,7 @@ class SlideController(QtGui.QWidget):
"""
log.debug(u'mainDisplaySetBackground live = %s' % self.isLive)
if not self.display.primary:
self.display.hideDisplay()
self.onHideDisplay(True)
def onSlideBlank(self):
"""
@ -937,7 +937,7 @@ class SlideController(QtGui.QWidget):
log.debug(u'SlideController onMediaStart')
if self.isLive:
file = os.path.join(item.get_frame_path(), item.get_frame_title())
self.display.video(file)
self.display.video(file, self.volume)
self.volumeSlider.setValue(self.volume)
else:
self.mediaObject.stop()
@ -954,6 +954,7 @@ class SlideController(QtGui.QWidget):
"""
log.debug(u'SlideController mediaVolume')
self.volume = self.volumeSlider.value()
print self.volume
self.display.videoVolume(self.volume)
def onMediaPause(self):

View File

@ -115,7 +115,7 @@ class MediaMediaItem(MediaManagerItem):
'You must select a media file to replace the background with.')):
item = self.listView.currentItem()
filename = unicode(item.data(QtCore.Qt.UserRole).toString())
self.parent.liveController.display.video(filename, True)
self.parent.liveController.display.video(filename, 0)
self.resetButton.setVisible(True)
def generateSlideData(self, service_item, item=None):