Logo ROOT   6.07/09
Reference Guide
Namespaces
gui_ex.py File Reference

Namespaces

 gui_ex
 

Detailed Description

A Simple GUI Example.

1 
2 import os, sys, ROOT
3 
4 def pygaus( x, par ):
5  import math
6  if (par[2] != 0.0):
7  arg1 = (x[0]-par[1])/par[2]
8  arg2 = (0.01*0.39894228)/par[2]
9  arg3 = par[0]/(1+par[3])
10 
11  gauss = arg3*arg2*math.exp(-0.5*arg1*arg1)
12  else:
13  print 'returning 0'
14  gauss = 0.
15  return gauss
16 
17 tpygaus = ROOT.TF1( 'pygaus', pygaus, -4, 4, 4 )
18 tpygaus.SetParameters( 1., 0., 1. )
19 
20 def MyDraw():
21  btn = ROOT.BindObject( ROOT.gTQSender, ROOT.TGTextButton )
22  if btn.WidgetId() == 10:
23  global tpygaus, window
24  tpygaus.Draw()
25  ROOT.gPad.Update()
26 
27 m = ROOT.TPyDispatcher( MyDraw )
28 
29 
30 class pMainFrame( ROOT.TGMainFrame ):
31  def __init__( self, parent, width, height ):
32  ROOT.TGMainFrame.__init__( self, parent, width, height )
33 
34  self.Canvas = ROOT.TRootEmbeddedCanvas( 'Canvas', self, 200, 200 )
35  self.AddFrame( self.Canvas, ROOT.TGLayoutHints() )
36  self.ButtonsFrame = ROOT.TGHorizontalFrame( self, 200, 40 )
37 
38  self.DrawButton = ROOT.TGTextButton( self.ButtonsFrame, '&Draw', 10 )
39  self.DrawButton.Connect( 'Clicked()', "TPyDispatcher", m, 'Dispatch()' )
40  self.ButtonsFrame.AddFrame( self.DrawButton, ROOT.TGLayoutHints() )
41 
42  self.ExitButton = ROOT.TGTextButton( self.ButtonsFrame, '&Exit', 20 )
43  self.ExitButton.SetCommand( 'TPython::Exec( "raise SystemExit" )' )
44  self.ButtonsFrame.AddFrame( self.ExitButton, ROOT.TGLayoutHints() )
45 
46  self.AddFrame( self.ButtonsFrame, ROOT.TGLayoutHints() )
47 
48  self.SetWindowName( 'My first GUI' )
49  self.MapSubwindows()
50  self.Resize( self.GetDefaultSize() )
51  self.MapWindow()
52 
53  def __del__(self):
54  self.Cleanup()
55 
56 
57 if __name__ == '__main__':
58  window = pMainFrame( ROOT.gClient.GetRoot(), 200, 200 )
Author
Wim Lavrijsen

Definition in file gui_ex.py.