At last first attemp at serviceitem

This commit is contained in:
Tim Bentley 2009-05-02 12:16:08 +01:00
parent ca0893caba
commit 0d27d61b7f
4 changed files with 170 additions and 33 deletions

View File

@ -76,7 +76,6 @@ class RenderManager:
def generate_preview(self, themedata):
self.calculate_default(QtCore.QSize(800,600))
self.renderer.set_theme(themedata)
self.build_text_rectangle(themedata)
frame = QtGui.QPixmap(self.width, self.height)
@ -96,14 +95,19 @@ class RenderManager:
def format_slide(self, words, footer):
self.calculate_default(QtCore.QSize(800,600))
frame = QtGui.QPixmap(self.width, self.height)
self.renderer.set_paint_dest(frame)
return self.renderer.format_slide(words, footer)
def generate_slide(self,main_text, footer_text, preview=True):
if preview == True:
self.calculate_default(QtCore.QSize(800,600))
frame = QtGui.QPixmap(self.width, self.height)
self.renderer.set_paint_dest(frame)
answer=self.renderer.render_lines(main_text, footer_text)
return self.frame
return frame
def calculate_default(self, screen):
self.width = screen.width()

View File

@ -3,7 +3,7 @@
"""
OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman
Portions copyright (c) 2008 Martin Thompson, Tim Bentley
Portions copyright (c) 2008-2009 Martin Thompson, Tim Bentley
This program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
@ -17,31 +17,55 @@ You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
"""
import logging
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class ServiceItem(QAbstractItemModel):
#was Qabstratctitemodel
class ServiceItem():
"""
The service item is a base class for the plugins to use to interact with
the service manager, the slide controller, and the projection screen
compositor.
"""
global log
log=logging.getLogger(u'ServiceItem')
log.info(u'Service Item created')
def __init__(self, hostplugin):
"""
Init Method
"""
self.plugin=hostplugin
self.shortname=hostplugin.name
self.items=[]
self.iconic_representation=None
self.plugin = hostplugin
self.shortname = hostplugin.name
self.items = []
self.iconic_representation = None
self.raw_slides = None
self.format_slides = []
self.frames = []
self.raw_footer = None
self.theme = None
log.debug(u'Service item created for %s', self.shortname)
def render(self):
"""
The render method is what the plugin uses to render it's meda to the
screen.
"""
pass
log.debug(u'Render called')
if self.theme == None:
self.render_manager.set_override_theme(None)
else:
self.render_manager.set_override_theme(self.theme)
for slide in self.raw_slides:
self.format_slides.append(self.render_manager.format_slide(slide, False))
for slide in self.format_slides:
self.frames.append(self.render_manager.generate_slide(slide, self.raw_footer, False))
print self.frames
def get_parent_node(self):
"""
@ -64,7 +88,7 @@ class ServiceItem(QAbstractItemModel):
"""
pass
def set_from_plugin(self, data):
def set_from_plugin(self):
"""
Takes data from the plugin media chooser
"""

View File

@ -17,11 +17,88 @@ You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
"""
import logging
import os
from time import sleep
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class SlideData(QAbstractListModel):
"""
Tree of items for an order of Theme.
Includes methods for reading and writing the contents to an OOS file
Root contains a list of ThemeItems
"""
global log
log=logging.getLogger(u'SlideData')
def __init__(self):
QAbstractListModel.__init__(self)
self.items=[]
self.rowheight=50
self.maximagewidth=self.rowheight*16/9.0;
log.info(u'Starting')
def clearItems(self):
self.items=[]
def rowCount(self, parent):
return len(self.items)
def insertRow(self, row, frame, text):
self.beginInsertRows(QModelIndex(),row,row)
log.info(u'insert row %d' % row)
# create a preview image
self.items.insert(row,(frame, text))
log.info(u'Items: %s' % self.items)
self.endInsertRows()
def removeRow(self, row):
self.beginRemoveRows(QModelIndex(), row,row)
self.items.pop(row)
self.endRemoveRows()
def addRow(self, frame, text):
self.insertRow(len(self.items), frame, text)
def data(self, index, role):
row=index.row()
if row > len(self.items): # if the last row is selected and deleted, we then get called with an empty row!
return QVariant()
if role==Qt.DisplayRole:
retval= self.items[row][1]
elif role == Qt.DecorationRole:
retval= self.items[row][0]
else:
retval= QVariant()
# log.info("Returning"+ str(retval))
if type(retval) is not type(QVariant):
return QVariant(retval)
else:
return retval
def __iter__(self):
for i in self.items:
yield i
def getValue(self, index):
row = index.row()
return self.items[row]
def getItem(self, row):
log.info(u'Get Item:%d -> %s' %(row, str(self.items)))
return self.items[row]
def getList(self):
filelist = [item[3] for item in self.items];
return filelist
class SlideController(QtGui.QWidget):
global log
log=logging.getLogger(u'SlideController')
def __init__(self, control_splitter):
QtGui.QWidget.__init__(self)
self.Pane = QtGui.QWidget(control_splitter)
@ -40,11 +117,18 @@ class SlideController(QtGui.QWidget):
self.Controller = QtGui.QScrollArea(self.Splitter)
self.Controller.setWidgetResizable(True)
self.ControllerContents = QtGui.QWidget(self.Controller)
self.ControllerContents.setGeometry(QtCore.QRect(0, 0, 228, 536))
self.Controller.setGeometry(QtCore.QRect(0, 0, 828, 536))
#self.ControllerContents = QtGui.QWidget(self.Controller)
#self.ControllerContents.setGeometry(QtCore.QRect(0, 0, 228, 536))
self.Controller.setWidget(self.ControllerContents)
self.CustomListView = QtGui.QListView(self.Splitter)
self.CustomListView.setAlternatingRowColors(True)
self.CustomListData = SlideData()
self.CustomListView.setModel(self.CustomListData)
self.Controller.setGeometry(QtCore.QRect(0, 0, 828, 536))
#self.Controller.setWidget(self.ControllerContents)
self.Controller.setWidget(self.CustomListView)
self.SlidePreview = QtGui.QLabel(self.Splitter)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
@ -60,8 +144,19 @@ class SlideController(QtGui.QWidget):
self.SlidePreview.setObjectName("SlidePreview")
def previewFrame(self, frame):
self.SlidePreview.setPixmap(frame)
#self.SlidePreview.setPixmap(frame)
imageLabel = QtGui.QLabel()
imageLabel.setPixmap(frame)
self.Controller.setWidget(imageLabel)
# imageLabel = QtGui.QLabel()
#imageLabel.setPixmap(frame)
# self.Controller.setWidget(imageLabel)
pass
def addServiceItem(self, serviceitem):
self.serviceitem = serviceitem
self.serviceitem.render()
print self.serviceitem.frames
for frame in self.serviceitem.frames:
self.CustomListData.addRow(frame, u'some text')
def render(self):
pass

View File

@ -24,6 +24,7 @@ from PyQt4 import QtCore, QtGui
from openlp.core import translate
from openlp.core.lib import MediaManagerItem
from openlp.core.lib import SongXMLParser
from openlp.core.lib import ServiceItem
from openlp.plugins.custom.lib import TextListData
@ -37,6 +38,7 @@ class CustomMediaItem(MediaManagerItem):
def __init__(self, parent, icon, title):
MediaManagerItem.__init__(self, parent, icon, title)
self.parent = parent
def setupUi(self):
# Add a toolbar
@ -185,9 +187,26 @@ class CustomMediaItem(MediaManagerItem):
self.CustomListData.deleteRow(index)
def onCustomPreviewClick(self):
service_item = ServiceItem(self.parent)
service_item.render_manager = self.parent.render_manager
self.generateSlideData(service_item)
self.parent.preview_controller.addServiceItem(service_item)
def onCustomLiveClick(self):
service_item = ServiceItem(self.parent)
service_item.render_manager = self.parent.render_manager
self.generateSlideData(service_item)
self.parent.live_controller.addServiceItem(service_item)
def onCustomAddClick(self):
service_item = ServiceItem(self.parent)
service_item.render_manager = self.parent.render_manager
self.generateSlideData(service_item)
def generateSlideData(self, service_item):
indexes = self.CustomListView.selectedIndexes()
main_lines=[]
footer_lines = []
raw_slides =[]
raw_footer = []
slide = None
theme = None
for index in indexes:
@ -200,21 +219,16 @@ class CustomMediaItem(MediaManagerItem):
self.parent.render_manager.set_override_theme(None)
else:
self.parent.render_manager.set_override_theme(theme)
service_item.theme = theme
songXML=SongXMLParser(customSlide.text)
verseList = songXML.get_verses()
for verse in verseList:
slide = self.parent.render_manager.format_slide(verse[1], False)
print verse
print slide
raw_slides.append(verse[1])
footer_lines.append(title + u' '+ credit)
raw_footer.append(title + u' '+ credit)
if slide is not None:
frame=self.parent.render_manager.generate_slide(slide, footer_lines, False)
frame=self.parent.render_manager.generate_slide(slide, raw_footer, False)
self.parent.preview_controller.previewFrame(frame)
def onCustomLiveClick(self):
pass
def onCustomAddClick(self):
pass
service_item.raw_slides = raw_slides
service_item.raw_footer = raw_footer