Hi,
I have found another problem in TGButtonGroup. I have attached a
class (SettingsDialog) in couple of files (*.h and *.C) producing a small
dialog with a few radio buttons in two TGButtonGroup frames. Whenever a
radio button is pressed a try to print the value selected followin the
examples in $ROOTSYS/tutorials/guitest.C, but I have found that it does
not print the button pressed, but the one that is released... Which of
course is useless for me. Am I doing something wrong?
Cheers,
Isidro
PD.: I am using:
ROOT Version 3.01/06 31 October 2001
gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
Linux RH 6.2 (CERN installation)
+---------------------------+--------------------------------+
| Isidro González Caballero | mailto:Isidro.Gonzalez@cern.ch |
| CERN-EP / Mailbox: F28010 | http://home.cern.ch/~iglez/ |
| 1211 Geneva 23 | -o- |
| Switzerland | Tel: +41 22 76 73060, 73316 |
+---------------------------+--------------------------------+
///////////////////////////////////////////////////////////////////////////
// //
// Input Dialog Widget //
// //
///////////////////////////////////////////////////////////////////////////
#ifndef SettingsDialog_h
#define SettingsDialog_h 1
#include <TGFrame.h>
#include <TGLayout.h>
#include <TGButtonGroup.h>
#include <TGTextEntry.h>
#include <TGTextBuffer.h>
#include <TGLabel.h>
#include <TGButton.h>
class SettingsDialog {
public:
SettingsDialog();
~SettingsDialog();
void CloseWindow() { delete this;}
void DoCancel();
void DoMaterialRadio();
void DoEnergyRadio();
private:
TGTransientFrame *fDialog; // transient frame, main dialog window
TGLayoutHints *fLDialog;
TGCompositeFrame *fRadios; // frame with materials and energy rad. buttons
TGLayoutHints *fLRadios;
//Materials
TGButtonGroup *fGMaterial; //Group frame with material buttons
TGRadioButton *fRMaterial[4];
TGLayoutHints *fLMaterial;
//Energies
TGButtonGroup *fGEnergy; //Group frame with energy buttons
TGRadioButton *fREnergy[5];
TGLayoutHints *fLEnergy;
//Text for NEvents
TGCompositeFrame *fText;
TGLayoutHints *fLText1, *fLText2;
TGTextEntry *fENEvents;
TGTextBuffer *fTNEvents;
TGLabel *fLNEvents;
//Buttons
TGHorizontalFrame *fButtons;
TGLayoutHints *fLButtons;
TGTextButton *fOk,*fCancel;
//Energy data...
Int_t energy;
char* material;
Int_t nEvents;
};
#endif
#include "SettingsDialog.h"
#include <TGString.h>
SettingsDialog::~SettingsDialog()
{
}
SettingsDialog::SettingsDialog() {
// Create simple input dialog.
const TGWindow *main = gClient->GetRoot();
fDialog = new TGTransientFrame(main, main, 100, 100, kVerticalFrame);
fDialog->Connect("CloseWindow()", "SettingsDialog", this, "CloseWindow()");
fLDialog = new TGLayoutHints(kLHintsTop | kLHintsExpandX,
2, 2, 3, 0);
// Main frame for materials and energy radio buttons
fRadios = new TGCompositeFrame(fDialog, 60, 20, kHorizontalFrame);
fLRadios = new TGLayoutHints(kLHintsTop | kLHintsLeft |
kLHintsExpandX | kLHintsExpandY,
2, 2, 2, 2);
//------------- Group Frame for materials
fLMaterial = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
0, 0, 5, 0);
//fGMaterial = new TGGroupFrame(fRadios, new TGString("Materials"));
fGMaterial = new TGButtonGroup(fRadios, "Materials");
fRMaterial[0] = new TGRadioButton(fGMaterial, new TGHotString("All"),
11);
fRMaterial[1] = new TGRadioButton(fGMaterial, new TGHotString("Aluminium"),
12);
fRMaterial[2] = new TGRadioButton(fGMaterial, new TGHotString("Iron"),
13);
fRMaterial[3] = new TGRadioButton(fGMaterial, new TGHotString("Lead"),
14);
fGMaterial->SetLayoutHints(fLMaterial,0);
for (unsigned int i = 0; i < 4; ++i) {
//fGMaterial->AddFrame(fRMaterial[i], fLMaterial);
fRMaterial[i]->Connect("Pressed()", "SettingsDialog",
this, "DoMaterialRadio()");
}
fRadios->AddFrame(fGMaterial,fLRadios);
//------------ Group Frame for materials
fLEnergy = new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX,
0, 0, 5, 0);
//fGEnergy = new TGGroupFrame(fRadios, new TGString("Energies"));
fGEnergy = new TGButtonGroup(fRadios, "Energies");
fREnergy[0] = new TGRadioButton(fGEnergy, new TGHotString("All"), 21);
fREnergy[1] = new TGRadioButton(fGEnergy, new TGHotString("113 MeV"), 22);
fREnergy[2] = new TGRadioButton(fGEnergy, new TGHotString("256 MeV"), 23);
fREnergy[3] = new TGRadioButton(fGEnergy, new TGHotString("597 MeV"), 24);
fREnergy[4] = new TGRadioButton(fGEnergy, new TGHotString("800 MeV"), 25);
fGEnergy->SetLayoutHints(fLEnergy,0);
for (unsigned int i = 0; i < 5; ++i) {
//fGEnergy->AddFrame(fREnergy[i], fLEnergy);
fREnergy[i]->Connect("Pressed()", "SettingsDialog",
this, "DoEnergyRadio()");
}
fRMaterial[0]->SetState(kButtonDown);
fREnergy[0]->SetState(kButtonDown);
fRadios->AddFrame(fGEnergy,fLRadios);
//Number of Events
fText = new TGCompositeFrame(fDialog, 60, 20, kHorizontalFrame);
fLNEvents = new TGLabel(fText, new TGString("Number of Events:"));
fENEvents = new TGTextEntry(fText, fTNEvents = new TGTextBuffer(7));
fTNEvents->AddText(0,"200000");
fENEvents->Resize(100, fENEvents->GetDefaultHeight());
fLText1 = new TGLayoutHints(kLHintsTop | kLHintsCenterY,
3, 5, 0, 0);
fLText2 = new TGLayoutHints(kLHintsBottom | kLHintsCenterY,
0, 2, 0, 0);
fText->AddFrame(fLNEvents, fLText1);
fText->AddFrame(fENEvents, fLText2);
//Buttons
fButtons = new TGHorizontalFrame(fDialog, 60, 20, kFixedWidth);
fLButtons = new TGLayoutHints(kLHintsCenterY | kLHintsExpandX,
5, 5, 0, 0);
fOk = new TGTextButton(fButtons, "&Ok", 1);
fCancel = new TGTextButton(fButtons, "&Cancel", 2);
fOk->Connect("Clicked()", "SettingsDialog", this, "DoOk()");
fCancel->Connect("Clicked()", "SettingsDialog", this, "DoCancel()");
fButtons->AddFrame(fOk,fLButtons);
fButtons->AddFrame(fCancel,fLButtons);
//Add subframes
fDialog->AddFrame(fRadios, fLDialog);
fDialog->AddFrame(fText, fLDialog);
fDialog->AddFrame(fButtons, fLDialog);
fDialog->MapSubwindows();
fDialog->Resize(fDialog->GetDefaultSize());
fDialog->SetWindowName("Settings");
fDialog->MapWindow();
gClient->WaitFor(fDialog);
}
SettingsDialog::~SettingsDialog() {
delete fOk;
delete fCancel;
delete fLButtons;
delete fButtons;
delete fLNEvents;
delete fENEvents;
delete fLText1;
delete fLText2;
for (int i = 0; i < 5; i++)
delete fREnergy[i];
delete fLEnergy; delete fGEnergy;
for (int i = 0; i < 4; i++)
delete fRMaterial[i];
delete fLMaterial;
delete fGMaterial;
delete fLRadios;
delete fRadios;
delete fLDialog;
delete fDialog;
}
void SettingsDialog::DoCancel() {
// Handle Cancel button.
fDialog->SendCloseMessage();
}
void SettingsDialog::DoOk() {
// Handle Ok button.
nEvents = atoi(fTNEvents->GetString());
cout << "Material = \"" << material << "\"" << endl;
cout << "Energy = " << energy << endl;
cout << "NEvents = " << nEvents << endl;
fDialog->SendCloseMessage();
}
void SettingsDialog::DoMaterialRadio() {
// Handle radio buttons.
TGButton *btn = (TGButton *) gTQSender;
Int_t id = btn->WidgetId();
cout << "ID= " << id << endl;
if (id == 11)
material = "";
else if (id == 12)
material = "Al";
else if (id == 13)
material = "Fe";
else if (id == 14)
material = "Pb";
cout << "Material = \"" << material << "\"" << endl;
}
void SettingsDialog::DoEnergyRadio() {
// Handle radio buttons.
TGButton *btn = (TGButton *) gTQSender;
Int_t id = btn->WidgetId();
if (id == 21)
energy = 0;
else if (id == 22)
energy = 113;
else if (id == 23)
energy = 256;
else if (id == 24)
energy = 597;
else if (id == 25)
energy = 800;
cout << "Energy = " << energy << endl;
}
This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:06 MET