forked from openlp/openlp
ServiceItem cleanup - rename arrays
This commit is contained in:
parent
6df4e5a369
commit
e618c3061c
openlp
@ -49,30 +49,28 @@ class ServiceItem(object):
|
||||
log = logging.getLogger(u'ServiceItem')
|
||||
log.info(u'Service Item created')
|
||||
|
||||
def __init__(self, hostplugin=None):
|
||||
def __init__(self, plugin=None):
|
||||
"""
|
||||
Set up the service item.
|
||||
|
||||
``hostplugin``
|
||||
``plugin``
|
||||
The plugin that this service item belongs to.
|
||||
"""
|
||||
self.plugin = hostplugin
|
||||
if hostplugin:
|
||||
self.RenderManager = self.plugin.render_manager
|
||||
self.shortname = hostplugin.name
|
||||
self.name = self.plugin.name
|
||||
if plugin:
|
||||
self.RenderManager = plugin.render_manager
|
||||
self.name = plugin.name
|
||||
self.title = u''
|
||||
self.audit = u''
|
||||
self.items = []
|
||||
self.iconic_representation = None
|
||||
self.raw_slides = None
|
||||
self.frames = []
|
||||
self.display_frames = []
|
||||
self.raw_footer = None
|
||||
self.theme = None
|
||||
self.service_item_path = None
|
||||
self.service_item_type = None
|
||||
self.editEnabled = False
|
||||
self.service_frames = []
|
||||
self.raw_frames = []
|
||||
self.uuid = unicode(uuid.uuid1())
|
||||
|
||||
def addIcon(self, icon):
|
||||
@ -92,14 +90,14 @@ class ServiceItem(object):
|
||||
The render method is what generates the frames for the screen.
|
||||
"""
|
||||
log.debug(u'Render called')
|
||||
self.frames = []
|
||||
self.display_frames = []
|
||||
if self.service_item_type == ServiceItemType.Text:
|
||||
log.debug(u'Formatting slides')
|
||||
if self.theme is None:
|
||||
self.RenderManager.set_override_theme(None)
|
||||
else:
|
||||
self.RenderManager.set_override_theme(self.theme)
|
||||
for slide in self.service_frames:
|
||||
for slide in self.raw_frames:
|
||||
before = time.time()
|
||||
formated = self.RenderManager.format_slide(slide[u'raw_slide'])
|
||||
for format in formated:
|
||||
@ -108,16 +106,16 @@ class ServiceItem(object):
|
||||
for line in format:
|
||||
lines += line + u'\n'
|
||||
title = lines.split(u'\n')[0]
|
||||
self.frames.append({u'title': title, u'text': lines,
|
||||
self.display_frames.append({u'title': title, u'text': lines,
|
||||
u'image': frame})
|
||||
log.info(u'Formatting took %4s' % (time.time() - before))
|
||||
elif self.service_item_type == ServiceItemType.Command:
|
||||
self.frames = self.service_frames
|
||||
self.display_frames = self.raw_frames
|
||||
elif self.service_item_type == ServiceItemType.Image:
|
||||
for slide in self.service_frames:
|
||||
for slide in self.raw_frames:
|
||||
slide[u'image'] = \
|
||||
self.RenderManager.resize_image(slide[u'image'])
|
||||
self.frames = self.service_frames
|
||||
self.display_frames = self.raw_frames
|
||||
else:
|
||||
log.error(u'Invalid value renderer :%s' % self.service_item_type)
|
||||
|
||||
@ -132,19 +130,19 @@ class ServiceItem(object):
|
||||
self.RenderManager.set_override_theme(None)
|
||||
else:
|
||||
self.RenderManager.set_override_theme(self.theme)
|
||||
format = self.frames[row][u'text'].split(u'\n')
|
||||
format = self.display_frames[row][u'text'].split(u'\n')
|
||||
frame = self.RenderManager.generate_slide(format,
|
||||
self.raw_footer)
|
||||
return frame
|
||||
|
||||
def add_from_image(self, path, frame_title, image):
|
||||
def add_from_image(self, path, title, image):
|
||||
"""
|
||||
Add an image slide to the service item.
|
||||
|
||||
``path``
|
||||
The directory in which the image file is located.
|
||||
|
||||
``frame_title``
|
||||
``title``
|
||||
A title for the slide in the service item.
|
||||
|
||||
``image``
|
||||
@ -152,10 +150,10 @@ class ServiceItem(object):
|
||||
"""
|
||||
self.service_item_type = ServiceItemType.Image
|
||||
self.service_item_path = path
|
||||
self.service_frames.append(
|
||||
{u'title': frame_title, u'text': None, u'image': image})
|
||||
self.raw_frames.append(
|
||||
{u'title': title, u'text': None, u'image': image})
|
||||
|
||||
def add_from_text(self, frame_title, raw_slide):
|
||||
def add_from_text(self, title, raw_slide):
|
||||
"""
|
||||
Add a text slide to the service item.
|
||||
|
||||
@ -166,24 +164,27 @@ class ServiceItem(object):
|
||||
The raw text of the slide.
|
||||
"""
|
||||
self.service_item_type = ServiceItemType.Text
|
||||
frame_title = frame_title.split(u'\n')[0]
|
||||
self.service_frames.append(
|
||||
{u'title': frame_title, u'raw_slide': raw_slide})
|
||||
title = title.split(u'\n')[0]
|
||||
self.raw_frames.append(
|
||||
{u'title': title, u'raw_slide': raw_slide})
|
||||
|
||||
def add_from_command(self, path, frame_title, image):
|
||||
def add_from_command(self, path, file_name, image):
|
||||
"""
|
||||
Add a slide from a command.
|
||||
|
||||
``frame_title``
|
||||
``path``
|
||||
The title of the slide in the service item.
|
||||
|
||||
``command``
|
||||
``file_name``
|
||||
The title of the slide in the service item.
|
||||
|
||||
``immage``
|
||||
The command of/for the slide.
|
||||
"""
|
||||
self.service_item_type = ServiceItemType.Command
|
||||
self.service_item_path = path
|
||||
self.service_frames.append(
|
||||
{u'title': frame_title, u'command': None, u'text':None, u'image': image})
|
||||
self.raw_frames.append(
|
||||
{u'title': file_name, u'command': None, u'text':None, u'image': image})
|
||||
|
||||
def get_service_repr(self):
|
||||
"""
|
||||
@ -192,7 +193,7 @@ class ServiceItem(object):
|
||||
"""
|
||||
service_header = {
|
||||
u'name': self.name.lower(),
|
||||
u'plugin': self.shortname,
|
||||
u'plugin': self.name,
|
||||
u'theme':self.theme,
|
||||
u'title':self.title,
|
||||
u'icon':self.icon,
|
||||
@ -202,13 +203,13 @@ class ServiceItem(object):
|
||||
}
|
||||
service_data = []
|
||||
if self.service_item_type == ServiceItemType.Text:
|
||||
for slide in self.service_frames:
|
||||
for slide in self.raw_frames:
|
||||
service_data.append(slide)
|
||||
elif self.service_item_type == ServiceItemType.Image:
|
||||
for slide in self.service_frames:
|
||||
for slide in self.raw_frames:
|
||||
service_data.append(slide[u'title'])
|
||||
elif self.service_item_type == ServiceItemType.Command:
|
||||
for slide in self.service_frames:
|
||||
for slide in self.raw_frames:
|
||||
service_data.append({u'title':slide[u'title'], u'image':slide[u'image']})
|
||||
return {u'header': service_header, u'data': service_data}
|
||||
|
||||
@ -234,7 +235,7 @@ class ServiceItem(object):
|
||||
self.audit = header[u'audit']
|
||||
if self.service_item_type == ServiceItemType.Text:
|
||||
for slide in serviceitem[u'serviceitem'][u'data']:
|
||||
self.service_frames.append(slide)
|
||||
self.raw_frames.append(slide)
|
||||
elif self.service_item_type == ServiceItemType.Image:
|
||||
for text_image in serviceitem[u'serviceitem'][u'data']:
|
||||
filename = os.path.join(path, text_image)
|
||||
@ -281,3 +282,6 @@ class ServiceItem(object):
|
||||
|
||||
def isText(self):
|
||||
return self.service_item_type == ServiceItemType.Text
|
||||
|
||||
def getFrames(self):
|
||||
return self.display_frames
|
||||
|
@ -388,14 +388,14 @@ class ServiceManager(QtGui.QWidget):
|
||||
#Repaint the screen
|
||||
self.ServiceManagerList.clear()
|
||||
for itemcount, item in enumerate(self.serviceItems):
|
||||
serviceitem = item[u'data']
|
||||
serviceitem = item[u'service_item']
|
||||
treewidgetitem = QtGui.QTreeWidgetItem(self.ServiceManagerList)
|
||||
treewidgetitem.setText(0,serviceitem.title)
|
||||
treewidgetitem.setIcon(0,serviceitem.iconic_representation)
|
||||
treewidgetitem.setData(0, QtCore.Qt.UserRole,
|
||||
QtCore.QVariant(item[u'order']))
|
||||
treewidgetitem.setExpanded(item[u'expanded'])
|
||||
for count, frame in enumerate(serviceitem.frames):
|
||||
for count, frame in enumerate(serviceitem.getFrames()):
|
||||
treewidgetitem1 = QtGui.QTreeWidgetItem(treewidgetitem)
|
||||
text = frame[u'title']
|
||||
treewidgetitem1.setText(0,text[:40])
|
||||
@ -431,12 +431,12 @@ class ServiceManager(QtGui.QWidget):
|
||||
zip = zipfile.ZipFile(unicode(filename), 'w')
|
||||
for item in self.serviceItems:
|
||||
service.append(
|
||||
{u'serviceitem':item[u'data'].get_service_repr()})
|
||||
if item[u'data'].service_item_type == ServiceItemType.Image or \
|
||||
item[u'data'].service_item_type == ServiceItemType.Command:
|
||||
for frame in item[u'data'].frames:
|
||||
{u'serviceitem':item[u'service_item'].get_service_repr()})
|
||||
if item[u'service_item'].service_item_type == ServiceItemType.Image or \
|
||||
item[u'service_item'].service_item_type == ServiceItemType.Command:
|
||||
for frame in item[u'service_item'].frames:
|
||||
path_from = unicode(os.path.join(
|
||||
item[u'data'].service_item_path, frame[u'title']))
|
||||
item[u'service_item'].service_item_path, frame[u'title']))
|
||||
zip.write(path_from)
|
||||
file = open(servicefile, u'wb')
|
||||
cPickle.dump(service, file)
|
||||
@ -545,7 +545,7 @@ class ServiceManager(QtGui.QWidget):
|
||||
tempServiceItems = self.serviceItems
|
||||
self.onNewService()
|
||||
for item in tempServiceItems:
|
||||
self.addServiceItem(item[u'data'])
|
||||
self.addServiceItem(item[u'service_item'])
|
||||
|
||||
def addServiceItem(self, item):
|
||||
"""
|
||||
@ -558,19 +558,19 @@ class ServiceManager(QtGui.QWidget):
|
||||
sitem, count = self.findServiceItem()
|
||||
item.render()
|
||||
if self.remoteEditTriggered:
|
||||
item.merge(self.serviceItems[sitem][u'data'])
|
||||
self.serviceItems[sitem][u'data'] = item
|
||||
item.merge(self.serviceItems[sitem][u'service_item'])
|
||||
self.serviceItems[sitem][u'service_item'] = item
|
||||
self.remoteEditTriggered = False
|
||||
self.repaintServiceList(sitem + 1, 0)
|
||||
self.parent.LiveController.replaceServiceManagerItem(item)
|
||||
else:
|
||||
if sitem == -1:
|
||||
self.serviceItems.append({u'data': item,
|
||||
self.serviceItems.append({u'service_item': item,
|
||||
u'order': len(self.serviceItems) + 1,
|
||||
u'expanded':True})
|
||||
self.repaintServiceList(len(self.serviceItems) + 1, 0)
|
||||
else:
|
||||
self.serviceItems.insert(sitem + 1, {u'data': item,
|
||||
self.serviceItems.insert(sitem + 1, {u'service_item': item,
|
||||
u'order': len(self.serviceItems)+1,
|
||||
u'expanded':True})
|
||||
self.repaintServiceList(sitem + 1, 0)
|
||||
@ -582,7 +582,7 @@ class ServiceManager(QtGui.QWidget):
|
||||
"""
|
||||
item, count = self.findServiceItem()
|
||||
self.parent.PreviewController.addServiceManagerItem(
|
||||
self.serviceItems[item][u'data'], count)
|
||||
self.serviceItems[item][u'service_item'], count)
|
||||
|
||||
def makeLive(self):
|
||||
"""
|
||||
@ -590,17 +590,17 @@ class ServiceManager(QtGui.QWidget):
|
||||
"""
|
||||
item, count = self.findServiceItem()
|
||||
self.parent.LiveController.addServiceManagerItem(
|
||||
self.serviceItems[item][u'data'], count)
|
||||
self.serviceItems[item][u'service_item'], count)
|
||||
|
||||
def remoteEdit(self):
|
||||
"""
|
||||
Posts a remote edit message to a plugin to allow item to be edited.
|
||||
"""
|
||||
item, count = self.findServiceItem()
|
||||
if self.serviceItems[item][u'data'].editEnabled:
|
||||
if self.serviceItems[item][u'service_item'].editEnabled:
|
||||
self.remoteEditTriggered = True
|
||||
Receiver().send_message(u'%s_edit' % self.serviceItems[item][u'data'].name, u'L:%s' %
|
||||
self.serviceItems[item][u'data'].editId )
|
||||
Receiver().send_message(u'%s_edit' % self.serviceItems[item][u'service_item'].name, u'L:%s' %
|
||||
self.serviceItems[item][u'service_item'].editId )
|
||||
|
||||
def onRemoteEditClear(self):
|
||||
self.remoteEditTriggered = False
|
||||
@ -698,5 +698,5 @@ class ServiceManager(QtGui.QWidget):
|
||||
def onThemeChangeAction(self):
|
||||
theme = unicode(self.sender().text())
|
||||
item, count = self.findServiceItem()
|
||||
self.serviceItems[item][u'data'].theme = theme
|
||||
self.serviceItems[item][u'service_item'].theme = theme
|
||||
self.regenerateServiceItems()
|
||||
|
@ -457,7 +457,7 @@ class SlideController(QtGui.QWidget):
|
||||
self.PreviewListWidget.clear()
|
||||
self.PreviewListWidget.setRowCount(0)
|
||||
self.PreviewListWidget.setColumnWidth(0, width)
|
||||
for framenumber, frame in enumerate(self.serviceitem.frames):
|
||||
for framenumber, frame in enumerate(self.serviceitem.getFrames()):
|
||||
self.PreviewListWidget.setRowCount(
|
||||
self.PreviewListWidget.rowCount() + 1)
|
||||
item = QtGui.QTableWidgetItem()
|
||||
@ -476,7 +476,7 @@ class SlideController(QtGui.QWidget):
|
||||
self.PreviewListWidget.setItem(framenumber, 0, item)
|
||||
if slide_height != 0:
|
||||
self.PreviewListWidget.setRowHeight(framenumber, slide_height)
|
||||
if self.serviceitem.frames[0][u'text']:
|
||||
if self.serviceitem.getFrames()[0][u'text']:
|
||||
self.PreviewListWidget.resizeRowsToContents()
|
||||
self.PreviewListWidget.setColumnWidth(
|
||||
0, self.PreviewListWidget.viewport().size().width())
|
||||
@ -528,7 +528,7 @@ class SlideController(QtGui.QWidget):
|
||||
if self.isLive:
|
||||
self.updatePreview()
|
||||
else:
|
||||
frame = self.serviceitem.frames[row][u'image']
|
||||
frame = self.serviceitem.getFrames()[row][u'image']
|
||||
before = time.time()
|
||||
if frame is None:
|
||||
frame = self.serviceitem.render_individual(row)
|
||||
|
@ -136,18 +136,18 @@ class PresentationMediaItem(MediaManagerItem):
|
||||
return False
|
||||
service_item.title = unicode(self.DisplayTypeComboBox.currentText())
|
||||
service_item.shortname = unicode(self.DisplayTypeComboBox.currentText())
|
||||
cont = self.controllers[service_item.shortname]
|
||||
controller = self.controllers[service_item.shortname]
|
||||
for item in items:
|
||||
bitem = self.ListView.item(item.row())
|
||||
filename = unicode((bitem.data(QtCore.Qt.UserRole)).toString())
|
||||
(path, name) = os.path.split(filename)
|
||||
cont.store_filename(filename)
|
||||
if cont.get_slide_preview_file(1) is None:
|
||||
cont.load_presentation(filename)
|
||||
controller.store_filename(filename)
|
||||
if controller.get_slide_preview_file(1) is None:
|
||||
controller.load_presentation(filename)
|
||||
i = 1
|
||||
img = cont.get_slide_preview_file(i)
|
||||
img = controller.get_slide_preview_file(i)
|
||||
while img:
|
||||
service_item.add_from_command(path, name, img)
|
||||
i = i + 1
|
||||
img = cont.get_slide_preview_file(i)
|
||||
img = controller.get_slide_preview_file(i)
|
||||
return True
|
||||
|
Loading…
Reference in New Issue
Block a user