For all Python fans out there, you might not know that OpenOffice.org can be run on Python. This is great because OpenOffice.org is a very interesting application but is hard to modify or develop on top of it. However extensions has been the way to go when you want to implement something new in OpenOffice.org. So here is a mini tour oriented to the way OpenOffice.org manage Python, which is different to the way OpenOffice.org handles the native OOoBasic. One thing is that OOoBasic is compatible with OpenOffice.org IDE that you get when you go to Tools > Macros > Manage Macros > OpenOffice.org Basic.How Macros are handled.
Macros are usually handled on 3 stages, it can be either file based, user based, or application base.
- The file based it means that the macros are stored in the file, this files will have the python source code within the document.
- User based is that the macros are saved on the user preferences, this is usually stored in linux on the dot folders, in windows under the Application data folder.
- Application base are stored in the applications folder which in linux is under /opt folder and on windows is under the Program Files folder.
As I said before, Python is not a native language to OpenOffice.org, however you will be happy to know that python is included by default under OpenOffice.org. Is stored at openoffice.org2.2/program/python-core-2.3.4/ (versions might change); so you are able to use this macros on every openoffice.org installation. As I mention before, the 3 layers that OOo can store macros will affect the installation of new macros developed in Python. The easiest one is to have python saved in your application, so let say that you have the file MyScript.py. To load it to your OpenOffice.org application will be:
$ su$ cp MyScript.py /opt/openoffice.org2.2/share/Scripts/ptyhon/
.The user account level will be similar nad will execute by just doing the following:
$ cp MyScript ~/.openoffice.org2.2/user/Scripts/python/
* Be careful since the python folder is not created by default you will need to do create a folder under the Script folder.The last one — the document level is actually quite hard and might just put it here for reference but is more complicated than just coping the script inside the document. You will actually have to edit an XML file in order to manually register the file inside the document. As you may know OpenDocuments are Zip files containing other files. They also have a file structure which will include:
meta.xmlcontent.xmlstyle.xmlmimetypecurrent.xmlConfiguration2/ accelerator images popmenu ...META-INF/ manifest.xmlThumbnails/ file.png
You will actually need to unzip and create a new folder called Scripts and inside create the python folder. Only then you will be able to copy your script MyScript.py inside the python folder.Here is where you will need to edit the registry which is in the META-INF/manifest file and add 3 lines (before the final tag manifest:manifest].
<manifest:file-entry manifest:media-type="" manifest:full-path="Scripts/python/MsgBox.py"/> <manifest:file-entry manifest:media-type="application/binary" manifest:full-path="Scripts/python/"/> <manifest:file-entry manifest:media-type="application/binary" manifest:full-path="Scripts/"/>