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