Root cern GUI: TGCheckButton states

Dear experts,
I confused about TGCheckButton states.

TGCheckButton should have four states:

enum EButtonState
 {    kButtonUp,
      kButtonDown,
      kButtonEngaged,
      kButtonDisabled
   };

My check_button can be in one from four states:
Up & Enabled
Down & Enabled
Up & Disabled
Down & Disabled

So, to set, for example, Down & Disabled I expect to use these commands:
SetState(kButtonDown); SetState(kButtonEngaged);
What I see in GUI: Down & Disabled
What members show: IsDown() = 0, IsEnabled() = 0.
But IsDown() should be True.

I saw this topic TGCheckButton and SetEnabled and understand now how to choose appropriate states using if/else and three bool variables: IsDown, IsEnabled, IsDisabledAndSelected.

Is any root function to set the appropriate states without complex if/else constructions?
I mean something like this: SetStates(Bool_t is_up, Bool_t is_enabled).

Thank you in advance.

Example:

#include <TApplication.h>
#include <TGClient.h>
#include <TGButton.h>
#include <TGFrame.h>
#include <TGLayout.h>
#include <TGWindow.h>
#include <TGLabel.h>
#include <TGNumberEntry.h>
#include <TString.h>

class MyMainFrame : public TGMainFrame
{
public:
   MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
   virtual ~MyMainFrame();

   TGCheckButton *check_button;
   void ShowStates(TGCheckButton *);

   ClassDef(MyMainFrame, 0)
};

MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h)
   : TGMainFrame(p, w, h)
{
   check_button = new TGCheckButton(this, "check_button");

   AddFrame(check_button, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY) );


//   enum EButtonState {
//      kButtonUp,
//      kButtonDown,
//      kButtonEngaged,
//      kButtonDisabled
//   };

   //var0
   //down, disabled
   check_button->SetState(kButtonDown);
   check_button->SetState(kButtonDisabled);

   //up, enabled
//   check_button->SetState(kButtonUp);
//   check_button->SetState(kButtonEngaged);

   //down, enabled
   //check_button->SetState(kButtonDown);
   //check_button->SetState(kButtonEngaged);

   //up, disabled
   //check_button->SetState(kButtonUp);
   //check_button->SetState(kButtonDisabled);

   ShowStates(check_button);

   TGTextButton *fExit = new TGTextButton(this, "&Exit", "gApplication->Terminate(0)");
   AddFrame(fExit, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY));

   SetCleanup(kDeepCleanup);
   SetWindowName("Test check_button");
   MapSubwindows();
   Resize(GetDefaultSize());
   MapWindow();
}

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

void MyMainFrame::ShowStates(TGCheckButton *ch_button)
{
    cout << ";IsDown() = " << ch_button->IsDown() <<
//            "; IsActive() = " << ch_button->IsActive() <<
//            "; IsOn() = " << ch_button->IsOn() <<
            "; IsEnabled() = " << ch_button->IsEnabled() <<
            "; IsDisabledAndSelected = " << ch_button->IsDisabledAndSelected() <<
            endl << endl;
}

void check_button()
{
   new MyMainFrame(gClient->GetRoot(), 500, 500);
}

Hi,

No, there is no such method available in ROOT.

Cheers, Bertrand.

Well, is possible to add such method in the next releases?

You mean a new method merging two calls into one? I don’t think it is worth a new method… (or did I misunderstood something?)

Well, may be you know how change button states in another way than I.
Usually 2 bits ( Up / Down ) and ( Enabled / Disabled ) are enough to set appropriate states.
But, as you can see from code, I can set Down & Disabled state (from GUI point of view it is correctly, but incorrect value for IsDown() ). But what should I do if I want to change new state to another one?
For example, if I have Down state I want to choose Up state.
But IsDown() method works incorrectly.

So, I should use 3 bits: (Up / Down), ( Enabled / Disabled ), (DisabledAndSelected True / False).
Do you agree?

OK, I’ll check what can be done, but on another hand, if you need a quick fix, you can implement your own… :wink:

You already gave the solution 9 years ago.
As I understand, the solution is to use 3 bits.

In my example it should be (see function FindState):

#include <TApplication.h>
#include <TGClient.h>
#include <TGButton.h>
#include <TGFrame.h>
#include <TGLayout.h>
#include <TGWindow.h>
#include <TGLabel.h>
#include <TGNumberEntry.h>
#include <TString.h>

class MyMainFrame : public TGMainFrame
{
public:
   MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h);
   virtual ~MyMainFrame();

   TGCheckButton *check_button;
   void ShowStates(TGCheckButton *);

   ClassDef(MyMainFrame, 0)
};

MyMainFrame::MyMainFrame(const TGWindow *p, UInt_t w, UInt_t h)
   : TGMainFrame(p, w, h)
{
   check_button = new TGCheckButton(this, "check_button");

   AddFrame(check_button, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY) );

   //var1
   //down, disabled
   //check_button->SetDisabledAndSelected(kTRUE);

   //up, enabled
   //check_button->SetDisabledAndSelected(kFALSE);
   //check_button->SetState(kButtonUp);

   //down, enabled
   //check_button->SetState(kButtonDown);

   //up, disabled
   check_button->SetDisabledAndSelected(kFALSE);
   check_button->SetState(kButtonDisabled);

   ShowStates(check_button);
   FindState(check_button);

   TGTextButton *fExit = new TGTextButton(this, "&Exit", "gApplication->Terminate(0)");
   AddFrame(fExit, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY));

   SetCleanup(kDeepCleanup);
   SetWindowName("Test check_button");
   MapSubwindows();
   Resize(GetDefaultSize());
   MapWindow();
}

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

void MyMainFrame::ShowStates(TGCheckButton *ch_button)
{
    cout << ";IsDown() = " << ch_button->IsDown() <<
//            "; IsActive() = " << ch_button->IsActive() <<
//            "; IsOn() = " << ch_button->IsOn() <<
            "; IsEnabled() = " << ch_button->IsEnabled() <<
            "; IsDisabledAndSelected = " << ch_button->IsDisabledAndSelected() <<
            endl << endl;
}

void MyMainFrame::FindState(TGCheckButton *ch_button)
{
    bool is_d = ch_button->IsDown();
    bool is_e = ch_button->IsEnabled();
    bool is_das = ch_button->IsDisabledAndSelected();

    if(is_das)
    {
        cout << "down, disabled" << endl;
    }
    else
    {
        if( is_d && is_e)
        {
            cout << "down, enabled" << endl;
        }
        else if( !is_d && is_e )
        {
            cout << "up, enabled" << endl;
        }
        else if( !is_d && !is_e )
        {
            cout << "up, disabled" << endl;
        }

    }
}

void check_button()
{
   new MyMainFrame(gClient->GetRoot(), 500, 500);
}

So, I a have fix.
And I ask to realize normal function something like this: SetStates(Bool_t is_up, Bool_t is_enabled).

As I said, I will see what can be done. Thanks for the proposal.

Thank you for your help, Bertrand.

You’re very welcome!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.