On Sat, Jan 28, 2012 at 10:31 AM, Jerzy Karczmarczuk <
jerzy.karczmarc...@unicaen.fr> wrote:

>  Benjamin Root about my miserable event problem :
>
> Still not sure why my suggestion would not work:
>
>
> http://matplotlib.sourceforge.net/api/cbook_api.html#matplotlib.cbook.CallbackRegistry
>
>
> I thought I told you. Probably I am doing something utterly false, but my
> distilled problem is that* I am generating events from within a callback*.
> Here you are a complete skeleton program.
>
>
> from pylab import *
> from matplotlib.cbook import *
> from matplotlib.widgets import Button
> fig=figure()
> ax = fig.add_subplot(1,1,1)
> xis=axis([0,1,0,1])
> subplots_adjust(left=0.1, bottom=0.1)
> clrax = axes([0.67, 0.02, 0.08, 0.04])
> clbut = Button(clrax, 'Clear', color="1.0")
> goax = axes([0.88, 0.02, 0.08, 0.04])
> gobut = Button(goax, 'Go', color="#40ffa0")
> cbacks = CallbackRegistry()
>
> def line(*evt):
>     plot(rand(2),rand(2)) ; draw()
>     cbacks.process('line_', None)
>
> linv  = cbacks.connect('line_', line)
>
> def clr(ev=None): del ax.lines[:]
> clbut.on_clicked(clr)
> def start(evt): cbacks.process('line_', None)
> gobut.on_clicked(start)
>
> subplot(1,1,1)
> show()
>
> The function line() is the main iterative engine, a "loop" without
> looping. It should post an event which re-launches it, and still leaving
> the master loop active, so I can clear the figure.
>
> Nope. This is a *recursive call*.
> Python bombs after a while, recursive limit exceeded, and only then the
> Clear button wakes up.
>
> Thank you for your effort.
>
> Jerzy
>
>
Jerzy,

So, where is your terminating condition?  Of course it will continuously
call itself if you have nothing to stop it.  Protect that call to "process"
with some sort of if-statement and use "evt" to carry some sort of state
that can be tested in that if-statement.

For example, I modified your example to use "evt" to carry an integer.  The
call to process() is protected by an if-statement that checks to see if evt
is less than 10, and the call to process passes "evt + 1".  The initial
call to process passes a value of zero.  The program then produces 10
random lines just fine when I press "Go".

Does that help clear up your problem?

Ben Root
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to