Re: How to make a gui

From: Ilka Antcheva <Ilka.Antcheva_at_cern.ch>
Date: Wed, 22 Feb 2006 16:28:03 +0100


Sorry for a very bad typo!!!

Please read the last phrase:
i.e. you will NOT use the Cleanup() method for container frames.

Cheers, Ilka

Ilka Antcheva wrote:

> Hi Roger,
>
> From the included code it seems that fMainV is not a data member of
> your class MyMainFrame, i.e. not known symbol in the method
> MyMainFrame::DoComboSelect.
>
> Next, I see that you have assigned the same widgets ID to any pair of
> slider and text entry. This is wrong, because the widget's id are used
> for event processing and they should be unique. So, you could apply a
> simple formula using 'i' to generate them.
>
> In addition, be careful when re-using the same layout hints (fLslider)
> for several widgets in AddFrame method. I hope you will delete
> fLslider in the destructor, as well as all created GUI elements in
> your application, i.e. you will use the Cleanup() method for container
> frames.
>
> Cheers, Ilka
>
> Roger Mason wrote:
>
>> Hello Rene,
>>
>> Rene Brun <Rene.Brun_at_cern.ch> writes:
>>
>>
>>
>>> see tutorial Slider3Demo.C (introduced a few weeks ago in CVS)
>>>
>>> Rene Brun
>>>
>>
>>
>> Thanks for your reply. I had a look through that tutorial and I think
>> I understand much of its workings.
>>
>> perhaps I should be more specific about the problem I'm having.
>> I have the following code fragment in a class MyMainFrame:
>>
>> // Vertical frame
>> fMainV = new TGVerticalFrame(fMainH,w/3,h);
>> fMainH->AddFrame(fMainV, new TGLayoutHints(kLHintsExpandY |
>> kLHintsExpandX,10,10,10,1));
>> fComboFuncNames = new TGComboBox(fMainV,100);
>> for (Int_t i = 0; i < 4; i++) {
>> fComboFuncNames->AddEntry(funcnames[i], i+1);
>> }
>> fComboFuncNames->Resize(w/10,h/20);
>> fComboFuncNames->Select(1);
>> fComboFuncNames->Connect("Selected(Int_t)","MyMainFrame",this,"DoComboSelect(Int_t)");
>>
>> fLcombo = new TGLayoutHints(kLHintsTop | kLHintsLeft,5,5,5,5);
>> fMainV->AddFrame(fComboFuncNames,fLcombo);
>> // Sliders should be added here but defer until the selection is
>> made in
>> // fComboFuncNames so we know how many to create.
>>
>> When an item is selected in fComboFuncNames the following function is
>> called. It is intended that this function should create a number of
>> sliders, the number created being dependent on the selected function.
>>
>> void MyMainFrame::DoComboSelect(Int_t sel) {
>> // Update the sliders depending on which function gets selected in
>> // the function selection combo.
>>
>> Int_t nparm;
>> switch (sel) {
>> case 1 : nparm = 3; // Gaussian
>> break;
>> case 2 : nparm = 3; // Lorentzian
>> break;
>> case 3 : nparm = 5; // Voigtian
>> break;
>> case 4 : nparm = 10; // Background (max order)
>> break;
>> default: nparm = 9;
>> }
>> // cout << "nparm = " << nparm << endl;
>>
>> for (Int_t i = 0; i < nparm; i++ ) {
>> VSid[i] = i;
>> TEid[i] = i;
>> fVSparms[i] = new TGVSlider(fMainV, 100, kSlider2, VSid[i]);
>> fTEparms[i] = new TGTextEntry(fMainV, fTBparms[i] = new
>> TGTextBuffer(10), TEid[i]);
>> fTBparms[i]->AddText(0, "0");
>> }
>>
>> //--- layout for sliders
>> fLslider = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 0, 3, 0);
>>
>> for (Int_t i = 0; i < nparm; i++ ) {
>> fMainV->AddFrame(fVSparms[i], fLslider);
>> fMainV->AddFrame(fTEparms[i], fLslider);
>> fTEparms[i]->Connect("TextChanged(char*)", "MyMainFrame", this,
>> "DoText(char*)");
>> }
>>
>> }
>>
>> The combo box is drawn correctly but when I make a selection the
>> following error is returned:
>>
>> root [0] .x MyExample.C
>> .x MyExample.C
>> root [1] Error: Can't call
>> TGVerticalFrame::AddFrame(fVSparms[i],fLslider) in current
>> scopePossible candidates are...
>> filename line:size busy function type and name (in
>> TGVerticalFrame)
>> filename line:size busy function type and name (in
>> TGCompositeFrame)
>> /usr/local/lib/root/libGui.so -1:-1 0 public: virtual void
>> AddFrame(TGFrame* f,TGLayoutHints* l=0);
>> filename line:size busy function type and name (in TGFrame)
>> filename line:size busy function type and name (in TGWindow)
>> filename line:size busy function type and name (in TGObject)
>> filename line:size busy function type and name (in TObject)
>> filename line:size busy function type and name (in TQObject)
>> Error: Can't call TGVerticalFrame::AddFrame(fVSparms[i],fLslider) in
>> current scope /home/rmason/Programming/rootmac/MyExample.C:265:
>> Possible candidates are...
>> filename line:size busy function type and name (in
>> TGVerticalFrame)
>> filename line:size busy function type and name (in
>> TGCompositeFrame)
>> /usr/local/lib/root/libGui.so -1:-1 0 public: virtual void
>> AddFrame(TGFrame* f,TGLayoutHints* l=0);
>> filename line:size busy function type and name (in TGFrame)
>> filename line:size busy function type and name (in TGWindow)
>> filename line:size busy function type and name (in TGObject)
>> filename line:size busy function type and name (in TObject)
>> filename line:size busy function type and name (in TQObject)
>> Error: Symbol fMainV is not defined in current scope
>> /home/rmason/Programming/rootmac/MyExample.C:265:
>> Error: Failed to evaluate
>> fMainV->AddFrame(fVSparms[i],fLslider)Possible candidates are...
>> filename line:size busy function type and name
>> I'm sure my poor understanding of C++ is responsible for the problem.
>> Any help you can offer will be most appreciated.
>>
>> Thanks,
>>
>> Roger
>>
>>
>>
>
Received on Wed Feb 22 2006 - 16:28:11 MET

This archive was generated by hypermail 2.2.0 : Mon Jan 01 2007 - 16:31:57 MET