forked from openlp/openlp
Try to make Pyro4 and LibreOffice talk to each other. Failing miserably
This commit is contained in:
parent
bf3e891567
commit
5eb0f62332
@ -20,13 +20,15 @@
|
||||
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||
###############################################################################
|
||||
|
||||
import sys
|
||||
import faulthandler
|
||||
import multiprocessing
|
||||
import sys
|
||||
|
||||
from openlp.core.common import is_win, is_macosx
|
||||
from openlp.core import main
|
||||
|
||||
faulthandler.enable()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
"""
|
||||
|
@ -37,6 +37,8 @@ def path_to_str(path=None):
|
||||
:return: An empty string if :param:`path` is None, else a string representation of the :param:`path`
|
||||
:rtype: str
|
||||
"""
|
||||
if isinstance(path, str):
|
||||
return path
|
||||
if not isinstance(path, Path) and path is not None:
|
||||
raise TypeError('parameter \'path\' must be of type Path or NoneType')
|
||||
if path is None:
|
||||
|
@ -61,6 +61,13 @@ class TextType(object):
|
||||
Notes = 2
|
||||
|
||||
|
||||
class LibreOfficeException(Exception):
|
||||
"""
|
||||
A specific exception for LO
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
@expose
|
||||
class LibreOfficeServer(object):
|
||||
"""
|
||||
@ -71,7 +78,6 @@ class LibreOfficeServer(object):
|
||||
Set up the server
|
||||
"""
|
||||
self._control = None
|
||||
self._desktop = None
|
||||
self._document = None
|
||||
self._presentation = None
|
||||
self._process = None
|
||||
@ -122,39 +128,35 @@ class LibreOfficeServer(object):
|
||||
'--minimized',
|
||||
'--nodefault',
|
||||
'--nofirststartwizard',
|
||||
'--accept=pipe,name=openlp_pipe;urp;'
|
||||
'--accept=socket,host=localhost,port=2002;urp;StarOffice.ServiceManager'
|
||||
]
|
||||
self._process = Popen(uno_command)
|
||||
|
||||
def setup_desktop(self):
|
||||
@property
|
||||
def desktop(self):
|
||||
"""
|
||||
Set up an UNO desktop instance
|
||||
"""
|
||||
if self.has_desktop():
|
||||
return
|
||||
uno_instance = None
|
||||
context = uno.getComponentContext()
|
||||
resolver = context.ServiceManager.createInstanceWithContext('com.sun.star.bridge.UnoUrlResolver', context)
|
||||
loop = 0
|
||||
while uno_instance is None and loop < 3:
|
||||
try:
|
||||
uno_instance = resolver.resolve('uno:pipe,name=openlp_pipe;urp;StarOffice.ComponentContext')
|
||||
uno_instance = resolver.resolve('uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext')
|
||||
except Exception as e:
|
||||
log.warning('Unable to find running instance ')
|
||||
loop += 1
|
||||
try:
|
||||
self._manager = uno_instance.ServiceManager
|
||||
manager = uno_instance.ServiceManager
|
||||
log.debug('get UNO Desktop Openoffice - createInstanceWithContext - Desktop')
|
||||
self._desktop = self._manager.createInstanceWithContext('com.sun.star.frame.Desktop', uno_instance)
|
||||
desktop = manager.createInstanceWithContext('com.sun.star.frame.Desktop', uno_instance)
|
||||
if not desktop:
|
||||
raise Exception('Failed to get UNO desktop')
|
||||
return desktop
|
||||
except Exception as e:
|
||||
log.warning('Failed to get UNO desktop')
|
||||
|
||||
def has_desktop(self):
|
||||
"""
|
||||
Say if we have a desktop object
|
||||
"""
|
||||
return hasattr(self, '_desktop') and self._desktop is not None
|
||||
|
||||
def shutdown(self):
|
||||
"""
|
||||
Shut down the server
|
||||
@ -163,24 +165,23 @@ class LibreOfficeServer(object):
|
||||
if hasattr(self, '_docs'):
|
||||
while self._docs:
|
||||
self._docs[0].close_presentation()
|
||||
if self.has_desktop():
|
||||
docs = self._desktop.getComponents()
|
||||
count = 0
|
||||
if docs.hasElements():
|
||||
list_elements = docs.createEnumeration()
|
||||
while list_elements.hasMoreElements():
|
||||
doc = list_elements.nextElement()
|
||||
if doc.getImplementationName() != 'com.sun.star.comp.framework.BackingComp':
|
||||
count += 1
|
||||
if count > 0:
|
||||
log.debug('LibreOffice not terminated as docs are still open')
|
||||
can_kill = False
|
||||
else:
|
||||
try:
|
||||
self._desktop.terminate()
|
||||
log.debug('LibreOffice killed')
|
||||
except:
|
||||
log.warning('Failed to terminate LibreOffice')
|
||||
docs = self.desktop.getComponents()
|
||||
count = 0
|
||||
if docs.hasElements():
|
||||
list_elements = docs.createEnumeration()
|
||||
while list_elements.hasMoreElements():
|
||||
doc = list_elements.nextElement()
|
||||
if doc.getImplementationName() != 'com.sun.star.comp.framework.BackingComp':
|
||||
count += 1
|
||||
if count > 0:
|
||||
log.debug('LibreOffice not terminated as docs are still open')
|
||||
can_kill = False
|
||||
else:
|
||||
try:
|
||||
self.desktop.terminate()
|
||||
log.debug('LibreOffice killed')
|
||||
except:
|
||||
log.warning('Failed to terminate LibreOffice')
|
||||
if getattr(self, '_process') and can_kill:
|
||||
self._process.kill()
|
||||
|
||||
@ -191,8 +192,10 @@ class LibreOfficeServer(object):
|
||||
self._file_path = file_path
|
||||
url = uno.systemPathToFileUrl(file_path)
|
||||
properties = (self._create_property('Hidden', True),)
|
||||
retries = 0
|
||||
self._document = None
|
||||
try:
|
||||
self._document = self._desktop.loadComponentFromURL(url, '_blank', 0, properties)
|
||||
self._document = self.desktop.loadComponentFromURL(url, '_blank', 0, properties)
|
||||
except:
|
||||
log.warning('Failed to load presentation {url}'.format(url=url))
|
||||
return False
|
||||
|
@ -23,6 +23,7 @@
|
||||
import logging
|
||||
import os
|
||||
import time
|
||||
from pathlib import Path
|
||||
from subprocess import Popen
|
||||
|
||||
from openlp.core.common import AppLocation, Registry, delete_file, is_macosx
|
||||
@ -65,11 +66,11 @@ class MacLOController(PresentationController):
|
||||
"""
|
||||
Start a LibreOfficeServer
|
||||
"""
|
||||
libreoffice_python = '/Applications/LibreOffice.app/Contents/Resources/python'
|
||||
libreoffice_server = os.path.join(AppLocation.get_directory(AppLocation.PluginsDir),
|
||||
'presentations', 'lib', 'libreofficeserver.py')
|
||||
if os.path.exists(libreoffice_python):
|
||||
self.server_process = Popen([libreoffice_python, libreoffice_server])
|
||||
libreoffice_python = Path('/Applications/LibreOffice.app/Contents/Resources/python')
|
||||
libreoffice_server = AppLocation.get_directory(AppLocation.PluginsDir).joinpath('presentations', 'lib',
|
||||
'libreofficeserver.py')
|
||||
if libreoffice_python.exists():
|
||||
self.server_process = Popen([str(libreoffice_python), str(libreoffice_server)])
|
||||
|
||||
@property
|
||||
def client(self):
|
||||
@ -124,9 +125,6 @@ class MacLODocument(PresentationDocument):
|
||||
Tell the LibreOfficeServer to start the presentation.
|
||||
"""
|
||||
log.debug('Load Presentation LibreOffice')
|
||||
self.client.setup_desktop()
|
||||
if not self.client.has_desktop():
|
||||
return False
|
||||
if not self.client.load_presentation(self.file_path, ScreenList().current['number'] + 1):
|
||||
return False
|
||||
self.create_thumbnails()
|
||||
|
Loading…
Reference in New Issue
Block a user