Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-14 Thread Noam Raphael
On 11/15/05, Fredrik Lundh <[EMAIL PROTECTED]> wrote: > If you want to write portable code that keeps things running "in the > background" while the users hack away at the standard interactive > prompt, InputHook won't help you. > So probably it should be improved, or changed a bit, to work also on

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-14 Thread Fredrik Lundh
Noam Raphael wrote: > It didn't. Strange freezes started to appear, only when working from > IDLE. This made me investigate a bit, and I've found that Tkinter > isn't run from a seperate thread - the dooneevent() function is called > repeatedly by PyOS_InputHook while the interpreter is idle. rep

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-14 Thread Noam Raphael
On 11/14/05, Michiel Jan Laurens de Hoon <[EMAIL PROTECTED]> wrote: > Ronald Oussoren wrote: > > > I wonder why nobody has suggested a seperate thread for managing the > > GUI and > > using the hook in Python's event loop to issue the call to update_plot. > > > Ha. That's probably the best solution

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-14 Thread skip
Michiel> 1) Currently, there's only one PyOS_InputHook. So we're stuck Michiel>if we find that some other extension module already set Michiel>PyOS_InputHook. An easy solution would be to have an Michiel>PyOS_AddInputHook/PyOS_RemoveInputHook API, and let Python Mic

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-14 Thread Aahz
On Sun, Nov 13, 2005, Josiah Carlson wrote: > > I personally like Edward Loper's idea of just running your own event > handler which deals with drawing, suspend/resume, etc... > >> If, however, Python contains an event loop that takes care of events as >> well as Python commands, redrawing won't

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-14 Thread Michiel Jan Laurens de Hoon
Ronald Oussoren wrote: > I wonder why nobody has suggested a seperate thread for managing the > GUI and > using the hook in Python's event loop to issue the call to update_plot. > Ha. That's probably the best solution I've heard so far, short of adding a Tcl-like event loop API to Python. There

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-14 Thread Ronald Oussoren
On 14-nov-2005, at 8:16, Josiah Carlson wrote: > > I personally like Edward Loper's idea of just running your own event > handler which deals with drawing, suspend/resume, etc... > >> If, however, Python contains an event loop that takes care of >> events as >> well as Python commands, redrawin

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-14 Thread Ronald Oussoren
On 14-nov-2005, at 16:00, [EMAIL PROTECTED] wrote: > > Ronald> ... except when the GUI you're using doesn't expose (or > even > Ronald> use) a file descriptor that you can use with select. > Not all the > Ronald> world is Linux. > > Can you be more specific? Are you referring to

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-14 Thread Fredrik Lundh
Michiel Jan Laurens de Hoon wrote: > This is exactly the problem. Drawing one picture may consist of many > Python commands to draw the individual elements (for example, several > graphs overlaying each other). We don't know where in the window each > element will end up until we have the list of

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-14 Thread Fredrik Lundh
Michiel Jan Laurens de Hoon wrote: > >Did you read my reply? ipython, based on code.py, implements a few simple > >threading tricks (they _are_ simple, since I know next to nothing about > >threading) and gives you interactive use of PyGTK, WXPython and PyQt > >applications in a manner similar to

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-14 Thread Michiel Jan Laurens de Hoon
[EMAIL PROTECTED] wrote: >Ronald> ... except when the GUI you're using doesn't expose (or even >Ronald> use) a file descriptor that you can use with select. Not all the >Ronald> world is Linux. > >Can you be more specific? Are you referring to Windows? I'm not suggesting >you'd be ab

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-14 Thread skip
Ronald> ... except when the GUI you're using doesn't expose (or even Ronald> use) a file descriptor that you can use with select. Not all the Ronald> world is Linux. Can you be more specific? Are you referring to Windows? I'm not suggesting you'd be able to use the same exact implem

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-14 Thread Martin v. Löwis
Michiel Jan Laurens de Hoon wrote: > If, however, Python contains an event loop that takes care of events as > well as Python commands, redrawing won't happen until Python has > executed all plot commands -- so no repainting in vain here. Ah, I think now I understand the problem. It seems that y

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-13 Thread Fernando Perez
Josiah Carlson wrote: > Or heck, if you are really lazy, people can use a plot() calls, but > until an update_plot() is called, the plot isn't updated. I really recommend that those interested in all these issues have a look at matplotlib. All of this has been dealt with there already, a long ti

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-13 Thread Martin v. Löwis
Michiel Jan Laurens de Hoon wrote: >>Yes, you can. Actually, Tkinter *always* runs in a separate thread >>(separate from all other threads). >> > Are you sure? If Tkinter is running in a separate thread, then why does > it need PyOS_InputHook? Well, my statement was (somewhat deliberately) misl

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-13 Thread Josiah Carlson
I personally like Edward Loper's idea of just running your own event handler which deals with drawing, suspend/resume, etc... > If, however, Python contains an event loop that takes care of events as > well as Python commands, redrawing won't happen until Python has > executed all plot commands

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-13 Thread Ronald Oussoren
On 14-nov-2005, at 2:20, Michiel Jan Laurens de Hoon wrote: > [EMAIL PROTECTED] wrote: > >> If I have a Gtk app I have to feed other (socket, callback) pairs >> to it. It >> takes care of adding it to the select() call. Python could >> dictate that the >> way to play ball is for other packa

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-13 Thread Edward Loper
As I understand it, you want to improve the performance of interactively run plot commands by queuing up all the plot sub-commands, and then drawing them all at once. Hooking into a python event loop certainly isn't the only way to do this. Perhaps you could consider the following approach:

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-13 Thread Fernando Perez
Michiel Jan Laurens de Hoon wrote: > Fernando Perez wrote: >>Did you read my reply? ipython, based on code.py, implements a few simple >>threading tricks (they _are_ simple, since I know next to nothing about >>threading) and gives you interactive use of PyGTK, WXPython and PyQt >>applications in

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-13 Thread Michiel Jan Laurens de Hoon
Fernando Perez wrote: >Michiel Jan Laurens de Hoon wrote: > > >>For an extension module such as >>PyGtk, the developers may decide that PyGtk is likely to be run in >>non-interactive mode only, for which the PyGtk mainloop is sufficient. >> >> > >Did you read my reply? ipython, based on code

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-13 Thread Michiel Jan Laurens de Hoon
Greg Ewing wrote: >Michiel Jan Laurens de Hoon wrote: > > >>Greg Ewing wrote: >> >> >>>How about running your event loop in a separate thread? >>> >>> >>I agree that this works for some extension modules, but not very well >>for extension modules for which graphical performance is cri

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-13 Thread Fernando Perez
Michiel Jan Laurens de Hoon wrote: > For an extension module such as > PyGtk, the developers may decide that PyGtk is likely to be run in > non-interactive mode only, for which the PyGtk mainloop is sufficient. Did you read my reply? ipython, based on code.py, implements a few simple threading tr

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-13 Thread Michiel Jan Laurens de Hoon
Martin v. Löwis wrote: >Michiel Jan Laurens de Hoon wrote: > > >>But there is another solution with threads: Can we let Tkinter run in a >>separate thread instead? >> >> > >Yes, you can. Actually, Tkinter *always* runs in a separate thread >(separate from all other threads). > > Are you

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-13 Thread Greg Ewing
Noam Raphael wrote: > On 11/13/05, Greg Ewing <[EMAIL PROTECTED]> wrote: > > > Noam Raphael wrote: > > > > > callback". Then, when the interpreter is idle, it will call all the > > > registered callbacks, one at a time, and everyone would be happy. > > > > Except for those who don't like busy wait

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-13 Thread Michiel Jan Laurens de Hoon
Noam Raphael wrote: >On 11/13/05, Greg Ewing <[EMAIL PROTECTED]> wrote: > > >>Noam Raphael wrote: >> >> >>>All that is needed to make Tkinter and Michiels' >>>code run together is a way to say "add this callback to the input >>>hook" instead of the current "replace the current input hook wit

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-13 Thread Greg Ewing
Michiel Jan Laurens de Hoon wrote: > Greg Ewing wrote: > > > How about running your event loop in a separate thread? > > I agree that this works for some extension modules, but not very well > for extension modules for which graphical performance is critical I don't understand. If the main thre

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-13 Thread Michiel Jan Laurens de Hoon
[EMAIL PROTECTED] wrote: >If I have a Gtk app I have to feed other (socket, callback) pairs to it. It >takes care of adding it to the select() call. Python could dictate that the >way to play ball is for other packages (Tkinter, PyGtk, wxPython, etc) to >feed Python the (socket, callback) pair.

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-13 Thread Michiel Jan Laurens de Hoon
Greg Ewing wrote: >Michiel Jan Laurens de Hoon wrote: > > >>I have an extension module for scientific visualization. This extension >>module opens one or more windows, in which plots can be made. >> >> > >What sort of windows are these? Are you using an existing >GUI toolkit, or rolling you

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-13 Thread Michiel Jan Laurens de Hoon
Martin v. Löwis wrote: >Michiel Jan Laurens de Hoon wrote: > > >>The problem with threading (apart from potential portability problems) >>is that Python doesn't let us know when it's idle. This would cause >>excessive repainting (I can give you an explicit example if you're >>interested). >>

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-13 Thread Martin v. Löwis
Mark Hammond wrote: > : Currently, event loops are available in Python via PyOS_InputHook, a > : pointer to a user-defined function that is called when Python is idle > : (waiting for user input). However, an event loop using PyOS_InputHook > : has some inherent limitations, so I am thinking about

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-13 Thread Martin v. Löwis
Michiel Jan Laurens de Hoon wrote: > I have an extension module for scientific visualization. This extension > module opens one or more windows, in which plots can be made. Something > similar to the plotting capabilities of Matlab. > > For the graphics windows to remain responsive, I need to ma

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-12 Thread Noam Raphael
On 11/13/05, Greg Ewing <[EMAIL PROTECTED]> wrote: > Noam Raphael wrote: > > > All that is needed to make Tkinter and Michiels' > > code run together is a way to say "add this callback to the input > > hook" instead of the current "replace the current input hook with this > > callback". Then, when

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-12 Thread Greg Ewing
Noam Raphael wrote: > All that is needed to make Tkinter and Michiels' > code run together is a way to say "add this callback to the input > hook" instead of the current "replace the current input hook with this > callback". Then, when the interpreter is idle, it will call all the > registered cal

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-12 Thread Greg Ewing
[EMAIL PROTECTED] wrote: > Python could dictate that the > way to play ball is for other packages (Tkinter, PyGtk, wxPython, etc) to > feed Python the (socket, callback) pair. Then you have a uniform way to > control event-driven applications. Certainly, if all other event-driven packages are wi

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter - Summary attempt

2005-11-12 Thread Fernando Perez
Jim Jewett wrote: > (6) Mark Hammond suggests that it might be easier to > replace the interactive portions of python based on the > "code" module. matplotlib suggests using ipython > instead of standard python for similar reasons. > > If that is really the simplest answer (and telling users >

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-12 Thread Noam Raphael
On 11/12/05, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > If I have a Gtk app I have to feed other (socket, callback) pairs to it. It > takes care of adding it to the select() call. Python could dictate that the > way to play ball is for other packages (Tkinter, PyGtk, wxPython, etc) to > feed

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-11 Thread skip
>> This sounds sort of like the situation that existed with sys.exitfunc >> before the creation of the atexit module. Can't we develop an API >> similar to that so that many different event-loop-wanting packages >> can play nice together? Greg> I can't see how that would help

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-11 Thread Greg Ewing
Michiel Jan Laurens de Hoon wrote: > I have an extension module for scientific visualization. This extension > module opens one or more windows, in which plots can be made. What sort of windows are these? Are you using an existing GUI toolkit, or rolling your own? > For the graphics windows to

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-11 Thread Greg Ewing
[EMAIL PROTECTED] wrote: > This sounds sort of like the situation that existed with sys.exitfunc before > the creation of the atexit module. Can't we develop an API similar to that > so that many different event-loop-wanting packages can play nice together? I can't see how that would help. If th

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-11 Thread skip
Michiel> 1) What if the user decides to import Tkinter next? Tkinter Michiel>notices that PyOS_InputHook is already set, and does not Michiel>reset it to its own event loop. Hence, Tkinter's events are Michiel>not handled. Similarly, if a user imports Tkinter before my

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-11 Thread Fredrik Lundh
Jim Jewett wrote: > > really? Python comes with a module that makes it trivial to get > > a fully working interpreter console ... > > Using an event loop (or an external GUI) should not require > forking the entire interactive mode, no matter how trivial that > fork is. repeating a bogus argumen

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter - Summary attempt

2005-11-11 Thread Fredrik Lundh
Jim Jewett wrote: > (6) Mark Hammond suggests that it might be easier to > replace the interactive portions of python based on the > "code" module. matplotlib suggests using ipython > instead of standard python for similar reasons. > > If that is really the simplest answer (and telling users > w

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-11 Thread Michiel Jan Laurens de Hoon
Martin v. Löwis wrote: >Before trying to explain the reason, please try to explain the >problem first. What is it *really* that you want to do which >you feel you currently can't do? > > Probably I should have started the discussion with this; sorry if I confused everybody. But here it is: I h

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter - Summary attempt

2005-11-11 Thread Michiel Jan Laurens de Hoon
I think this is an excellent summary of the discussion so far. Probably clearer than my own posts. Thanks, Jim! --Michiel. Jim Jewett wrote: >There has been enough misunderstanding in this thread >that the summarizers are going to have trouble. So I'm >posting this draft in hopes of clarificat

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-10 Thread Mark Hammond
Michiel wrote: > Guido van Rossum wrote: > > >On 11/9/05, Michiel Jan Laurens de Hoon > <[EMAIL PROTECTED]> wrote: > > > > > >>My application doesn't need a toolkit at all. My problem is that because > >>of Tkinter being the standard Python toolkit, we cannot have a decent > >>event loop in Python.

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-10 Thread Martin v. Löwis
Michiel Jan Laurens de Hoon wrote: > I have come to this conclusion after several years of maintaining a > scientific plotting package and trying to set up an event loop for > it. Whereas there are some solutions that more or less work, none of > them work very well, and the solutions that we found

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-10 Thread Martin v. Löwis
Michiel Jan Laurens de Hoon wrote: >>You are missing multi-threading, which is the widely used >>approach to doing things simultaneously in a single process. > > The problem with threading (apart from potential portability problems) > is that Python doesn't let us know when it's idle. This would

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-10 Thread Michiel Jan Laurens de Hoon
Guido van Rossum wrote: >On 11/9/05, Michiel Jan Laurens de Hoon <[EMAIL PROTECTED]> wrote: > > >>My application doesn't need a toolkit at all. My problem is that because >>of Tkinter being the standard Python toolkit, we cannot have a decent >>event loop in Python. So this is the disadvantage I

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-10 Thread Phillip J. Eby
At 01:47 PM 11/10/2005 +, Donovan Baarda wrote: >Twisted is an async-framework that I believe has support for using a >variety of different event-loops, including Tkinter and wxWidgets, as >well as it's own. Technically, it just gives Tkinter a chance to run every so often; you specifically *

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-10 Thread Michiel Jan Laurens de Hoon
Martin v. Löwis wrote: > Michiel Jan Laurens de Hoon wrote: > >> It's not because it likes to be in charge, it's because there's no >> other way to do it in Python. > > As I said: this is simply not true. You are right in the sense it is possible to get events handled using the solutions you pr

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-10 Thread Guido van Rossum
On 11/9/05, Michiel Jan Laurens de Hoon <[EMAIL PROTECTED]> wrote: > My application doesn't need a toolkit at all. My problem is that because > of Tkinter being the standard Python toolkit, we cannot have a decent > event loop in Python. So this is the disadvantage I see in Tkinter. That's a non-s

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-10 Thread Donovan Baarda
On Thu, 2005-11-10 at 00:40 -0500, Michiel Jan Laurens de Hoon wrote: > Stephen J. Turnbull wrote: > > >Michiel> What is the advantage of Tk in comparison to other GUI > >Michiel> toolkits? [...] > My application doesn't need a toolkit at all. My problem is that because > of Tkinter being

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-09 Thread Martin v. Löwis
Michiel Jan Laurens de Hoon wrote: > It's not because it likes to be in charge, it's because there's no other > way to do it in Python. As I said: this is simply not true. > Tkinter is a special case among GUI toolkits because it is married to > Tcl. It doesn't just need to handle its GUI event

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-09 Thread Martin v. Löwis
Michiel Jan Laurens de Hoon wrote: > At this point, I can't propose a specific modification yet because I > don't know the reasoning that went behind the original choice of Tk as > the default GUI toolkit for Python (and hence, I don't know if those > reasons are still valid today). I don't kno

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-09 Thread Michiel Jan Laurens de Hoon
Stephen J. Turnbull wrote: >Michiel> What is the advantage of Tk in comparison to other GUI >Michiel> toolkits? > >IMO, Tk's _advantage_ is that it's there already. As a standard >component, it works well for typical simple GUI applications (thus >satisfying "batteries included" IMO), and

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-09 Thread Michiel Jan Laurens de Hoon
Greg Ewing wrote: >I'm not sure the event-loop situation would be >much different with another one, anyway. From what >I've seen of GUI toolkits, they all have their own >form of event loop, and they all provide some way >of hooking other things into it (as does Tkinter), >but whichever one you're

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-09 Thread Stephen J. Turnbull
> "Michiel" == Michiel Jan Laurens de Hoon <[EMAIL PROTECTED]> writes: Michiel> What is the advantage of Tk in comparison to other GUI Michiel> toolkits? IMO, Tk's _advantage_ is that it's there already. As a standard component, it works well for typical simple GUI applications (thus

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-09 Thread Jean-Paul Calderone
On Thu, 10 Nov 2005 16:02:04 +1300, Greg Ewing <[EMAIL PROTECTED]> wrote: >Michiel Jan Laurens de Hoon wrote: > >> At this point, I can't propose a specific modification yet because I >> don't know the reasoning that went behind the original choice of Tk as >> the default GUI toolkit for Python > >

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-09 Thread Greg Ewing
Michiel Jan Laurens de Hoon wrote: > At this point, I can't propose a specific modification yet because I > don't know the reasoning that went behind the original choice of Tk as > the default GUI toolkit for Python Probably because at the time it was really the only cross-platform GUI toolkit

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-09 Thread Michiel Jan Laurens de Hoon
Martin v. Löwis wrote: > Michiel Jan Laurens de Hoon wrote: > >> 2) Will Tkinter always be the standard toolkit for Python, or are >> there plans to replace it at some point? > > > Python does not evolve along a grand master plan. Instead, individual > contributors propose specific modifications,

Re: [Python-Dev] Event loops, PyOS_InputHook, and Tkinter

2005-11-08 Thread Martin v. Löwis
Michiel Jan Laurens de Hoon wrote: > 1) Did I miss something? Is there some way to get an event loop with > Tkinter? Yes, and yes. You are missing multi-threading, which is the widely used approach to doing things simultaneously in a single process. In one thread, user interaction can occur; in a