Page 1 of 1

[Solved] Basic - Python? / Intercept context menu

PostPosted: Thu Jan 21, 2016 4:34 pm
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   Expand viewCollapse view
<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?

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

PostPosted: Fri Jan 22, 2016 2:05 pm
by sng
I have managed to solve it myself :D

I have included the code

Code: Select all   Expand viewCollapse view
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: