SlideController clean up part 1

This commit is contained in:
Tim Bentley 2009-08-23 21:15:05 +01:00
parent f6578fc000
commit 57f04820f0
4 changed files with 237 additions and 255 deletions

View File

@ -28,7 +28,7 @@ from openlp.core.lib import Receiver
from openlp.core.resources import * from openlp.core.resources import *
from openlp.core.ui import MainWindow, SplashScreen from openlp.core.ui import MainWindow, SplashScreen
logging.basicConfig(level=logging.DEBUG, logging.basicConfig(level=logging.INFO,
format=u'%(asctime)s:%(msecs)3d %(name)-15s %(levelname)-8s %(message)s', format=u'%(asctime)s:%(msecs)3d %(name)-15s %(levelname)-8s %(message)s',
datefmt=u'%m-%d %H:%M:%S', filename=u'openlp.log', filemode=u'w') datefmt=u'%m-%d %H:%M:%S', filename=u'openlp.log', filemode=u'w')

View File

@ -30,10 +30,11 @@ class EventReceiver(QtCore.QObject):
QtCore.QObject.__init__(self) QtCore.QObject.__init__(self)
def send_message(self, event, msg=None): def send_message(self, event, msg=None):
print "send_message ", event , msg
self.emit(QtCore.SIGNAL(event), msg) self.emit(QtCore.SIGNAL(event), msg)
def received(self, msg=None): def received(self, msg=None):
print msg print "received ", msg
class Receiver(): class Receiver():

View File

@ -21,7 +21,7 @@ import logging
import os import os
from PyQt4 import QtCore, QtGui from PyQt4 import QtCore, QtGui
from openlp.core.lib import OpenLPToolbar, translate, buildIcon from openlp.core.lib import OpenLPToolbar, translate, buildIcon, Receiver
class SlideList(QtGui.QTableWidget): class SlideList(QtGui.QTableWidget):
""" """
@ -64,7 +64,6 @@ class SlideController(QtGui.QWidget):
Set up the Slide Controller. Set up the Slide Controller.
""" """
self.toolbarList = {} self.toolbarList = {}
self.previewList = {}
QtGui.QWidget.__init__(self, parent) QtGui.QWidget.__init__(self, parent)
self.isLive = isLive self.isLive = isLive
self.parent = parent self.parent = parent
@ -118,118 +117,6 @@ class SlideController(QtGui.QWidget):
self.grid.setMargin(8) self.grid.setMargin(8)
self.grid.setObjectName(u'grid') self.grid.setObjectName(u'grid')
# Actual preview screen # Actual preview screen
masterPreview = MasterPreview(self.PreviewFrame).getPreview()
self.registerPreview(u'master', masterPreview)
self.SlidePreview = self.retrievePreview(u'master')
self.grid.addWidget(self.SlidePreview, 0, 0, 1, 1)
# Signals
QtCore.QObject.connect(self.PreviewListWidget,
QtCore.SIGNAL(u'clicked(QModelIndex)'), self.BaseToolbar.onSlideSelected)
QtCore.QObject.connect(self.PreviewListWidget,
QtCore.SIGNAL(u'activated(QModelIndex)'), self.BaseToolbar.onSlideSelected)
# Add Late Arrivals
self.BaseToolbar.PreviewListWidget = self.PreviewListWidget
self.BaseToolbar.SlidePreview = self.SlidePreview
self.BaseToolbar.mainDisplay = self.parent.mainDisplay
def registerToolbar(self, handle,controller):
"""
Register a new toolbar with the controller
``handle``
Identifier for the toolbar being stored this should equal the
plugins name.
``controller``
The toolbar class which should extend MasterToolbar
"""
#store the handle name in lower case so no probems later
self.toolbarList[handle.lower()] = controller
def registerPreview(self, handle,controller):
"""
Register a new preview with the controller
``handle``
Identifier for the preview being stored this should equal the
plugins name.
``controller``
The preview class which should extend MasterToolbar
"""
#store the handle name in lower case so no probems later
self.previewList[handle.lower()] = controller
def retrieveToolbar(self, handle):
"""
Find the toolbar and return master if none present
Add extra information back into toolbar class
``handle``
Identifier for the toolbar being requested
"""
try:
toolbar = self.toolbarList[handle.lower()]
except:
toolbar = self.toolbarList[u'master']
toolbar.PreviewListWidget = self.PreviewListWidget
toolbar.SlidePreview = self.SlidePreview
toolbar.mainDisplay = self.parent.mainDisplay
return toolbar
def retrievePreview(self, handle):
"""
Find the preview and return master if none present
Add extra information back into toolbar class
``handle``
Identifier for the toolbar being requested
"""
try:
preview = self.previewList[handle.lower()]
except:
preview = self.previewList[u'master']
return preview
def addServiceItem(self, item):
"""
Method to install the service item into the controller and
request the correct the toolbar of the plugin
Called by plugins
"""
self.SlidePreview = self.retrievePreview(item.shortname)
self.BaseToolbar = self.retrieveToolbar(item.shortname)
self.ControllerLayout.removeWidget(self.Toolbar)
#remove the old toolbar
self.Toolbar.clear()
self.Toolbar = self.BaseToolbar.getToolbar()
self.ControllerLayout.addWidget(self.Toolbar)
self.BaseToolbar.addServiceItem(item)
def addServiceManagerItem(self, item, slideno):
"""
Method to install the service item into the controller and
request the correct the toolbar of the plugin
Called by ServiceManager
"""
self.SlidePreview = self.retrievePreview(item.shortname)
self.BaseToolbar = self.retrieveToolbar(item.shortname)
self.ControllerLayout.removeWidget(self.Toolbar)
#remove the old toolbar
self.Toolbar.clear()
self.Toolbar = self.BaseToolbar.getToolbar()
self.ControllerLayout.addWidget(self.Toolbar)
self.BaseToolbar.addServiceManagerItem(item, slideno)
class MasterPreview(QtCore.QObject):
"""
Class from which all Previews should extend allowing plugins to
have their own previews
"""
def __init__(self, parent):
self.parent = parent
QtCore.QObject.__init__(self)
self.definePreview()
def getPreview(self):
return self.SlidePreview
def definePreview(self):
self.SlidePreview = QtGui.QLabel(self.parent) self.SlidePreview = QtGui.QLabel(self.parent)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed,
QtGui.QSizePolicy.Fixed) QtGui.QSizePolicy.Fixed)
@ -244,6 +131,192 @@ class MasterPreview(QtCore.QObject):
self.SlidePreview.setLineWidth(1) self.SlidePreview.setLineWidth(1)
self.SlidePreview.setScaledContents(True) self.SlidePreview.setScaledContents(True)
self.SlidePreview.setObjectName(u'SlidePreview') self.SlidePreview.setObjectName(u'SlidePreview')
self.grid.addWidget(self.SlidePreview, 0, 0, 1, 1)
# Signals
QtCore.QObject.connect(self.PreviewListWidget,
QtCore.SIGNAL(u'clicked(QModelIndex)'), self.onSlideSelected)
QtCore.QObject.connect(self.PreviewListWidget,
QtCore.SIGNAL(u'activated(QModelIndex)'), self.onSlideSelected)
# Window Event Handlers
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'slide_first'), self.onSlideSelectedFirst)
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'slide_previous'), self.onSlideSelectedPrevious)
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'slide_next'), self.onSlideSelectedNext)
QtCore.QObject.connect(Receiver.get_receiver(),
QtCore.SIGNAL(u'slide_last'), self.onSlideSelectedLast)
# Add Late Arrivals
# self.BaseToolbar.PreviewListWidget = self.PreviewListWidget
# self.BaseToolbar.SlidePreview = self.SlidePreview
# self.BaseToolbar.mainDisplay = self.parent.mainDisplay
def registerToolbar(self, handle,controller):
"""
Register a new toolbar with the controller
``handle``
Identifier for the toolbar being stored this should equal the
plugins name.
``controller``
The toolbar class which should extend MasterToolbar
"""
#store the handle name in lower case so no probems later
self.toolbarList[handle.lower()] = controller
def retrieveToolbar(self, handle):
"""
Find the toolbar and return master if none present
Add extra information back into toolbar class
``handle``
Identifier for the toolbar being requested
"""
try:
toolbar = self.toolbarList[handle.lower()]
except:
toolbar = self.toolbarList[u'master']
# toolbar.PreviewListWidget = self.PreviewListWidget
# toolbar.SlidePreview = self.SlidePreview
# toolbar.mainDisplay = self.parent.mainDisplay
return toolbar
def addServiceItem(self, item):
"""
Method to install the service item into the controller and
request the correct the toolbar of the plugin
Called by plugins
"""
self.BaseToolbar = self.retrieveToolbar(item.shortname)
self.ControllerLayout.removeWidget(self.Toolbar)
#remove the old toolbar
self.Toolbar.clear()
self.Toolbar = self.BaseToolbar.getToolbar()
self.ControllerLayout.addWidget(self.Toolbar)
item.render()
self.displayServiceManagerItems(item, 0)
def addServiceManagerItem(self, item, slideno):
"""
Method to install the service item into the controller and
request the correct the toolbar of the plugin
Called by ServiceManager
"""
self.BaseToolbar = self.retrieveToolbar(item.shortname)
self.ControllerLayout.removeWidget(self.Toolbar)
#remove the old toolbar
self.Toolbar.clear()
self.Toolbar = self.BaseToolbar.getToolbar()
self.ControllerLayout.addWidget(self.Toolbar)
self.displayServiceManagerItems(item, slideno)
def displayServiceManagerItems(self, serviceitem, slideno):
"""
Loads a ServiceItem into the system from ServiceManager
Display the slide number passed
"""
log.debug(u'add Service Manager Item')
self.serviceitem = serviceitem
slide_pixmap = QtGui.QPixmap.fromImage(self.serviceitem.frames[0][u'image'])
slide_width = 300
slide_height = slide_width * slide_pixmap.height() / slide_pixmap.width()
self.PreviewListWidget.clear()
self.PreviewListWidget.setRowCount(0)
self.PreviewListWidget.setColumnWidth(0, slide_width)
for framenumber, frame in enumerate(self.serviceitem.frames):
self.PreviewListWidget.setRowCount(self.PreviewListWidget.rowCount() + 1)
pixmap = QtGui.QPixmap.fromImage(frame[u'image'])
item = QtGui.QTableWidgetItem()
label = QtGui.QLabel()
label.setMargin(8)
label.setScaledContents(True)
label.setPixmap(pixmap)
self.PreviewListWidget.setCellWidget(framenumber, 0, label)
self.PreviewListWidget.setItem(framenumber, 0, item)
self.PreviewListWidget.setRowHeight(framenumber, slide_height)
slide_width = self.PreviewListWidget.viewport().size().width()
self.PreviewListWidget.setColumnWidth(0, slide_width)
if slideno > self.PreviewListWidget.rowCount():
self.PreviewListWidget.selectRow(self.PreviewListWidget.rowCount())
else:
self.PreviewListWidget.selectRow(slideno)
self.onSlideSelected()
self.PreviewListWidget.setFocus()
#Screen event methods
def onBlankScreen(self):
"""
Blank the screen.
"""
self.mainDisplay.blankDisplay()
def onSlideSelected(self):
"""
Generate the preview when you click on a slide.
if this is the Live Controller also display on the screen
"""
row = self.PreviewListWidget.currentRow()
if row > -1 and row < self.PreviewListWidget.rowCount():
label = self.PreviewListWidget.cellWidget(row, 0)
smallframe = label.pixmap()
frame = self.serviceitem.frames[row][u'image']
self.SlidePreview.setPixmap(smallframe)
if self.isLive:
self.parent.mainDisplay.frameView(frame)
def onSlideSelectedFirst(self):
"""
Go to the first slide.
"""
print "oSSF"
self.PreviewListWidget.selectRow(0)
self.onSlideSelected()
def onBlankScreen(self):
"""
Blank the screen.
"""
self.parent.mainDisplay.blankDisplay()
def onSlideSelected(self):
"""
Generate the preview when you click on a slide.
if this is the Live Controller also display on the screen
"""
row = self.PreviewListWidget.currentRow()
if row > -1 and row < self.PreviewListWidget.rowCount():
label = self.PreviewListWidget.cellWidget(row, 0)
smallframe = label.pixmap()
frame = self.serviceitem.frames[row][u'image']
self.SlidePreview.setPixmap(smallframe)
if self.isLive:
self.parent.mainDisplay.frameView(frame)
def onSlideSelectedNext(self):
"""
Go to the next slide.
"""
row = self.PreviewListWidget.currentRow() + 1
if row == self.PreviewListWidget.rowCount():
row = 0
self.PreviewListWidget.selectRow(row)
self.onSlideSelected()
def onSlideSelectedPrevious(self):
"""
Go to the previous slide.
"""
row = self.PreviewListWidget.currentRow() - 1
if row == -1:
row = self.PreviewListWidget.rowCount() - 1
self.PreviewListWidget.selectRow(row)
self.onSlideSelected()
def onSlideSelectedLast(self):
"""
Go to the last slide.
"""
self.PreviewListWidget.selectRow(self.PreviewListWidget.rowCount() - 1)
self.onSlideSelected()
class MasterToolbar(QtCore.QObject): class MasterToolbar(QtCore.QObject):
@ -277,126 +350,33 @@ class MasterToolbar(QtCore.QObject):
self.Toolbar.addToolbarButton(u'First Slide', self.Toolbar.addToolbarButton(u'First Slide',
u':/slides/slide_first.png', u':/slides/slide_first.png',
translate(u'SlideController', u'Move to first'), translate(u'SlideController', u'Move to first'),
self.onSlideSelectedFirst) self.onSlideFirst)
self.Toolbar.addToolbarButton(u'Previous Slide', self.Toolbar.addToolbarButton(u'Previous Slide',
u':/slides/slide_previous.png', u':/slides/slide_previous.png',
translate(u'SlideController', u'Move to previous'), translate(u'SlideController', u'Move to previous'),
self.onSlideSelectedPrevious) self.onSlidePrevious)
self.Toolbar.addToolbarButton(u'Next Slide', self.Toolbar.addToolbarButton(u'Next Slide',
u':/slides/slide_next.png', u':/slides/slide_next.png',
translate(u'SlideController', u'Move to next'), translate(u'SlideController', u'Move to next'),
self.onSlideSelectedNext) self.onSlideNext)
if self.isLive: if self.isLive:
self.Toolbar.addToolbarButton(u'Last Slide', self.Toolbar.addToolbarButton(u'Last Slide',
u':/slides/slide_last.png', u':/slides/slide_last.png',
translate(u'SlideController', u'Move to last'), translate(u'SlideController', u'Move to last'),
self.onSlideSelectedLast) self.onSlideLast)
self.Toolbar.addSeparator() self.Toolbar.addSeparator()
self.Toolbar.addToolbarButton(u'Close Screen', self.Toolbar.addToolbarButton(u'Close Screen',
u':/slides/slide_close.png', u':/slides/slide_close.png',
translate(u'SlideController', u'Close Screen'), translate(u'SlideController', u'Close Screen'),
self.onBlankScreen) self.onSlideBlank)
def serviceLoaded(self): def onSlideFirst(self):
""" Receiver().send_message(u'slide_first')
method to allow toolbars to know when the service item def onSlidePrevious(self):
is fully in place Receiver().send_message(u'slide_previous')
""" def onSlideNext(self):
pass Receiver().send_message(u'slide_next')
def onSlideLast(self):
def onSlideSelectedFirst(self): Receiver().send_message(u'slide_last')
""" def onSlideBlank(self):
Go to the first slide. Receiver().send_message(u'slide_blank')
"""
self.PreviewListWidget.selectRow(0)
self.onSlideSelected()
def onSlideSelectedNext(self):
"""
Go to the next slide.
"""
row = self.PreviewListWidget.currentRow() + 1
if row == self.PreviewListWidget.rowCount():
row = 0
self.PreviewListWidget.selectRow(row)
self.onSlideSelected()
def onSlideSelectedPrevious(self):
"""
Go to the previous slide.
"""
row = self.PreviewListWidget.currentRow() - 1
if row == -1:
row = self.PreviewListWidget.rowCount() - 1
self.PreviewListWidget.selectRow(row)
self.onSlideSelected()
def onSlideSelectedLast(self):
"""
Go to the last slide.
"""
self.PreviewListWidget.selectRow(self.PreviewListWidget.rowCount() - 1)
self.onSlideSelected()
def onBlankScreen(self):
"""
Blank the screen.
"""
self.mainDisplay.blankDisplay()
def onSlideSelected(self):
"""
Generate the preview when you click on a slide.
if this is the Live Controller also display on the screen
"""
row = self.PreviewListWidget.currentRow()
if row > -1 and row < self.PreviewListWidget.rowCount():
label = self.PreviewListWidget.cellWidget(row, 0)
smallframe = label.pixmap()
frame = self.serviceitem.frames[row][u'image']
self.SlidePreview.setPixmap(smallframe)
if self.isLive:
self.mainDisplay.frameView(frame)
def addServiceItem(self, serviceitem, slideno = 1):
"""
Loads a ServiceItem into the system from plugins
Display the first slide
"""
log.debug(u'add Service Item')
serviceitem.render()
self.addServiceManagerItem(serviceitem, 0)
def addServiceManagerItem(self, serviceitem, slideno):
"""
Loads a ServiceItem into the system from ServiceManager
Display the slide number passed
"""
log.debug(u'add Service Manager Item')
self.serviceitem = serviceitem
slide_pixmap = QtGui.QPixmap.fromImage(self.serviceitem.frames[0][u'image'])
slide_width = 300
slide_height = slide_width * slide_pixmap.height() / slide_pixmap.width()
self.PreviewListWidget.clear()
self.PreviewListWidget.setRowCount(0)
self.PreviewListWidget.setColumnWidth(0, slide_width)
for framenumber, frame in enumerate(self.serviceitem.frames):
self.PreviewListWidget.setRowCount(self.PreviewListWidget.rowCount() + 1)
pixmap = QtGui.QPixmap.fromImage(frame[u'image'])
item = QtGui.QTableWidgetItem()
label = QtGui.QLabel()
label.setMargin(8)
label.setScaledContents(True)
label.setPixmap(pixmap)
self.PreviewListWidget.setCellWidget(framenumber, 0, label)
self.PreviewListWidget.setItem(framenumber, 0, item)
self.PreviewListWidget.setRowHeight(framenumber, slide_height)
slide_width = self.PreviewListWidget.viewport().size().width()
self.PreviewListWidget.setColumnWidth(0, slide_width)
if slideno > self.PreviewListWidget.rowCount():
self.PreviewListWidget.selectRow(self.PreviewListWidget.rowCount())
else:
self.PreviewListWidget.selectRow(slideno)
self.onSlideSelected()
self.serviceLoaded()
self.PreviewListWidget.setFocus()

View File

@ -43,37 +43,38 @@ class ImageToolbar(MasterToolbar):
sizeToolbarPolicy.setHeightForWidth( sizeToolbarPolicy.setHeightForWidth(
self.Toolbar.sizePolicy().hasHeightForWidth()) self.Toolbar.sizePolicy().hasHeightForWidth())
if self.isLive: if self.isLive:
self.Toolbar.addToolbarButton(u'First Slide', pass
u':/slides/slide_first.png', # self.Toolbar.addToolbarButton(u'First Slide',
translate(u'SlideController', u'Move to first'), # u':/slides/slide_first.png',
self.onSlideSelectedFirst) # translate(u'SlideController', u'Move to first'),
self.Toolbar.addToolbarButton(u'Previous Slide', # self.onSlideSelectedFirst)
u':/slides/slide_previous.png', # self.Toolbar.addToolbarButton(u'Previous Slide',
translate(u'SlideController', u'Move to previous'), # u':/slides/slide_previous.png',
self.onSlideSelectedPrevious) # translate(u'SlideController', u'Move to previous'),
self.Toolbar.addToolbarButton(u'Next Slide', # self.onSlideSelectedPrevious)
u':/slides/slide_next.png', # self.Toolbar.addToolbarButton(u'Next Slide',
translate(u'SlideController', u'Move to next'), # u':/slides/slide_next.png',
self.onSlideSelectedNext) # translate(u'SlideController', u'Move to next'),
if self.isLive: # self.onSlideSelectedNext)
self.Toolbar.addToolbarButton(u'Last Slide', # if self.isLive:
u':/slides/slide_last.png', # self.Toolbar.addToolbarButton(u'Last Slide',
translate(u'SlideController', u'Move to last'), # u':/slides/slide_last.png',
self.onSlideSelectedLast) # translate(u'SlideController', u'Move to last'),
self.Toolbar.addSeparator() # self.onSlideSelectedLast)
self.Toolbar.addToolbarButton(u'Close Screen', # self.Toolbar.addSeparator()
u':/slides/slide_close.png', # self.Toolbar.addToolbarButton(u'Close Screen',
translate(u'SlideController', u'Close Screen'), # u':/slides/slide_close.png',
self.onBlankScreen) # translate(u'SlideController', u'Close Screen'),
self.Toolbar.addSeparator() # self.onBlankScreen)
self.Toolbar.addToolbarButton(u'Start Loop', # self.Toolbar.addSeparator()
u':/media/media_time.png', # self.Toolbar.addToolbarButton(u'Start Loop',
translate(u'SlideController', u'Start continuous loop'), # u':/media/media_time.png',
self.onStartLoop) # translate(u'SlideController', u'Start continuous loop'),
self.Toolbar.addToolbarButton(u'Stop Loop', # self.onStartLoop)
u':/media/media_stop.png', # self.Toolbar.addToolbarButton(u'Stop Loop',
translate(u'SlideController', u'Stop continuous loop'), # u':/media/media_stop.png',
self.onStopLoop) # translate(u'SlideController', u'Stop continuous loop'),
# self.onStopLoop)
self.Toolbar.addSeparator() self.Toolbar.addSeparator()
self.DelaySpinBox = QtGui.QSpinBox(self.Toolbar) self.DelaySpinBox = QtGui.QSpinBox(self.Toolbar)
self.SpinWidget = QtGui.QWidgetAction(self.Toolbar) self.SpinWidget = QtGui.QWidgetAction(self.Toolbar)