-
Notifications
You must be signed in to change notification settings - Fork 1.5k
TGCommandPlugin TTimer #8269
Copy link
Copy link
Closed
Labels
Description
Explain what you would like to see improved
The TGCommandPlugin has an internal TTimer that I think is redundant. I don't understand why the function CheckRemote needs to be checked every one second, which also calls frame->Layout(). Shouldn't it be better to just check in the beginning with a TTimer::SingleShot? Or if gROOT->GetApplication() changes during lifetime, with a signal/slot ?
fTimer = new TTimer(this, 1000);
fTimer->Reset();
fTimer->TurnOn();
...
////////////////////////////////////////////////////////////////////////////////
/// Handle timer event.
Bool_t TGCommandPlugin::HandleTimer(TTimer *t)
{
if ((fTimer == 0) || (t != fTimer)) return kTRUE;
CheckRemote("");
return kTRUE;
}
void TGCommandPlugin::CheckRemote(const char * /*str*/)
{
Pixel_t pxl;
TApplication *app = gROOT->GetApplication();
if (!app->InheritsFrom("TRint"))
return;
TString sPrompt = ((TRint*)app)->GetPrompt();
Int_t end = sPrompt.Index(":root [", 0);
if (end > 0 && end != kNPOS) {
// remote session
sPrompt.Remove(end);
gClient->GetColorByName("#ff0000", pxl);
fLabel->SetTextColor(pxl);
fLabel->SetText(Form("Command (%s):", sPrompt.Data()));
}
else {
// local session
gClient->GetColorByName("#000000", pxl);
fLabel->SetTextColor(pxl);
fLabel->SetText("Command (local):");
}
fHf->Layout();
}
Alternatively, it would be nice to provide a function to stop the timer by the user, when performance is needed and you are sure that TApplication is always the same.
Setup
- ROOT from git master
- Ubuntu 20
- Self-built
Additional context
Reactions are currently unavailable