Hi Eric, On 23/08/07, Eric Emsellem <[EMAIL PROTECTED]> wrote: > Hi > > sorry to post this again but all my attempts to solve the matplotlib > problem below failed and I desperately need this to progress. > > I would like to use mpl_connect and disconnect to examine a series of 2d > arrays in turn (with a "for" loop), one after the other: > > ==> at each iteration I'd like to be able to use the left mouse button > to evaluate the sum of all x,y coordinates I select by (right) clicking > somewhere in the present array, and then switch to the next 2d data > array after I hit the right mouse button (button==3). I have no clue how > to do this and the program I wrote so far is just hanging there and does > nothing. Didn't see anything like this in the archive. > > Any way to get out of this? Thanks for your help.
As a general rule of thumb, if you're using a loop like while newoffset.stay: pass, then you're doing something wrong. This will take control of all execution and let nothing else happen. You have to do the control by switching between functions. Here's a modification to your code that I think does what you want: import numpy as n import pylab as p class offset: def __init__(self, parent) : self.parent = parent self.xc = 0. self.yc = 0. self.stay = 1 def on_click(self, event) : if event.button == 1: if event.inaxes is not None: print "Adding point %d, %d" % (event.xdata, event.ydata) self.xc += event.xdata self.yc += event.ydata elif event.button == 3: print "Switching data" self.parent.show_next() class displayer: def __init__(self): self.i = 0 self.alldata = [n.random.rand(10,10) for x in xrange(3)] self.newoffset = offset(self) self.binding = p.connect('button_press_event', self.newoffset.on_click) self.show_next() def show_next(self): if self.i < len(self.alldata): p.imshow(self.alldata[self.i]) self.i += 1 else: p.disconnect(self.binding) print self.newoffset.xc, self.newoffset.yc I hope that helps you see the concept. Angus. -- AJC McMorland, PhD Student Physiology, University of Auckland ------------------------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/ _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users