latest hacking

This commit is contained in:
Tim Bentley 2010-02-01 19:42:52 +00:00
parent 3610b232bd
commit 17a08e3847
3 changed files with 146 additions and 183 deletions

View File

@ -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

View File

@ -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)

View File

@ -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'):
"""