Creating the Extension Project using Python

As stated earlier an Extension project is a way to develop extension for the LibreOffice, which can be distributed. This tutorial will talk about the development of the same using Python language

Creating the Project

To launch the Extension Project creation wizard, you can either select File > New > Other > LibreOffice and then choose Extension Project or Right click in the open space under the Package Explorer and follow the same steps which you would have done if clicked on File. You will see a screen similar to the one below.

Figure 1.: New Project Wizard

: New Project Wizard

Clicking on the next will take you to the New Wizard Page which is similar to most New Wizard Pages. There you need to fill out the necessary details and select the language as Python. When you click Next you are Presented with the Service Craetion Page after that you are presented with the Interface creation Page when you click Next. The sequence of images that will follow are :

Figure 2.: Sequence in Project Wizard

: Sequence in Project Wizard

Files and Folder Structure

Once the project is created you will see it listed under the Package Explorer and a basic Python file with the same name as that of the Project will open. The Project tree on the Package Explorer will look the one below

Figure 3.: The Project Tree Structure

: The Project Tree Structure

In the folder structure few points that are important:

  • The Source Python files should be placed under the source folder, if folders are created to seggregate the python files then these folders need to be placed under the source folder.

  • If the associated project is being created with the help of idl file, then you can make the changes in the idl files, these changes would be automatically reflected in the urd and ultimately in the types.rdb file.

  • By Default the contents of the source folder, types.rdb are selected for creation of the ".oxt" file. Using the package.properties file you need to select the other files that need to be present in the ".oxt" file like the desciption.xml, images folder, etc. In case if you find that any of the default files are not getting inside the ".oxt", select them from "package.properties".

  • Lastly description.xml is a file that needs to be filled out, since it contains the description regarding the extension that has been created.

The basic Python file looks like the one below where you can make the necessary changes.

Figure 4.: The Starting Python File

: Starting Python File

How to Run the Project

In order to Run the Extension Project which you created, Right Click on the Project > Run As > LibreOffice extension . If the project has been properly created it will start an instance of the LibreOffice where you will have the options to select any of the LibreOffice Programs like Calc, Writer, Impress, Math. If the extension being developed is a generic one then any of the programs will work, if it is made for specific program, its better to open that particular one.

*Note: If in the first instance the LibreOffice instance does not show up, try running the Extension Project again

How to Debug the Project

Now we move onto one of the most important feature which is Debugging the project. In order to "Debug" any Extension Project developed using Python Right Click on the Project > Debug As > LibreOffice extension . Before you go for Debugging Remember to add the line pydev.settrace() before the line where you would like to start the debugging.

To import the pydev, you can write only pydevd and request a code-completion which will add pydevd.py to sys.path and do the settrace

Figure 5.: Debugging in the Python File

: Debugging in the Python File
Once you have Clicked on Debug As > LibreOffice extension, A LibreOffice instance will open up which will assist in the debugging. So once you have inititated the execution of the extension from the LibreOffice instance, the execution will start and pause at the line below pydev.settrace. To see that you need to switch to the Debugging Perspective in Eclipse. If it is not showing, then Click on Window on Menu Bar > Perspective > Open Perspective > Other.... It will open a list of perspectives from there select Debug option. It will open a screen like the one below, with the line highlighted where the execution has paused. You can add new breakpoints similar to how we add when we debug a Java Program.

*Note : The python program which has opened is referenced from inside the oxt file. So we need to add the breakpoints to this one and not the one which we coded into.

Figure 5.: Debugger use when Debugging the Python Extension Project

: Debugger use when Debugging the Python Extension Project

A short video has been made to guide you through the process, it does not include the Services and Interface page in New Wizard and also the idl files are not present. You can check it out to get the idea specially on running and debugging. Python Language in LoEclipse Extension