Dear Fons and Rooter,
The attached code will generate a button whose background will be changed
to green in every new iteration within an infinit loop. After about 35000
iterations(at least in my computer), error messages apprears like:
>>> Warning in <TGClient::GetColorByName>: couldn't retrieve color green
Is it due my personal reason or ROOT has some limition on that ?
Sncerely yours
Xie
#ifndef _controlpanel_
#define _controlpanel_
//=======================//
// Build Control Panel //
//=======================//
#include <stdlib.h>
#include <iostream.h>
#include <TGXW.h>
#include <TEnv.h>
#include <TGLabel.h>
#include <TGPicture.h>
#include <TGButton.h>
#include <TGTextEntry.h>
#include <TGTab.h>
#include <TGIcon.h>
#include <TGSlider.h>
#include <TRootEmbeddedCanvas.h>
#include <TCanvas.h>
#include <TH1.h>
#include <TH2.h>
#include <TRandom.h>
#include <TSystem.h>
#include <TGCanvas.h>
//-- Class definition ---
class ControlPanel : public TGMainFrame {
private:
TGTextButton *status;
TGLayoutHints *PCLayout ;
int count;
public:
ControlPanel(const TGWindow *p, const TGWindow *main, UInt_t w, UInt_t h,
UInt_t options = kMainFrame | kVerticalFrame);
~ControlPanel();
void CloseWindow(){delete this;};
Int_t DistancetoPrimitive(Int_t px, Int_t py){return 0;};
Bool_t ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2);
void ExecuteEvent(Int_t event, Int_t px, Int_t py);
void ChangeTGFrameColorbyName(TGFrame *Button,
const char *name);
ClassDef(ControlPanel,1)
};
#endif
#include "ControlPanel.h"
ClassImp(ControlPanel)
//_____________________________________________________________
ControlPanel::ControlPanel(const TGWindow *p, const TGWindow *main, UInt_t w,
UInt_t h, UInt_t options) : TGMainFrame(p, w, h)
{
PCLayout = new TGLayoutHints(kLHintsTop|kLHintsLeft|kLHintsExpandX
|kLHintsExpandY,1,1,1,1);
status = new TGTextButton(this, "0.0",1);
status->Associate(this);
count=0;
AddFrame(status, PCLayout);
MapSubwindows();
Resize(400,300);
MapWindow();
}
//_______________________________________
ControlPanel::~ControlPanel()
{
}
//_______________________________________
Bool_t ControlPanel::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
{
int i, j, k;
switch (GET_MSG(msg)) {
case kC_COMMAND:
switch (GET_SUBMSG(msg)) {
case kCM_BUTTON:
switch(parm1) {
case 1:
while(1) {
count++;
ChangeTGFrameColorbyName(status, "green");
gSystem->ProcessEvents();
printf("--%d\n", count);
}
break;
default:
break;
}
default:
break;
}
break;
default:
break;
}
return kTRUE;
}
//______________________________________________________
void ControlPanel::ExecuteEvent(Int_t event, Int_t px, Int_t py)
{ //_____ mouse Control _____
Float_t x,y;
switch(event)
{
case kMouseMotion:
case kButton1Down:
case kButton1Up:
break;
}
}
//______________________________________
void ControlPanel::ChangeTGFrameColorbyName(TGFrame *Button,const char *name)
{
SetWindowAttributes_t wattr;
wattr.fMask = kWABackPixel;
gClient->GetColorByName(name, wattr.fBackgroundPixel);
gGXW->ChangeWindowAttributes(Button->GetId(), &wattr);
gClient->NeedRedraw(Button); //__ redraw the button___
}
This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:31 MET