Re: [ROOT] Re: Root GUI

From: Valeriy Onuchin (Valeri.Onoutchine@cern.ch)
Date: Tue Oct 12 2004 - 10:05:20 MEST


Hi Varum,
sorry I overlooked the question.
1. I do not see when DoDraw is called (?)
2. when you asked "How do I add more child frames", what 
    do you mean? How can you add more TRootEmbeddedCanvases?
 
Regards. Valeriy

> Hi,
> just a little bit of self advertisment ;-)
> Varun, you can use GuiBuilder to create such design in 5 min.
> TRootEmbeddedCanvas is not yet in GuiBuilder widget pallete
> but you can copy&paste it from guitest.C.
> An alternative to "divide your canvas" create several TRootEmbeddedCanvases.
> 
> Regards. Valeriy 
> 
> > Varun,
> > 
> > Your problem has nothing to do with the GUI. Simply divide your canvas
> > into multiple pads. See examples in the tutorials.
> > 
> > Rene Brun
> > 
> > Varun Gopalakrishna wrote:
> > > 
> > > Hello rooters,
> > > 
> > > I am having a lot of problems with the ROOT GUI..I had a couple of
> > > questions.
> > > My requirements are that I need to view multiple plots/histogram at the
> > > same time in the same window. what do i need to?
> > > 
> > > I have tried my hand at the code below which just helps  me to create a
> > > single frame and add my histogram to it. How do I add more child frames?
> > > 
> > > Thanks
> > > 
> > > Varun
> > > 
> > > //-------------------------------------------------------------------------
> > > 
> > > #include <TGClient.h>
> > >  #include <TCanvas.h>
> > > #include <TF1.h>
> > > #include <TRandom.h>
> > >  #include <TGButton.h>
> > > #include <TGFrame.h>
> > > #include <TRootEmbeddedCanvas.h>
> > > #include <RQ_OBJECT.h>
> > > 
> > > class MyMainFrame
> > > {
> > > RQ_OBJECT("MyMainFrame")
> > > 
> > > private: TGMainFrame *fMain;
> > >  TRootEmbeddedCanvas *fEcanvas;
> > > 
> > > public:
> > > 
> > > MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h);
> > > 
> > > virtual ~MyMainFrame();
> > > 
> > > void DoDraw();
> > > void drawthis();//*SIGNAL*
> > > };
> > > 
> > > MyMainFrame::MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h)
> > >  {
> > > 
> > > // Create a main frame
> > > 
> > >  fMain = new TGMainFrame(p,w,h);
> > > // Create canvas widjet
> > > 
> > >  fEcanvas = new TRootEmbeddedCanvas("Ecanvas",fMain,750,750);
> > > fMain->AddFrame(fEcanvas, new TGLayoutHints(kLHintsExpandX |
> > > kLHintsExpandY,10,10,10,1));
> > > // Create a horizontal frame widget with buttons
> > > TGHorizontalFrame *hframe = new TGHorizontalFrame(fMain,200,40);
> > > TGTextButton *draw = new TGTextButton(hframe,"&Last 5 Hours");
> > > draw->Connect("Clicked()","MyMainFrame",this,"drawthis()");
> > > hframe->AddFrame(draw, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
> > > TGTextButton *exit = new TGTextButton(hframe,"&Stop",
> > > "gApplication->Terminate(0)");
> > > hframe->AddFrame(exit, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
> > > fMain->AddFrame(hframe, new TGLayoutHints(kLHintsCenterX,2,2,2,2));
> > > 
> > > TGTextButton *b1 = new TGTextButton(hframe,"&Last 10 Hours");
> > > b1->Connect("Clicked()","MyMainFrame",this,"drawthis()");
> > > hframe->AddFrame(b1, new TGLayoutHints(kLHintsCenterX,6,6,4,5));
> > > TGTextButton *stop = new TGTextButton(hframe,"&Exit",
> > > "gApplication->Terminate(0)");
> > > hframe->AddFrame(stop, new TGLayoutHints(kLHintsCenterX,6,6,4,5));
> > > fMain->AddFrame(hframe, new TGLayoutHints(kLHintsCenterX,2,2,2,2));
> > > 
> > > //TGTextButton *exit = new TGTextButton(hframe,"&Exit");
> > > //exit->SetCommand("gApplication->Terminate()");
> > > /*fMain->AddFrame(hFrame1,fLayout1);
> > > fMain->AddFrame(hFrame2,fLayout2);
> > > fMain->Resize(frame->GetDefaultSize());
> > > // lays out frames
> > > fMain->MapSubwindows();
> > > // maps subwindows
> > > fMain->HideFrame(hFrame2);
> > > // hides frame hFrame2
> > > fMain->MapWindow(); // maps main frame
> > > 
> > > // Set a name to the main frame
> > > 
> > > fMain->SetWindowName("Simple Example");
> > > // Map all subwindows of main frame
> > > fMain->MapSubwindows();
> > > // Initialize the layout algorithm
> > > fMain->Resize(fMain->GetDefaultSize());
> > > // Map main frame
> > > fMain->MapWindow();
> > > }
> > > 
> > > void MyMainFrame::DoDraw()
> > > {
> > > // Draws function graphics in randomly choosen interval
> > > TF1 *f1 = new TF1("f1","sin(x)/x",0,gRandom->Rndm()*10);
> > > f1->SetFillColor(19);
> > >  f1->SetFillStyle(1);
> > > f1->SetLineWidth(3);
> > >  f1->Draw();
> > > TCanvas *fCanvas = fEcanvas->GetCanvas();
> > >  fCanvas->cd();
> > >  fCanvas->Update();
> > >  //printf("in draw this");
> > >   //drawthis();
> > > }
> > > 
> > > MyMainFrame::~MyMainFrame()
> > > {
> > > // Clean up used widgets: frames, buttons, layouthints
> > > fMain->Cleanup();
> > > delete fMain;
> > > }
> > > 
> > > void example()
> > > {
> > > // Popup the GUI...
> > >  new MyMainFrame(gClient->GetRoot(),200,200);
> > > }
> > > 
> > > void MyMainFrame::drawthis(){
> > > 
> > > {
> > >   printf(" really inside the method!!!");
> > > 
> > > Int_t i =0,pos=8;
> > > Double_t j=0.0;
> > > Char_t ch;
> > > Float_t max=0.0,min=0.0;
> > > // Create a new canvas.
> > > /*c1 = new TCanvas("c1","Dynamic Filling Example",200,10,700,500);
> > >   c1->SetFillColor(42);
> > >   c1->GetFrame()->SetFillColor(21);
> > >   c1->GetFrame()->SetBorderSize(6);
> > >   c1->GetFrame()->SetBorderMode(-1);*/
> > > 
> > > // Create a new ROOT binary machine independent file.
> > > // Note that this file may contain any kind of ROOT objects, histograms,
> > > // pictures, graphics objects, detector geometries, tracks, events, etc..
> > > // This file is now becoming the current directory.
> > >   FILE *fp=fopen("data.dat","r+");
> > >   if (fp == NULL)
> > >      printf("Cannot open file\n");
> > >   TFile *hfile = gROOT->FindObject("hsimple.root"); if (hfile)
> > > hfile->Close();
> > >   hfile = new TFile("hsimple.root","RECREATE","Demo ROOT file with
> > > histograms");
> > > 
> > > // Create some histograms, a profile histogram and an ntuple
> > > hpx    = new TH1F("hpx","This is the px distribution",100,-1,1);
> > > 
> > > //  Set canvas/frame attributes (save old attributes)
> > >   hpx->SetFillColor(48);
> > > 
> > >   gBenchmark->Start("hsimple");
> > > 
> > > // Fill histograms randomly
> > > //while(true) {
> > >   TCanvas *fCanvas = fEcanvas->GetCanvas();
> > >   fCanvas->cd();
> > >   while((fscanf(fp,"%lf",&j)!=EOF)){
> > > 
> > >       printf("the value read is %lf\n",j);
> > >     hpx->Fill(j);
> > >     hpx->Draw();
> > >     //fCanvas->cd();
> > >     fCanvas->Modified();
> > >     fCanvas->Update();
> > >     // c1->Modified();
> > >     //c1->Update();
> > >      gBenchmark->Show("hsimple");
> > >      gSystem->ProcessEvents();
> > >      }
> > >   //gBenchmark->Show("hsimple");
> > >   pos=ftell(fp);
> > >   fseek(fp,0,SEEK_END);
> > >   if (pos!=ftell(fp))break;
> > >   fseek(fp,pos,SEEK_SET);
> > > }
> > > //}
> > >   fclose(fp);
> > > //gBenchmark->Show("hsimple");
> > > 
> > > // Save all objects in this file
> > >   hpx->SetFillColor(0);
> > >   hfile->Write();
> > >   hpx->SetFillColor(48);
> > > 
> > > // Note that the file is automatically close when application terminates
> > > // or when the file destructor is called.
> > > }
> > 
> > 
> 



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:09 MET