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