Ask Your Question
0

Launching a Writer document from Python

asked 2017-09-22 14:32:36 +0200

reuben gravatar image

I would like to open a Writer document from a Python script that I can close reliably. Subprocess.call() opens the document fine, but I cannot close it. The basic idea is to pop open a window with a file generated from a template. When the user regenerates the file, Python closes the window and opens the new file. Is this possible?

Thanks Reuben

edit retag flag offensive close merge delete

Comments

Does your call() routine give you access to the newly created Frame/Component?
Does your script belong to an instance under LibO? You need access to the StarDesktop service. I think you need not to start an arbitrary subprocess, but to use something like

theOtherComponent = StarDesktop.LoadComponentFromURL(theURLformattedFilePathName, parameters)

and later the Store and/or the StoreAsURL and the Close methods of the Component.

Lupp gravatar imageLupp ( 2017-09-22 14:56:30 +0200 )edit

subprocess.call() simply does not have a reliable pid or anything. Mostly because the soffice.bin might be running already or might be closed from a different process.

reuben gravatar imagereuben ( 2017-09-22 18:22:11 +0200 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2017-09-22 16:21:26 +0200

karolus gravatar image

hallo

to get Access to the soffice-process you have to run soffice in socket-mode or pipe-mode. see this Answer

edit flag offensive delete link more

Comments

Could you give me a small example that opens/shows the file '/home/reuben/test.odt' , waits three seconds, and then closes it again? I am still totally lost in the connection between Python and Libreoffice.

reuben gravatar imagereuben ( 2017-09-22 18:15:47 +0200 )edit

Ok, got it. I was baffled by the lack of doc.show() or similar. Vastly different from Gtk, anyway.

reuben gravatar imagereuben ( 2017-12-11 03:22:30 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-09-22 14:32:36 +0200

Seen: 478 times

Last updated: Sep 22 '17