exec_macro.C

Go to the documentation of this file.
00001 #include "TSystem.h"
00002 #include "TString.h"
00003 #include "TGClient.h"
00004 #include "TGWindow.h"
00005 #include "TClass.h"
00006 #include "THashList.h"
00007 #include "TROOT.h"
00008 #include "TInterpreter.h"
00009 #include "TEnv.h"
00010 #include "TVirtualX.h"
00011 #include "TImage.h"
00012 
00013 //______________________________________________________________________________
00014 Int_t exec_macro(const char *macro, Bool_t comp = kFALSE, Bool_t save = kTRUE)
00015 {
00016    // Execute the macro and save a capture in a png file.
00017    // This macro is used by stressGUI to execute and compare
00018    // the output of the GUI tutorials.
00019 
00020    enum EErrorCodes {
00021       kSuccess,
00022       kScriptDirNotFound,
00023       kCannotRunScript,
00024       kNumErrorCodes
00025    };
00026 
00027    if (gROOT->IsBatch() || !(gClient))
00028       return kCannotRunScript;
00029    TString pwd(gSystem->pwd());
00030    if (!gSystem->cd(gSystem->DirName(macro)))
00031       return kScriptDirNotFound;
00032    Int_t err = 0;
00033    TString cmd(".x ");
00034    cmd += gSystem->BaseName(macro);
00035    if (comp) cmd += "+";
00036    gVirtualX->Sync(1);
00037    gROOT->ProcessLine(cmd, &err);
00038    if (err != TInterpreter::kNoError)
00039       return kCannotRunScript;
00040    gSystem->cd(pwd);
00041 
00042    UInt_t nMainFrames = 0;
00043    TClass* clGMainFrame = TClass::GetClass("TGMainFrame");
00044    TGWindow* win = 0;
00045    TIter iWin(gClient->GetListOfWindows());
00046    while ((win = (TGWindow*)iWin())) {
00047       const TObject* winGetParent = win->GetParent();
00048       Bool_t winIsMapped = kFALSE;
00049       if (winGetParent == gClient->GetDefaultRoot())
00050          winIsMapped = win->IsMapped();
00051       if (winIsMapped && win->InheritsFrom(clGMainFrame)) {
00052          win->MapRaised();
00053          if (save) {
00054             TString outfile = gSystem->BaseName(macro);
00055             outfile.ReplaceAll(".C", TString::Format("_%d.png",
00056                                ++nMainFrames));
00057             TImage *img = TImage::Create();
00058             win->RaiseWindow();
00059             img->FromWindow(win->GetId());
00060             img->WriteImage(outfile.Data());
00061             delete img;
00062          }
00063       }
00064    }
00065    if (!gEnv->GetValue("X11.Sync", 0))
00066       gVirtualX->Sync(0);
00067    return kSuccess;
00068 }

Generated on Tue Jul 5 15:44:23 2011 for ROOT_528-00b_version by  doxygen 1.5.1