Quickstart python MacOS extensions

I need a quick start LibreOffice extension creation with python on MacOS Big Sur.

I have a Word taskpane add-in in javascript I wish to convert to LibreOffice writer using python.

I currently have 3.9.2 python installed with LO 7.0.4.2

There are quite a few websites discussing the topic but, unfortunately, many are out-of-date or give incorrect information. However, from combining information from them, I’ve figured out that in two terminal windows I need to run
/Applications/LibreOffice.app/Contents/MacOS/soffice --writer
–accept=“socket,host=localhost,port=2002;urp;StarOffice.ServiceManager”
and
/Applications/LibreOffice.app/Contents/MacOS/Resources/python
Both terminals are left running.

My /Applications/LibreOffice.app/Contents/MacOS/ folder has uno within it. So, apparently, the following should work:

import uno
     print("Hello World!")

but I get the error ‘ModuleNotFoundError: No module named ‘uno’’

I’m using variously IDLE and spyder as my editors.

What have I missed?

I have another question. There’s a fair few tutorials on LO python macros. Are macros different to extensions (this is not clear)? I’m assuming there is some useful information there if they are different but perhaps there are some important differences that I have not yet understood and that might lead me down the wrong path. I want to produce a graphical interface (like a Word taskpane) to an external database – so ‘extension’ I think.

Thanks in advance.

Hello,
your mentioned method to handle python macros is one of two. If you use a port you have a external program, running outside of LibreOffice. Therefore the libraries have to installed in your external python and you have to get the primary entrypoint XSCRIPTCONTEXT.

The other way is to stay inside LibreOffice and place your marcro in the right place as shown here in a forums post
It is useful to have the APSO-extension to help here.

If you read the documentation to Base you may find you don’t need macros or Python at all to create your interface. A simple form or dialogue may do.

You may bundle macros, task-bar, buttons etc afterwards as an extension, but it is not your first step to go. It is a concept for distribution to users which can’t handle installing macros…

Hi,

Happy Python!

note: IDE_utils provides (Libre/Open)Office Python macro simple enablement for IDEs.