ServiceItem cleanup - rename arrays

This commit is contained in:
Tim Bentley 2009-11-14 08:40:14 +00:00
parent 6df4e5a369
commit e618c3061c
4 changed files with 65 additions and 61 deletions

View File

@ -49,30 +49,28 @@ class ServiceItem(object):
log = logging.getLogger(u'ServiceItem') log = logging.getLogger(u'ServiceItem')
log.info(u'Service Item created') log.info(u'Service Item created')
def __init__(self, hostplugin=None): def __init__(self, plugin=None):
""" """
Set up the service item. Set up the service item.
``hostplugin`` ``plugin``
The plugin that this service item belongs to. The plugin that this service item belongs to.
""" """
self.plugin = hostplugin if plugin:
if hostplugin: self.RenderManager = plugin.render_manager
self.RenderManager = self.plugin.render_manager self.name = plugin.name
self.shortname = hostplugin.name
self.name = self.plugin.name
self.title = u'' self.title = u''
self.audit = u'' self.audit = u''
self.items = [] self.items = []
self.iconic_representation = None self.iconic_representation = None
self.raw_slides = None self.raw_slides = None
self.frames = [] self.display_frames = []
self.raw_footer = None self.raw_footer = None
self.theme = None self.theme = None
self.service_item_path = None self.service_item_path = None
self.service_item_type = None self.service_item_type = None
self.editEnabled = False self.editEnabled = False
self.service_frames = [] self.raw_frames = []
self.uuid = unicode(uuid.uuid1()) self.uuid = unicode(uuid.uuid1())
def addIcon(self, icon): def addIcon(self, icon):
@ -92,14 +90,14 @@ class ServiceItem(object):
The render method is what generates the frames for the screen. The render method is what generates the frames for the screen.
""" """
log.debug(u'Render called') log.debug(u'Render called')
self.frames = [] self.display_frames = []
if self.service_item_type == ServiceItemType.Text: if self.service_item_type == ServiceItemType.Text:
log.debug(u'Formatting slides') log.debug(u'Formatting slides')
if self.theme is None: if self.theme is None:
self.RenderManager.set_override_theme(None) self.RenderManager.set_override_theme(None)
else: else:
self.RenderManager.set_override_theme(self.theme) self.RenderManager.set_override_theme(self.theme)
for slide in self.service_frames: for slide in self.raw_frames:
before = time.time() before = time.time()
formated = self.RenderManager.format_slide(slide[u'raw_slide']) formated = self.RenderManager.format_slide(slide[u'raw_slide'])
for format in formated: for format in formated:
@ -108,16 +106,16 @@ class ServiceItem(object):
for line in format: for line in format:
lines += line + u'\n' lines += line + u'\n'
title = lines.split(u'\n')[0] 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}) u'image': frame})
log.info(u'Formatting took %4s' % (time.time() - before)) log.info(u'Formatting took %4s' % (time.time() - before))
elif self.service_item_type == ServiceItemType.Command: 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: elif self.service_item_type == ServiceItemType.Image:
for slide in self.service_frames: for slide in self.raw_frames:
slide[u'image'] = \ slide[u'image'] = \
self.RenderManager.resize_image(slide[u'image']) self.RenderManager.resize_image(slide[u'image'])
self.frames = self.service_frames self.display_frames = self.raw_frames
else: else:
log.error(u'Invalid value renderer :%s' % self.service_item_type) log.error(u'Invalid value renderer :%s' % self.service_item_type)
@ -132,19 +130,19 @@ class ServiceItem(object):
self.RenderManager.set_override_theme(None) self.RenderManager.set_override_theme(None)
else: else:
self.RenderManager.set_override_theme(self.theme) 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, frame = self.RenderManager.generate_slide(format,
self.raw_footer) self.raw_footer)
return frame 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. Add an image slide to the service item.
``path`` ``path``
The directory in which the image file is located. The directory in which the image file is located.
``frame_title`` ``title``
A title for the slide in the service item. A title for the slide in the service item.
``image`` ``image``
@ -152,10 +150,10 @@ class ServiceItem(object):
""" """
self.service_item_type = ServiceItemType.Image self.service_item_type = ServiceItemType.Image
self.service_item_path = path self.service_item_path = path
self.service_frames.append( self.raw_frames.append(
{u'title': frame_title, u'text': None, u'image': image}) {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. Add a text slide to the service item.
@ -166,24 +164,27 @@ class ServiceItem(object):
The raw text of the slide. The raw text of the slide.
""" """
self.service_item_type = ServiceItemType.Text self.service_item_type = ServiceItemType.Text
frame_title = frame_title.split(u'\n')[0] title = title.split(u'\n')[0]
self.service_frames.append( self.raw_frames.append(
{u'title': frame_title, u'raw_slide': raw_slide}) {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. Add a slide from a command.
``frame_title`` ``path``
The title of the slide in the service item. 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. The command of/for the slide.
""" """
self.service_item_type = ServiceItemType.Command self.service_item_type = ServiceItemType.Command
self.service_item_path = path self.service_item_path = path
self.service_frames.append( self.raw_frames.append(
{u'title': frame_title, u'command': None, u'text':None, u'image': image}) {u'title': file_name, u'command': None, u'text':None, u'image': image})
def get_service_repr(self): def get_service_repr(self):
""" """
@ -192,7 +193,7 @@ class ServiceItem(object):
""" """
service_header = { service_header = {
u'name': self.name.lower(), u'name': self.name.lower(),
u'plugin': self.shortname, u'plugin': self.name,
u'theme':self.theme, u'theme':self.theme,
u'title':self.title, u'title':self.title,
u'icon':self.icon, u'icon':self.icon,
@ -202,13 +203,13 @@ class ServiceItem(object):
} }
service_data = [] service_data = []
if self.service_item_type == ServiceItemType.Text: if self.service_item_type == ServiceItemType.Text:
for slide in self.service_frames: for slide in self.raw_frames:
service_data.append(slide) service_data.append(slide)
elif self.service_item_type == ServiceItemType.Image: 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']) service_data.append(slide[u'title'])
elif self.service_item_type == ServiceItemType.Command: 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']}) service_data.append({u'title':slide[u'title'], u'image':slide[u'image']})
return {u'header': service_header, u'data': service_data} return {u'header': service_header, u'data': service_data}
@ -234,7 +235,7 @@ class ServiceItem(object):
self.audit = header[u'audit'] self.audit = header[u'audit']
if self.service_item_type == ServiceItemType.Text: if self.service_item_type == ServiceItemType.Text:
for slide in serviceitem[u'serviceitem'][u'data']: 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: elif self.service_item_type == ServiceItemType.Image:
for text_image in serviceitem[u'serviceitem'][u'data']: for text_image in serviceitem[u'serviceitem'][u'data']:
filename = os.path.join(path, text_image) filename = os.path.join(path, text_image)
@ -281,3 +282,6 @@ class ServiceItem(object):
def isText(self): def isText(self):
return self.service_item_type == ServiceItemType.Text return self.service_item_type == ServiceItemType.Text
def getFrames(self):
return self.display_frames

View File

@ -388,14 +388,14 @@ class ServiceManager(QtGui.QWidget):
#Repaint the screen #Repaint the screen
self.ServiceManagerList.clear() self.ServiceManagerList.clear()
for itemcount, item in enumerate(self.serviceItems): for itemcount, item in enumerate(self.serviceItems):
serviceitem = item[u'data'] serviceitem = item[u'service_item']
treewidgetitem = QtGui.QTreeWidgetItem(self.ServiceManagerList) treewidgetitem = QtGui.QTreeWidgetItem(self.ServiceManagerList)
treewidgetitem.setText(0,serviceitem.title) treewidgetitem.setText(0,serviceitem.title)
treewidgetitem.setIcon(0,serviceitem.iconic_representation) treewidgetitem.setIcon(0,serviceitem.iconic_representation)
treewidgetitem.setData(0, QtCore.Qt.UserRole, treewidgetitem.setData(0, QtCore.Qt.UserRole,
QtCore.QVariant(item[u'order'])) QtCore.QVariant(item[u'order']))
treewidgetitem.setExpanded(item[u'expanded']) treewidgetitem.setExpanded(item[u'expanded'])
for count, frame in enumerate(serviceitem.frames): for count, frame in enumerate(serviceitem.getFrames()):
treewidgetitem1 = QtGui.QTreeWidgetItem(treewidgetitem) treewidgetitem1 = QtGui.QTreeWidgetItem(treewidgetitem)
text = frame[u'title'] text = frame[u'title']
treewidgetitem1.setText(0,text[:40]) treewidgetitem1.setText(0,text[:40])
@ -431,12 +431,12 @@ class ServiceManager(QtGui.QWidget):
zip = zipfile.ZipFile(unicode(filename), 'w') zip = zipfile.ZipFile(unicode(filename), 'w')
for item in self.serviceItems: for item in self.serviceItems:
service.append( service.append(
{u'serviceitem':item[u'data'].get_service_repr()}) {u'serviceitem':item[u'service_item'].get_service_repr()})
if item[u'data'].service_item_type == ServiceItemType.Image or \ if item[u'service_item'].service_item_type == ServiceItemType.Image or \
item[u'data'].service_item_type == ServiceItemType.Command: item[u'service_item'].service_item_type == ServiceItemType.Command:
for frame in item[u'data'].frames: for frame in item[u'service_item'].frames:
path_from = unicode(os.path.join( 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) zip.write(path_from)
file = open(servicefile, u'wb') file = open(servicefile, u'wb')
cPickle.dump(service, file) cPickle.dump(service, file)
@ -545,7 +545,7 @@ class ServiceManager(QtGui.QWidget):
tempServiceItems = self.serviceItems tempServiceItems = self.serviceItems
self.onNewService() self.onNewService()
for item in tempServiceItems: for item in tempServiceItems:
self.addServiceItem(item[u'data']) self.addServiceItem(item[u'service_item'])
def addServiceItem(self, item): def addServiceItem(self, item):
""" """
@ -558,19 +558,19 @@ class ServiceManager(QtGui.QWidget):
sitem, count = self.findServiceItem() sitem, count = self.findServiceItem()
item.render() item.render()
if self.remoteEditTriggered: if self.remoteEditTriggered:
item.merge(self.serviceItems[sitem][u'data']) item.merge(self.serviceItems[sitem][u'service_item'])
self.serviceItems[sitem][u'data'] = item self.serviceItems[sitem][u'service_item'] = item
self.remoteEditTriggered = False self.remoteEditTriggered = False
self.repaintServiceList(sitem + 1, 0) self.repaintServiceList(sitem + 1, 0)
self.parent.LiveController.replaceServiceManagerItem(item) self.parent.LiveController.replaceServiceManagerItem(item)
else: else:
if sitem == -1: if sitem == -1:
self.serviceItems.append({u'data': item, self.serviceItems.append({u'service_item': item,
u'order': len(self.serviceItems) + 1, u'order': len(self.serviceItems) + 1,
u'expanded':True}) u'expanded':True})
self.repaintServiceList(len(self.serviceItems) + 1, 0) self.repaintServiceList(len(self.serviceItems) + 1, 0)
else: 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'order': len(self.serviceItems)+1,
u'expanded':True}) u'expanded':True})
self.repaintServiceList(sitem + 1, 0) self.repaintServiceList(sitem + 1, 0)
@ -582,7 +582,7 @@ class ServiceManager(QtGui.QWidget):
""" """
item, count = self.findServiceItem() item, count = self.findServiceItem()
self.parent.PreviewController.addServiceManagerItem( self.parent.PreviewController.addServiceManagerItem(
self.serviceItems[item][u'data'], count) self.serviceItems[item][u'service_item'], count)
def makeLive(self): def makeLive(self):
""" """
@ -590,17 +590,17 @@ class ServiceManager(QtGui.QWidget):
""" """
item, count = self.findServiceItem() item, count = self.findServiceItem()
self.parent.LiveController.addServiceManagerItem( self.parent.LiveController.addServiceManagerItem(
self.serviceItems[item][u'data'], count) self.serviceItems[item][u'service_item'], count)
def remoteEdit(self): def remoteEdit(self):
""" """
Posts a remote edit message to a plugin to allow item to be edited. Posts a remote edit message to a plugin to allow item to be edited.
""" """
item, count = self.findServiceItem() item, count = self.findServiceItem()
if self.serviceItems[item][u'data'].editEnabled: if self.serviceItems[item][u'service_item'].editEnabled:
self.remoteEditTriggered = True self.remoteEditTriggered = True
Receiver().send_message(u'%s_edit' % self.serviceItems[item][u'data'].name, u'L:%s' % Receiver().send_message(u'%s_edit' % self.serviceItems[item][u'service_item'].name, u'L:%s' %
self.serviceItems[item][u'data'].editId ) self.serviceItems[item][u'service_item'].editId )
def onRemoteEditClear(self): def onRemoteEditClear(self):
self.remoteEditTriggered = False self.remoteEditTriggered = False
@ -698,5 +698,5 @@ class ServiceManager(QtGui.QWidget):
def onThemeChangeAction(self): def onThemeChangeAction(self):
theme = unicode(self.sender().text()) theme = unicode(self.sender().text())
item, count = self.findServiceItem() item, count = self.findServiceItem()
self.serviceItems[item][u'data'].theme = theme self.serviceItems[item][u'service_item'].theme = theme
self.regenerateServiceItems() self.regenerateServiceItems()

View File

@ -457,7 +457,7 @@ class SlideController(QtGui.QWidget):
self.PreviewListWidget.clear() self.PreviewListWidget.clear()
self.PreviewListWidget.setRowCount(0) self.PreviewListWidget.setRowCount(0)
self.PreviewListWidget.setColumnWidth(0, width) 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.setRowCount(
self.PreviewListWidget.rowCount() + 1) self.PreviewListWidget.rowCount() + 1)
item = QtGui.QTableWidgetItem() item = QtGui.QTableWidgetItem()
@ -476,7 +476,7 @@ class SlideController(QtGui.QWidget):
self.PreviewListWidget.setItem(framenumber, 0, item) self.PreviewListWidget.setItem(framenumber, 0, item)
if slide_height != 0: if slide_height != 0:
self.PreviewListWidget.setRowHeight(framenumber, slide_height) 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.resizeRowsToContents()
self.PreviewListWidget.setColumnWidth( self.PreviewListWidget.setColumnWidth(
0, self.PreviewListWidget.viewport().size().width()) 0, self.PreviewListWidget.viewport().size().width())
@ -528,7 +528,7 @@ class SlideController(QtGui.QWidget):
if self.isLive: if self.isLive:
self.updatePreview() self.updatePreview()
else: else:
frame = self.serviceitem.frames[row][u'image'] frame = self.serviceitem.getFrames()[row][u'image']
before = time.time() before = time.time()
if frame is None: if frame is None:
frame = self.serviceitem.render_individual(row) frame = self.serviceitem.render_individual(row)

View File

@ -136,18 +136,18 @@ class PresentationMediaItem(MediaManagerItem):
return False return False
service_item.title = unicode(self.DisplayTypeComboBox.currentText()) service_item.title = unicode(self.DisplayTypeComboBox.currentText())
service_item.shortname = 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: for item in items:
bitem = self.ListView.item(item.row()) bitem = self.ListView.item(item.row())
filename = unicode((bitem.data(QtCore.Qt.UserRole)).toString()) filename = unicode((bitem.data(QtCore.Qt.UserRole)).toString())
(path, name) = os.path.split(filename) (path, name) = os.path.split(filename)
cont.store_filename(filename) controller.store_filename(filename)
if cont.get_slide_preview_file(1) is None: if controller.get_slide_preview_file(1) is None:
cont.load_presentation(filename) controller.load_presentation(filename)
i = 1 i = 1
img = cont.get_slide_preview_file(i) img = controller.get_slide_preview_file(i)
while img: while img:
service_item.add_from_command(path, name, img) service_item.add_from_command(path, name, img)
i = i + 1 i = i + 1
img = cont.get_slide_preview_file(i) img = controller.get_slide_preview_file(i)
return True return True