Automatic updating of a GUI:need threads?

Hi,

I’m writing a small GUI, and I’d like the following functionality:

  1. The plots/images update themselves every N seconds
  2. The GUI responds to user input (button clicks, options, tabs…)

the TApplication.Run() gives me (2) just fine, but I can’t see how to integrate an automatic update loop at the same time.

Do I need to run this multi-threaded, with one thread handling each task, or is there some built-in feature to allow periodic updates?

Cheers,
Daniel

Hi Daniel,

Please take a look into RootShower sample, you can implement HandleTimer() within your code, refreshing canvas/pad every x seconds.
HTH.

Cheers,
Bertrand.

Hi Daniel,

[quote=“danielw”]Hi,

I’m writing a small GUI, and I’d like the following functionality:

  1. The plots/images update themselves every N seconds
  2. The GUI responds to user input (button clicks, options, tabs…)

the TApplication.Run() gives me (2) just fine, but I can’t see how to integrate an automatic update loop at the same time.

Do I need to run this multi-threaded, with one thread handling each task, or is there some built-in feature to allow periodic updates?

Cheers,
Daniel[/quote]

There are many examples how to do it in $ROOTSYS/test, $ROOTSYS/tutorials e.g.

tutorials/anim.C
test/Hello.cxx, Aclock.cxx

IMHO, working with threads is “quite tricky task”,
I would recommend to use root.cern.ch/root/htmldoc/TTimer.html
class if it’s possible. It is easy esspesially with signal-slots.
For example, to update gPad periodically each 1 sec you can use:

TTimer *timer = new TTimer(1000);
timer->Connect(“Timeout()”, “TPad”, gPad, “Modified()”);

Regards. Valeriy

Thanks – that works exactly as I needed!

Daniel

Hi Daniel,
I revisited thread safety under windows (win32gdk) recently.
Two classes under win32gdk are thread safe: TInterpreter, TVirtualX
Now it is quite easy to make any method of any class with dictionary
to be thread safe.
For example for TCanvas::Update this is

   TCanvas * c1;
   if (!gVirtualX->IsCmdThread()) {
      gInterpreter->Execute(c1, c1->IsA(), "Update", "");
   } else {
      c1->Update();
   }

It can be done inside the source code or inside a macro.

Regards. Valeriy

1 Like