Re: [Matplotlib-users] stuck after a mpl_connect - how to disconnect and go on
Hi thanks a lot for this feedback! Your example is quite nice indeed. However there is something I may not have fully understand. If I use the example you sketch, I of course need to call the displayer class (right?), by doing something like: test = displayer() However, then I hit the same problem again: I would need to define ALL the commands I wish to go through WITHIN the displayer class (and more precisely into the show_next function), because any command put after the test = displayer() would be executed anyway without waiting that I finally hit the right mouse button. Or is there something I didn't catch which would allow me to go around this? (what my program is supposed to do at the end is to go through a series of (3xdataframes), and for each dataframe in turn, use the offset trick, then reinitialise everything and start with the next series... This seems to imply that I need to specify the full set of commands within the displayer class show_next function) thanks again Eric - 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
Re: [Matplotlib-users] stuck after a mpl_connect - how to disconnect and go on
Hi Eric, On 23/08/07, Eric Emsellem [EMAIL PROTECTED] wrote: thanks a lot for this feedback! Your example is quite nice indeed. However there is something I may not have fully understand. If I use the example you sketch, I of course need to call the displayer class (right?), by doing something like: test = displayer() However, then I hit the same problem again: I would need to define ALL the commands I wish to go through WITHIN the displayer class (and more precisely into the show_next function), because any command put after the test = displayer() would be executed anyway without waiting that I finally hit the right mouse button. I'm not sure why this is a problem. Yes, you need to put all your code into the callback routines of displayer, but just think of it as wrapping your program code inside the class. Your __main__ code then simply becomes test = displayer()... and away you go. Also, I realised shortly after sending my email that you can of course do away with the offset class in this example, and put those methods into the displayer class too, which will make things a little simpler. Or is there something I didn't catch which would allow me to go around this? (what my program is supposed to do at the end is to go through a series of (3xdataframes), and for each dataframe in turn, use the offset trick, then reinitialise everything and start with the next series... This seems to imply that I need to specify the full set of commands within the displayer class show_next function) thanks again Eric 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
[Matplotlib-users] stuck after a mpl_connect - how to disconnect and go on
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. Eric #= # stupid simple code just to illustrate the kind of things I would like to achieve # This does not work and just hang there... #= import numpy as num class offset: def __init__(self) : self.xc = 0. self.yc = 0. self.stay = 1 def on_click(self, event) : if event.button == 1: if event.inaxes is not None: self.xc += event.xdata self.yc += event.ydata elif event.button == 3: self.stay = 0 data1 = num.random.rand(10,10) data2 = num.random.rand(10,10) data3 = num.random.rand(10,10) alldata = [data1, data2, data3] for i in range(len(alldata)) : imshow(alldata[i]) newoffset = offset() binding = connect('button_press_event', newoffset.on_click) while newoffset.stay : pass disconnect(binding) print newoffset.xc, newoffset.yc - 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
Re: [Matplotlib-users] stuck after a mpl_connect - how to disconnect and go on
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
Re: [Matplotlib-users] stuck after a mpl_connect - how to disconnect and go on
On 8/22/07, Angus McMorland [EMAIL PROTECTED] wrote: 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. Angus is right w/ resepct to mpl -- we don't have any support for blocking calls. This is a very frequent request and you are certainly right Eric to *expect* something like this to work, but in the context of multiple GUIs w/ threads it is not too easy. One could probably make tkagg work with only minor modifications to mpl, but the other GUIs would be harder becasue they are threaded. So using event handling and callbacks are the way to solve this problem, as Angus suggests in his solution, but they are harder for people to get their head around than blocking calls, so hopefully we will get support for this idiom before the end of time. JDH - 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