Making extension for Idle to change its right click menu

57 Views Asked by At

I need to make an extension for Idle, that lets me change its right click menu (context menu?) to add events/options that i want to be there. Mainly for Idle Editor. I only found documentation on how to change the classic top menu, but havent seen anything about changing the right click menu.

I have a standalone program that lets me make new rmenu in Tkinter and need to implement it into Idle. I found editor.py, where is the rmenu configured, but havent made much out of it.

1

There are 1 best solutions below

0
Terry Jan Reedy On

As discovered, IDLE provides a mechanism for user extensions to declare new main menu entries that IDLE will insert into the main menu. It does not currently provide a similar mechanism for inserting into the right-click context menu. This seems like a sensible idea so I added draft issue "IDLE config extension: allow addition to context menu" to the IDLE project page with a reference to this question. I will consider this should I focus on extensions some time in the future.

In the meanwhile, look at the sample extension idlelib/zzdummy.py. Instead of the menudefs declaration, you would have to add code in YourExtClass.__init__ to do 1 of 2 things:

  1. Add (append) a tuple to text.rmenu_defs (a list). The example in editor.EditorWindow.rmenu_specs (currently line 589) is ("Close", "<<close-window>>", None). The actual editor rmenu_specs is in pyshell line 153. Use None for the 3rd member.

  2. add a command to text.rmenu using code like that in editor.EditorWindow.make_rmenu.

The choice depends on whether IDLE installs extensions before or after making rmenu.