]> Git — Sourcephile - reloto-libreoffice.git/blob - connect_to_libre_office.py
Polissage documents Jugement Majoritaire.
[reloto-libreoffice.git] / connect_to_libre_office.py
1 import uno
2
3 def getModel():
4 # get the uno component context from the PyUNO runtime
5 localContext = uno.getComponentContext()
6
7 # create the UnoUrlResolver
8 resolver = localContext.ServiceManager.createInstanceWithContext(
9 "com.sun.star.bridge.UnoUrlResolver", localContext)
10
11 # connect to the running office
12 context = resolver.resolve("uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
13 manager = context.ServiceManager
14
15 # get the central desktop object
16 desktop = manager.createInstanceWithContext("com.sun.star.frame.Desktop", context)
17
18 # access the current writer document
19 return (desktop.getCurrentComponent(), context)
20
21 def debug(msg):
22 print(msg)