Programming with Python Scripts

A Python macro is a function within a .py file, identified as a module. Unlike LibreOffice Basic and its dozen of UNO objects functions or services, Python macros use the XSCRIPTCONTEXT UNO single object, shared with JavaScript and BeanShell. The g_exportedScripts global tuple explicitly lists selectable macros from a module. Python modules hold autonomous code logic, and are independent from one another.

XSCRIPTCONTEXT Global Variable

Genuine Basic UNO facilities can be inferred from XSCRIPTCONTEXT global variable. Refer to LibreOffice API for a complete description of XSCRIPTCONTEXT. XSCRIPTCONTEXT methods summarize as:

Methods

Kirjeldus

Mapped in Basic as

getDocument()

The document reference on which the script can operate.

ThisComponent

getDesktop()

The desktop reference on which the script can operate.

StarDesktop

getComponentContext()

The component context which the script can use to create other uno components.

GetDefaultContext


HelloWorld and Capitalise installation shared scripts illustrate UNO-related macros making use of XSCRIPTCONTE