On Fri, Jul 18, 2008 at 11:27:50AM +0200, David M. Kaplan wrote:
> Hi,
> 
> On Thu, 2008-07-17 at 16:55 -0400, Paul Kienzle wrote:
> >    FigureCanvasBase:
> >        def start_event_loop(self, ...): 
> >            raise NotImplemented
> >    FigureCanvasEventLoopMixin:
> >        def start_event_loop(self, ...):
> >            generic interactive using time.sleep
> >    MyInteractiveBackend(FigureCanvasBase,FigureCanvasEventLoopMixin):
> >        ... no start_event_loop since using the generic mixin ...
> > 
> 
> So just to make sure that I understand this, "MyInteractiveBackend"
> would be any backend canvas class for whom we want to implement the
> standard generic mixin.  For example, the class FigureCanvasGTK would
> inherit FigureCanvasEventLoopMixin until we get around to writing
> something specific for GTK.  On the other hand, FigureCanvasWx wouldn't
> inherit the mixin, but would use the WX specific code you sent
> yesterday.  And FigureCanvasPs wouldn't get anything at all.  Am I
> getting this?

Yes.

> If so, then I will go ahead and make the appropriate modifications.
> Looking at the list of backends, I think it suffices to inherit the
> mixin for the following backends: cairo, cocoagg, fltkagg?, gdk?, gtk,
> qt4, qt, tkagg (wx covered with its own code).  All other interactive
> backends should inherit from these.  The ones with the question marks I
> am not really sure about, but will assume true unless told otherwise.

$ grep -l button_press_event backends/*.py
backends/backend_cocoaagg.py
backends/backend_fltkagg.py
backends/backend_gtk.py
backends/backend_qt.py
backends/backend_qt4.py
backends/backend_template.py
backends/backend_tkagg.py
backends/backend_wx.py

> I agree with Gael that warning is probably sufficient.  This will allow
> code running in the background to pass over interactive commands such as
> ginput.  This may be better than an immediate error, but could cause
> problems later in the script when data is expected, but one gets [].

If exceptions aren't used, then non-interactive backends should
return [], and all calls to ginput should be checked:

  x = ginput(3,timeout=2)
  if len(x) < 3:
      print "ginput only returned %d inputs"%(len(x))

Since users aren't going to remember to do this, it is better to 
raise an exception so that they at least know later why their code 
is breaking.

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


-------------------------------------------------------------------------
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