Re: Random Numbers revisited.

Stanislav Terechtchenko (Stanislav.Terechtchenko@cern.ch)
Wed, 29 Jul 1998 20:51:20 +0200 (METDST)


Hi Rooters.
I have the simple GUI code. If the call sleep(1) in method
MyWin::Loop() is commented everything works well, otherwise
there is no more reaction on the button click. Any hints?
Thank you.
Stas.

------------------------------------------------------------
#include <stdlib.h>
#include "TROOT.h"
#include "TApplication.h"
#include "TGClient.h"
#include "TGFrame.h"
#include "TGButton.h"
#include "TTimer.h"
#include "TSystem.h"

Int_t gFlag = 0;

class MyTimer : public TTimer {
public:
MyTimer(Long_t ms = 1000, Bool_t mode = kFALSE) : TTimer(ms, mode) {}
Bool_t Notify() {
fprintf(stderr,"Notify\t");
gClient->HandleInput();
Reset();
fprintf(stderr,"OK\n");
return kFALSE;
}
};

class MyWin : public TGMainFrame {
TGTextButton *fButton;
MyTimer *fTimer;
public:
MyWin(const TGWindow *p, UInt_t w, UInt_t h);
virtual Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t);
void Loop();
};

MyWin::MyWin(const TGWindow *p, UInt_t w, UInt_t h) : TGMainFrame(p, w, h)
{
fButton = new TGTextButton(this,"Click here",150);
fButton->Associate(this);
MapSubwindows();
MapWindow();
fTimer = new MyTimer();
gSystem->AddTimer(fTimer);
}

Bool_t MyWin::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
{
switch (GET_MSG(msg)) {
case kC_COMMAND:
switch (GET_SUBMSG(msg)) {
case kCM_BUTTON:
case kCM_MENU:
switch (parm1) {
case 150:
if(gFlag) gFlag = 0;
else {
gFlag = 1;
Loop();
}
default:
break;
}
default:
break;
}
default:
break;
}
return kTRUE;
}

void MyWin::Loop() {
while(gFlag) {
fprintf(stderr,"loop");
// sleep(1);
}
}

extern void InitGui();
VoidFuncPtr_t initfuncs[] = { InitGui, 0 };

TROOT root("GGG", "GGG test environement", initfuncs);

main(int argc, char **argv)
{
TApplication theApp("App", &argc, argv);
new MyWin(gClient->GetRoot(), 400, 220);
// TBrowser *br = new TBrowser("browser","H2 Root online browser");
theApp.Run();
return 0;
}