From: Gael V. <gae...@no...> - 2008-01-30 02:05:26
|
Hi all, A while ago (a year or so), I was looking for a ginput-like function with matplotlib. For those who don't know what I am talking about, it is a blocking call that can be used in a script to ask the user to enter coordinnate by clicking on the figure. This is incredibly handy, as it allows some simple user interaction without worrying about events loop and Co. At the time I gave up on that. I have made progress with GUI and event loops, and a recent post on the matplotlib-user list put me back to work on this ( http://www.nabble.com/ginput-is-here%21-%28for-wx-anyway%29-to14960506.html ). I have a preliminary patch to add this feature to matplotlib that I attach. I add a method to the backend canvases, to be able to deal with event-loop-handling, and following Jack Gurkesaft I create my own a small event-loop to poll for events inside my function. This is a kludge, but it allows to block the function while still processing events. If you have better ideas. I have implemented the functionnality for all the interactive backends I could test (and thus not cocoa), but I am not too sure my gtk code is kosher, I wouldn't mind advice on this one. The code of ginput itself is currently in a seperate file (matplotlib.ginput, that you can run for a demo) because I wasn't too sure where to add it. This is a first version of the patch. I would like comments on it, especially where to add the code itself, and if the proposed additions to the backends look all right. Once I have comments, I plan to: * Make right click cancel an input * Allow infinite number of inputs, terminated by right-click * Add optional display of inputs * Rework docstrings More suggestions welcomed, This could (and should, IMHO) open the road to other blocking calls for user interaction, like the selection of a window, as they make life really easy for people wanting to hack quick data analysis scripts. Cheers, Gaël |