Hi,

On Fri, 2008-07-18 at 11:52 -0400, Paul Kienzle wrote:
> If exceptions aren't used, then non-interactive backends should
> return []
> 

I think I have changed my mind on this one - an error seems more
appropriate.  The real-world use cases for this are (1) someone doesn't
realize they are in a non-user-interface backend and runs ginput and (2)
someone is running in the background a script that contains interactive
elements.  In both cases, using these functions is almost certainly an
error on the users side and it is impossible to decide what the user
would like to have returned in this case.  If the user really wants
potentially non-interactive run of the code, he could use try, except to
deal with that.

> The current code has another problem in that timeouts will return
> a partial list.  This could be handle by raising RuntimeError in
> ginput:
> 
>   class BlockingInput:
>     ...
>     def __call__(...):
>         ...
>         if n > 0 and len(self.clicks) < n:
>             raise RuntimeError("Timeout when selecting inputs")
>         return self.clicks
> 
> If you want to get fancy and return the partial list of clicks, 
> this can be done with our own exception class:
> 
>   --blocking_input.py--
>   class InputError(Exception):
>     def __init__(self, message, points):
>         self.message = message
>         self.points = points
>   class BlockingInput:
>     ...
>     def __call__(...):
>         ...
>         if n > 0 and len(self.clicks) < n:
>             raise InputError("Not enough inputs",self.clicks)
>         return self.clicks
> 
> Importing an extra symbol to catch the error would be ugly.  I 
> suggest hiding it in the functions that need it instead:
> 
>   --pyplot.py--
>   def ginput(*args, **kwargs):
>     ...
>   ginput.InputError = matplotlib.blocking_input.InputError
> 
> This allows the pylab user to write:
> 
>   try:
>     x = ginput(3,timeout=2)
>   except ginput.InputError,e:
>     print "ginput only returned %d inputs"%(len(e.points))
> 
> - Paul
> 

For ginput, there are a number of ways that an impartial list could be
returned and this is often a desired outcome (for example, I often
decide after the fact that I want fewer points than I initially
thought).  Perhaps as a compromise we could set the default timeout to
-1 so the user needs to actually choose a timeout (presumably indicating
he/she accepts the consequences).  But allowing the user to manually
decide to select fewer points using the second mouse button has proved
quite useful to me and the user would still need to test in this case.
We could warn if not enough points are returned, but an error seems too
much to me. 

Cheers,
David

-- 
**********************************
David M. Kaplan
Charge de Recherche 1
Institut de Recherche pour le Developpement
Centre de Recherche Halieutique Mediterraneenne et Tropicale
av. Jean Monnet
B.P. 171
34203 Sete cedex
France

Phone: +33 (0)4 99 57 32 27
Fax: +33 (0)4 99 57 32 95
http://www.ur097.ird.fr/team/dkaplan/index.html
**********************************



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to