Sgnal/slots trouble

Hi Rooters

i am trying to create sgnal/slots with pyroot but havaing a lot of trouble. Basically, I am trying to do the same example than the root/tutorials/gui/numberEntry.C but in Python, and when I try to make the connections, it says:

Error in TQObject::CheckConnectArgs: slot DoSetlabel() does not exist

However, my main frame inherits from TGMainFrame (python inheritance…). I couldn’t find a pyroot tutorial on the topic although there are for GUI.

Thanks

I am using Root 5.21/06 with gcc 4.3.1 on a linux box.

Matthieu,

to use signal/slots with python, there is the trouble of inheritance and dictionaries from the python side. To work around that, the TPyDispatcher object should be used. The translated numberEntry.C (i.e. numberEntry.py) follows:

[code]#####
from ROOT import *

class pMyMainFrame( TGMainFrame ):
def init( self, parent, width, height ):
TGMainFrame.init( self, parent, width, height )

  self.fHor1 = TGHorizontalFrame( self, 60, 20, kFixedWidth )
  self.fExit = TGTextButton( self.fHor1, "&Exit", "gApplication->Terminate(0)" )
  self.fExit.SetCommand( 'TPython::Exec( "raise SystemExit" )' )
  self.fHor1.AddFrame( self.fExit, TGLayoutHints( kLHintsTop | kLHintsLeft | 
                                                  kLHintsExpandX, 4, 4, 4, 4 ) )
  self.AddFrame( self.fHor1, TGLayoutHints( kLHintsBottom | kLHintsRight, 2, 2, 5, 1 ) )

  self.fNumber = TGNumberEntry( self, 0, 9,999, TGNumberFormat.kNESInteger,
                                           TGNumberFormat.kNEANonNegative, 
                                           TGNumberFormat.kNELLimitMinMax,
                                           0, 99999 )
  self.fLabelDispatch = TPyDispatcher( self.DoSetlabel )
  self.fNumber.Connect(
     "ValueSet(Long_t)", "TPyDispatcher", self.fLabelDispatch, "Dispatch()" )
  self.fNumber.GetNumberEntry().Connect(
     "ReturnPressed()", "TPyDispatcher", self.fLabelDispatch, "Dispatch()" )
  self.AddFrame( self.fNumber, TGLayoutHints( kLHintsTop | kLHintsLeft, 5, 5, 5, 5 ) )
  self.fGframe = TGGroupFrame( self, "Value" )
  self.fLabel = TGLabel( self.fGframe, "No input." )
  self.fGframe.AddFrame( self.fLabel, TGLayoutHints( kLHintsTop | kLHintsLeft, 5, 5, 5, 5) )
  self.AddFrame( self.fGframe, TGLayoutHints( kLHintsExpandX, 2, 2, 1, 1 ) )

  self.SetCleanup( kDeepCleanup )
  self.SetWindowName( "Number Entry" )
  self.MapSubwindows()
  self.Resize( self.GetDefaultSize() )
  self.MapWindow()

def del( self ):
self.Cleanup()

def DoSetlabel( self ):
self.fLabel.SetText( Form( “%d” % self.fNumber.GetNumberEntry().GetIntNumber() ) )
self.fGframe.Layout()

if name == ‘main’:
window = pMyMainFrame( gClient.GetRoot(), 50, 50 )
#####[/code]

I’ll throw it under tutorials/pyroot.

Cheers,
Wim

Hi Wim

Thanks for your answer. To add this information int the tutorials would be most useful. Also can you add conversion type? For instance, to be able to use Double_t* in C++ interface (C-array), the equivalent in python is “array”. I discovered this reading python examples, but it was not obvious (I used first a python “list”). To add this information int the ROOT manual would be useful.

Thanks