Logo ROOT  
Reference Guide
numberEntry.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_gui
3 /// This macro gives an example of how to create a number entry and how to update a label according to the changed value of this number entry.
4 /// To run it do either:
5 /// ~~~
6 /// .x numberEntry.C
7 /// .x numberEntry.C++
8 /// ~~~
9 ///
10 /// \macro_code
11 ///
12 /// \author Ilka Antcheva 1/12/2006
13 
14 #include <TApplication.h>
15 #include <TGClient.h>
16 #include <TGButton.h>
17 #include <TGFrame.h>
18 #include <TGLayout.h>
19 #include <TGWindow.h>
20 #include <TGLabel.h>
21 #include <TGNumberEntry.h>
22 #include <TString.h>
23 
24 class MyMainFrame : public TGMainFrame {
25 
26 private:
27  TGCompositeFrame *fHor1;
28  TGTextButton *fExit;
29  TGGroupFrame *fGframe;
30  TGNumberEntry *fNumber;
31  TGLabel *fLabel;
32 
33 public:
34  MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
35  virtual ~MyMainFrame();
36  void DoSetlabel();
37 
38  ClassDef(MyMainFrame, 0)
39 };
40 
41 MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h)
42  : TGMainFrame(p, w, h)
43 {
44 
45  fHor1 = new TGHorizontalFrame(this, 60, 20, kFixedWidth);
46  fExit = new TGTextButton(fHor1, "&Exit", "gApplication->Terminate(0)");
47  fHor1->AddFrame(fExit, new TGLayoutHints(kLHintsTop | kLHintsLeft |
48  kLHintsExpandX, 4, 4, 4, 4));
49  AddFrame(fHor1,new TGLayoutHints(kLHintsBottom | kLHintsRight, 2, 2, 5, 1));
50 
51  fNumber = new TGNumberEntry(this, 0, 9,999, TGNumberFormat::kNESInteger,
54  0, 99999);
55  fNumber->Connect("ValueSet(Long_t)", "MyMainFrame", this, "DoSetlabel()");
56  (fNumber->GetNumberEntry())->Connect("ReturnPressed()", "MyMainFrame", this,
57  "DoSetlabel()");
58  AddFrame(fNumber, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5));
59  fGframe = new TGGroupFrame(this, "Value");
60  fLabel = new TGLabel(fGframe, "No input.");
61  fGframe->AddFrame(fLabel, new TGLayoutHints(kLHintsTop | kLHintsLeft,
62  5, 5, 5, 5));
63  AddFrame(fGframe, new TGLayoutHints(kLHintsExpandX, 2, 2, 1, 1));
64 
65  SetCleanup(kDeepCleanup);
66  SetWindowName("Number Entry");
67  MapSubwindows();
68  Resize(GetDefaultSize());
69  MapWindow();
70 }
71 
72 MyMainFrame::~MyMainFrame()
73 {
74  // Destructor.
75 
76  Cleanup();
77 }
78 
79 void MyMainFrame::DoSetlabel()
80 {
81  // Slot method connected to the ValueSet(Long_t) signal.
82  // It displays the value set in TGNumberEntry widget.
83 
84  fLabel->SetText(Form("%ld",fNumber->GetNumberEntry()->GetIntNumber()));
85 
86  // Parent frame Layout() method will redraw the label showing the new value.
87  fGframe->Layout();
88 }
89 
90 void numberEntry()
91 {
92  new MyMainFrame(gClient->GetRoot(), 50, 50);
93 }
TGWindow
Definition: TGWindow.h:31
kFixedWidth
@ kFixedWidth
Definition: GuiTypes.h:387
TGNumberFormat::kNELLimitMinMax
@ kNELLimitMinMax
Definition: TGNumberEntry.h:59
TGMainFrame
Definition: TGFrame.h:443
kLHintsTop
@ kLHintsTop
Definition: TGLayout.h:34
TGLayout.h
Form
char * Form(const char *fmt,...)
kLHintsLeft
@ kLHintsLeft
Definition: TGLayout.h:31
TGLabel
Definition: TGLabel.h:32
TGTextButton
Definition: TGButton.h:142
TGNumberFormat::kNEANonNegative
@ kNEANonNegative
Definition: TGNumberEntry.h:51
TGHorizontalFrame
Definition: TGFrame.h:422
TString.h
TGWindow.h
gClient
#define gClient
Definition: TGClient.h:166
kLHintsBottom
@ kLHintsBottom
Definition: TGLayout.h:36
TApplication.h
h
#define h(i)
Definition: RSha256.hxx:106
TGFrame.h
kLHintsRight
@ kLHintsRight
Definition: TGLayout.h:33
TGLayoutHints
Definition: TGLayout.h:57
TGGroupFrame
Definition: TGFrame.h:586
UInt_t
unsigned int UInt_t
Definition: RtypesCore.h:46
TGClient.h
TGLabel.h
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
TGButton.h
kDeepCleanup
@ kDeepCleanup
Definition: TGFrame.h:50
numberEntry
Definition: numberEntry.py:1
TGNumberEntry.h
kLHintsExpandX
@ kLHintsExpandX
Definition: TGLayout.h:37
TGNumberEntry
Definition: TGNumberEntry.h:157
TGCompositeFrame
Definition: TGFrame.h:323
TGNumberFormat::kNESInteger
@ kNESInteger
Definition: TGNumberEntry.h:34