[Idle-dev] Embedding IDLE

Thomas Goddard goddard@cgl.ucsf.EDU
Thu, 23 Mar 2000 14:40:46 -0800 (PST)


Here are some suggestions to facilitate embedding IDLE as part of
another Tkinter application.

I work on a molecular visualization program that is user extendable in
Python.  I want to be able to start IDLE from this program.  IDLE will
run in the same Python interpretter as the molecular visualization program.

To start an IDLE shell window within the molecular visualization program
IDLE should not do some of the steps it does when started standalone:

1) Don't do command-line argument parsing
2) Don't start the Tkinter event loop
3) Don't call Tkinter quit() when the last IDLE window is closed
4) Don't reset Tkinter _default_root to None

To achieve 1) and 2) the IDLE 0.5 shell window initialization code in
PyShell.py main() needs to be separated out from the command-line argument
parsing and event loop start-up.  This just involves packaging about 10
lines of code in a separate routine.

When the last IDLE window closes, the FileList close_edit() method in
FileList.py calls Tkinter quit() exitting the event loop.  This should
only be done if the PyShell.py main() routine called Tkinter mainloop().

In the PyShell class the begin() routine sets Tkinter._default_root = None.
I guess this is so that code run in IDLE sees a clean Tkinter.  This should
not be done if IDLE is running within another Tkinter application as it can
break the graphical interface of that application.  The _default_root = None
code could be moved to PyShell.py main().  This changes the behaviour of
IDLE, since Tkinter _default_root will then only be set once when starting
IDLE standalone, instead of each time a PyShell is created.

The molecular visualization code wants to redisplay the IDLE shell window
if the user asks for it a second time.  It would be helpful to have a
method of the IDLE EditorWindow class to determine if the window has been
closed, so I don't try to raise a destroyed window.

Tom Goddard
Computer Graphics Lab
UC San Francisco