Catching mouse events

I’d like to catch mouse cursor position in a canvas with pyROOT. I know how to do that with C++, but not sure how to in python. I modified gui_ex.py, adding a line in the class:

self.Canvas.GetCanvas().Connect("ProcessedEvent()", "TPyDispatcher", mc, "Dispatch()")

but python says:
Error in TQObject::CheckConnectArgs: signal TCanvas::ProcessedEvent() does not exist

what should I do?

OK, somehow I thought that functions given should be without parameters. They shouldn’t. The following is found in ROOT:

       self.Canvas.GetCanvas().Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)", "TPyDispatcher", mc, "Dispatch()")

However, crashes. I need to gain more understainding of how python handles those events…

Hi,

TPyDispatcher only has a limited set of methods that can be called: PyObject* Dispatch(); PyObject* Dispatch( const char* param ); PyObject* Dispatch( Double_t param ); PyObject* Dispatch( Long_t param ); PyObject* Dispatch( Long64_t param );
Adding a TPyDispatcher derived class (in C++), that calls TPyDispatcher::DispatchVA with the right format for the extra needed function, and using that (both that new class and that specific function in the Connect()), probably does the trick.

Underneath, it is CINT doing the lookups, which is why it needs the full function prototype to match the specific overload. In your example, a function taking arguments is now matched up with one that takes none.

Cheers,
Wim