wxmpl, PlotPanel and connecting mpl events...

Hi,

I'm building a simple wxpython + matplotlib application using wxmpl (no pylab).

I'm currently trying to get X and Y coordinates of a point I click inside a graph plotted in a PlotPanel.
So I'm trying to connect the PlotPanel to a button_press_event. The problem is it fails silently. No error, but it seems that the connected function is never called and even that the connecting itself never happens.

My hypothesis: I see that the PlotPanel has default zooming when selecting a box with the mouse, so I think it is already connected with button_press_event? should I disconnect? how (what's the id)? Should I use something different from PlotPanel?

···

-------------------
Here are relevant code snippets:

class MainWindow(wx.Frame):
         def __init__(self,parent,id,title):
wx.Frame.__init__(self,parent,ID_FRAME,title,size=(800,600),style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)

             self.control=wxmpl.PlotPanel(self,1)

[Then, if I send the right wxpython event (I want my plot giving me coordinates only when I say the gui to do it), I call ClickPlot, that should turn on the connection between the mpl event 'button_press_event' and another function, for my PlotPanel.]

def ClickPlot(self,event):
      #test code
      print 'you're calling ClickPlot()'
             def click_me(mpl_event):
    #test code
                 print 'you click me!'
                 if mpl_event.inaxes:
                     print 'in axes too!'
               
    disconnect_id=self.control.mpl_connect('button_press_event',click_me)

--------------------------

I checked and ClickPlot() is called, but as said before, click_me() is not. Any idea? What could I do to figure out what's (not) happening?

Thanks,
Massimo

--
Massimo Sandal
University of Bologna
Department of Biochemistry "G.Moruzzi"

snail mail:
Via Irnerio 48, 40126 Bologna, Italy

email:
massimo.sandal@...898...

tel: +39-051-2094388
fax: +39-051-2094387

Further little testing I forgot...

Printing disconnect_id gives me an id, so there is an answer from self.control.mpl_connect() ...

I also tested with 'key_press_event' to see if the mouse events were the problem, but no luck...

m.

···

--
Massimo Sandal
University of Bologna
Department of Biochemistry "G.Moruzzi"

snail mail:
Via Irnerio 48, 40126 Bologna, Italy

email:
massimo.sandal@...898...

tel: +39-051-2094388
fax: +39-051-2094387

Massimo,

Sorry for the slow reply. I seem to be perpetually behind in my mailing list reading.

For better or for worse, WxMpl currently eschews the Matplotlib event API and expects developers to use the wxPython event API [1]. However, there is a PointEvent which is emitted when the user left-clicks on an axes. I have attached a demonstration script which uses this event to draw a scatter plot of user selected points. Please let me know if you have any other questions.

Ken

pointevent.py (2.22 KB)