GUI Background Processes

Hello,

I am writing a GUI that controls a power supply and I would like the read values to be updated in real time without affecting the user interface. I have so far been successful in updating the values in a set interval but only when the application is idle. The code is as follows…

gApplication->Connect(“HandleIdleTimer()”,“Class”,this,“DoHandleIdle()”);
gROOT->Idle(3,"");

I believe this is sending the idle signal to the application every 3 seconds however it only works when the main frame is in focus and the application is idle (obviously). I want to achieve the same effect without the application being idle and without the main frame in focus. Is there any way to do this?

Thanks,
Shawn

Hi,

You can create a timer in your Gui class, and update your values in the method YourGuiClass::HandleTimer(TTimer *t)
You can take a look at TSessionViewer.cxx to see a working example…

Cheers,
Bertrand.

Hi,

I’ve been trying to do something similar to this, using TSessionViewer as my example. I haven’t gotten it to work correctly yet. When I declare the TTimer with the TObject argument, an error message tells me that it’s unable to be called that way. When I drop the TObject argument, fTimer can’t be called from any other method within the class. Could someone let me know what I’m doing wrong? Thanks!

// barebones.C
#include  <TGClient.h>
#include  <TCanvas.h>
#include  <TF1.h>
#include  <TRandom.h>
#include  <TGButton.h>
#include  <TGFrame.h>
#include  <TRootEmbeddedCanvas.h>
#include  <RQ_OBJECT.h>
#include  <TTimer.h>

class MyMainFrame {
    RQ_OBJECT("MyMainFrame")
private:
    TGMainFrame *fMain;
  TRootEmbeddedCanvas *fEcanvas;
  TTimer *fTimer;
  //char *s;
public:
  MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h);
  virtual ~MyMainFrame();
  void DoDraw();
  void EnableTimer();
  void DisableTimer();

};

//this function really just initializes things
MyMainFrame::MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h) {
  
  fMain = new TGMainFrame(p,w,h);
  // Create a horizontal frame widget with buttons
  TGHorizontalFrame *hframe = new TGHorizontalFrame(fMain,200,200);

  TGTextButton *draw = new TGTextButton(hframe,"&Draw");
  draw->Connect("Clicked()","MyMainFrame",this,"EnableTimer()");
  hframe->AddFrame(draw, new TGLayoutHints(kLHintsCenterX,5,5,3,4));

  TGTextButton *exit = new TGTextButton(hframe,"&Exit","gApplication->Terminate(0)");
  hframe->AddFrame(exit, new TGLayoutHints(kLHintsCenterX,5,5,3,4));

  TGTextButton *start = new TGTextButton(hframe,"&Stop Monitor");
  hframe->AddFrame(start, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
  start->Connect("Clicked()","MyMainFrame",this,"DisableTimer()");

  fMain->AddFrame(hframe, new TGLayoutHints(kLHintsCenterX,2,2,2,2));
  fMain->SetWindowName("Online Monitor");
  fMain->MapSubwindows();
  fMain->Resize(fMain->GetDefaultSize());
  fMain->MapWindow();
}

void MyMainFrame::DoDraw() {
  cout << fTimer << endl;

}

void MyMainFrame::EnableTimer()
{
  *fTimer = new TTimer(this, 1000);
  fTimer->Connect("Timeout()", "MyMainFrame", this, "DoDraw()");
  fTimer->Reset();
  // Enable timer.
  fTimer->TurnOn();

}

void MyMainFrame::DisableTimer()
{
  cout << fTimer << endl;
  fTimer->TurnOff();
}

MyMainFrame::~MyMainFrame() {
  fMain->Cleanup();
  delete fMain;
}

void barebones() {
  new MyMainFrame(gClient->GetRoot(),200,200);
}

Well, you already have the answer… Your class MyMainFrame doesn’t inherit from TObject…
See your modified (and working) code below:

[code]// barebones.C
#include <TGClient.h>
#include <TCanvas.h>
#include <TF1.h>
#include <TRandom.h>
#include <TGButton.h>
#include <TGFrame.h>
#include <TRootEmbeddedCanvas.h>
#include <RQ_OBJECT.h>
#include <TTimer.h>

class MyMainFrame : public TGMainFrame {

private:
TRootEmbeddedCanvas *fEcanvas;
TTimer *fTimer;
//char *s;
public:
MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h);
virtual ~MyMainFrame();
void DoDraw();
void EnableTimer();
void DisableTimer();

};

//this function really just initializes things
MyMainFrame::MyMainFrame(const TGWindow *p,UInt_t w,UInt_t h) :
TGMainFrame(p, w, h)
{

// Create a horizontal frame widget with buttons
TGHorizontalFrame *hframe = new TGHorizontalFrame(this,200,200);

TGTextButton *draw = new TGTextButton(hframe,"&Draw");
draw->Connect(“Clicked()”,“MyMainFrame”,this,“EnableTimer()”);
hframe->AddFrame(draw, new TGLayoutHints(kLHintsCenterX,5,5,3,4));

TGTextButton *exit = new TGTextButton(hframe,"&Exit",“gApplication->Terminate(0)”);
hframe->AddFrame(exit, new TGLayoutHints(kLHintsCenterX,5,5,3,4));

TGTextButton *start = new TGTextButton(hframe,"&Stop Monitor");
hframe->AddFrame(start, new TGLayoutHints(kLHintsCenterX,5,5,3,4));
start->Connect(“Clicked()”,“MyMainFrame”,this,“DisableTimer()”);

AddFrame(hframe, new TGLayoutHints(kLHintsCenterX,2,2,2,2));
SetWindowName(“Online Monitor”);
MapSubwindows();
Resize(GetDefaultSize());
MapWindow();
}

void MyMainFrame::DoDraw()
{
static Int_t count = 0;
cout << ++count << endl;
}

void MyMainFrame::EnableTimer()
{
fTimer = new TTimer(this, 1000);
fTimer->Connect(“Timeout()”, “MyMainFrame”, this, “DoDraw()”);
fTimer->Reset();
// Enable timer.
fTimer->TurnOn();
}

void MyMainFrame::DisableTimer()
{
cout << fTimer << endl;
fTimer->TurnOff();
}

MyMainFrame::~MyMainFrame()
{
Cleanup();
}

void barebones()
{
new MyMainFrame(gClient->GetRoot(),200,200);
}

[/code]
Cheers,
Bertrand.

Thank you very much!