From 96e3f7bce6d2e93156a09176745f325dbc6642e0 Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Fri, 25 Sep 2009 23:20:34 +0100 Subject: [PATCH 1/3] Inherit common presentationcontroller --- openlp/plugins/presentations/lib/__init__.py | 1 + .../presentations/lib/impresscontroller.py | 8 +- .../presentations/lib/messagelistener.py | 8 +- .../presentations/lib/pptviewcontroller.py | 130 +++++++++++------- .../presentations/presentationplugin.py | 14 +- 5 files changed, 96 insertions(+), 65 deletions(-) diff --git a/openlp/plugins/presentations/lib/__init__.py b/openlp/plugins/presentations/lib/__init__.py index fe9bcb619..4b6577bdb 100644 --- a/openlp/plugins/presentations/lib/__init__.py +++ b/openlp/plugins/presentations/lib/__init__.py @@ -24,6 +24,7 @@ import os +from presentationcontroller import PresentationController from impresscontroller import ImpressController if os.name == u'nt': #from powerpointcontroller import PowerpointController diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index 763afd1d2..af78f9060 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -73,7 +73,7 @@ class ImpressController(object): log.debug(u'Kill') self.closePresentation() - def loadPresentation(self, presentation): + def load_presentation(self, presentation): """ Called when a presentation is added to the SlideController. It builds the environment, starts communcations with the background @@ -137,7 +137,7 @@ class ImpressController(object): log.exception(u'Failed to get COM desktop') return None - def closePresentation(self): + def close_presentation(self): """ Close presentation and clean up objects Triggerent by new object being added to SlideController orOpenLP @@ -178,13 +178,13 @@ class ImpressController(object): slideNumber = property(getSlideNumber, setSlideNumber) - def nextStep(self): + def next_step(self): """ Triggers the next effect of slide on the running presentation """ self.xSlideShowController.gotoNextEffect() - def previousStep(self): + def previous_step(self): """ Triggers the previous slide on the running presentation """ diff --git a/openlp/plugins/presentations/lib/messagelistener.py b/openlp/plugins/presentations/lib/messagelistener.py index 586a371f7..30d8081a7 100644 --- a/openlp/plugins/presentations/lib/messagelistener.py +++ b/openlp/plugins/presentations/lib/messagelistener.py @@ -56,25 +56,25 @@ class MessageListener(object): Save the handler as any new presentations start here """ self.handler, file = self.decodeMessage(message) - self.controllers[self.handler].loadPresentation(file) + self.controllers[self.handler].load_presentation(file) def next(self, message): """ Based on the handler passed at startup triggers the next slide event """ - self.controllers[self.handler].nextStep() + self.controllers[self.handler].next_step() def previous(self, message): """ Based on the handler passed at startup triggers the previous slide event """ - self.controllers[self.handler].previousStep() + self.controllers[self.handler].previous_step() def shutDown(self, message): """ Based on the handler passed at startup triggers slide show to shut down """ - self.controllers[self.handler].closePresentation() + self.controllers[self.handler].close_presentation() def decodeMessage(self, message): """ diff --git a/openlp/plugins/presentations/lib/pptviewcontroller.py b/openlp/plugins/presentations/lib/pptviewcontroller.py index 07db40cd1..509b52ead 100644 --- a/openlp/plugins/presentations/lib/pptviewcontroller.py +++ b/openlp/plugins/presentations/lib/pptviewcontroller.py @@ -22,12 +22,15 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### +import os import logging from ctypes import * from ctypes.wintypes import RECT -class PptviewController(object): +from presentationcontroller import PresentationController + +class PptviewController(PresentationController): """ Class to control interactions with PowerPOint Viewer Presentations It creates the runtime Environment , Loads the and Closes the Presentation @@ -36,29 +39,34 @@ class PptviewController(object): global log log = logging.getLogger(u'PptviewController') - def __init__(self): - log.debug(u'Initialising') + def __init__(self, plugin): + """ + Initialise the class + """ + log.debug(u'Initialised') + PresentationController.__init__(self, plugin, u'Powerpoint Viewer') self.process = None - self.document = None - self.presentation = None self.pptid = None - self.startPPTView() + self.thumbnailpath = os.path.join(plugin.config.get_data_path(), + u'pptview', u'thumbnails') + self.thumbprefix = u'slide' + self.start_process() - def startPPTView(self): + def start_process(self): """ Loads the PPTVIEWLIB library """ log.debug(u'start PPTView') - self.presentation = cdll.LoadLibrary(r'openlp\plugins\presentations\lib\pptviewlib\pptviewlib.dll') + self.process = cdll.LoadLibrary(r'openlp\plugins\presentations\lib\pptviewlib\pptviewlib.dll') def kill(self): """ Called at system exit to clean up any running presentations """ log.debug(u'Kill') - self.closePresentation() + self.close_presentation() - def loadPresentation(self, presentation): + def load_presentation(self, presentation): """ Called when a presentation is added to the SlideController. It builds the environment, starts communcations with the background @@ -71,17 +79,20 @@ class PptviewController(object): """ log.debug(u'LoadPresentation') if self.pptid >= 0: - self.closePresentation() - rect = RECT(0, 0, 800, 600) # until such time I can get screen info + self.close_presentation() + rendermanager = self.plugin.render_manager + #screen = rendermanager.screen_list[rendermanager.current_display] + # x? y? + rect = RECT(0, 0, rendermanager.width, rendermanager.height) filename = str(presentation.replace(u'/', u'\\')); try: - tempfolder = None #r'c:\temp\pptviewlib\' + filename.split('u\\')[-1] - self.pptid = self.presentation.OpenPPT(filename, None, rect, tempfolder) + self.pptid = self.process.OpenPPT(filename, None, rect, + str(self.thumbnailpath)) except: log.exception(u'Failed to load presentation') - #self.slidecount = pptdll.GetSlideCount(self.pptid) - def closePresentation(self): + + def close_presentation(self): """ Close presentation and clean up objects Triggerent by new object being added to SlideController orOpenLP @@ -89,93 +100,110 @@ class PptviewController(object): """ if self.pptid < 0: return - self.presentation.ClosePPT(self.pptid) + self.process.ClosePPT(self.pptid) self.pptid = -1 - def nextStep(self): - """ - Triggers the next effect of slide on the running presentation - """ - if self.pptid < 0: - return - self.presentation.NextStep(self.pptid) - - def previousStep(self): - """ - Triggers the previous slide on the running presentation - """ - if self.pptid < 0: - return - self.presentation.PrevStep(self.pptid) - - def isActive(self): + def is_active(self): """ Returns true if a presentation is currently active """ return self.pptid >= 0 - def resume(self): + def resume_presentation(self): """ Resumes a previously paused presentation """ if self.pptid < 0: return - self.presentation.Resume(self.pptid) + self.process.Resume(self.pptid) - def pause(self): + def pause_presentation(self): """ Not implemented (pauses a presentation) """ return - def blankScreen(self): + def blank_screen(self): """ Blanks the screen """ if self.pptid < 0: return - self.presentation.Blank(self.pptid) + self.process.Blank(self.pptid) - def unblankScreen(self): + def unblank_screen(self): """ Unblanks (restores) the presentationn """ if self.pptid < 0: return - self.presentation.Unblank(self.pptid) + self.process.Unblank(self.pptid) - def stop(self): + def stop_presentation(self): """ Stops the current presentation and hides the output """ if self.pptid < 0: return - self.presentation.Stop(self.pptid) + self.process.Stop(self.pptid) - def go(self): + def start_presentation(self): """ Starts a presentation from the beginning """ if self.pptid < 0: return - self.presentation.RestartShow(self.pptid) + self.process.RestartShow(self.pptid) - def getSlideNumber(self): + def get_slide_number(self): """ Returns the current slide number """ if self.pptid < 0: - return -1 - return self.presentation.GetCurrentSlide(self.pptid) + return 0 + return self.process.GetCurrentSlide(self.pptid) - def setSlideNumber(self, slideno): + def get_slide_count(self): + """ + Returns total number of slides + """ + if self.pptid < 0: + return 0 + return self.process.GetSlideCount(self.pptid) + + def goto_slide(self, slideno): """ Moves to a specific slide in the presentation """ if self.pptid < 0: return - self.presentation.GotoSlide(self.pptid, slideno) + self.process.GotoSlide(self.pptid, slideno) - slideNumber = property(getSlideNumber, setSlideNumber) + def next_step(self): + """ + Triggers the next effect of slide on the running presentation + """ + if self.pptid < 0: + return + self.process.NextStep(self.pptid) + def previous_step(self): + """ + Triggers the previous slide on the running presentation + """ + if self.pptid < 0: + return + self.process.PrevStep(self.pptid) + + def get_slide_preview_file(self, slide_no): + """ + Returns an image path containing a preview for the requested slide + + ``slide_no`` + The slide an image is required for, starting at 1 + """ + if self.pptid < 0: + return + return os.path.join(self.thumbnailpath, + self.thumbprefix + slide_no + u'.bmp') diff --git a/openlp/plugins/presentations/presentationplugin.py b/openlp/plugins/presentations/presentationplugin.py index 1e098b597..8dd687e88 100644 --- a/openlp/plugins/presentations/presentationplugin.py +++ b/openlp/plugins/presentations/presentationplugin.py @@ -68,8 +68,8 @@ class PresentationPlugin(Plugin): self, self.icon, u'Presentations', self.controllers) return self.media_item - def registerControllers(self, handle, controller): - self.controllers[handle] = controller + def registerControllers(self, controller): + self.controllers[controller.name] = controller def check_pre_conditions(self): """ @@ -88,7 +88,8 @@ class PresentationPlugin(Plugin): #Check to see if we have uno installed import uno openoffice = ImpressController() - self.registerControllers(u'Impress', openoffice) + openoffice.name = u'Impress' # until controller updated + self.registerControllers(openoffice) except: log.exception(u'Failed to set up plugin for Impress') if os.name == u'nt': @@ -99,15 +100,16 @@ class PresentationPlugin(Plugin): #Check to see if we are Win32 from win32com.client import Dispatch powerpoint = PowerpointController() - self.registerControllers(u'Powerpoint', powerpoint) + powerpoint.name = u'Powerpoint' # until controller updated + self.registerControllers(powerpoint) except: log.exception(u'Failed to set up plugin for Powerpoint') #Lets see if Powerpoint Viewer is required (Default is Not wanted) if int(self.config.get_config( u'Powerpoint Viewer', QtCore.Qt.Unchecked)) == QtCore.Qt.Checked: try: - pptview = PptviewController() - self.registerControllers(u'Powerpoint Viewer', pptview) + pptview = PptviewController(self) + self.registerControllers(pptview) except: log.exception(u'Failed to set up plugin for Powerpoint Viewer') #If we have no available controllers disable plugin From c01ed3eb84a8121490b264e4d5f76cac6595dea2 Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Sat, 26 Sep 2009 21:51:05 +0100 Subject: [PATCH 2/3] Inherit from presentationcontrollers plus powerpoint --- openlp/plugins/presentations/lib/__init__.py | 7 +- .../presentations/lib/impresscontroller.py | 70 +++-- .../presentations/lib/powerpointcontroller.py | 251 +++++++++-------- .../presentations/lib/pptviewcontroller.py | 260 ++++++++---------- .../presentations/lib/presentationtab.py | 3 +- .../presentations/presentationplugin.py | 62 ++--- 6 files changed, 321 insertions(+), 332 deletions(-) diff --git a/openlp/plugins/presentations/lib/__init__.py b/openlp/plugins/presentations/lib/__init__.py index 4b6577bdb..61aa34228 100644 --- a/openlp/plugins/presentations/lib/__init__.py +++ b/openlp/plugins/presentations/lib/__init__.py @@ -22,13 +22,10 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### -import os - from presentationcontroller import PresentationController from impresscontroller import ImpressController -if os.name == u'nt': - #from powerpointcontroller import PowerpointController - from pptviewcontroller import PptviewController +from powerpointcontroller import PowerpointController +from pptviewcontroller import PptviewController from messagelistener import MessageListener from mediaitem import PresentationMediaItem from presentationtab import PresentationTab diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index af78f9060..869fd5fb2 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -36,7 +36,10 @@ else: from PyQt4 import QtCore -class ImpressController(object): +from presentationcontroller import PresentationController + + +class ImpressController(PresentationController): """ Class to control interactions with Impress presentations. It creates the runtime environment, loads and closes the presentation as @@ -45,14 +48,29 @@ class ImpressController(object): global log log = logging.getLogger(u'ImpressController') - def __init__(self): + def __init__(self, plugin): + """ + Initialise the class + """ log.debug(u'Initialising') + PresentationController.__init__(self, plugin, u'Impress') self.process = None self.document = None self.presentation = None - self.startOpenoffice() + self.controller = None - def startOpenoffice(self): + def is_available(self): + """ + PPT Viewer is able to run on this machine + """ + log.debug(u'is_available') + try: + self.start_process() + return True + except: + return False + + def start_process(self): """ Loads a running version of OpenOffice in the background. It is not displayed to the user but is available to the UNO interface @@ -71,7 +89,7 @@ class ImpressController(object): Called at system exit to clean up any running presentations """ log.debug(u'Kill') - self.closePresentation() + self.close_presentation() def load_presentation(self, presentation): """ @@ -86,10 +104,10 @@ class ImpressController(object): """ log.debug(u'LoadPresentation') if os.name == u'nt': - desktop = self.getCOMDesktop() + desktop = self.get_com_desktop() url = u'file:///' + presentation.replace(u'\\', u'/').replace(u':', u'|').replace(u' ', u'%20') else: - desktop = self.getUNODesktop() + desktop = self.get_uno_desktop() url = uno.systemPathToFileUrl(presentation) if desktop is None: return @@ -100,19 +118,19 @@ class ImpressController(object): url, "_blank", 0, properties) self.presentation = self.document.getPresentation() self.presentation.start() - self.xSlideShowController = \ + self.controller = \ desktop.getCurrentComponent().Presentation.getController() except: log.exception(u'Failed to load presentation') - def getUNODesktop(self): + def get_uno_desktop(self): log.debug(u'getUNODesktop') ctx = None loop = 0 context = uno.getComponentContext() resolver = context.ServiceManager.createInstanceWithContext( u'com.sun.star.bridge.UnoUrlResolver', context) - while ctx == None and loop < 3: + while ctx is None and loop < 3: try: ctx = resolver.resolve(u'uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext') except: @@ -127,7 +145,7 @@ class ImpressController(object): log.exception(u'Failed to get UNO desktop') return None - def getCOMDesktop(self): + def get_com_desktop(self): log.debug(u'getCOMDesktop') try: smgr = Dispatch("com.sun.star.ServiceManager") @@ -150,43 +168,45 @@ class ImpressController(object): self.document.dispose() self.document = None - def isActive(self): + def is_loaded(self): + return self.presentation is not None and self.document is not None + + def is_active(self): + if not self.is_loaded(): + return False return self.presentation.isRunning() and self.presentation.isActive() - def resume(self): + def unblank_screen(self): return self.presentation.resume() - def pause(self): - return self.presentation.pause() - - def blankScreen(self): + def blank_screen(self): self.presentation.blankScreen(0) - def stop(self): + def stop_presentation(self): self.presentation.deactivate() # self.presdoc.end() - def go(self): + def start_presentation(self): self.presentation.activate() # self.presdoc.start() - def getSlideNumber(self): + def get_slide_number(self): return self.presentation.getCurrentSlideIndex - def setSlideNumber(self, slideno): + def goto_slide(self, slideno): self.presentation.gotoSlideIndex(slideno) - slideNumber = property(getSlideNumber, setSlideNumber) - def next_step(self): """ Triggers the next effect of slide on the running presentation """ - self.xSlideShowController.gotoNextEffect() + self.controller.gotoNextEffect() def previous_step(self): """ Triggers the previous slide on the running presentation """ - self.xSlideShowController.gotoPreviousSlide() + self.controller.gotoPreviousSlide() + + # def get_slide_preview_file(self, slide_no): diff --git a/openlp/plugins/presentations/lib/powerpointcontroller.py b/openlp/plugins/presentations/lib/powerpointcontroller.py index b239e350c..fd03f7d13 100644 --- a/openlp/plugins/presentations/lib/powerpointcontroller.py +++ b/openlp/plugins/presentations/lib/powerpointcontroller.py @@ -21,148 +21,161 @@ # with this program; if not, write to the Free Software Foundation, Inc., 59 # # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### -try: + +import os +import logging + +if os.name == u'nt': from win32com.client import Dispatch -except: - pass + +from presentationcontroller import PresentationController # PPT API documentation: # http://msdn.microsoft.com/en-us/library/aa269321(office.10).aspx -class PowerPointApp(object): - def __init__(self): +class PowerpointController(PresentationController): + """ + Class to control interactions with PowerPoint Presentations + It creates the runtime Environment , Loads the and Closes the Presentation + As well as triggering the correct activities based on the users input + """ + global log + log = logging.getLogger(u'PowerpointController') + + def __init__(self, plugin): + """ + Initialise the class + """ log.debug(u'Initialising') + PresentationController.__init__(self, plugin, u'Powerpoint') self.process = None - self.document = None self.presentation = None - self.startPowerpoint() - def startPowerpoint(self): + def is_available(self): + """ + PowerPoint is able to run on this machine + """ + log.debug(u'is_available') + if os.name != u'nt': + return False try: - self._app = Dispatch(u'PowerPoint.Application') + self.start_process() + return True except: - self._app = None - return - self._app.Visible = True - self._app.WindowState = 2 - - def getApp(self): - if self._app == None: - self.createApp() - if self._app == None: - return None - if self._app.Windows.Count == 0: - self.createApp() - return self._app - - app = property(getApp) - - def quit(self): - self._app.Quit() - self._app = None - -class PowerPointPres(object): - - def __init__(self, pptApp, filename): - self.pptApp = pptApp - self.filename = filename - self.open() - - def getPres(self): - if self._pres == None: - for p in self.pptApp.app.Presentations: - if p.FullName == self.filename: - self._pres = p - break - if self._pres != None: - try: - x = self._pres.Name - except: - self._pres = None - if self._pres == None: - self.openPres() - return self._pres - - pres = property(getPres) - - def open(self): - self.pptApp.app.Presentations.Open(self.filename, False, False, True) - self._pres = self.pptApp.app.Presentations(ppt.app.Presentations.Count) - - def close(self): - self.pres.Close() - self._pres = None - - def isActive(self): - if self.pres.SlideShowWindow == None: return False - if self.pres.SlideShowWindow.View == None: - return False - return True - def resume(self): - self.pres.SlideShowSettings.Run() - self.pres.SlideShowWindow.View.State = 1 - self.pres.SlideShowWindow.Activate() + if os.name == u'nt': + def start_process(self): + """ + Loads PowerPoint process + """ + self.process = Dispatch(u'PowerPoint.Application') + self.process.Visible = True + self.process.WindowState = 2 - def pause(self): - if self.isActive(): - self.pres.SlideShowWindow.View.State = 2 + def is_loaded(self): + """ + Returns true if a presentation is loaded + """ + if self.process is None: + return False + if self.process.Windows.Count == 0: + return False + + def kill(self): + self.process.Quit() + self.process = None - def blankScreen(self): - if self.isActive(): - self.pres.SlideShowWindow.View.State = 3 + def load_presentation(self, presentation): + """ + Called when a presentation is added to the SlideController. + It builds the environment, starts communcations with the background + OpenOffice task started earlier. If OpenOffice is not present is is + started. Once the environment is available the presentation is loaded + and started. - def stop(self): - if self.isActive(): - self.pres.SlideShowWindow.View.Exit() + ``presentation`` + The file name of the presentations to run. + """ + self.filename = presentation + self.process.Presentations.Open(presentation, False, False, True) + self.presentation = self.process.Presentations(self.process.Presentations.Count) + self.start_presentation() + + def close_presentation(self): + """ + Close presentation and clean up objects + Triggerent by new object being added to SlideController orOpenLP + being shut down + """ + self.presentation.Close() + self.presentation = None - def go(self): - self.pres.SlideShowSettings.Run() + def is_active(self): + """ + Returns true if a presentation is currently active + """ + if not self.is_loaded(): + return False + if self.presentation.SlideShowWindow == None: + return False + if self.presentation.SlideShowWindow.View == None: + return False + return True - def getCurrentSlideIndex(self): - if self.isActive(): - return self.pres.SlideShowWindow.View.CurrentShowPosition - else: - return -1 + def unblank_screen(self): + """ + Unblanks (restores) the presentationn + """ + self.presentation.SlideShowSettings.Run() + self.presentation.SlideShowWindow.View.State = 1 + self.presentation.SlideShowWindow.Activate() - def setCurrentSlideIndex(self, slideno): - if not self.isActive(): - self.resume() - self.pres.SlideShowWindow.View.GotoSlide(slideno) + def blank_screen(self): + """ + Blanks the screen + """ + self.presentation.SlideShowWindow.View.State = 3 - #currentSlideIndex = property(getSlideNumber, setSlideNumber) + def stop_presentation(self): + """ + Stops the current presentation and hides the output + """ + self.presentation.SlideShowWindow.View.Exit() - def nextStep(self): - if not self.isActive(): - self.resume() - self.pres.SlideShowWindow.View.Next() + def start_presentation(self): + """ + Starts a presentation from the beginning + """ + self.presentation.SlideShowSettings.Run() + rendermanager = self.plugin.render_manager + rect = rendermanager.screen_list[rendermanager.current_display][u'size'] + self.presentation.SlideShowWindow.Top = rect.y() / 20 + self.presentation.SlideShowWindow.Height = rect.height() / 20 + self.presentation.SlideShowWindow.Left = rect.x() / 20 + self.presentation.SlideShowWindow.Width = rect.width() / 20 - def prevStep(self): - if not self.isActive(): - self.resume() - self.pres.SlideShowWindow.View.Previous() + def get_slide_number(self): + """ + Returns the current slide number + """ + return self.presentation.SlideShowWindow.View.CurrentShowPosition - def moveWindow(self, top, height, left, width): - if not self.isActive(): - self.resume() - self.pres.SlideShowWindow.Top = top / 20 - self.pres.SlideShowWindow.Height = height / 20 - self.pres.SlideShowWindow.Left = left / 20 - self.pres.SlideShowWindow.Width = width / 20 + def get_slide_count(self): + """ + Returns total number of slides + """ + return self.presentation.Slides.Count + + def goto_slide(self, slideno): + self.presentation.SlideShowWindow.View.GotoSlide(slideno) -class PowerPointSlide(object): - def __init__(self, pres, index): - self.pres = pres - self.slide = pres.Slides[index] + def next_step(self): + self.presentation.SlideShowWindow.View.Next() + + def previous_step(self): + self.presentation.SlideShowWindow.View.Previous() + + #def get_slide_preview_file(self, slide_no): - def preview(self): - if self.preview == None: - self.slide.Copy - # import win32clipboard as w - # import win32con - # w.OpenClipboard() - # self.preview = w.GetClipboardData.GetData(win32con.CF_BITMAP) - # w.CloseClipboard() - return self.preview diff --git a/openlp/plugins/presentations/lib/pptviewcontroller.py b/openlp/plugins/presentations/lib/pptviewcontroller.py index 509b52ead..97c0ceb5d 100644 --- a/openlp/plugins/presentations/lib/pptviewcontroller.py +++ b/openlp/plugins/presentations/lib/pptviewcontroller.py @@ -25,8 +25,9 @@ import os import logging -from ctypes import * -from ctypes.wintypes import RECT +if os.name == u'nt': + from ctypes import * + from ctypes.wintypes import RECT from presentationcontroller import PresentationController @@ -34,7 +35,7 @@ class PptviewController(PresentationController): """ Class to control interactions with PowerPOint Viewer Presentations It creates the runtime Environment , Loads the and Closes the Presentation - As well as trigggering the correct activities based on the users input + As well as triggering the correct activities based on the users input """ global log log = logging.getLogger(u'PptviewController') @@ -43,167 +44,148 @@ class PptviewController(PresentationController): """ Initialise the class """ - log.debug(u'Initialised') + log.debug(u'Initialising') PresentationController.__init__(self, plugin, u'Powerpoint Viewer') self.process = None self.pptid = None self.thumbnailpath = os.path.join(plugin.config.get_data_path(), u'pptview', u'thumbnails') self.thumbprefix = u'slide' - self.start_process() - def start_process(self): + def is_available(self): """ - Loads the PPTVIEWLIB library + PPT Viewer is able to run on this machine """ - log.debug(u'start PPTView') - self.process = cdll.LoadLibrary(r'openlp\plugins\presentations\lib\pptviewlib\pptviewlib.dll') - - def kill(self): - """ - Called at system exit to clean up any running presentations - """ - log.debug(u'Kill') - self.close_presentation() - - def load_presentation(self, presentation): - """ - Called when a presentation is added to the SlideController. - It builds the environment, starts communcations with the background - OpenOffice task started earlier. If OpenOffice is not present is is - started. Once the environment is available the presentation is loaded - and started. - - ``presentation`` - The file name of the presentations to run. - """ - log.debug(u'LoadPresentation') - if self.pptid >= 0: - self.close_presentation() - rendermanager = self.plugin.render_manager - #screen = rendermanager.screen_list[rendermanager.current_display] - # x? y? - rect = RECT(0, 0, rendermanager.width, rendermanager.height) - filename = str(presentation.replace(u'/', u'\\')); + log.debug(u'is_available') + if os.name != u'nt': + return False try: - self.pptid = self.process.OpenPPT(filename, None, rect, - str(self.thumbnailpath)) + self.start_process() + return True except: - log.exception(u'Failed to load presentation') + return False + if os.name == u'nt': + def start_process(self): + """ + Loads the PPTVIEWLIB library + """ + log.debug(u'start PPTView') + self.process = cdll.LoadLibrary(r'openlp\plugins\presentations\lib\pptviewlib\pptviewlib.dll') - def close_presentation(self): - """ - Close presentation and clean up objects - Triggerent by new object being added to SlideController orOpenLP - being shut down - """ - if self.pptid < 0: - return - self.process.ClosePPT(self.pptid) - self.pptid = -1 + def kill(self): + """ + Called at system exit to clean up any running presentations + """ + log.debug(u'Kill') + self.close_presentation() - def is_active(self): - """ - Returns true if a presentation is currently active - """ - return self.pptid >= 0 + def load_presentation(self, presentation): + """ + Called when a presentation is added to the SlideController. + It builds the environment, starts communcations with the background + OpenOffice task started earlier. If OpenOffice is not present is is + started. Once the environment is available the presentation is loaded + and started. - def resume_presentation(self): - """ - Resumes a previously paused presentation - """ - if self.pptid < 0: - return - self.process.Resume(self.pptid) + ``presentation`` + The file name of the presentations to run. + """ + log.debug(u'LoadPresentation') + if self.pptid >= 0: + self.close_presentation() + rendermanager = self.plugin.render_manager + rect = rendermanager.screen_list[rendermanager.current_display][u'size'] + rect = RECT(rect.x(), rect.y(), rect.right(), rect.bottom()) + filename = str(presentation.replace(u'/', u'\\')); + try: + self.pptid = self.process.OpenPPT(filename, None, rect, + str(self.thumbnailpath)) + except: + log.exception(u'Failed to load presentation') - def pause_presentation(self): - """ - Not implemented (pauses a presentation) - """ - return + def close_presentation(self): + """ + Close presentation and clean up objects + Triggerent by new object being added to SlideController orOpenLP + being shut down + """ + self.process.ClosePPT(self.pptid) + self.pptid = -1 - def blank_screen(self): - """ - Blanks the screen - """ - if self.pptid < 0: - return - self.process.Blank(self.pptid) + def is_loaded(self): + """ + Returns true if a presentation is loaded + """ + return self.pptid >= 0 + + def is_active(self): + """ + Returns true if a presentation is currently active + """ + return self.pptid >= 0 - def unblank_screen(self): - """ - Unblanks (restores) the presentationn - """ - if self.pptid < 0: - return - self.process.Unblank(self.pptid) + def blank_screen(self): + """ + Blanks the screen + """ + self.process.Blank(self.pptid) - def stop_presentation(self): - """ - Stops the current presentation and hides the output - """ - if self.pptid < 0: - return - self.process.Stop(self.pptid) + def unblank_screen(self): + """ + Unblanks (restores) the presentationn + """ + self.process.Unblank(self.pptid) - def start_presentation(self): - """ - Starts a presentation from the beginning - """ - if self.pptid < 0: - return - self.process.RestartShow(self.pptid) + def stop_presentation(self): + """ + Stops the current presentation and hides the output + """ + self.process.Stop(self.pptid) - def get_slide_number(self): - """ - Returns the current slide number - """ - if self.pptid < 0: - return 0 - return self.process.GetCurrentSlide(self.pptid) + def start_presentation(self): + """ + Starts a presentation from the beginning + """ + self.process.RestartShow(self.pptid) - def get_slide_count(self): - """ - Returns total number of slides - """ - if self.pptid < 0: - return 0 - return self.process.GetSlideCount(self.pptid) + def get_slide_number(self): + """ + Returns the current slide number + """ + return self.process.GetCurrentSlide(self.pptid) - def goto_slide(self, slideno): - """ - Moves to a specific slide in the presentation - """ - if self.pptid < 0: - return - self.process.GotoSlide(self.pptid, slideno) + def get_slide_count(self): + """ + Returns total number of slides + """ + return self.process.GetSlideCount(self.pptid) - def next_step(self): - """ - Triggers the next effect of slide on the running presentation - """ - if self.pptid < 0: - return - self.process.NextStep(self.pptid) + def goto_slide(self, slideno): + """ + Moves to a specific slide in the presentation + """ + self.process.GotoSlide(self.pptid, slideno) - def previous_step(self): - """ - Triggers the previous slide on the running presentation - """ - if self.pptid < 0: - return - self.process.PrevStep(self.pptid) + def next_step(self): + """ + Triggers the next effect of slide on the running presentation + """ + self.process.NextStep(self.pptid) - def get_slide_preview_file(self, slide_no): - """ - Returns an image path containing a preview for the requested slide + def previous_step(self): + """ + Triggers the previous slide on the running presentation + """ + self.process.PrevStep(self.pptid) - ``slide_no`` - The slide an image is required for, starting at 1 - """ - if self.pptid < 0: - return - return os.path.join(self.thumbnailpath, - self.thumbprefix + slide_no + u'.bmp') + def get_slide_preview_file(self, slide_no): + """ + Returns an image path containing a preview for the requested slide + + ``slide_no`` + The slide an image is required for, starting at 1 + """ + return os.path.join(self.thumbnailpath, + self.thumbprefix + slide_no + u'.bmp') diff --git a/openlp/plugins/presentations/lib/presentationtab.py b/openlp/plugins/presentations/lib/presentationtab.py index f6a9c397f..0cbeb4b9f 100644 --- a/openlp/plugins/presentations/lib/presentationtab.py +++ b/openlp/plugins/presentations/lib/presentationtab.py @@ -31,7 +31,8 @@ class PresentationTab(SettingsTab): """ PresentationsTab is the Presentations settings tab in the settings dialog. """ - def __init__(self): + def __init__(self, controllers): + self.controllers = controllers SettingsTab.__init__(self, translate(u'PresentationTab', u'Presentation'), u'Presentations') diff --git a/openlp/plugins/presentations/presentationplugin.py b/openlp/plugins/presentations/presentationplugin.py index 8dd687e88..502b71c4c 100644 --- a/openlp/plugins/presentations/presentationplugin.py +++ b/openlp/plugins/presentations/presentationplugin.py @@ -28,14 +28,7 @@ import logging from PyQt4 import QtCore, QtGui from openlp.core.lib import Plugin -from openlp.plugins.presentations.lib import PresentationMediaItem, \ - PresentationTab, ImpressController -if os.name == u'nt': - try: - from openlp.plugins.presentations.lib import PowerpointController - except: - pass - from openlp.plugins.presentations.lib import PptviewController +from openlp.plugins.presentations.lib import * class PresentationPlugin(Plugin): @@ -57,7 +50,7 @@ class PresentationPlugin(Plugin): """ Create the settings Tab """ - self.presentation_tab = PresentationTab() + self.presentation_tab = PresentationTab(self.controllers) return self.presentation_tab def get_media_manager_item(self): @@ -77,41 +70,24 @@ class PresentationPlugin(Plugin): If Not do not install the plugin. """ log.debug('check_pre_conditions') - #Lets see if Impress is required (Default is Not wanted) + #Lets see if Powerpoint is required (Default is Not wanted) + controller = PowerpointController(self) if int(self.config.get_config( - u'Impress', QtCore.Qt.Unchecked)) == QtCore.Qt.Checked: - try: - if os.name == u'nt': - #Check to see if we are Win32 - from win32com.client import Dispatch - else: - #Check to see if we have uno installed - import uno - openoffice = ImpressController() - openoffice.name = u'Impress' # until controller updated - self.registerControllers(openoffice) - except: - log.exception(u'Failed to set up plugin for Impress') - if os.name == u'nt': - #Lets see if Powerpoint is required (Default is Not wanted) - if int(self.config.get_config( - u'Powerpoint', QtCore.Qt.Unchecked)) == QtCore.Qt.Checked: - try: - #Check to see if we are Win32 - from win32com.client import Dispatch - powerpoint = PowerpointController() - powerpoint.name = u'Powerpoint' # until controller updated - self.registerControllers(powerpoint) - except: - log.exception(u'Failed to set up plugin for Powerpoint') - #Lets see if Powerpoint Viewer is required (Default is Not wanted) - if int(self.config.get_config( - u'Powerpoint Viewer', QtCore.Qt.Unchecked)) == QtCore.Qt.Checked: - try: - pptview = PptviewController(self) - self.registerControllers(pptview) - except: - log.exception(u'Failed to set up plugin for Powerpoint Viewer') + controller.name, QtCore.Qt.Unchecked)) == QtCore.Qt.Checked: + if controller.is_available(): + self.registerControllers(controller) + #Lets see if Impress is required (Default is Not wanted) + controller = ImpressController(self) + if int(self.config.get_config( + controller.name, QtCore.Qt.Unchecked)) == QtCore.Qt.Checked: + if controller.is_available(): + self.registerControllers(controller) + #Lets see if Powerpoint Viewer is required (Default is Not wanted) + controller = PptviewController(self) + if int(self.config.get_config( + controller.name, QtCore.Qt.Unchecked)) == QtCore.Qt.Checked: + if controller.is_available(): + self.registerControllers(controller) #If we have no available controllers disable plugin if len(self.controllers) > 0: return True From d94abc85e69178e2daa01c2dc8549717cf6e33ce Mon Sep 17 00:00:00 2001 From: Jonathan Corwin Date: Sat, 26 Sep 2009 22:00:45 +0100 Subject: [PATCH 3/3] It helps to add new files --- .../lib/presentationcontroller.py | 227 ++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100644 openlp/plugins/presentations/lib/presentationcontroller.py diff --git a/openlp/plugins/presentations/lib/presentationcontroller.py b/openlp/plugins/presentations/lib/presentationcontroller.py new file mode 100644 index 000000000..ade258674 --- /dev/null +++ b/openlp/plugins/presentations/lib/presentationcontroller.py @@ -0,0 +1,227 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4 +""" +OpenLP - Open Source Lyrics Projection +Copyright (c) 2008 Raoul Snyman +Portions copyright (c) 2008-2009 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 logging + +class PresentationController(object): + """ + Base class for presentation controllers to inherit from + Class to control interactions with presentations. + It creates the runtime environment, loads and closes the presentation as + well as triggering the correct activities based on the users input + + **Basic Attributes** + + ``name`` + The name that appears in the options and the media manager + + ``plugin`` + The presentationplugin object + + **Hook Functions** + + ``kill()`` + Called at system exit to clean up any running presentations + + ``is_available()`` + Returns True if presentation application is installed/can run on this machine + + ``load_presentation(presentation)`` + Load a presentation file + + ``close_presentation()`` + Close presentation and clean up objects + + ``presentation_loaded()`` + Returns True if presentation is currently loaded + + ``is_active()`` + Returns True if a presentation is currently running + + ``blank_screen()`` + Blanks the screen, making it black. + + ``unblank_screen()`` + Unblanks the screen, restoring the output + + ``stop_presentation()`` + Stops the presentation, removing it from the output display + + ``start_presentation()`` + Starts the presentation from the beginning + + ``get_slide_number()`` + Returns the current slide number, from 1 + + ``get_slide_count()`` + Returns total number of slides + + ``goto_slide(slide_no)`` + Jumps directly to the requested slide. + + ``next_step()`` + Triggers the next effect of slide on the running presentation + + ``previous_step()`` + Triggers the previous slide on the running presentation + + ``get_slide_preview_file(slide_no)`` + Returns a path to an image containing a preview for the requested slide + + """ + global log + log = logging.getLogger(u'PresentationController') + log.info(u'loaded') + + def __init__(self, plugin=None, name=u'PresentationController'): + """ + This is the constructor for the presentationcontroller object. + This provides an easy way for descendent plugins to populate common data. + This method *must* be overridden, like so:: + + class MyPresentationController(PresentationController): + def __init__(self, plugin): + PresentationController.__init(self, plugin, u'My Presenter App') + + ``plugin`` + Defaults to *None*. The presentationplugin object + + ``name`` + Name of the application, to appear in the application + """ + self.plugin = plugin + self.name = name + self.start_process() + + def is_available(self): + """ + Presentation app is able to run on this machine + """ + return False + + def start_process(self): + """ + Loads a running version of the presentation application in the background. + """ + pass + + def kill(self): + """ + Called at system exit to clean up any running presentations and + close the application + """ + log.debug(u'Kill') + self.close_presentation() + + def load_presentation(self, presentation): + """ + Called when a presentation is added to the SlideController. + Loads the presentation and starts it + + ``presentation`` + The file name of the presentatios to the run. + """ + pass + + def close_presentation(self): + """ + Close presentation and clean up objects + Triggered by new object being added to SlideController + """ + pass + + def is_active(self): + """ + Returns True if a presentation is currently running + """ + return False + + def is_loaded(self): + """ + Returns true if a presentation is loaded + """ + return False + + def blank_screen(self): + """ + Blanks the screen, making it black. + """ + pass + + def unblank_screen(self): + """ + Unblanks (restores) the presentationn + """ + pass + + def stop_presentation(self): + """ + Stops the presentation, removing it from the output display + """ + pass + + def start_presentation(self): + """ + Starts the presentation from the beginning + """ + pass + + def get_slide_number(self): + """ + Returns the current slide number, from 1 + """ + return 0 + + def get_slide_count(self): + """ + Returns total number of slides + """ + return 0 + + def goto_slide(self, slide_no): + """ + Jumps directly to the requested slide. + + ``slide_no`` + The slide to jump to, starting at 1 + """ + pass + + def next_step(self): + """ + Triggers the next effect of slide on the running presentation + This might be the next animation on the current slide, or the next slide + """ + pass + + def previous_step(self): + """ + Triggers the previous slide on the running presentation + """ + pass + + def get_slide_preview_file(self, slide_no): + """ + Returns an image path containing a preview for the requested slide + + ``slide_no`` + The slide an image is required for, starting at 1 + """ + return None