Signals / Slots

Hi all,

could somebody provide an example of how to connect to signals from PyROOT in cases where there is an additional parameter (e.g. TGScrollBar::PositionChanged(Int_t) ) ? Looking at TPyDispatcher::Dispatch(), it seems to me that it is prepared to handle such cases, but I can’t figure out how to pass the format parameter…

Thanks in advance,

Norbert

Norbert,

sorry, I can’t figure it out either. Best I can come up with, is to add a helper class with ACLiC. E.g. in a file MyDispatcher.C:[code]#include “TPyDispatcher.h”

class MyDispatcher {
public:
MyDispatcher( const TPyDispatcher& pd ) : fDispatcher( pd ) {}

PyObject* Dispatch( Int_t i ) {
return fDispatcher.Dispatch( “l”, i );
}

private:
TPyDispatcher fDispatcher;
};[/code]
and then in the python code:ROOT.gROOT.LoadMacro( "MyDispatcher.C+" ) m = ROOT.MyDispatcher( ROOT.TPyDispatcher( MySlider ) )
where ‘MySlider’ is a free function (callable) that takes a single parameter (the int), and it is connected for example. with:self.Slider.Connect( 'PositionChanged(Int_t)', "MyDispatcher", s, 'Dispatch(Int_t)' )
There are a couple of issues that prevent the ellipsis from working the way I expected: the way overload selection is done, and the fact that most of the basic types have been written out in full individual Emit() overloads in TQObject.

The best thing to do (for me) is to add these specific overloads to TPyDispatcher, and forward the calls to Dispatch() as above, but that then won’t be available until 5.20.

Cheers,
Wim

P.S. An uglier, but shorter, version is to have MyDispatcher.C like:struct MyDispatcher { PyObject* Dispatch( Int_t i ) { return (reinterpret_cast< TPyDispatcher* >(this))->Dispatch( "l", i ); } };
then load it as a macro (no ‘+’ that triggers ACLiC in gROOT.LoadMacro). Then you only need to specify “MyDispatcher” for the class name in Connect (as above), but you can use the TPyDispatcher instance directly as the receiver (the actual “this” delivered to MyDispatcher::Dispatch will be the TPyDIspatcher, so the reinterpret_cast works fine).

Wim,

thanks for looking into this. I will use the workaround you suggested, and wait for version 5.20 .

Norbert