Impress fixes

This commit is contained in:
Jonathan Corwin 2009-10-23 21:22:16 +01:00
parent 5dac7a0c4d
commit b8810abd4b
1 changed files with 30 additions and 14 deletions

View File

@ -28,6 +28,7 @@ Place, Suite 330, Boston, MA 02111-1307 USA
import logging import logging
import os import os
import time
if os.name == u'nt': if os.name == u'nt':
from win32com.client import Dispatch from win32com.client import Dispatch
@ -85,7 +86,7 @@ class ImpressController(PresentationController):
self.manager._FlagAsMethod(u'Bridge_GetValueObject') self.manager._FlagAsMethod(u'Bridge_GetValueObject')
else: else:
# -headless # -headless
cmd = u'openoffice.org -nologo -norestore -minimized -invisible ' + u'"' + u'-accept=socket,host=localhost,port=2002;urp;'+ u'"' cmd = u'openoffice.org -nologo -norestore -minimized -invisible -nofirststartwizard -accept="socket,host=localhost,port=2002;urp;"'
self.process = QtCore.QProcess() self.process = QtCore.QProcess()
self.process.startDetached(cmd) self.process.startDetached(cmd)
self.process.waitForStarted() self.process.waitForStarted()
@ -96,6 +97,12 @@ class ImpressController(PresentationController):
""" """
log.debug(u'Kill') log.debug(u'Kill')
self.close_presentation() self.close_presentation()
if os.name != u'nt':
desktop = self.get_uno_desktop()
try:
desktop.terminate()
except:
pass
def load_presentation(self, presentation): def load_presentation(self, presentation):
""" """
@ -121,18 +128,19 @@ class ImpressController(PresentationController):
url = uno.systemPathToFileUrl(presentation) url = uno.systemPathToFileUrl(presentation)
if desktop is None: if desktop is None:
return return
self.desktop = desktop
properties = []
properties.append(self.create_property(u'Minimized', True))
properties = tuple(properties)
try: try:
self.desktop = desktop
properties = []
properties = tuple(properties)
self.document = desktop.loadComponentFromURL(url, u'_blank', self.document = desktop.loadComponentFromURL(url, u'_blank',
0, properties) 0, properties)
self.presentation = self.document.getPresentation()
self.presentation.Display = self.plugin.render_manager.current_display + 1
self.controller = None
except: except:
log.exception(u'Failed to load presentation') log.exception(u'Failed to load presentation')
return return
self.presentation = self.document.getPresentation()
self.presentation.Display = self.plugin.render_manager.current_display + 1
self.controller = None
self.create_thumbnails() self.create_thumbnails()
def create_thumbnails(self): def create_thumbnails(self):
@ -148,13 +156,7 @@ class ImpressController(PresentationController):
else: else:
thumbdir = uno.systemPathToFileUrl(self.thumbnailpath) thumbdir = uno.systemPathToFileUrl(self.thumbnailpath)
props = [] props = []
if os.name == u'nt': props.append(self.create_property(u'FilterName', u'impress_png_Export'))
prop = self.manager.Bridge_GetStruct(u'com.sun.star.beans.PropertyValue')
else:
prop = PropertyValue()
prop.Name = u'FilterName'
prop.Value = u'impress_png_Export'
props.append(prop)
props = tuple(props) props = tuple(props)
doc = self.document doc = self.document
pages = doc.getDrawPages() pages = doc.getDrawPages()
@ -164,6 +166,15 @@ class ImpressController(PresentationController):
doc.storeToURL(thumbdir + u'/' + self.thumbnailprefix + doc.storeToURL(thumbdir + u'/' + self.thumbnailprefix +
unicode(idx+1) + u'.png', props) unicode(idx+1) + u'.png', props)
def create_property(self, name, value):
if os.name == u'nt':
prop = self.manager.Bridge_GetStruct(u'com.sun.star.beans.PropertyValue')
else:
prop = PropertyValue()
prop.Name = name
prop.Value = value
return prop
def get_uno_desktop(self): def get_uno_desktop(self):
log.debug(u'getUNODesktop') log.debug(u'getUNODesktop')
ctx = None ctx = None
@ -245,6 +256,11 @@ class ImpressController(PresentationController):
def start_presentation(self): def start_presentation(self):
if self.controller is None or not self.controller.isRunning(): if self.controller is None or not self.controller.isRunning():
self.presentation.start() self.presentation.start()
# start() returns before the getCurrentComponent is ready. Try for 5 seconds
i = 1
while self.desktop.getCurrentComponent() is None and i < 50:
time.sleep(0.1)
i = i + 1
self.controller = self.desktop.getCurrentComponent().Presentation.getController() self.controller = self.desktop.getCurrentComponent().Presentation.getController()
else: else:
self.controller.activate() self.controller.activate()