|
From: Andrea G. <and...@ti...> - 2006-02-04 11:15:05
|
Hello NG,
I was surfing over the matplotlib classes API, and I didn't find
anything about a way to connect an event like a mouse left double-click. Is
this actually possible? If this is not, is there a way to hack the
button_press_event handler in a way to discard the first click (maybe based
on a time.time() call?) and take only the second click if, say, less than 1
second is gone after the first click?
Thanks in advance for every idea.
Andrea.
"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77
|
|
From: Christopher B. <Chr...@no...> - 2006-02-06 19:50:27
|
Andrea, Are you using MPL with wxPython? I'd expect so. In which case, you can use it embedded, and have wx do the event handling. I really think that's the way to go. I'm not sure it's such a good idea for MPL to wrap GUI functionality, let's not try to build a yet another GUI toolkit -- that way lies AnyGUI, and that way lies madness! Make sure to check out wxmpl and/or Mplot: http://agni.phys.iit.edu/~kmcivor/wxmpl/ http://cars9.uchicago.edu/~newville/Python/MPlot/ By the way, unifying those two packages would be a great wxPython/MPL project, if you're looking for a new one! -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chr...@no... |
|
From: John H. <jdh...@ac...> - 2006-02-06 19:55:35
|
>>>>> "Christopher" == Christopher Barker <Chr...@no...> writes:
Christopher> Andrea, Are you using MPL with wxPython? I'd expect
Christopher> so.
Christopher> In which case, you can use it embedded, and have wx
Christopher> do the event handling. I really think that's the way
Christopher> to go. I'm not sure it's such a good idea for MPL to
Christopher> wrap GUI functionality, let's not try to build a yet
Christopher> another GUI toolkit -- that way lies AnyGUI, and that
Christopher> way lies madness!
and that way underlies the matplotlib toolbar, and matplotlib code
that you can share with others and have others contribute to!
Madness? Yes, but just crazy enough that it might work :-)
JDH
|
|
From: Andrea G. <and...@ti...> - 2006-02-06 20:03:20
|
Hello Chris, > Are you using MPL with wxPython? I'd expect so. Yes, I am using it with wxPython, and I am sometimes frustrated by the difficulty to find which method in matplotlib API does something that Pylab does with another syntax. > Make sure to check out wxmpl and/or Mplot: I have checked wxmpl, but it seems to me that it has the same mouse events as matplotlib has (button down/up/motion) and nothing more. Moreover, both matplotlib and wxmpl fail to get the mouse_down event if you click very fast on the figure canvas. I mean, I can click say 30 times in 10 seconds on the MPL canvas, but only 20 clicks get captured by the event. So it's quite difficult to hack the single mouse_down event to simulate the double-click because quite often MPL misses a mouse click... wxmpl suffers of the same desease, from my tests. So I ended up in a dirty hack of a MPL single mouse_down to transform it in a double-click, but quite often I have o click 3/4 times to get the double-click working. I don't think it's the slowness of my PCs, because they are quite fast. Thank you very much for your suggestions. Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.virgilio.it/infinity77 |
|
From: Christopher B. <Chr...@no...> - 2006-02-06 20:53:32
Attachments:
wxMplSample.py
|
Andrea Gavana wrote:
> I have checked wxmpl, but it seems to me that it has the same mouse events
> as matplotlib has (button down/up/motion) and nothing more.
wxmpl provides a subclass of wxPanel, so it's there somewhere. I haven't
done mouse events, so I I don't know where yet. I do think wxmpl could
use some more work.
> matplotlib and wxmpl fail to get the mouse_down event if you click very fast
> on the figure canvas.
I'm guessing that what's happening is that the two mouse clicks close
together are getting caught as a double-click, so the second one doesn't
show up as a single click.
> So I ended up in a dirty
> hack of a MPL single mouse_down to transform it in a double-click,
ugh. I'd poke around more in the wxmpl code. Maybe I'll do that myself.
OK-- I started doing that, but first I just tried binding a event to a
wxmpl.PlotPanel, and it works fine. I've enclosed a little sample. It
should write to the console when you left, right or double-left click on
the PlotPanel.
Note that when you double click, you get one left click event and one
double click event, but not two left click events.
Of course, you'll now need to figure out how to query the FigureCanvas
to see what the axes coords are, but I'm sure you can find code on MPL
that will give you hints.
By the way, you could hack backend_wx.py to add the double click events,
but that would be ugly if it wasn't added everywhere else in MPL --
which is kind of why I think that way lies madness ;-)
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chr...@no...
|
|
From: Andrea G. <and...@ti...> - 2006-02-06 21:09:00
|
Thanks a bunch Chris, it really helps... however I have just hacked a little bit backend_wx.py and backend_bases.py to include a mouse double click. For the moment it's working like a charm. Let's cross the fingers ;-) BTW, I didn't receive any answer on this thread: http://sourceforge.net/mailarchive/forum.php?thread_id=9639992&forum_id=33405 Do you happen to have some suggestion on how to solve this issue? Thank you very much for your help. Andrea. "Imagination Is The Only Weapon In The War Against Reality." http://xoomer.virgilio.it/infinity77 |
|
From: Christopher B. <Chr...@no...> - 2006-02-06 23:13:25
|
Andrea Gavana wrote: > Thanks a bunch Chris, it really helps... No problem. > bit backend_wx.py and backend_bases.py to include a mouse double click. For > the moment it's working like a charm. Let's cross the fingers ;-) Make sure you send the patch to John or matplotlib-devel, it might make sense to add teh double click events to all the back-ends. > BTW, I didn't receive any answer on this thread: > > http://sourceforge.net/mailarchive/forum.php?thread_id=9639992&forum_id=33405 > > Do you happen to have some suggestion on how to solve this issue? well, no. but the first thing I'd do is make a wx-free script that used the OO interface. That keeps the embedded in wx stuff out of it, and it it doesn't work you can have a simple example to send to the group to get help. OK. I've done some of that. first your first problem. There is a bug in axes.tick_right. Here's a script: #!/usr/bin/env python import pylab import matplotlib.numerix as N Fig = pylab.figure() ax2 = Fig.add_subplot(111) ax2.yaxis.tick_right() ax2.yaxis.set_label_position('right') t = N.arange(0.01, 10.0, 0.01) s1 = N.exp(t) ax2.plot(t, s1, 'b-') ax2.set_xlabel('time (s)') ax2.set_ylabel('exp') pylab.show() -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chr...@no... |
|
From: Christopher B. <Chr...@no...> - 2006-02-06 23:24:07
Attachments:
wxMplTwinx.py
|
Andrea Gavana wrote: > BTW, I didn't receive any answer on this thread: > > http://sourceforge.net/mailarchive/forum.php?thread_id=9639992&forum_id=33405 > > Do you happen to have some suggestion on how to solve this issue? Well, you got me curious, so what I did was start by writing an OO version of the script that worked: #!/usr/bin/env python import matplotlib, pylab import matplotlib.numerix as N Fig = pylab.figure() ax1 = Fig.add_subplot(111) t = N.arange(0.01, 10.0, 0.01) s2 = N.sin(2*N.pi*t) ax1.plot(t, s2, 'r.') ax1.set_ylabel('sin') #Create second axes with ticks on right # code adapted from pylab.twinx ax2 = Fig.add_axes(ax1.get_position(), sharex=ax1, frameon=False) ax2.yaxis.tick_right() ax2.yaxis.set_label_position('right') s1 = N.exp(t) ax2.plot(t, s1, 'b-') ax2.set_xlabel('time (s)') ax2.set_ylabel('exp') pylab.show() Then I put it in my simple wxmpl example. It works. I've enclosed that. You need to click the "plot" button to make it plot. -Chris -- Christopher Barker, Ph.D. Oceanographer NOAA/OR&R/HAZMAT (206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception Chr...@no... |