Here’s a pretty minimal setup for building an extension for LibreOffice in Python.

Working backwards, I’ve called the extension mdda_fns.oxt. Here’s the makefile, which is in the root of the package development tree :

The essential files for anything to work are :

• description.xml : Contains overall information about the extension : names, descriptions, licensing, help information, upgrading, etc. The filename for this file is FIXED;

• META-INF/manifest.xml : Contains a file listing of the extension package (which is rolled up into the zip/oxt. Along with each file, the filetype identifies how it will be treated when the system loads it in. The filename for this file is FIXED;

• Addons.xcu : Contains an XML description of how the extension is wired into the actual LibreOffice GUI : As a menu-item, ToolButton on a Toolbar; etc; Arbitrary filename (listed in ‘manifest.xml’)

• src/Interface.py : This is a Python file, which I’ve put in the interface code. Arbitrary filename (listed in ‘manifest.xml’);

• package/ : This directory houses stuff related to the overall package : see ‘description.xml’;

Here is the contents of those files :

description.xml

META-INF/manifest.xml

Addons.xcu : Here, I’ve commented out the toolbar and image stuff : I just want to put a top menubar entry.

Also, see the vnd.sun.star.script: entry? That’s what’s required if you want to preprocess this as a script file (of the sort one would put in ~/.libreoffice/3/user/Scripts/python/. But it gets very awkward to address these from the UI elements. Much better to use the service: type, and create the named interface (note how com.platformedia.libreoffice.extensions.mdda_fn.TestButton is defined in the .py file below).

Note that the menu is defined to work for spreadsheets (search for ‘Context’), so that it won’t appear if one is loading up a wordprocessing document.

src/Interface.py : Also noteworthy is the interface definition code half-way down the script, and also the ‘main’ code that allows one to test the extension quickly (in this case, it loads up a test workbook, and presses the button in the python file for inspection). To retest, you’ll need to close up oocalc and relaunch. print comments go to stdout (the command line terminal, usually).

Notes : Essential packaging info

• http://user.services.openoffice.org/en/forum/viewtopic.php?f=45&t;=43398

• http://wiki.services.openoffice.org/wiki/UNO_component_packaging#Python_component_testing

• http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Extensions/Extensions

Hope this helps someone.