First test of service manager works

bzr-revno: 372
This commit is contained in:
Martin Thompson 2009-03-04 21:55:24 +00:00
parent cf364ae208
commit 068f963077
5 changed files with 182 additions and 26 deletions

View File

@ -20,6 +20,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
import os
from time import sleep
from copy import deepcopy
from PyQt4 import *
from PyQt4 import QtCore, QtGui
from PyQt4.QtCore import *
@ -46,16 +47,16 @@ class ServiceData(QAbstractItemModel):
def rowCount(self, parent):
return len(self.items)
def insertRow(self, row, service_item):
self.beginInsertRows(QModelIndex(),row,row)
log.info("insert row %d:%s"%(row,filename))
# self.beginInsertRows(QModelIndex(),row,row)
log.info("insert row %d:%s"%(row,service_item))
self.items.insert(row, service_item)
self.endInsertRows()
# self.endInsertRows()
def removeRow(self, row):
self.beginRemoveRows(QModelIndex(), row,row)
self.items.pop(row)
self.endRemoveRows()
def addRow(self, filename):
self.insertRow(len(self.items), filename)
def addRow(self, item):
self.insertRow(len(self.items), item)
def data(self, index, role):
@ -82,7 +83,9 @@ class ServiceData(QAbstractItemModel):
else:
return retval
def __iter__(self):
for i in self.items:
yield i
class ServiceManager(QWidget):
@ -124,8 +127,53 @@ class ServiceManager(QWidget):
def addServiceItem(self, item):
"""Adds service item"""
pass
log.info("addServiceItem")
indexes=self.TreeView.selectedIndexes()
assert len(indexes) <= 1 # can only have one selected index in this view
if indexes == []:
log.info("No row")
row = 0
selected_item = None
else:
row=index.row()
# if currently selected is of correct type, add it to it
selected_item=self.service_data(row)
log.info("row:%d"%row)
if type(selected_item) == type(item):
log.info("Add to existing item")
selected_item.add(item)
else:
log.info("Create new item")
# otherwise create a new one
# print item
# print item.imgs
# i=deepcopy(item)
# print i
# print i.imgs
self.service_data.insertRow(row, item)
# for i in self.service_data:
# print item.imgs
# print i.imgs
def removeServiceItem(self):
"""Remove currently selected item"""
pass
def oos_as_text(self):
text=[]
log.info( "oos as text")
log.info("Data:"+str(self.service_data))
for i in self.service_data:
text.append("# " + str(i))
text.append(i.get_oos_text())
return '\n'.join(text)
def write_oos(self, filename):
"""
Write a full OOS file out - iterate over plugins and call their respective methods
This format is totally arbitrary testing purposes - something sensible needs to go in here!
"""
oosfile=open(filename, "w")
oosfile.write("# BEGIN OOS\n")
oosfile.write(self.oos_as_text)
oosfile.write("# END OOS\n")
oosfile.close()

View File

@ -0,0 +1,88 @@
"""
OpenLP - Open Source Lyrics Projection
Copyright (c) 2008 Raoul Snyman
Portions copyright (c) 2008 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
Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
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 time
import sys
import os, os.path
from PyQt4 import QtGui, QtCore
mypath=os.path.split(os.path.abspath(__file__))[0]
sys.path.insert(0,(os.path.join(mypath, '..','..', '..','..')))
from openlp.core.ui import ServiceManager
from openlp.plugins.images import ImageServiceItem
import logging
logging.basicConfig(filename="test_service_manager.log",level=logging.INFO, filemode="w")
# # from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66062
# def whoami(depth=1):
# return sys._getframe(depth).f_code.co_name
global app
global log
log=logging.getLogger("TestServiceManager")
class TestServiceManager_base:
def __init__(self):
pass
# if not os.path.exists("test_results"):
# os.mkdir("test_results")
def setup_class(self):
log.info( "class setup"+str(self))
try:
if app is None:
app = QtGui.QApplication([])
except UnboundLocalError:
app = QtGui.QApplication([])
def teardown_class(self):
pass
def setup_method(self, method):
log.info("Setup method:"+str(method))
self.expected_answer="Don't know yet"
self.answer=None
self.s=ServiceManager(None)
log.info("--------------- Setup Done -------------")
def teardown_method(self, method):
self.s=None
def test_easy(self):
log.info("test_easy")
item=ImageServiceItem(None)
item.add("test.gif")
self.s.addServiceItem(item)
answer = self.s.oos_as_text()
log.info("Answer = " + str(answer))
lines=answer.split("\n")
log.info("lines = " + str(lines))
assert lines[0].startswith("# <openlp.plugins.images.imageserviceitem.ImageServiceItem object")
assert lines[1] == "test.gif"
log.info("done")
if __name__=="__main__":
t=TestServiceManager_base()
t.setup_class()
t.setup_method(None)
t.test_easy()
t.teardown_method(None)
print "Pass"
log.info("Pass")

View File

@ -0,0 +1,3 @@
from imageplugin import ImagePlugin
from imageserviceitem import ImageServiceItem

View File

@ -38,6 +38,8 @@ class ImageServiceItem(ServiceItem):
When something goes live/previews -
it simply tells the slide controller to use it???
It contains 1 or more images
"""
global log
log=logging.getLogger("ImageServiceItem")
@ -46,13 +48,14 @@ class ImageServiceItem(ServiceItem):
"""
Init Method
"""
log.info("init")
self.imgs=ListWithPreviews()
self.slide_controller=controller
self.slide_controller.ControllerContents=QtGui.QListView()
c=self.slide_controller.ControllerContents
c.uniformItemSizes=True
c.setModel(self.imgs)
c.setGeometry(0,0,200,200)
# self.slide_controller=controller
# self.slide_controller.ControllerContents=QtGui.QListView()
# c=self.slide_controller.ControllerContents
# c.uniformItemSizes=True
# c.setModel(self.imgs)
# c.setGeometry(0,0,200,200)
def render(self):
"""
@ -78,17 +81,26 @@ class ImageServiceItem(ServiceItem):
Manager.
"""
pass
def add(self, filename):
def add(self, data):
"""
append an image to the list
"""
log.info("add:"+filename)
self.imgs.addRow(filename)
if type(data)==type("string"):
log.info("add filename:"+data)
self.imgs.addRow(data)
else: # it's another service item to be merged in
log.info("add Item..."+str(data))
for filename in data.get_file_list():
self.add(filename)
def get_oos_text(self):
"""
Turn the image list into a set of filenames for storage in the oos file
"""
log.info("Get oos text")
log.info(str(self.imgs))
log.info(str(self.imgs.get_file_list()))
return '\n'.join(self.imgs.get_file_list())
def set_from_oos(self, text):

View File

@ -23,6 +23,7 @@ class ListWithPreviews(QAbstractListModel):
(prefix, shortfilename) = os.path.split(str(filename))
log.info("shortfilename=%s"%(shortfilename))
# create a preview image
if os.path.exists(filename):
preview = QPixmap(str(filename))
w=self.maximagewidth;h=self.rowheight
preview = preview.scaled(w,h, Qt.KeepAspectRatio)
@ -32,6 +33,10 @@ class ListWithPreviews(QAbstractListModel):
p.fill(Qt.transparent)
painter=QPainter(p)
painter.drawPixmap((w-realw)/2,(h-realh)/2,preview)
else:
w=self.maximagewidth;h=self.rowheight
p=QPixmap(w,h)
p.fill(Qt.transparent)
# finally create the row
self.items.insert(row, (filename, p, shortfilename))
self.endInsertRows()