Re: [ROOT] Layout in TGButtonGroup

From: Fons Rademakers (Fons.Rademakers@cern.ch)
Date: Thu Nov 01 2001 - 11:27:46 MET


Hi Isidro,

  you forgot to implement SettingDialog::DoRadio() to handle the radio
button toggling. Also where you connected the signals to the DoRadio()
slot you did specify the TestMsgBox class instead of SettingDialog.

Attached working version.

-- Fons



-- 
Org:    CERN, European Laboratory for Particle Physics.
Mail:   1211 Geneve 23, Switzerland
E-Mail: Fons.Rademakers@cern.ch              Phone: +41 22 7679248
WWW:    http://root.cern.ch/~rdm/            Fax:   +41 22 7679480

///////////////////////////////////////////////////////////////////////////
//                                                                       //
// 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 SettingDialog {

public:
  SettingDialog();
  ~SettingDialog();


  void DoCancel();
  void DoRadio();

private:
  TGTransientFrame *fDialog;  // transient frame, main dialog window
  TGLayoutHints    *fLDialog;


  TGCompositeFrame *fRadios;  // frame with materials and energy rad. buttons
  TGLayoutHints    *fLRadios;

  //Materials
  TGGroupFrame    *fGMaterial; //Group frame with material buttons
  TGRadioButton    *fRMaterial[4];
  TGLayoutHints    *fLMaterial;

  //Energies
  TGGroupFrame    *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;
};

#endif


#include "SettingsDialog.h"

#include <TGString.h>

SettingDialog::~SettingDialog()
{
}

SettingDialog::SettingDialog() {

   // Create simple input dialog.
   const TGWindow *main = gClient->GetRoot();
   fDialog = new TGTransientFrame(main, main, 100, 100, kVerticalFrame);
   fDialog->Connect("CloseWindow()", "SettingDialog", 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"));
   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);
   for (unsigned int i = 0; i < 4; ++i) {
     fGMaterial->AddFrame(fRMaterial[i], fLMaterial);
     fRMaterial[i]->Connect("Pressed()", "SettingDialog", this, "DoRadio()");
   }
   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"));
   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);
   for (unsigned int i = 0; i < 5; ++i) {
     fGEnergy->AddFrame(fREnergy[i], fLEnergy);
     fREnergy[i]->Connect("Pressed()", "SettingDialog", this, "DoRadio()");
   }
   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()", "SettingDialog", this, "DoOk()");
   fCancel->Connect("Clicked()", "SettingDialog", 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);
}

void SettingDialog::DoCancel() {
  // Handle Close button.

  fDialog->SendCloseMessage();
}

void SettingDialog::DoRadio() {
  // Handle radio buttons.

   TGButton *btn = (TGButton *) gTQSender;
   Int_t id = btn->WidgetId();

   if (id >= 11 && id <= 14) {
      for (int i = 0; i < 4; i++)
         if (fRMaterial[i]->WidgetId() != id)
            fRMaterial[i]->SetState(kButtonUp);
   }

   if (id >= 21 && id <= 25) {
      for (int i = 0; i < 5; i++)
         if (fREnergy[i]->WidgetId() != id)
            fREnergy[i]->SetState(kButtonUp);
   }


}



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:51:05 MET