[Patches] [ python-Patches-989712 ] Support using Tk without a mainloop

SourceForge.net noreply at sourceforge.net
Fri Feb 4 14:08:38 CET 2005


Patches item #989712, was opened at 2004-07-13 05:16
Message generated for change (Comment added) made by mdehoon
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=989712&group_id=5470

Category: IDLE
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Noam Raphael (noamr)
Assigned to: Kurt B. Kaiser (kbk)
Summary: Support using Tk without a mainloop

Initial Comment:
In the regular python shell, you can open Tk windows,
and they will operate even though you didn't call
Tkinter.mainloop(). This is useful, for example, when
you manipulate matplotlib graphs from within the python
shell.
This is done by a hook, installed when a tkapp object
is being initialized, which handles Tk events while the
shell is waiting for user input.

I imitated this behaviour in IDLE: When the subprocess
is idle, it checks whether Tkinter._default_root is set
(this happens when the Tkinter.Tk class, which makes a
tkapp object, is initialized, unless
Tkinter._use_default_root is False), and if so, handles
Tk events.

For me it works very well.

Have a good day,
Noam Raphael

----------------------------------------------------------------------

Comment By: Michiel de Hoon (mdehoon)
Date: 2005-02-04 22:08

Message:
Logged In: YES 
user_id=488897

I agree, this is basically the same bug as #798058. The call
to readline.call_input_hook sounds like a good solution. But
the hook function should be different than the current
EventHook in _tkinter.c. That hook function sits in a loop
until a keyboard event is noticed. A problem occurs if there
is more than one hook function. Currently, that is not
possible in Python, since there is only one PyOS_InputHook.
I am working on a patch in which PyOS_InputHook is replaced
by PyOS_AddInputHook and PyOS_RemoveInputHook, so that there
can be more than one hook functions.

Now suppose that there is one hook function to handle Tk
events, and another one e.g. handling messages to windows in
Microsoft Windows. (This is a real issue for one of my
extension modules). If python sits in a loop in _tkinter.c's
EventHook until a key is pressed, the MS windows won't get
their messages.

The following structure might work better:

while(there is no keyboard input or other interesting event) {
            Call PyOS_InputHook #1
            Call PyOS_InputHook #2
            etc.
}
where each of the PyOS_InputHook functions should return if
there is no more work for them. The tricky part is to find
out which events to wait for; some of the events may be
handled by one of the PyOS_InputHook functions.

Obviously I need to do some more thinking about this.


----------------------------------------------------------------------

Comment By: Kurt B. Kaiser (kbk)
Date: 2005-02-04 10:02

Message:
Logged In: YES 
user_id=149084

Hm, this seems closely related to Bug 798058

I'd lost track of it because it got switched to tkinter.

----------------------------------------------------------------------

Comment By: Noam Raphael (noamr)
Date: 2005-01-30 20:58

Message:
Logged In: YES 
user_id=679426

in _tkinter.c, look for EventHook - you'll find the
EventHook function, which is called when the interpreter is
idle, and the Enable/Disable EventHook functions.

In readline.c, line 765, you'll find the call to
PyOS_InputHook, when waiting for input.

Perhaps a more general approach would be to let Python code
call PyOS_InputHook, for example, by defining
readline.call_input_hook() and readline.has_input_hook().
Then IDLE would be able to call them when idle, with no
Tkinter-specific code.

----------------------------------------------------------------------

Comment By: Kurt B. Kaiser (kbk)
Date: 2004-07-15 05:44

Message:
Logged In: YES 
user_id=149084

Can you give me some more information on the hook in the
Python interpreter?  Where is it in the code?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=989712&group_id=5470


More information about the Patches mailing list