Closing window

Hi ROOTers

I am trying to implement the action of clicking at the corner of the window - the “x” button to close my application. I reviewed the chapter 25 of the ROOT documentation “Writing a Graphical User Interface” but I could not find any information about this. How could I implement it?

This is my relevant code:

MainFrame::MainFrame(const TGWindow *p,UInt_t w,UInt_t h,int argc, char **argv) : TGMainFrame(p,w,h) {

// Creates widgets of the example
fEcanvas = new TRootEmbeddedCanvas (“Ecanvas”,this,200,200);
AddFrame(fEcanvas, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,
10,10,10,1));
TGHorizontalFrame *hframe=new TGHorizontalFrame(this, 200,40);
TGTextButton *draw = new TGTextButton(hframe,"&Draw");
draw->Connect(“Clicked()”,“MainFrame”,this,“Test()”);
hframe->AddFrame(draw, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
TGTextButton *exit = new TGTextButton(hframe,"&Exit ",
“gApplication->Terminate()”);
hframe->AddFrame(exit, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
AddFrame(hframe,new TGLayoutHints(kLHintsCenterX,2,2,2,2));

// Sets window name and shows the main frame
SetWindowName(“Simple Example”);
MapSubwindows();
Resize(GetDefaultSize());
MapWindow();

PMT_Analyze(argc,argv);
}

Thank you,

Cristian

Hi Christian,

The way of doing that is included in several tutorial examples located at $ROOTSYS/tutorials/gui directory. You are right, it is not explained in the GUI chapter of ROOT User’s Guide. I will complete it for the next edition.

The technique is simple when using signals/slots. You have to add the following lines in the constructor:

Connect("CloseWindow()", "MainFrame", this, "DoExit()"); DontCallClose(); where DoExit slot method looks like[code]void MainFrame::DoExit()
{
// Exit this application via the Exit button or Window Manager.
// Use one of the both lines according to your needs.
// Please note to re-run this macro in the same ROOT session,
// you have to compile it to get signals/slots ‘on place’.

DeleteWindow(); // to stay in the ROOT session
//gApplication->Terminate(); // to exit and close the ROOT session
}
[/code]I am attaching a tutorial macro too.

Cheers, Ilka
buttongroupState.C (3.51 KB)

Great Thank you!