Here is a simple (but complete) example, and in Python!
:
[code]from ROOT import *
def PrintMessage( event ):
if event.fType == kGKeyPress:
print “PrintMessage() : key pressed!”
m = TPyDispatcher( PrintMessage )
class pMainFrame( TGMainFrame ):
def init( self, parent, width, height ):
TGMainFrame.init( self, parent, width, height )
self.fButton = TGTextButton( self, 'E&xit Application', 10 )
self.AddFrame( self.fButton, TGLayoutHints( kLHintsExpandX | kLHintsCenterY, 20, 20, 20, 20) )
self.fQuitDispatch = TPyDispatcher( self.quit )
self.fButton.Connect( 'Clicked()', 'TPyDispatcher', self.fQuitDispatch, 'Dispatch()' )
self.fTextEntry = TGTextEntry( self, '' , 50)
self.AddFrame( self.fTextEntry, TGLayoutHints( kLHintsExpandX | kLHintsCenterY, 20, 20, 20, 20) )
self.AddInput( kKeyPressMask )
gVirtualX.GrabKey(self.GetId(), gVirtualX.KeysymToKeycode(kKey_F3), kKeyControlMask, 1 )
self.fEventDispatch = TPyDispatcher( self.EventSlot )
self.Connect( 'ProcessedEvent(Event_t*)', 'TPyDispatcher', self.fEventDispatch, 'Dispatch(Event_t*)' )
self.Connect( 'ProcessedEvent(Event_t*)', 'TPyDispatcher', m, 'Dispatch(Event_t*)' )
self.MapSubwindows()
self.Layout()
self.MapWindow()
self.Resize(150,100)
def del( self ):
self.Cleanup()
def HandleKey( self, event ):
print “pMainFrame::HandleKey() : key pressed!”
def EventSlot( self, event ):
if event.fType == kGKeyPress:
print “pMainFrame::EventSlot() : key pressed!”
def quit(self):
print 'Bye bye…'
self.CloseWindow()
gApplication.Terminate()
exit()
if name == ‘main’:
window = pMainFrame( gClient.GetRoot(), 200, 200 )
[/code]
Cheers, Bertrand.