On Sat, Jan 28, 2012 at 10:31 AM, Jerzy Karczmarczuk <jerzy.karczmarczuk@unicaen.fr> wrote:
Benjamin Root about my miserable event problem : 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
ax = fig.add_subplot(1,1,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[:]
def start(evt): cbacks.process('line_', None)

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.



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