KaliVeda  1.12/06
Heavy-Ion Analysis Toolkit
KVNameValueListGUI.cpp
Go to the documentation of this file.
1 //Created by KVClassFactory on Fri Feb 17 09:32:40 2017
2 //Author: John Frankland,,,
3 
4 #include "KVNameValueListGUI.h"
5 
6 #include <TGLabel.h>
7 #include <TGNumberEntry.h>
8 #include <TGTextEntry.h>
9 #include "TTimer.h"
10 #include "TMath.h"
11 
13 
14 
15 
18 {
19  TGTextEntry* text = new TGTextEntry(hf, theList->GetStringValue(i));
20  max_width = TMath::Max(max_width, text->GetDefaultWidth() + 10);
21  text->Resize(text->GetDefaultWidth(), text->GetDefaultHeight());
22  hf->AddFrame(text, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 3, 2, 1, 1));
23  return text;
24 }
25 
26 
27 
29 
31 {
32  TGCheckButton* but = new TGCheckButton(hf);
33  but->Resize(but->GetDefaultWidth(), 10);
34  hf->AddFrame(but, new TGLayoutHints(kLHintsTop | kLHintsCenterX | kLHintsExpandX, 3, 2, 1, 1));
36  return but;
37 }
38 
39 
40 
42 
44 {
45  TGNumberEntry* num = new TGNumberEntry(hf, theList->GetDoubleValue(i), 10, -1,
50  num->Resize(num->GetDefaultWidth(), num->GetDefaultHeight());
51  hf->AddFrame(num, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 3, 2, 1, 1));
52  return num;
53 }
54 
55 
56 
58 
60 {
61  TGNumberEntry* num = new TGNumberEntry(hf, theList->GetDoubleValue(i), 10, -1,
66  num->Resize(num->GetDefaultWidth(), num->GetDefaultHeight());
67  hf->AddFrame(num, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX, 3, 2, 1, 1));
68  return num;
69 }
70 
71 
72 
74 
76 {
77  for (int i = 0; i < theList->GetNpar(); ++i) {
79  if (par->IsDouble()) {
80  par->Set(dynamic_cast<TGNumberEntry*>(fData[i])->GetNumber());
81  }
82  else if (par->IsInt()) {
83  par->Set((Int_t)dynamic_cast<TGNumberEntry*>(fData[i])->GetNumber());
84  }
85  else if (par->IsString()) {
86  par->Set(dynamic_cast<TGTextEntry*>(fData[i])->GetText());
87  }
88  else if (par->IsBool()) {
89  par->Set(dynamic_cast<TGCheckButton*>(fData[i])->IsDown());
90  }
91  }
92 }
93 
94 
95 
98 
100 {
101  // return all values to original state
103  *fCancel = kTRUE;
104 }
105 
106 
107 
110 
111 KVNameValueListGUI::KVNameValueListGUI(const TGWindow* main, KVNameValueList* params, Bool_t* cancel_pressed, Bool_t wait_for_main)
112  : fData(params->GetNpar())
113 {
114  // Constructor
115  fMain = new TGTransientFrame(gClient->GetDefaultRoot(), main, 1, 1, kVerticalFrame);
117  fMain->Connect("CloseWindow()", "KVNameValueListGUI", this, "DoClose()");
118  fMain->DontCallClose(); // to avoid double deletions.
119  // use hierarchical cleaning
121 
122  fCancel = cancel_pressed;
123  *fCancel = kFALSE;
124 
125  // SET UP GUI
126  theList = params;
127  theList->Copy(fOriginal); // copy original values in case "Cancel" is pressed
128  // for each name-value pair, add a horizontal frame with a label (name)
129  // and a text entry box (value)
131  max_width = 1;
132  for (Int_t i = 0; i < nentries; ++i) {
134  TGLabel* lab = new TGLabel(hf, theList->GetNameAt(i));
136  lab->Resize(lab->GetDefaultWidth(), lab->GetDefaultHeight());
137  hf->AddFrame(lab, new TGLayoutHints(kLHintsCenterY | kLHintsLeft | kLHintsExpandX, 2, 3, 1, 1));
138 
139  if (theList->GetParameter(i)->IsInt()) {
140  fData[i] = AddAInt(i, hf);
141  }
142  else if (theList->GetParameter(i)->IsDouble()) {
143  fData[i] = AddADouble(i, hf);
144  }
145  else if (theList->GetParameter(i)->IsBool()) {
146  fData[i] = AddABool(i, hf);
147  }
148  else {
149  fData[i] = AddAString(i, hf);
150  }
151 
152  fMain->AddFrame(hf, new TGLayoutHints(kLHintsTop | kLHintsExpandX, 1, 1, 1, 1));
153  }
154 
155  //--- create the OK, Apply and Cancel buttons
156 
157  UInt_t width = max_width * 2, height = 0;
158 
160 
161  fOKBut = new TGTextButton(hf, "&OK", 1);
162  hf->AddFrame(fOKBut, new TGLayoutHints(kLHintsCenterY | kLHintsExpandX, 2, 3, 0, 0));
163  height = fOKBut->GetDefaultHeight();
164  fOKBut->SetToolTipText("Save changes and close");
165  fOKBut->Resize(max_width, height);
166  fOKBut->Connect("Clicked()", "KVNameValueListGUI", this, "ReadData()");
167  fOKBut->Connect("Clicked()", "KVNameValueListGUI", this, "DoClose()");
168 
169  fCancelBut = new TGTextButton(hf, "&Cancel", 3);
171  fCancelBut->Resize(max_width, height);
172  fCancelBut->SetToolTipText("Discard changes and close");
173  fCancelBut->Connect("Clicked()", "KVNameValueListGUI", this, "RestoreData()");
174  fCancelBut->Connect("Clicked()", "KVNameValueListGUI", this, "DoClose()");
175 
177 
178  // map all widgets and calculate size of dialog
179  fMain->MapSubwindows();
180 
181  height = fMain->GetDefaultHeight();
182  fMain->Resize(width, height);
183  fMain->SetWMSize(width, height);
184  fMain->SetWMSizeHints(width, height, width, height, 0, 0);
189 
190  // position relative to the parent's window
193 
194  fMain->MapWindow();
195  if (wait_for_main) gClient->WaitFor(fMain);
196 }
197 
198 
199 
200 
203 
205 {
206  // Destructor
207  if (fMain) {
208  delete fMain;
209  fMain = 0;
210  }
211 }
212 
213 
214 
215 
217 
219 {
220  TTimer::SingleShot(150, "KVNameValueListGUI", this, "CloseWindow()");
221 }
222 
223 
224 
225 
227 
229 {
230  delete this;
231 }
232 
233 
int Int_t
unsigned int UInt_t
kVerticalFrame
ClassImp(KVPartitionList) void KVPartitionList
Initialisation.
const Bool_t kFALSE
bool Bool_t
const Bool_t kTRUE
include TDocParser_001 C image html pict1_TDocParser_001 png width
kButtonDown
kButtonUp
#define gClient
kMWMDecorResizeH
kMWMFuncAll
kMWMFuncResize
kMWMDecorMaximize
kMWMDecorMinimize
kMWMDecorMenu
kMWMDecorAll
kMWMFuncMaximize
kMWMInputModeless
kMWMFuncMinimize
kDeepCleanup
kLHintsLeft
kLHintsCenterY
kLHintsCenterX
kLHintsBottom
kLHintsTop
kLHintsExpandX
int nentries
GUI for setting KVNameValueList parameters.
virtual TObject * AddABool(Int_t i, TGHorizontalFrame *hf)
TGTransientFrame * fMain
virtual TObject * AddAString(Int_t i, TGHorizontalFrame *hf)
virtual TObject * AddAInt(Int_t i, TGHorizontalFrame *hf)
KVNameValueListGUI(const TGWindow *main, KVNameValueList *params, Bool_t *cancel_pressed, Bool_t wait_for_main=kTRUE)
Constructor.
virtual TObject * AddADouble(Int_t i, TGHorizontalFrame *hf)
virtual ~KVNameValueListGUI()
Destructor.
TGTextButton * fCancelBut
Cancel button.
void RestoreData()
return all values to original state
TGTextButton * fOKBut
OK button.
KVNameValueList * theList
KVNameValueList fOriginal
Handles lists of named parameters with different types, a list of KVNamedParameter objects.
KVNamedParameter * GetParameter(Int_t idx) const
return the parameter object with index idx
Double_t GetDoubleValue(const Char_t *name) const
const Char_t * GetNameAt(Int_t idx) const
Int_t GetNpar() const
return the number of stored parameters
Int_t GetEntries() const
Bool_t GetBoolValue(const Char_t *name) const
void Copy(TObject &nvl) const
A generic named parameter storing values of different types.
Bool_t IsDouble() const
void Set(const char *, const char *)
Bool_t IsInt() const
Bool_t IsBool() const
Bool_t IsString() const
virtual void SetToolTipText(const char *text, Long_t delayms=400)
virtual void SetState(EButtonState state, Bool_t emit=kFALSE)
virtual void AddFrame(TGFrame *f, TGLayoutHints *l=0)
virtual UInt_t GetDefaultWidth() const
virtual void SetCleanup(Int_t mode=kLocalCleanup)
virtual void MapSubwindows()
virtual UInt_t GetDefaultHeight() const
virtual UInt_t GetDefaultWidth() const
virtual UInt_t GetDefaultHeight() const
virtual void Resize(TGDimension size)
virtual void MapWindow()
void DontCallClose()
void SetWMSize(UInt_t w, UInt_t h)
void SetMWMHints(UInt_t value, UInt_t funcs, UInt_t input)
void SetWMSizeHints(UInt_t wmin, UInt_t hmin, UInt_t wmax, UInt_t hmax, UInt_t winc, UInt_t hinc)
void SetWindowName(const char *name=0)
UInt_t GetDefaultHeight() const
virtual void CenterOnParent(Bool_t croot=kTRUE, EPlacement pos=kCenter)
virtual const char * GetTitle() const
Bool_t Connect(const char *signal, const char *receiver_class, void *receiver, const char *slot)
static void SingleShot(Int_t milliSec, const char *receiver_class, void *receiver, const char *method)
TText * text
int main(int argc, char **argv)
Double_t Max(Double_t a, Double_t b)