~tomasgroth/openlp/mupdf

« back to all changes in this revision

Viewing changes to openlp/plugins/presentations/lib/messagelistener.py

  • Committer: Tomas Groth
  • Date: 2013-12-31 12:15:18 UTC
  • Revision ID: tomasgroth@yahoo.dk-20131231121518-fwqf5lzui6f60oyf
Changed the way a serviceitem from the servicemanager is copied and converted. Also fixed for PEP8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
###############################################################################
29
29
 
30
30
import logging
 
31
import copy
31
32
 
32
33
from PyQt4 import QtCore
33
34
 
318
319
        hide_mode = message[2]
319
320
        file = item.get_frame_path()
320
321
        self.handler = item.processor
321
 
        # When starting presentation from the servicemanager/slidecontroller we convert 
 
322
        # When starting presentation from the servicemanager we convert
322
323
        # PDF/XPS-serviceitems into image-serviceitems. When started from the mediamanager
323
 
        # the conversion has already been done.
 
324
        # the conversion has already been done at this point.
324
325
        if file.endswith('.pdf') or file.endswith('.xps'):
325
326
            log.debug('Converting from pdf/xps to images for serviceitem with file %s', file)
326
 
            # Create a new image-serviceitem which will overwrite the old one
327
 
            new_item = ServiceItem()
328
 
            new_item.name = 'images'
 
327
            # Create a copy of the original item, and then clear the original item so it can be filled with images
 
328
            item_cpy = copy.copy(item)
 
329
            item.__init__(None)
329
330
            if is_live:
330
 
                self.media_item.generate_slide_data(new_item, item, False, False, ServiceItemContext.Live, file)
 
331
                self.media_item.generate_slide_data(item, item_cpy, False, False, ServiceItemContext.Live, file)
331
332
            else:
332
 
                self.media_item.generate_slide_data(new_item, item, False, False, ServiceItemContext.Preview, file)
333
 
            # We need to overwrite the current serviceitem to make the slidecontroller
334
 
            # present the images, so we do some copying
335
 
            service_repr = {'serviceitem': new_item.get_service_repr(True) }
336
 
            item.set_from_service(service_repr)
337
 
            item._raw_frames = new_item._raw_frames
338
 
            # When presenting PDF or XPS, we are using the image presentation code, 
 
333
                self.media_item.generate_slide_data(item, item_cpy, False, False, ServiceItemContext.Preview, file)
 
334
            # Some of the original serviceitem attributes is needed in the new serviceitem
 
335
            item.footer = item_cpy.footer
 
336
            item.from_service = item_cpy.from_service
 
337
            item.iconic_representation = item_cpy.iconic_representation
 
338
            item.image_border = item_cpy.image_border
 
339
            item.main = item_cpy.main
 
340
            item.theme_data = item_cpy.theme_data
 
341
            # When presenting PDF or XPS, we are using the image presentation code,
339
342
            # so handler & processor is set to None, and we skip adding the handler.
340
343
            self.handler = None
341
344
        if self.handler == self.media_item.automatic:
346
349
            controller = self.live_handler
347
350
        else:
348
351
            controller = self.preview_handler
349
 
        # When presenting PDF or XPS, we are using the image presentation code, 
 
352
        # When presenting PDF or XPS, we are using the image presentation code,
350
353
        # so handler & processor is set to None, and we skip adding the handler.
351
 
        if self.handler == None:
 
354
        if self.handler is None:
352
355
            self.controller = controller
353
356
        else:
354
357
            controller.add_handler(self.controllers[self.handler], file, hide_mode, message[3])