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