Create aTRootCanvas from within GUI app

Hello

I am writing a data monitoring application and went the route of TG objects instead of simple TCanvas/TPad objects, so that I could use Tabs and other features. I have a number of tabs, each with an EmbeddedCanvas and a number of histograms.

I would now like to add feature that would allow me to print or save a histogram or canvas during a run. I thought the easiest way to do this would be to spawn a TRootCanvas object, use DrawClone to grab the image I want, then the “Save As” menu item.

I am able to spawn a canvas using

TCanvas* tCanvas = new TCanvas(“cImg”,“cImg”,5);
tCanvas->Draw();

which draws the canvas, but as soon as I generate any mouse event in the new window my application freezes up. Looking at the classes I am guessing this is because TRootCanvas inherits from TGMainFrame and this is clashing with my application’s own TGMainFrame.

Is there a way to create a TRootCanvas so I can use all its builtin functions?

Thanks

Anthony

Hi Anthony,

There are several ways to achieve the stated goals:

  • If you want to use many features of TRootCanvas application, your application class could derive it (writing that I know that it could be not easy to change the entire GUI design especially at the point it is almost done).
  • You could re-use the code for saving and/or printing from TRootCanvas in your application (it is quite independent, see PrintCanvas() method and the code under kFileSaveAs case).
  • You can save any of your embedded canvases via the context menu. After the right-mouse click on the canvas (it is important to pick up the canvas object by clicking on an area near to window borders), you select “SaveAs” menu entry and give the file name. The file extension will define the saving format.

Cheers, Ilka

Hi Anthony,

You can try something like this:

TCanvas *gEditCanvas;
[...]
   tabId = fMyTab->GetCurrent(); // get tab id
   gEditCanvas = new TCanvas("gEditCanvas","Graphic Editor");
   gEditCanvas->ToggleEventStatus(); // show event status bar
   gEditCanvas->ToggleToolBar(); // show toolbar
   gEditCanvas->ToggleEditor(); // show editor
   gEditCanvas->cd();
   if (tabId == 0)
      fCanvasA->DrawClonePad(); // clone the canvas A into gEditCanvas
   if (tabId == 1)
      fCanvasB->DrawClonePad(); // clone the canvas B into gEditCanvas
[...]

It will open a new canvas with status bar, editor and toolbar, from where you can edit, modify and save in whatever format you need.

Cheers,
Bertrand.

Ilka, Bertrand,

Thanks. I tried Bertrand’s solution and it works great.

Anthony

Hi Anthony,

Yes, what Bertrand proposed is the simplest way. I completely forgot about it.

Cheers, Ilka