[Idle-dev] Running with subprocesses?
Douglas S. Blank
dblank at brynmawr.edu
Fri Aug 17 06:39:13 CEST 2007
>On 8/16/07, Douglas S. Blank <dblank at brynmawr.edu> wrote:
>> I'm working on a plugin extension for IDLE that can run a test when
>> Control+C is pressed. Unfortunately, Control+C (or <Cancel> in Tkinter
>> bindings) is not handled as other key bindings are. Instead there is a
>> cancel_callback in the pyshell instance that is called.
>> So, I've tried to replace the cancel_callback method from inside the
>> extension (I have a working version from an external main---but it is
>> really hacky). However, it looks like editwin.flist.pyshell doesn't
>> exist yet when the constructor of the extension is called.
>> Is there any way for my extension module to have some code that gets
>> called after the pyshell has been created?
>> Sample code:
>> class ExtensionTest:
>> def __init__(self, editwin):
>> # works for other windows, after the shell is made, but:
>> print editwin.flist.pyshell.cancel_callback, "does not exist yet"
>> # when constructed for the shell
>First off - Why Ctrl+C? It seems the simplest solution would be to
>bind to a different hotkey, unless you deliberately want to override
>the ability to use Ctrl+C to raise KeyboardInterrupt exceptions.
Yeah, I know---it is really a nonstandard goal. But, I do have this
working, albeit in a hackish manner:
when the user types Control+C, not only will the code stop if running, but
the robot that we are controlling (which might be moving) will stop as
>The answer is to just use editwin, and not flist.pyshell. When PyShell
>is initialized, it will load the extension (the extensions are loaded
>once per EditorWindow instance). You can set the 'enable_editor'
>config option to False (or zero) for the extension to cause it to be
>loaded only for the PyShell window and not for file editing windows.
Ok, that worked. But now I can't figure out how the extension can get
access to the shell's environment. Remember that I'm running IDLE with
Thanks for any ideas (but I'm thinking my original hacks will just have to
>If you want to be 100% sure, you can do 'isinstance(PyShell.PyShell,
>editwin)' to ensure that the window is a shell window (so that things
>don't go wrong if a user changes the 'enable_editor' config option).
>Douglas S. Blank
>Associate Professor, Bryn Mawr College
>Office: 610 526 6501
More information about the IDLE-dev