From 04d7a9227ef4bf060f3274fe108349fada7b6358 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 29 Jan 2010 11:59:13 +0000 Subject: [PATCH 1/6] Automate Presentation filters --- openlp/plugins/presentations/lib/impresscontroller.py | 1 + openlp/plugins/presentations/lib/mediaitem.py | 10 ++++++++-- .../plugins/presentations/lib/powerpointcontroller.py | 3 ++- openlp/plugins/presentations/lib/pptviewcontroller.py | 1 + .../presentations/lib/presentationcontroller.py | 3 ++- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index d2a31e202..ee15d27be 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -62,6 +62,7 @@ class ImpressController(PresentationController): """ log.debug(u'Initialising') PresentationController.__init__(self, plugin, u'Impress') + self.supports= [u'.odp', u'.ppt', u'.pps'] self.process = None self.document = None self.presentation = None diff --git a/openlp/plugins/presentations/lib/mediaitem.py b/openlp/plugins/presentations/lib/mediaitem.py index c1394c547..0b14f797d 100644 --- a/openlp/plugins/presentations/lib/mediaitem.py +++ b/openlp/plugins/presentations/lib/mediaitem.py @@ -63,7 +63,13 @@ class PresentationMediaItem(MediaManagerItem): def retranslateUi(self): self.OnNewPrompt = self.trUtf8('Select Presentation(s)') - self.OnNewFileMasks = self.trUtf8('Presentations (*.ppt *.pps *.odp)') + fileType = u'' + for controller in self.controllers: + if self.controllers[controller].enabled: + for type in self.controllers[controller].supports: + if fileType.find(type) == -1: + fileType += type + u' ' + self.OnNewFileMasks = self.trUtf8('Presentations (%s)' % fileType) def requiredIcons(self): MediaManagerItem.requiredIcons(self) @@ -151,4 +157,4 @@ class PresentationMediaItem(MediaManagerItem): service_item.add_from_command(path, name, img) i = i + 1 img = controller.get_slide_preview_file(i) - return True \ No newline at end of file + return True diff --git a/openlp/plugins/presentations/lib/powerpointcontroller.py b/openlp/plugins/presentations/lib/powerpointcontroller.py index d64314c76..18b644112 100644 --- a/openlp/plugins/presentations/lib/powerpointcontroller.py +++ b/openlp/plugins/presentations/lib/powerpointcontroller.py @@ -52,6 +52,7 @@ class PowerpointController(PresentationController): """ log.debug(u'Initialising') PresentationController.__init__(self, plugin, u'Powerpoint') + self.supports= [u'.ppt', u'.pps'] self.process = None self.presentation = None @@ -255,4 +256,4 @@ class PowerpointController(PresentationController): if os.path.isfile(path): return path else: - return None \ No newline at end of file + return None diff --git a/openlp/plugins/presentations/lib/pptviewcontroller.py b/openlp/plugins/presentations/lib/pptviewcontroller.py index 02b280540..0cf2405f1 100644 --- a/openlp/plugins/presentations/lib/pptviewcontroller.py +++ b/openlp/plugins/presentations/lib/pptviewcontroller.py @@ -49,6 +49,7 @@ class PptviewController(PresentationController): log.debug(u'Initialising') self.process = None PresentationController.__init__(self, plugin, u'Powerpoint Viewer') + self.supports= [u'.ppt', u'.pps'] self.pptid = None def check_available(self): diff --git a/openlp/plugins/presentations/lib/presentationcontroller.py b/openlp/plugins/presentations/lib/presentationcontroller.py index 82c014b64..ac9581d28 100644 --- a/openlp/plugins/presentations/lib/presentationcontroller.py +++ b/openlp/plugins/presentations/lib/presentationcontroller.py @@ -136,6 +136,7 @@ class PresentationController(object): ``name`` Name of the application, to appear in the application """ + self.supports = [] self.plugin = plugin self.name = name self.available = self.check_available() @@ -313,4 +314,4 @@ class PresentationController(object): else: prefix = u'preview' Receiver.send_message(u'%s_slidecontroller_change' % prefix, - self.slidenumber - 1) \ No newline at end of file + self.slidenumber - 1) From 1fd98217abcb51edae32a585afe1e6b8c13fba84 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 29 Jan 2010 13:06:47 +0000 Subject: [PATCH 2/6] Pass active presentation types to other controllers --- openlp/core/lib/eventreceiver.py | 5 ++++- openlp/core/ui/servicemanager.py | 7 ++++++- openlp/plugins/presentations/presentationplugin.py | 10 ++++++++-- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/openlp/core/lib/eventreceiver.py b/openlp/core/lib/eventreceiver.py index f3b43d2b7..e72314652 100644 --- a/openlp/core/lib/eventreceiver.py +++ b/openlp/core/lib/eventreceiver.py @@ -104,6 +104,9 @@ class EventReceiver(QtCore.QObject): ``remote_edit_clear`` Informs all components that remote edit has been aborted. + ``presentation types`` + Informs all components of the presentation types supported. + """ global log log = logging.getLogger(u'EventReceiver') @@ -161,4 +164,4 @@ class Receiver(): """ Get the global ``eventreceiver`` instance. """ - return Receiver.eventreceiver \ No newline at end of file + return Receiver.eventreceiver diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 44170e616..6bb09a92e 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -225,12 +225,17 @@ class ServiceManager(QtGui.QWidget): QtCore.SIGNAL(u'update_themes'), self.updateThemeList) QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'remote_edit_clear'), self.onRemoteEditClear) + QtCore.QObject.connect(Receiver.get_receiver(), + QtCore.SIGNAL(u'presentation types'), self.onPresentationTypes) # Last little bits of setting up self.config = PluginConfig(u'ServiceManager') self.servicePath = self.config.get_data_path() self.service_theme = unicode( self.config.get_config(u'service theme', u'')) + def onPresentationTypes(self, presentation_types): + self.presentation_types = presentation_types + def onMoveSelectionUp(self): """ Moves the selection up the window @@ -617,7 +622,7 @@ class ServiceManager(QtGui.QWidget): else: pos = parentitem.data(0, QtCore.Qt.UserRole).toInt()[0] count = item.data(0, QtCore.Qt.UserRole).toInt()[0] - #adjuest for zero based arrays + #adjust for zero based arrays pos = pos - 1 return pos, count diff --git a/openlp/plugins/presentations/presentationplugin.py b/openlp/plugins/presentations/presentationplugin.py index a380e9bb0..502557508 100644 --- a/openlp/plugins/presentations/presentationplugin.py +++ b/openlp/plugins/presentations/presentationplugin.py @@ -26,7 +26,7 @@ import os import logging -from openlp.core.lib import Plugin, build_icon +from openlp.core.lib import Plugin, build_icon, Receiver from openlp.plugins.presentations.lib import * class PresentationPlugin(Plugin): @@ -51,6 +51,12 @@ class PresentationPlugin(Plugin): log.info(u'Presentations Initialising') Plugin.initialise(self) self.insert_toolbox_item() + presentation_types = [] + for controller in self.controllers: + if self.controllers[controller].enabled: + presentation_types.append({u'%s' % controller : self.controllers[controller].supports}) + Receiver.send_message( + u'presentation types', presentation_types) def finalise(self): log.info(u'Plugin Finalise') @@ -106,4 +112,4 @@ class PresentationPlugin(Plugin): 'the ability to show presentations using a number of different ' 'programs. The choice of available presentation programs is ' 'available to the user in a drop down box.') - return about_text \ No newline at end of file + return about_text From 3610b232bda1e1269ce862c19c872f3fd85c6019 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Fri, 29 Jan 2010 16:38:28 +0000 Subject: [PATCH 3/6] Fix up saving and loading service items --- openlp.pyw | 2 +- openlp/core/ui/servicemanager.py | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/openlp.pyw b/openlp.pyw index 58925fdb9..4741059d2 100755 --- a/openlp.pyw +++ b/openlp.pyw @@ -159,7 +159,7 @@ def main(): help="Set the Qt4 style (passed directly to Qt4).") # Set up logging filename = u'openlp.log' - logfile = FileHandler(filename) + logfile = FileHandler(filename, u'w') logfile.setFormatter(logging.Formatter( u'%(asctime)s %(name)-15s %(levelname)-8s %(message)s')) log.addHandler(logfile) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 6bb09a92e..5f384a955 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -438,10 +438,10 @@ class ServiceManager(QtGui.QWidget): for item in self.serviceItems: service.append({u'serviceitem':item[u'service_item'].get_service_repr()}) if item[u'service_item'].uses_file(): - for frame in item[u'service_item'].get_frames: + for frame in item[u'service_item'].get_frames(): path_from = unicode(os.path.join( item[u'service_item'].service_item_path, - frame.get_frame_title())) + frame[u'title'])) zip.write(path_from) file = open(servicefile, u'wb') cPickle.dump(service, file) @@ -504,7 +504,8 @@ class ServiceManager(QtGui.QWidget): serviceitem = ServiceItem() serviceitem.RenderManager = self.parent.RenderManager serviceitem.set_from_service(item, self.servicePath) - self.addServiceItem(serviceitem) + if self.validateItem(serviceitem): + self.addServiceItem(serviceitem) try: if os.path.isfile(p_file): os.remove(p_file) @@ -521,6 +522,14 @@ class ServiceManager(QtGui.QWidget): self.serviceName = name[len(name) - 1] self.parent.serviceChanged(True, self.serviceName) + def validateItem(self, serviceItem): + print "---" + print serviceItem.name + print serviceItem.title + print serviceItem.service_item_path + print serviceItem.service_item_type + return True + def cleanUp(self): """ Empties the servicePath of temporary files From 17a08e384747d3355f05cc00706794947e470d3b Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Mon, 1 Feb 2010 19:42:52 +0000 Subject: [PATCH 4/6] latest hacking --- .../presentations/lib/impresscontroller.py | 36 ++- .../presentations/lib/messagelistener.py | 291 +++++++----------- .../lib/presentationcontroller.py | 2 +- 3 files changed, 146 insertions(+), 183 deletions(-) diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index ee15d27be..b160b3b4b 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -62,11 +62,12 @@ class ImpressController(PresentationController): """ log.debug(u'Initialising') PresentationController.__init__(self, plugin, u'Impress') - self.supports= [u'.odp', u'.ppt', u'.pps'] + self.supports= [u'.odp', u'.ppt', u'.pps', u'.pptx', u'.ppsx'] self.process = None self.document = None self.presentation = None self.controller = None + self.desktop = None def check_available(self): """ @@ -86,7 +87,7 @@ class ImpressController(PresentationController): It is not displayed to the user but is available to the UNO interface when required. """ - log.debug(u'start Openoffice') + log.debug(u'start process Openoffice') if os.name == u'nt': self.manager = self.get_com_servicemanager() self.manager._FlagAsMethod(u'Bridge_GetStruct') @@ -102,7 +103,7 @@ class ImpressController(PresentationController): """ Called at system exit to clean up any running presentations """ - log.debug(u'Kill') + log.debug(u'Kill OpenOffice') self.close_presentation() if os.name != u'nt': desktop = self.get_uno_desktop() @@ -122,8 +123,9 @@ class ImpressController(PresentationController): ``presentation`` The file name of the presentatios to the run. """ - log.debug(u'LoadPresentation') + log.debug(u'Load Presentation OpenOffice') self.store_filename(presentation) + print "s.dsk1 ", self.desktop if os.name == u'nt': desktop = self.get_com_desktop() if desktop is None: @@ -136,6 +138,7 @@ class ImpressController(PresentationController): if desktop is None: return self.desktop = desktop + print "s.dsk2 ", self.desktop properties = [] properties.append(self.create_property(u'Minimized', True)) properties = tuple(properties) @@ -154,9 +157,9 @@ class ImpressController(PresentationController): """ Create thumbnail images for presentation """ + log.debug(u'create thumbnails OpenOffice') if self.check_thumbnails(): return - if os.name == u'nt': thumbdir = u'file:///' + self.thumbnailpath.replace( u'\\', u'/').replace(u':', u'|').replace(u' ', u'%20') @@ -171,13 +174,14 @@ class ImpressController(PresentationController): page = pages.getByIndex(idx) doc.getCurrentController().setCurrentPage(page) path = u'%s/%s%s.png'% (thumbdir, self.thumbnailprefix, - unicode(idx+1)) + unicode(idx + 1)) try: doc.storeToURL(path , props) except: log.exception(u'%s\nUnable to store preview' % path) def create_property(self, name, value): + log.debug(u'create property OpenOffice') if os.name == u'nt': prop = self.manager.Bridge_GetStruct(u'com.sun.star.beans.PropertyValue') else: @@ -187,7 +191,7 @@ class ImpressController(PresentationController): return prop def get_uno_desktop(self): - log.debug(u'getUNODesktop') + log.debug(u'get UNO Desktop Openoffice') ctx = None loop = 0 context = uno.getComponentContext() @@ -197,6 +201,7 @@ class ImpressController(PresentationController): try: ctx = resolver.resolve(u'uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext') except: + log.exception(u'Unable to fine running instance ') self.start_process() loop += 1 try: @@ -209,7 +214,7 @@ class ImpressController(PresentationController): return None def get_com_desktop(self): - log.debug(u'getCOMDesktop') + log.debug(u'get COM Desktop OpenOffice') try: desktop = self.manager.createInstance(u'com.sun.star.frame.Desktop') return desktop @@ -218,7 +223,7 @@ class ImpressController(PresentationController): return None def get_com_servicemanager(self): - log.debug(u'get_com_servicemanager') + log.debug(u'get_com_servicemanager openoffice') try: return Dispatch(u'com.sun.star.ServiceManager') except: @@ -231,6 +236,7 @@ class ImpressController(PresentationController): Triggerent by new object being added to SlideController orOpenLP being shut down """ + log.debug(u'close Presentation OpenOffice') if self.document: if self.presentation: try: @@ -243,32 +249,44 @@ class ImpressController(PresentationController): self.document = None def is_loaded(self): + log.debug(u'is loaded OpenOffice') + print "is_loaded " if self.presentation is None or self.document is None: + print "no present or document" return False try: if self.document.getPresentation() is None: + print "no getPresentation" return False except: return False return True def is_active(self): + log.debug(u'is active OpenOffice') + print "is_active " if not self.is_loaded(): + print "False " return False + print "self.con ", self.controller if self.controller is None: return False return True def unblank_screen(self): + log.debug(u'unblank screen OpenOffice') return self.controller.resume() def blank_screen(self): + log.debug(u'blank screen OpenOffice') self.controller.blankScreen(0) def stop_presentation(self): + log.debug(u'stop presentation OpenOffice') self.controller.deactivate() def start_presentation(self): + log.debug(u'start presentation OpenOffice') if self.controller is None or not self.controller.isRunning(): self.presentation.start() # start() returns before the getCurrentComponent is ready. Try for 5 seconds diff --git a/openlp/plugins/presentations/lib/messagelistener.py b/openlp/plugins/presentations/lib/messagelistener.py index 0b2fd6003..fafaa2d95 100644 --- a/openlp/plugins/presentations/lib/messagelistener.py +++ b/openlp/plugins/presentations/lib/messagelistener.py @@ -4,8 +4,8 @@ ############################################################################### # OpenLP - Open Source Lyrics Projection # # --------------------------------------------------------------------------- # -# Copyright (c) 2008-2010 Raoul Snyman # -# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael # +# Copyright (c) 2008-2009 Raoul Snyman # +# Portions copyright (c) 2008-2009 Tim Bentley, Jonathan Corwin, Michael # # Gorven, Scott Guerrieri, Maikel Stuivenberg, Martin Thompson, Jon Tibble, # # Carsten Tinggaard # # --------------------------------------------------------------------------- # @@ -30,118 +30,6 @@ from PyQt4 import QtCore from openlp.core.lib import Receiver -class Controller(object): - """ - This is the Presentation listener who acts on events from the slide - controller and passes the messages on the the correct presentation handlers - """ - global log - log = logging.getLogger(u'Controller') - log.info(u'Controller loaded') - - def __init__(self, live): - self.isLive = live - log.info(u'%s controller loaded' % live) - - def addHandler(self, controller, file): - log.debug(u'Live = %s, addHandler %s' % (self.isLive, file)) - self.controller = controller - if self.controller.is_loaded(): - self.shutdown() - self.controller.load_presentation(file) - if self.isLive: - self.controller.start_presentation() - Receiver.send_message(u'live_slide_hide') - self.controller.slidenumber = 0 - - def activate(self): - log.debug(u'Live = %s, activate' % self.isLive) - if self.controller.is_active(): - return - if not self.controller.is_loaded(): - self.controller.load_presentation(self.controller.filepath) - if self.isLive: - self.controller.start_presentation() - if self.controller.slidenumber > 1: - self.controller.goto_slide(self.controller.slidenumber) - - def slide(self, slide, live): - log.debug(u'Live = %s, slide' % live) -# if not isLive: -# return - self.activate() - self.controller.goto_slide(int(slide) + 1) - self.controller.poll_slidenumber(live) - - def first(self): - """ - Based on the handler passed at startup triggers the first slide - """ - log.debug(u'Live = %s, first' % self.isLive) - if not self.isLive: - return - self.activate() - self.controller.start_presentation() - self.controller.poll_slidenumber(self.isLive) - - def last(self): - """ - Based on the handler passed at startup triggers the first slide - """ - log.debug(u'Live = %s, last' % self.isLive) - if not self.isLive: - return - self.activate() - self.controller.goto_slide(self.controller.get_slide_count()) - self.controller.poll_slidenumber(self.isLive) - - def next(self): - """ - Based on the handler passed at startup triggers the next slide event - """ - log.debug(u'Live = %s, next' % self.isLive) - if not self.isLive: - return - self.activate() - self.controller.next_step() - self.controller.poll_slidenumber(self.isLive) - - def previous(self): - """ - Based on the handler passed at startup triggers the previous slide event - """ - log.debug(u'Live = %s, previous' % self.isLive) - if not self.isLive: - return - self.activate() - self.controller.previous_step() - self.controller.poll_slidenumber(self.isLive) - - def shutdown(self): - """ - Based on the handler passed at startup triggers slide show to shut down - """ - log.debug(u'Live = %s, shutdown' % self.isLive) - self.controller.close_presentation() - self.controller.slidenumber = 0 - #self.timer.stop() - - def blank(self): - if not self.isLive: - return - if not self.controller.is_loaded(): - return - if not self.controller.is_active(): - return - self.controller.blank_screen() - - def unblank(self): - if not self.is_live: - return - self.activate() - self.controller.unblank_screen() - - class MessageListener(object): """ This is the Presentation listener who acts on events from the slide @@ -153,8 +41,8 @@ class MessageListener(object): def __init__(self, controllers): self.controllers = controllers - self.previewHandler = Controller(False) - self.liveHandler = Controller(True) + self.handler = None + self.is_live = None # messages are sent from core.ui.slidecontroller QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'presentations_start'), self.startup) @@ -183,62 +71,133 @@ class MessageListener(object): Start of new presentation Save the handler as any new presentations start here """ - log.debug(u'Startup called with message %s' % message) - self.handler, file, isLive = self.decodeMessage(message) - if isLive: - self.liveHandler.addHandler(self.controllers[self.handler], file) - else: - self.previewHandler.addHandler(self.controllers[self.handler], file) + log.debug(u'startup %s ' % message) + self.handler, file, self.is_live = self.decodeMessage(message) + self.controller = self.controllers[self.handler] + if self.controller.is_loaded(): + self.shutdown(None) + print "aaa ", self.is_live + self.controller.load_presentation(file) + if self.is_live: + self.controller.start_presentation() + Receiver.send_message(u'live_slide_hide') + self.controller.slidenumber = 0 + self.timer.start() + + def activate(self): + log.debug(u'activate') + if self.controller.is_active(): + return + if not self.controller.is_loaded(): + self.controller.load_presentation(self.controller.filepath) + log.debug(u'activate 2') + print "activate 2" + self.controller.start_presentation() + log.debug(u'activate 3') + print "activate 3" + if self.controller.slidenumber > 1: + self.controller.goto_slide(self.controller.slidenumber) def slide(self, message): + log.debug(u'slide %s ' % message) + #Not wanted for preview frame + if not self.is_live: + return slide, live = self.splitMessage(message) - if live: - self.liveHandler.slide(slide, live) - else: - self.previewHandler.slide(slide, live) + self.activate() + print ">>> ", message + if message: + print message[0], self.is_live + self.controller.goto_slide(int(slide) + 1) + self.controller.poll_slidenumber(self.is_live) - def first(self, isLive): - if isLive: - self.liveHandler.first() - else: - self.previewHandler.first() + def first(self, message): + """ + Based on the handler passed at startup triggers the first slide + """ + log.debug(u'first %s ' % message) + #Not wanted for preview frame + if not self.is_live: + return + self.activate() + self.controller.start_presentation() + self.controller.poll_slidenumber(self.is_live) - def last(self, isLive): - if isLive: - self.liveHandler.last() - else: - self.previewHandler.last() + def last(self, message): + """ + Based on the handler passed at startup triggers the first slide + """ + log.debug(u'last %s ' % message) + #Not wanted for preview frame + if not self.is_live: + return + self.activate() + self.controller.goto_slide(self.controller.get_slide_count()) + self.controller.poll_slidenumber(self.is_live) - def next(self, isLive): - if isLive: - self.liveHandler.next() - else: - self.previewHandler.next() + def next(self, message): + """ + Based on the handler passed at startup triggers the next slide event + """ + log.debug(u'next ', message) + #Not wanted for preview frame + if not self.is_live: + return + self.activate() + self.controller.next_step() + self.controller.poll_slidenumber(self.is_live) - def previous(self, isLive): - if isLive: - self.liveHandler.previous() - else: - self.previewHandler.previous() + def previous(self, message): + """ + Based on the handler passed at startup triggers the previous slide event + """ + log.debug(u'previous %s' % message) + if not self.is_live: + return + self.activate() + self.controller.previous_step() + self.controller.poll_slidenumber(self.is_live) - def shutdown(self, isLive): - if isLive: - self.liveHandler.shutdown() + def shutdown(self, message): + """ + Based on the handler passed at startup triggers slide show to shut down + """ + log.debug(u'shutdown %s ' % message) + if self.is_live: Receiver.send_message(u'live_slide_show') - else: - self.previewHandler.shutdown() + self.controller.close_presentation() + self.controller.slidenumber = 0 + self.timer.stop() def blank(self): - if self.isLive: - self.liveHandler.blank() - else: - self.previewHandler.blank() + log.debug(u'blank') + if not self.is_live: + return + if not self.controller.is_loaded(): + return + if not self.controller.is_active(): + return + self.controller.blank_screen() def unblank(self): - if self.isLive: - self.liveHandler.unblank() - else: - self.previewHandler.unblank() + log.debug(u'unblank') + if not self.is_live: + return + self.activate() + self.controller.unblank_screen() + + def decodeMessage(self, message): + """ + Splits the message from the SlideController into it's component parts + + ``message`` + Message containing Presentaion handler name and file to be presented. + """ + file = os.path.join(message[1], message[2]) + return message[0], file, message[4] + + def timeout(self): + self.controller.poll_slidenumber(self.is_live) def splitMessage(self, message): """ @@ -250,17 +209,3 @@ class MessageListener(object): """ bits = message.split(u':') return bits[0], bits[1] - - def decodeMessage(self, message): - """ - Splits the initial message from the SlideController - into it's component parts - - ``message`` - Message containing Presentaion handler name and file to be presented. - """ - file = os.path.join(message[1], message[2]) - return message[0], file, message[4] - - def timeout(self): - self.controller.poll_slidenumber(self.is_live) diff --git a/openlp/plugins/presentations/lib/presentationcontroller.py b/openlp/plugins/presentations/lib/presentationcontroller.py index ac9581d28..db42a482d 100644 --- a/openlp/plugins/presentations/lib/presentationcontroller.py +++ b/openlp/plugins/presentations/lib/presentationcontroller.py @@ -118,7 +118,7 @@ class PresentationController(object): """ global log log = logging.getLogger(u'PresentationController') - log.info(u'loaded') + log.info(u'PresentationController loaded') def __init__(self, plugin=None, name=u'PresentationController'): """ From 377f3ad6ea96d0859fa870592a31d142ba4f51fd Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Mon, 1 Feb 2010 20:06:50 +0000 Subject: [PATCH 5/6] Put the messagelistener back --- .../presentations/lib/messagelistener.py | 291 +++++++++++------- 1 file changed, 173 insertions(+), 118 deletions(-) diff --git a/openlp/plugins/presentations/lib/messagelistener.py b/openlp/plugins/presentations/lib/messagelistener.py index fafaa2d95..0b2fd6003 100644 --- a/openlp/plugins/presentations/lib/messagelistener.py +++ b/openlp/plugins/presentations/lib/messagelistener.py @@ -4,8 +4,8 @@ ############################################################################### # OpenLP - Open Source Lyrics Projection # # --------------------------------------------------------------------------- # -# Copyright (c) 2008-2009 Raoul Snyman # -# Portions copyright (c) 2008-2009 Tim Bentley, Jonathan Corwin, Michael # +# Copyright (c) 2008-2010 Raoul Snyman # +# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael # # Gorven, Scott Guerrieri, Maikel Stuivenberg, Martin Thompson, Jon Tibble, # # Carsten Tinggaard # # --------------------------------------------------------------------------- # @@ -30,6 +30,118 @@ from PyQt4 import QtCore from openlp.core.lib import Receiver +class Controller(object): + """ + This is the Presentation listener who acts on events from the slide + controller and passes the messages on the the correct presentation handlers + """ + global log + log = logging.getLogger(u'Controller') + log.info(u'Controller loaded') + + def __init__(self, live): + self.isLive = live + log.info(u'%s controller loaded' % live) + + def addHandler(self, controller, file): + log.debug(u'Live = %s, addHandler %s' % (self.isLive, file)) + self.controller = controller + if self.controller.is_loaded(): + self.shutdown() + self.controller.load_presentation(file) + if self.isLive: + self.controller.start_presentation() + Receiver.send_message(u'live_slide_hide') + self.controller.slidenumber = 0 + + def activate(self): + log.debug(u'Live = %s, activate' % self.isLive) + if self.controller.is_active(): + return + if not self.controller.is_loaded(): + self.controller.load_presentation(self.controller.filepath) + if self.isLive: + self.controller.start_presentation() + if self.controller.slidenumber > 1: + self.controller.goto_slide(self.controller.slidenumber) + + def slide(self, slide, live): + log.debug(u'Live = %s, slide' % live) +# if not isLive: +# return + self.activate() + self.controller.goto_slide(int(slide) + 1) + self.controller.poll_slidenumber(live) + + def first(self): + """ + Based on the handler passed at startup triggers the first slide + """ + log.debug(u'Live = %s, first' % self.isLive) + if not self.isLive: + return + self.activate() + self.controller.start_presentation() + self.controller.poll_slidenumber(self.isLive) + + def last(self): + """ + Based on the handler passed at startup triggers the first slide + """ + log.debug(u'Live = %s, last' % self.isLive) + if not self.isLive: + return + self.activate() + self.controller.goto_slide(self.controller.get_slide_count()) + self.controller.poll_slidenumber(self.isLive) + + def next(self): + """ + Based on the handler passed at startup triggers the next slide event + """ + log.debug(u'Live = %s, next' % self.isLive) + if not self.isLive: + return + self.activate() + self.controller.next_step() + self.controller.poll_slidenumber(self.isLive) + + def previous(self): + """ + Based on the handler passed at startup triggers the previous slide event + """ + log.debug(u'Live = %s, previous' % self.isLive) + if not self.isLive: + return + self.activate() + self.controller.previous_step() + self.controller.poll_slidenumber(self.isLive) + + def shutdown(self): + """ + Based on the handler passed at startup triggers slide show to shut down + """ + log.debug(u'Live = %s, shutdown' % self.isLive) + self.controller.close_presentation() + self.controller.slidenumber = 0 + #self.timer.stop() + + def blank(self): + if not self.isLive: + return + if not self.controller.is_loaded(): + return + if not self.controller.is_active(): + return + self.controller.blank_screen() + + def unblank(self): + if not self.is_live: + return + self.activate() + self.controller.unblank_screen() + + class MessageListener(object): """ This is the Presentation listener who acts on events from the slide @@ -41,8 +153,8 @@ class MessageListener(object): def __init__(self, controllers): self.controllers = controllers - self.handler = None - self.is_live = None + self.previewHandler = Controller(False) + self.liveHandler = Controller(True) # messages are sent from core.ui.slidecontroller QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'presentations_start'), self.startup) @@ -71,133 +183,62 @@ class MessageListener(object): Start of new presentation Save the handler as any new presentations start here """ - log.debug(u'startup %s ' % message) - self.handler, file, self.is_live = self.decodeMessage(message) - self.controller = self.controllers[self.handler] - if self.controller.is_loaded(): - self.shutdown(None) - print "aaa ", self.is_live - self.controller.load_presentation(file) - if self.is_live: - self.controller.start_presentation() - Receiver.send_message(u'live_slide_hide') - self.controller.slidenumber = 0 - self.timer.start() - - def activate(self): - log.debug(u'activate') - if self.controller.is_active(): - return - if not self.controller.is_loaded(): - self.controller.load_presentation(self.controller.filepath) - log.debug(u'activate 2') - print "activate 2" - self.controller.start_presentation() - log.debug(u'activate 3') - print "activate 3" - if self.controller.slidenumber > 1: - self.controller.goto_slide(self.controller.slidenumber) + log.debug(u'Startup called with message %s' % message) + self.handler, file, isLive = self.decodeMessage(message) + if isLive: + self.liveHandler.addHandler(self.controllers[self.handler], file) + else: + self.previewHandler.addHandler(self.controllers[self.handler], file) def slide(self, message): - log.debug(u'slide %s ' % message) - #Not wanted for preview frame - if not self.is_live: - return slide, live = self.splitMessage(message) - self.activate() - print ">>> ", message - if message: - print message[0], self.is_live - self.controller.goto_slide(int(slide) + 1) - self.controller.poll_slidenumber(self.is_live) + if live: + self.liveHandler.slide(slide, live) + else: + self.previewHandler.slide(slide, live) - def first(self, message): - """ - Based on the handler passed at startup triggers the first slide - """ - log.debug(u'first %s ' % message) - #Not wanted for preview frame - if not self.is_live: - return - self.activate() - self.controller.start_presentation() - self.controller.poll_slidenumber(self.is_live) + def first(self, isLive): + if isLive: + self.liveHandler.first() + else: + self.previewHandler.first() - def last(self, message): - """ - Based on the handler passed at startup triggers the first slide - """ - log.debug(u'last %s ' % message) - #Not wanted for preview frame - if not self.is_live: - return - self.activate() - self.controller.goto_slide(self.controller.get_slide_count()) - self.controller.poll_slidenumber(self.is_live) + def last(self, isLive): + if isLive: + self.liveHandler.last() + else: + self.previewHandler.last() - def next(self, message): - """ - Based on the handler passed at startup triggers the next slide event - """ - log.debug(u'next ', message) - #Not wanted for preview frame - if not self.is_live: - return - self.activate() - self.controller.next_step() - self.controller.poll_slidenumber(self.is_live) + def next(self, isLive): + if isLive: + self.liveHandler.next() + else: + self.previewHandler.next() - def previous(self, message): - """ - Based on the handler passed at startup triggers the previous slide event - """ - log.debug(u'previous %s' % message) - if not self.is_live: - return - self.activate() - self.controller.previous_step() - self.controller.poll_slidenumber(self.is_live) + def previous(self, isLive): + if isLive: + self.liveHandler.previous() + else: + self.previewHandler.previous() - def shutdown(self, message): - """ - Based on the handler passed at startup triggers slide show to shut down - """ - log.debug(u'shutdown %s ' % message) - if self.is_live: + def shutdown(self, isLive): + if isLive: + self.liveHandler.shutdown() Receiver.send_message(u'live_slide_show') - self.controller.close_presentation() - self.controller.slidenumber = 0 - self.timer.stop() + else: + self.previewHandler.shutdown() def blank(self): - log.debug(u'blank') - if not self.is_live: - return - if not self.controller.is_loaded(): - return - if not self.controller.is_active(): - return - self.controller.blank_screen() + if self.isLive: + self.liveHandler.blank() + else: + self.previewHandler.blank() def unblank(self): - log.debug(u'unblank') - if not self.is_live: - return - self.activate() - self.controller.unblank_screen() - - def decodeMessage(self, message): - """ - Splits the message from the SlideController into it's component parts - - ``message`` - Message containing Presentaion handler name and file to be presented. - """ - file = os.path.join(message[1], message[2]) - return message[0], file, message[4] - - def timeout(self): - self.controller.poll_slidenumber(self.is_live) + if self.isLive: + self.liveHandler.unblank() + else: + self.previewHandler.unblank() def splitMessage(self, message): """ @@ -209,3 +250,17 @@ class MessageListener(object): """ bits = message.split(u':') return bits[0], bits[1] + + def decodeMessage(self, message): + """ + Splits the initial message from the SlideController + into it's component parts + + ``message`` + Message containing Presentaion handler name and file to be presented. + """ + file = os.path.join(message[1], message[2]) + return message[0], file, message[4] + + def timeout(self): + self.controller.poll_slidenumber(self.is_live) From 632fae5a7662207e7bfa16847e1eb7736a95f279 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Tue, 2 Feb 2010 18:16:11 +0000 Subject: [PATCH 6/6] Remove print statements --- openlp/core/ui/servicemanager.py | 10 +++++----- .../presentations/lib/impresscontroller.py | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/openlp/core/ui/servicemanager.py b/openlp/core/ui/servicemanager.py index 5f384a955..1eef9a81b 100644 --- a/openlp/core/ui/servicemanager.py +++ b/openlp/core/ui/servicemanager.py @@ -523,11 +523,11 @@ class ServiceManager(QtGui.QWidget): self.parent.serviceChanged(True, self.serviceName) def validateItem(self, serviceItem): - print "---" - print serviceItem.name - print serviceItem.title - print serviceItem.service_item_path - print serviceItem.service_item_type +# print "---" +# print serviceItem.name +# print serviceItem.title +# print serviceItem.service_item_path +# print serviceItem.service_item_type return True def cleanUp(self): diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index b160b3b4b..b58a9affc 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -125,7 +125,7 @@ class ImpressController(PresentationController): """ log.debug(u'Load Presentation OpenOffice') self.store_filename(presentation) - print "s.dsk1 ", self.desktop + #print "s.dsk1 ", self.desktop if os.name == u'nt': desktop = self.get_com_desktop() if desktop is None: @@ -138,7 +138,7 @@ class ImpressController(PresentationController): if desktop is None: return self.desktop = desktop - print "s.dsk2 ", self.desktop + #print "s.dsk2 ", self.desktop properties = [] properties.append(self.create_property(u'Minimized', True)) properties = tuple(properties) @@ -250,13 +250,13 @@ class ImpressController(PresentationController): def is_loaded(self): log.debug(u'is loaded OpenOffice') - print "is_loaded " + #print "is_loaded " if self.presentation is None or self.document is None: - print "no present or document" + #print "no present or document" return False try: if self.document.getPresentation() is None: - print "no getPresentation" + #print "no getPresentation" return False except: return False @@ -264,11 +264,11 @@ class ImpressController(PresentationController): def is_active(self): log.debug(u'is active OpenOffice') - print "is_active " + #print "is_active " if not self.is_loaded(): - print "False " + #print "False " return False - print "self.con ", self.controller + #print "self.con ", self.controller if self.controller is None: return False return True