Radio Buttons revisited

radiobuttonsrevisited

Now let’s start at the very beginning.

When you read you begin with A B C, when you write your codes with gtkmm3 you begin with radio buttons.

#include "radiobuttons.h"
#include <iostream>
void myfunc (int);

RadioButtons::RadioButtons() :
  m_Box_Top(Gtk::ORIENTATION_VERTICAL),
  m_Box1(Gtk::ORIENTATION_VERTICAL, 10),
  m_Box2(Gtk::ORIENTATION_VERTICAL, 10),
  m_RadioButton1("CW"),
  m_RadioButton2("CW-R"),
  m_RadioButton3("LSB"),
  m_RadioButton4("USB"),
  m_Button_Quit ("Quit")
{
  set_title("Spinor Lab");
  set_border_width(10);

  Gtk::RadioButton::Group group = m_RadioButton1.get_group();
  m_RadioButton2.set_group(group);
  m_RadioButton3.set_group(group);
  m_RadioButton4.set_group(group);

  add(m_Box_Top);

  m_Box_Top.pack_start(m_Box1);
  m_Box_Top.pack_start(m_Separator);
  m_Box_Top.pack_start(m_Box2);

  m_Box2.set_border_width(10);
  m_Box1.set_border_width(10);

  m_Box1.pack_start(m_RadioButton1);
  m_Box1.pack_start(m_RadioButton2);
  m_Box1.pack_start(m_RadioButton3);
  m_Box1.pack_start(m_RadioButton4);

  m_RadioButton1.set_active();

  m_Box2.pack_start(m_Button_Quit);

  m_Button_Quit.set_can_default();
  m_Button_Quit.grab_default();

  m_Button_Quit.signal_clicked().connect (sigc::mem_fun(*this, &RadioButtons::on_button_clicked ) );
  m_RadioButton1.signal_clicked().connect(sigc::mem_fun(*this, &RadioButtons::on_button_clicked1) );
  m_RadioButton2.signal_clicked().connect(sigc::mem_fun(*this, &RadioButtons::on_button_clicked2) );
  m_RadioButton3.signal_clicked().connect(sigc::mem_fun(*this, &RadioButtons::on_button_clicked3) );
  m_RadioButton4.signal_clicked().connect(sigc::mem_fun(*this, &RadioButtons::on_button_clicked4) );

  show_all_children();
}

void RadioButtons::on_button_clicked1()
{
  if(m_RadioButton1.get_active()) {
    std::cout << "clicked1: active" << std::endl;
	myfunc(1);
  }
}

There is a lot of room for improvement.

void myfunc (int index) {
  std::cout << "myfunc: " << index << std::endl;
  switch (index) {
    case 1: 
      operating_mode = 0x03; 
      dsp_filter     = 0x01; 
      break;  
    case 2: 
      operating_mode = 0x07; 
      dsp_filter     = 0x01; 
      break;  
    case 3: 
      operating_mode = 0x00; 
      dsp_filter     = 0x01; 
      break;  
    case 4: 
      operating_mode = 0x01; 
      dsp_filter     = 0x01; 
      break;  
    }
  set_operating_mode();
}

Leave a Reply

Your email address will not be published. Required fields are marked *