LibreOffice on Raspberry Pi (Debian / buster).
Shortcut on desktop correctly opens Base form (ODT), ideal because this presents the end user with the minimal information necessary.
ODT form shows data in fields and has a search field and search button.
A separate python3 script (not a macro with LibreOffice) listens to incoming data from the network and the plan was for that script to send the data into the input field in the form and then push the search button (which does a RecFind) on the same form.
However, am I right in thinking that –
-
This cant be made to work because uno cannot connect to an ODT and the whole LibreOffice suite has to be opened first?
-
Uno requires LibreOffice to be running on a port as otherwise uno cannot connect.
-
The only feasible way this may have worked is to have LibreOffice automatically open the most recent ‘file’ when LibreOffice starts.
However, the example macro provided here (Is it possible to automatically open most recent document on start? doesn’t work (nothing opens).
Is there any solution for this, I see only one python example which shows uno use (and the few C examples which exist only mention StarOffice)?
My knowledge of uno is mostly non-existent.
This is what I eventually ended up with, very messy / confusing (to me) but seems to work.
#Open socket to LibraOffice with delay to allow program to wait for connection
os.popen('/usr/lib/libreoffice/program/soffice /home/pi/Desktop/Access --accept="socket,host=localhost,port=2002;urp;StarOffice.ServiceManager"')
time.sleep(8) # Sleep for 5 seconds
# get the uno component context from the PyUNO runtime
localContext = uno.getComponentContext()
# create the UnoUrlResolver
resolver = localContext.ServiceManager.createInstanceWithContext(
"com.sun.star.bridge.UnoUrlResolver", localContext)
# connect to the running office
global ctx
ctx = resolver.resolve(
"uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext")
smgr = ctx.ServiceManager
And then I attempted to ‘push’ the button on the form using python script to ‘simulate button press’ or to run the macro which the button would normally call, both attempts failed. I found this code but I suspect it is only for Windows.
def causeKeyPressedEventToBeFired(oEvent=None):
oDoc = XSCRIPTCONTEXT.getDocument()
oController = oDoc.getCurrentController()
oForm = oDoc.getDrawPage().getForms().getByName("Form")
oTextBox = oForm.getByName("Search")
oControlView = oController.getControl(oTextBox)
oControlView.setFocus()
oEvent = uno.createUnoStruct("com.sun.star.awt.KeyEvent")
oEvent.Source = oControlView
from com.sun.star.awt.Key import A
oEvent.KeyCode = A
oEvent.KeyChar = "a" # works in Python but strangely not in Basic
simulate_KeyPress(oEvent)
def simulate_KeyPress(oKeyEvent):
oDoc = XSCRIPTCONTEXT.getDocument()
oWindow = oDoc.CurrentController.Frame.getContainerWindow()
oKeyEvent.Source = oWindow
oToolkit = oWindow.getToolkit()
oToolkit.keyPress(oKeyEvent)
oToolkit.keyRelease(oKeyEvent)
Two steps forward, 10 back.
Thanks