[Pad Auto Exec] Pause AddExec

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

Hi,

The problem is that cin >> str; is blocking…
You could use a dialog to enter a string. Here is an example.
First load the Dialogs.C macro (ROOT knows where to find it) gROOT->LoadMacro("Dialogs.C");
Then, in your inputString() function, replace cin >> str; by str = GetStringDialog("Enter a string", "");
And delete (or comment out) those lines:

//      gPad->DeleteExec("myexec");
      cout << "The string is again:"<<inputString()<<endl;
//      gPad->AddExec("myexec","myexec()");

Cheers, Bertrand.

Thanks a lot, it is working well. Since I am compiling the code as following: “.L code.C++”.
Instead to load the macro with “LoadMacro”, I directly included the file Dialogs.C as following: ‘# include “Dialogs.C”’.

Is it possible to have directly the pointer on the dialog box in order to use only the keyboard?
(just to gain a little of time while interacting with the Dialog boxes)

Thanks again.

Yes, you can edit the Dialogs.C macro (or copy the code in your own source), and add gVirtualX->SetInputFocus(fTE->GetId()) in the InputDialog constructor, as shown below:

   // popup dialog and wait till user replies
   fDialog->MapWindow();
   fRetStr = retstr;
   gVirtualX->SetInputFocus(fTE->GetId());
   gClient->WaitFor(fDialog);

Cheers, Bertrand.

1 Like

It works like a charm. thank you.

Then, I have another question, time to time the pointer (focus) is not staying on the current Pad. Is there a way to also specify a similar thing like “SetInputFocus” but for the current Pad, please?

something like CurrentPad->cd() should do it…

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.