Image display refactoring

This commit is contained in:
Tim Bentley 2010-06-30 05:52:52 +01:00
parent ebb368559f
commit 4767ec08a2
3 changed files with 88 additions and 38 deletions

View File

@ -35,6 +35,7 @@ import uuid
from PyQt4 import QtGui
from openlp.core.lib import build_icon, resize_image
from openlp.core.utils import AppLocation
log = logging.getLogger(__name__)
@ -92,6 +93,7 @@ class ServiceItem(object):
self.is_valid = True
self.cache = {}
self.icon = None
self.serviceItemPath = AppLocation.get_section_data_path(u'serviceItems')
def add_capability(self, capability):
"""
@ -153,9 +155,12 @@ class ServiceItem(object):
del self.cache[len(self._display_frames)]
log.log(15, u'Formatting took %4s' % (time.time() - before))
elif self.service_item_type == ServiceItemType.Image:
for slide in self._raw_frames:
for count, slide in enumerate(self._raw_frames):
slide[u'image'] = resize_image(slide[u'image'],
self.render_manager.width, self.render_manager.height)
path = os.path.join(self.serviceItemPath, self._uuid + unicode(count) + u'.png')
slide[u'image'].save(path)
slide[u'display'] = path
elif self.service_item_type == ServiceItemType.Command:
pass
else:
@ -371,7 +376,8 @@ class ServiceItem(object):
if self.service_item_type == ServiceItemType.Text:
return self.render_individual(row)
else:
return {u'main':self._raw_frames[row][u'image'], u'trans':None}
return {u'main':self._raw_frames[row][u'image'],
u'trans':None, u'display':self._raw_frames[row][u'display']}
def get_frame_title(self, row=0):
"""

View File

@ -26,14 +26,21 @@
import logging
import os
from PyQt4 import QtCore, QtGui
from PyQt4 import QtCore, QtGui, QtWebKit
from PyQt4.phonon import Phonon
from openlp.core.lib import Receiver, resize_image
from openlp.core.ui import HideMode
from openlp.core.utils import AppLocation
log = logging.getLogger(__name__)
HTMLIMAGE = """<html>
<body>
<img src=\"file://%s\" alt\"Hello\">
</body></html>
"""
class DisplayManager(QtGui.QWidget):
"""
Wrapper class to hold the display widgets.
@ -76,10 +83,16 @@ class DisplayManager(QtGui.QWidget):
def addAlert(self, alertMessage, location):
"""
Handles the add Alert Message to the Displays
Handles the addition of an Alert Message to the Displays
"""
self.mainDisplay.addAlert(alertMessage, location)
def displayImage(self, path):
"""
Handles the addition of a background Image to the displays
"""
self.mainDisplay.displayImage(path)
def onStartVideo(self, item):
"""
Handles the Starting of a Video and Display Management
@ -183,7 +196,7 @@ class MainDisplay(DisplayWidget):
self.primary = True
self.blankFrame = None
self.frame = None
#Hide desktop for now untill we know where to put it
#Hide desktop for now until we know where to put it
#and what size it should be.
self.setVisible(False)
@ -198,6 +211,7 @@ class MainDisplay(DisplayWidget):
#Sort out screen locations and sizes
self.setGeometry(self.screen[u'size'])
self.scene.setSceneRect(0,0,self.size().width(), self.size().height())
self.imageDisplay.setGeometry(0, 0, self.size().width(), self.size().height())
#Build a custom splash screen
self.InitialFrame = QtGui.QImage(
self.screen[u'size'].width(),
@ -211,7 +225,7 @@ class MainDisplay(DisplayWidget):
(self.screen[u'size'].width() - splash_image.width()) / 2,
(self.screen[u'size'].height() - splash_image.height()) / 2,
splash_image)
self.display_image.setPixmap(QtGui.QPixmap.fromImage(self.InitialFrame))
#self.display_image.setPixmap(QtGui.QPixmap.fromImage(self.InitialFrame))
self.repaint()
#Build a Black screen
painter = QtGui.QPainter()
@ -241,9 +255,15 @@ class MainDisplay(DisplayWidget):
self.setScene(self.scene)
def setupImage(self):
self.display_image = QtGui.QGraphicsPixmapItem()
self.display_image.setZValue(2)
self.scene.addItem(self.display_image)
# self.display_image = QtGui.QGraphmaindisplay.pyicsPixmapItem()
# self.display_image.setZValue(2)
# self.scene.addItem(self.display_image)
self.imageDisplay = QtWebKit.QWebView()
self.proxy = QtGui.QGraphicsProxyWidget()
self.proxy.setWidget(self.imageDisplay)
self.proxy.setWindowFlags(QtCore.Qt.Window | QtCore.Qt.FramelessWindowHint)
self.proxy.setZValue(2)
self.scene.addItem(self.proxy)
def setupText(self):
#self.display_text = QtGui.QGraphicsTextItem()
@ -319,7 +339,7 @@ class MainDisplay(DisplayWidget):
def addAlert(self, message, location):
"""
Places the Alert text on the display at the correct location
``messgae``
``message``
Text to be displayed
``location``
Where on the screen the text should be. From the AlertTab
@ -334,7 +354,16 @@ class MainDisplay(DisplayWidget):
self.alertText.setPos(0,self.size().height() - 76)
self.alertText.setHtml(message)
def frameView(self, frame, transition=False, display=True):
def displayImage(self, path):
"""
Places the Image passed on the display screen
``path``
The path to the image to be displayed
"""
log.debug(u'adddisplayImage')
self.imageDisplay.setHtml(HTMLIMAGE % path)
def frameView(self, frame, transition=False):
"""
Called from a slide controller to display a frame
if the alert is in progress the alert is added on top
@ -343,33 +372,44 @@ class MainDisplay(DisplayWidget):
``transition``
Are transitions required.
"""
log.debug(u'frameView %d' % display)
if display:
if transition:
if self.frame is not None:
self.display_text.setPixmap(
QtGui.QPixmap.fromImage(self.frame))
self.update()
self.frame = None
if frame[u'trans'] is not None:
self.display_text.setPixmap(
QtGui.QPixmap.fromImage(frame[u'trans']))
self.repaint()
self.frame = frame[u'trans']
log.debug(u'frameView')
if transition:
if self.frame is not None:
self.display_text.setPixmap(
QtGui.QPixmap.fromImage(frame[u'main']))
self.display_frame = frame[u'main']
QtGui.QPixmap.fromImage(self.frame))
self.update()
self.frame = None
if frame[u'trans'] is not None:
self.display_text.setPixmap(
QtGui.QPixmap.fromImage(frame[u'trans']))
self.repaint()
else:
if isinstance(frame, QtGui.QPixmap):
self.display_text.setPixmap(frame)
else:
self.display_text.setPixmap(QtGui.QPixmap.fromImage(frame))
self.display_frame = frame
if not self.isVisible() and self.screens.display:
self.setVisible(True)
self.frame = frame[u'trans']
self.display_text.setPixmap(
QtGui.QPixmap.fromImage(frame[u'main']))
self.display_frame = frame[u'main']
self.repaint()
else:
self.storeText = QtGui.QPixmap.fromImage(frame[u'main'])
if isinstance(frame, QtGui.QPixmap):
self.display_text.setPixmap(frame)
else:
self.display_text.setPixmap(QtGui.QPixmap.fromImage(frame))
self.display_frame = frame
if not self.isVisible() and self.screens.display:
self.setVisible(True)
def closeEvent(self, event):
"""
Shutting down cleans up background files
"""
serviceItemPath = AppLocation.get_section_data_path(u'serviceItems')
for file in os.listdir(serviceItemPath):
file_path = os.path.join(serviceItemPath, file)
try:
if os.path.isfile(file_path):
os.remove(file_path)
except OSError:
log.exception(u'Failed to clean up servicePath')
class VideoDisplay(Phonon.VideoWidget):
"""

View File

@ -105,6 +105,7 @@ class SlideController(QtGui.QWidget):
self.isLive = isLive
self.parent = parent
self.mainDisplay = self.parent.displayManager.mainDisplay
self.displayManager = self.parent.displayManager
self.loopList = [
u'Start Loop',
u'Loop Separator',
@ -526,8 +527,8 @@ class SlideController(QtGui.QWidget):
# blanked = self.blankButton.isChecked()
# else:
# blanked = False
# Receiver.send_message(u'%s_start' % serviceItem.name.lower(),
# [serviceItem, self.isLive, blanked, slideno])
Receiver.send_message(u'%s_start' % serviceItem.name.lower(),
[serviceItem, self.isLive, True, slideno])
self.slideList = {}
width = self.parent.ControlSplitter.sizes()[self.split]
#Set pointing cursor when we have somthing to point at
@ -781,7 +782,10 @@ class SlideController(QtGui.QWidget):
log.log(
15, u'Slide Rendering took %4s' % (time.time() - before))
if self.isLive:
self.mainDisplay.frameView(frame, True)#, self.canDisplay)
if self.serviceItem.is_text():
self.mainDisplay.frameView(frame, True)
else:
self.displayManager.displayImage(frame[u'display'])
self.selectedRow = row
Receiver.send_message(u'slidecontroller_%s_changed' % self.typePrefix,
row)