[Solved] Basic - Python? / Intercept context menu

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
sng
Posts: 45
Joined: Thu Jan 15, 2015 1:48 pm
Location: Corfu, Greece

[Solved] Basic - Python? / Intercept context menu

Post by sng »

Hi all

I have a writer extension I would like to intercept the context menu and add a submenu with a number of items

I have found this basic code, which can add an item on the context menu, but no submenu.

Then I remembered hanya's example called InterceptContextMenu, which is in python, and i believe i can make it add a submenu.

I have copied the code to a file called contextmenu.py, but the thing is that i cannot "activate" it from within the extension. I tried adding to the manifest.xml:

Code: Select all

<manifest:file-entry manifest:media-type="application/vnd.sun.star.uno-component;type=Python" manifest:full-path="contextmenu.py"/>
but when i try to install it i get an error (I don't have it right now but i can get it if needed).

How do i activate this code in the extension?
Last edited by sng on Fri Jan 22, 2016 2:06 pm, edited 1 time in total.
AOO 4.1.2 on Windows 7, LO 5.1.4.2 on Manjaro Linux
sng
Posts: 45
Joined: Thu Jan 15, 2015 1:48 pm
Location: Corfu, Greece

Re: Basic - Python? / Intercept context menu (add submenu)

Post by sng »

I have managed to solve it myself :D

I have included the code

Code: Select all

controller = doc.getCurrentController()
    controller.registerContextMenuInterceptor(SheetTabContextMenuInterceptor(doc))
within a python function in my cmi.py file presented in my previous post Auto execute BASIC macro from python

It was that easy :crazy:

This proves that i'm hopeless with python (but at least i'm trying...)

Marked as solved

BTW, the code already creates a submenu so I'm pleased :bravo:
AOO 4.1.2 on Windows 7, LO 5.1.4.2 on Manjaro Linux
Post Reply