Writing User Defined Functions in Python

I stored the following simple Python script in /usr/lib/libreoffice/share/Scripts/python/pythonSamples :

import uno

def newsum(a, b):

…return a + b

What should I do to make this work as a user-defined-function in Libre Office so calling =newsum(5, 7) would simply return 12?

I have been struggling with this for a while, so any help is highly appreciated!

Note:
My configuration is:
Libre Office 3.6 on Ubuntu 12.10; Python plug-in has been loaded correctly [Tools → Macros → Organize Macros → Python works fine].

Hi @OrionWorld,

It looks like there’s some information about user-defined-functions in this document:
https://www.openoffice.org/udk/python/python-bridge.html

This example sounds very relevant:

python-tokencounter-calc-addin.oxt

Adds a function named tokencount to calc, which counts the number of words within a calc cell. After adding the extension, the office must be restarted (including terminating the quickstarter) to make the function appear in the function list.

@ qubit, thanks for your answer. For some reason I feel there should be some simple way to call a python script from basic macro. Would be interesting to work out a simple instruction to the newsum(a,b) function in LO calc.

@OrionWorld – I’m not sure of a simple way to call a python script from a BASIC macro, but it sounds like a good feature to me.

Please feel free to file an enhancement bug and provide a description of how you’d like the config/registration of the Python scripts to work. Don’t forget to mark your bug as an ‘enhancement’.

Please post a link to any bugs you file in a comment below using the format “fdo#123456”.

This should be a comment, not an answer