Dear ROOTers,
I am trying to implement a simple macro interacting with the current TPad (gPad) using the keyboard and mouse position. This routine is executed using: gPad->AddExec(“myexec”, “myexec()”), which basically checks if we interact with the Pad when typing on some specific keys (drawline, zoom, makes some fits …).
Unfortunately, since I use some keys, it is impossible for example to pick up a string from the keyboard (e.g. a filename). I just would like to PAUSE the execution of this “macros”, record a string and then restart the execution of the script. It is currently possible by clicking in the tab “Option->Pad Auto Exec”. I just want to have the same feature but with command lines.
I already tried to stop the execution via “gPad->DeleteExec(“myexec”)”, but it does not work.
***************** code ********************
string inputString()
{
TPaveText* GoToTerm = new TPaveText(0.7,0.01,0.9,0.05,"NDC");
GoToTerm->SetFillColor(kWhite);
GoToTerm->SetTextSize(0.04);
GoToTerm->SetTextAlign(12);
GoToTerm->SetTextFont(132);
GoToTerm->AddText("#color[2]{Go to Term}");
GoToTerm->Draw("same");
gPad->Modified();
gPad->Update();
string str;
cin >> str;
cout<<"The string is :"<<str<<endl;
GoToTerm->Delete();
gPad->Modified();
gPad->Update();
return str;
}
void myexec()
{
// get event information
int event = gPad->GetEvent();
int px = gPad->GetEventX(); //cout<<"px : "<<px<<endl;
static int last_px;
// some magic to get the coordinates
Double_t xd = gPad->AbsPixeltoX(px);
Float_t x = gPad->PadtoX(xd);
static Float_t last_x;
if(event!=kKeyPress){
last_x=x;
return;
}
switch(px){
case 's': // 115 ---> "s"
ev.push_back((char*)"s");
last_px=px;
Event_Monitoring();
gPad->DeleteExec("myexec");
cout << "The string is again:"<<inputString()<<endl;
gPad->AddExec("myexec","myexec()");
break;
case 'L': // 76 ---> "L"
ev.push_back((char*)"L");
gPad->SetLogy(0);
gPad->Modified();
gPad->Update();
last_px=px;
Event_Monitoring();
break;
};
}
***************************************************************************
For the present piece of code, while typing on the Pad and not on the terminal, the keys that have been pressed are stored in memory and after the std::cin done, the commands associated to the keys are performed.
Moreover, on the terminal, when typing nothing appears on the terminal, which is a problem since we don’t see what we type.
I also tried with gROOT->ProcessLine(“command”) to delete “myexec” but it does not work.
Please, any help will be welcome. I am out of ideas.
Chris