ROOT
v6-30
Reference Guide
Loading...
Searching...
No Matches
buttonChangelabel.C
Go to the documentation of this file.
1
/// \file
2
/// \ingroup tutorial_gui
3
/// This macro gives an example for changing text button labels anytime the Start or Pause buttons are clicked.
4
/// To run it do either:
5
/// ~~~
6
/// .x buttonChangelabel.C
7
/// .x buttonChangelabel.C++
8
/// ~~~
9
///
10
/// \macro_code
11
///
12
/// \author Ilka Antcheva 1/12/2006
13
14
#include <
TGClient.h
>
15
#include <
TGButton.h
>
16
#include <
TGFrame.h
>
17
18
class
MyMainFrame :
public
TGMainFrame
{
19
20
private
:
21
TGCompositeFrame
*fCframe;
22
TGTextButton
*fStart, *fPause, *fExit;
23
Bool_t
start
, pause;
24
25
public
:
26
MyMainFrame(
const
TGWindow
*
p
,
UInt_t
w
,
UInt_t
h
);
27
~MyMainFrame()
override
;
28
// slots
29
void
ChangeStartLabel();
30
void
ChangePauseLabel();
31
32
ClassDef
(MyMainFrame, 0)
33
};
34
35
void
MyMainFrame::ChangeStartLabel()
36
{
37
// Slot connected to the Clicked() signal.
38
// It will toggle labels "Start" and "Stop".
39
40
fStart->SetState(
kButtonDown
);
41
if
(!start) {
42
fStart->SetText(
"&Stop"
);
43
start
=
kTRUE
;
44
}
else
{
45
fStart->SetText(
"&Start"
);
46
start
=
kFALSE
;
47
}
48
fStart->SetState(
kButtonUp
);
49
}
50
51
void
MyMainFrame::ChangePauseLabel()
52
{
53
// Slot connected to the Clicked() signal.
54
// It will toggle labels "Resume" and "Pause".
55
56
fPause->SetState(
kButtonDown
);
57
if
(!pause) {
58
fPause->SetText(
"&Resume"
);
59
pause =
kTRUE
;
60
}
else
{
61
fPause->SetText(
"&Pause"
);
62
pause =
kFALSE
;
63
}
64
fPause->SetState(
kButtonUp
);
65
}
66
67
MyMainFrame::MyMainFrame(
const
TGWindow
*
p
,
UInt_t
w
,
UInt_t
h
) :
68
TGMainFrame
(
p
,
w
,
h
)
69
{
70
// Create a horizontal frame containing buttons
71
fCframe =
new
TGCompositeFrame
(
this
, 170, 20,
kHorizontalFrame
|
kFixedWidth
);
72
73
fStart =
new
TGTextButton
(fCframe,
"&Start"
);
74
fStart->Connect(
"Clicked()"
,
"MyMainFrame"
,
this
,
"ChangeStartLabel()"
);
75
fCframe->AddFrame(fStart,
new
TGLayoutHints
(
kLHintsTop
|
kLHintsExpandX
,
76
3, 2, 2, 2));
77
fStart->SetToolTipText(
"Click to toggle the button label (Start/Stop)"
);
78
start
=
kFALSE
;
79
80
fPause =
new
TGTextButton
(fCframe,
"&Pause"
);
81
fPause->Connect(
"Clicked()"
,
"MyMainFrame"
,
this
,
"ChangePauseLabel()"
);
82
fPause->SetToolTipText(
"Click to toggle the button label (Pause/Resume)"
);
83
fCframe->AddFrame(fPause,
new
TGLayoutHints
(
kLHintsTop
|
kLHintsExpandX
,
84
3, 2, 2, 2));
85
pause =
kFALSE
;
86
87
AddFrame(fCframe,
new
TGLayoutHints
(
kLHintsCenterX
, 2, 2, 5, 1));
88
89
fExit =
new
TGTextButton
(
this
,
"&Exit "
,
"gApplication->Terminate(0)"
);
90
AddFrame(fExit,
new
TGLayoutHints
(
kLHintsTop
|
kLHintsExpandX
,5,5,2,2));
91
92
SetWindowName(
"Change Labels"
);
93
94
MapSubwindows
();
95
Resize(GetDefaultSize());
96
MapWindow();
97
}
98
99
100
MyMainFrame::~MyMainFrame()
101
{
102
// Clean up all widgets, frames and layouthints that were used
103
fCframe->Cleanup();
104
Cleanup();
105
}
106
107
108
void
buttonChangelabel()
109
{
110
// Popup the GUI...
111
new
MyMainFrame(
gClient
->GetRoot(), 350, 80);
112
}
kFixedWidth
@ kFixedWidth
Definition
GuiTypes.h:387
kHorizontalFrame
@ kHorizontalFrame
Definition
GuiTypes.h:382
h
#define h(i)
Definition
RSha256.hxx:106
Bool_t
bool Bool_t
Definition
RtypesCore.h:63
UInt_t
unsigned int UInt_t
Definition
RtypesCore.h:46
kFALSE
constexpr Bool_t kFALSE
Definition
RtypesCore.h:101
kTRUE
constexpr Bool_t kTRUE
Definition
RtypesCore.h:100
ClassDef
#define ClassDef(name, id)
Definition
Rtypes.h:337
TGButton.h
kButtonDown
@ kButtonDown
Definition
TGButton.h:54
kButtonUp
@ kButtonUp
Definition
TGButton.h:53
TGClient.h
gClient
#define gClient
Definition
TGClient.h:157
TGFrame.h
kLHintsCenterX
@ kLHintsCenterX
Definition
TGLayout.h:25
kLHintsTop
@ kLHintsTop
Definition
TGLayout.h:27
kLHintsExpandX
@ kLHintsExpandX
Definition
TGLayout.h:30
w
winID w
Definition
TGWin32VirtualGLProxy.cxx:39
p
winID h TVirtualViewer3D TVirtualGLPainter p
Definition
TGWin32VirtualGLProxy.cxx:51
MapSubwindows
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize MapSubwindows
Definition
TGWin32VirtualXProxy.cxx:94
TGCompositeFrame
The base class for composite widgets (menu bars, list boxes, etc.).
Definition
TGFrame.h:287
TGLayoutHints
This class describes layout hints used by the layout classes.
Definition
TGLayout.h:50
TGMainFrame
Defines top level windows that interact with the system Window Manager.
Definition
TGFrame.h:397
TGTextButton
Yield an action as soon as it is clicked.
Definition
TGButton.h:142
TGWindow
ROOT GUI Window base class.
Definition
TGWindow.h:23
TMVA_SOFIE_GNN.start
start
Definition
TMVA_SOFIE_GNN.py:199
tutorials
gui
buttonChangelabel.C
ROOT v6-30 - Reference Guide Generated on Thu Dec 12 2024 06:12:39 (GVA Time) using Doxygen 1.9.8