forked from openlp/openlp
Cleanups from Last merge and documentation
This commit is contained in:
parent
4a5767a5cf
commit
feca90483a
@ -68,7 +68,7 @@ class SlideController(QtGui.QWidget):
|
||||
self.settingsmanager = settingsmanager
|
||||
self.isLive = isLive
|
||||
self.parent = parent
|
||||
self.image_list = [u'Start Loop', u'Stop Loop', u'Loop Spearator', u'Image SpinBox']
|
||||
self.image_list = [u'Start Loop', u'Stop Loop', u'Loop Separator', u'Image SpinBox']
|
||||
self.timer_id = 0
|
||||
self.item = None
|
||||
self.Panel = QtGui.QWidget(parent.ControlSplitter)
|
||||
@ -131,7 +131,7 @@ class SlideController(QtGui.QWidget):
|
||||
translate(u'SlideController', u'Close Screen'),
|
||||
self.onBlankScreen)
|
||||
if isLive:
|
||||
self.Toolbar.addToolbarSeparator(u'Loop Spearator')
|
||||
self.Toolbar.addToolbarSeparator(u'Loop Separator')
|
||||
self.Toolbar.addToolbarButton(u'Start Loop',
|
||||
u':/media/media_time.png',
|
||||
translate(u'SlideController', u'Start continuous loop'),
|
||||
|
@ -1,188 +0,0 @@
|
||||
# -*- 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
|
||||
"""
|
||||
# OOo API documentation:
|
||||
# http://api.openoffice.org/docs/common/ref/com/sun/star/presentation/XSlideShowController.html
|
||||
# http://docs.go-oo.org/sd/html/classsd_1_1SlideShow.html
|
||||
# http://www.oooforum.org/forum/viewtopic.phtml?t=5252
|
||||
# http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Working_with_Presentations
|
||||
# http://mail.python.org/pipermail/python-win32/2008-January/006676.html
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import time
|
||||
import uno
|
||||
|
||||
class Openoffice(object):
|
||||
def __init__(self):
|
||||
self.startOpenoffice()
|
||||
|
||||
def createResolver(self):
|
||||
self.localContext = uno.getComponentContext()
|
||||
self.resolver = self.localContext.ServiceManager.createInstanceWithContext(u'com.sun.star.bridge.UnoUrlResolver', self.localContext)
|
||||
try:
|
||||
self.ctx = self.resolver.resolve(u'uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext')
|
||||
except:
|
||||
return False
|
||||
return True
|
||||
|
||||
def buildEnvironment(self):
|
||||
self.smgr = self.ctx.ServiceManager
|
||||
self.desktop = self.smgr.createInstanceWithContext( "com.sun.star.frame.Desktop", self.ctx )
|
||||
self.model = self.desktop.getCurrentComponent()
|
||||
text = self.model.Text
|
||||
cursor = text.createTextCursor()
|
||||
text.insertString(cursor, "Hello world", 0)
|
||||
self.ctx.ServiceManager
|
||||
self.createApp()
|
||||
if self._sm == None:
|
||||
# start OO here
|
||||
# Create output log file
|
||||
time.sleep(10)
|
||||
self.createApp()
|
||||
|
||||
def startOpenoffice(self):
|
||||
cmd = u'openoffice.org -nologo -norestore -invisible -minimized -impress' + u'"' + u'-accept=socket,host=localhost,port=2002;urp;'+ u'"'
|
||||
retval = subprocess.Popen(cmd, shell=True)
|
||||
self.oopid = retval.pid
|
||||
|
||||
def checkOoPid(self):
|
||||
if os.name == u'nt':
|
||||
import win32api
|
||||
handle = win32api.OpenProcess(PROCESS_TERMINATE, False, self.oopid)
|
||||
#todo need some code here
|
||||
return True
|
||||
elif os.name == u'mac':
|
||||
pass
|
||||
else:
|
||||
procfile = open("/proc/%d/stat" %(self.oopid))
|
||||
file = procfile.readline().split()[1]
|
||||
print file
|
||||
if file == u'(soffice)' or file == u'(openoffice.org)':
|
||||
return True
|
||||
return False
|
||||
|
||||
def createApp(self):
|
||||
try:
|
||||
self._app = self._sm.createInstance( "com.sun.star.frame.Desktop" )
|
||||
print "started"
|
||||
except:
|
||||
print "oops"
|
||||
self._sm = None
|
||||
self._app = None
|
||||
return
|
||||
|
||||
def getApp(self):
|
||||
if self._app == None:
|
||||
self.createApp()
|
||||
if self._app == None:
|
||||
return None
|
||||
return self._app
|
||||
|
||||
app = property(getApp)
|
||||
|
||||
def quit(self):
|
||||
self._app.Terminate()
|
||||
self._app = None
|
||||
self._sm = None
|
||||
|
||||
class ImpressCOMPres(object):
|
||||
|
||||
def __init__(self, oooApp, filename):
|
||||
self.oooApp = oooApp
|
||||
self.filename = filename
|
||||
self.open()
|
||||
|
||||
def getPres(self):
|
||||
if self._pres == None:
|
||||
self.open()
|
||||
return self._pres
|
||||
|
||||
pres = property(getPres)
|
||||
|
||||
def open(self):
|
||||
self.comp = self.oooApp.app.loadComponentFromURL(u'file:///' + self.filename, '_blank', 0, [])
|
||||
self.presdoc = self.comp.getPresentation()
|
||||
self.presdoc.start()
|
||||
self._pres = self.presdoc.getController()
|
||||
|
||||
def close(self):
|
||||
self.pres.deactivate()
|
||||
self.presdoc.end()
|
||||
self.comp.dispose()
|
||||
self._pres = None
|
||||
self.presdoc = None
|
||||
self.comp = None
|
||||
|
||||
def isActive(self):
|
||||
return self.pres.isRunning() and self.pres.isActive()
|
||||
|
||||
def resume(self):
|
||||
return self.pres.resume()
|
||||
|
||||
def pause(self):
|
||||
return self.pres.pause()
|
||||
|
||||
def blankScreen(self):
|
||||
self.pres.blankScreen(0)
|
||||
|
||||
def stop(self):
|
||||
self.pres.deactivate()
|
||||
# self.presdoc.end()
|
||||
|
||||
def go(self):
|
||||
self.pres.activate()
|
||||
# self.presdoc.start()
|
||||
|
||||
def getSlideNumber(self):
|
||||
return self.pres.getCurrentSlideIndex
|
||||
|
||||
def setSlideNumber(self, slideno):
|
||||
self.pres.gotoSlideIndex(slideno)
|
||||
|
||||
slideNumber = property(getSlideNumber, setSlideNumber)
|
||||
|
||||
def nextStep(self):
|
||||
self.pres.gotoNextEffect()
|
||||
|
||||
def prevStep(self):
|
||||
self.pres.gotoPreviousSlide()
|
||||
|
||||
def moveWindow(self, top, height, left, width):
|
||||
# position the window somehow
|
||||
pass
|
||||
|
||||
class ImpressCOMSlide(object):
|
||||
def __init__(self, pres, index):
|
||||
self.pres = pres
|
||||
self.slide = pres.getSlideByIndex(index)
|
||||
|
||||
def preview(self):
|
||||
if self.preview == None:
|
||||
# get a slide somehow
|
||||
pass
|
||||
return self.preview
|
||||
|
||||
if __name__ == '__main__':
|
||||
ooo = Openoffice()
|
||||
ooo.createResolver()
|
||||
show = ImpressCOMPres(ooo, u'/home/timali/test1.odp')
|
||||
show.go()
|
||||
#show.resume()
|
||||
#show.nextStep()
|
@ -35,6 +35,11 @@ import sys
|
||||
from PyQt4 import QtCore
|
||||
|
||||
class ImpressController(object):
|
||||
"""
|
||||
Class to contol interactions with Impress Presentations
|
||||
It creates the runtime Environment , Loads the and Closes the Presentation
|
||||
As well as trigggering the correct activities based on the users input
|
||||
"""
|
||||
global log
|
||||
log = logging.getLogger(u'ImpressController')
|
||||
|
||||
@ -46,6 +51,11 @@ class ImpressController(object):
|
||||
self.startOpenoffice()
|
||||
|
||||
def startOpenoffice(self):
|
||||
"""
|
||||
Loads a running version of OpenOffice inthe background.
|
||||
It is not displayed to the user but is available to the Uno interface
|
||||
when required.
|
||||
"""
|
||||
log.debug(u'start Openoffice')
|
||||
cmd = u'openoffice.org -nologo -norestore -minimized -headless ' + u'"' + u'-accept=socket,host=localhost,port=2002;urp;'+ u'"'
|
||||
self.process = QtCore.QProcess()
|
||||
@ -53,15 +63,34 @@ class ImpressController(object):
|
||||
self.process.waitForStarted()
|
||||
|
||||
def kill(self):
|
||||
"""
|
||||
Called at system exit to clean up any running presentations
|
||||
"""
|
||||
log.debug(u'Kill')
|
||||
self.closePresentation()
|
||||
|
||||
def loadPresentation(self, presentation):
|
||||
log.debug(u'create Resolver')
|
||||
"""
|
||||
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 ts started.
|
||||
Once the environment is available the presentation is loaded and started.
|
||||
|
||||
``presentation``
|
||||
The file name of the presentatios to the run.
|
||||
"""
|
||||
log.debug(u'LoadPresentation')
|
||||
ctx = None
|
||||
loop = 0
|
||||
context = uno.getComponentContext()
|
||||
resolver = context.ServiceManager.createInstanceWithContext(u'com.sun.star.bridge.UnoUrlResolver', context)
|
||||
while ctx == None and loop < 3:
|
||||
try:
|
||||
ctx = resolver.resolve(u'uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext')
|
||||
except:
|
||||
self.startOpenoffice()
|
||||
loop += 1
|
||||
try:
|
||||
context = uno.getComponentContext()
|
||||
resolver = context.ServiceManager.createInstanceWithContext(u'com.sun.star.bridge.UnoUrlResolver', context)
|
||||
ctx = resolver.resolve(u'uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext')
|
||||
smgr = ctx.ServiceManager
|
||||
desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop", ctx )
|
||||
url = uno.systemPathToFileUrl(presentation)
|
||||
@ -70,7 +99,7 @@ class ImpressController(object):
|
||||
self.document = desktop.loadComponentFromURL(url, "_blank", 0, properties)
|
||||
self.presentation = self.document.getPresentation()
|
||||
self.presentation.start()
|
||||
self.xSlideSshowController = desktop.getCurrentComponent().Presentation.getController()
|
||||
self.xSlideShowController = desktop.getCurrentComponent().Presentation.getController()
|
||||
except:
|
||||
log.error(u'Failed reason %s' % sys.exc_info())
|
||||
|
||||
@ -116,8 +145,14 @@ class ImpressController(object):
|
||||
slideNumber = property(getSlideNumber, setSlideNumber)
|
||||
|
||||
def nextStep(self):
|
||||
self.xSlideSshowController.gotoNextEffect()
|
||||
"""
|
||||
Triggers the next effect of slide on the running presentation
|
||||
"""
|
||||
self.xSlideShowController.gotoNextEffect()
|
||||
|
||||
def previousStep(self):
|
||||
self.xSlideSshowController.gotoPreviousSlide()
|
||||
"""
|
||||
Triggers the previous slide on the running presentation
|
||||
"""
|
||||
self.xSlideShowController.gotoPreviousSlide()
|
||||
|
||||
|
@ -59,15 +59,30 @@ class MessageListener(object):
|
||||
self.controllers[self.handler].loadPresentation(file)
|
||||
|
||||
def next(self, message):
|
||||
"""
|
||||
Based on the handler passed at startup triggers the next slide event
|
||||
"""
|
||||
self.controllers[self.handler].nextStep()
|
||||
|
||||
def previous(self, message):
|
||||
"""
|
||||
Based on the handler passed at startup triggers the previous slide event
|
||||
"""
|
||||
self.controllers[self.handler].previousStep()
|
||||
|
||||
def shutDown(self, message):
|
||||
"""
|
||||
Based on the handler passed at startup triggers slide show to shut down
|
||||
"""
|
||||
self.controllers[self.handler].closePresentation()
|
||||
|
||||
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.
|
||||
"""
|
||||
bits = message.split(u':')
|
||||
file = os.path.join(bits[1], bits[2])
|
||||
return bits[0], file
|
||||
|
Loading…
Reference in New Issue
Block a user