Radio Buttons

radiobutton

It works, but initially a signal is issued that tells “10 wpm” is toggled. This is strange because the default depressed button is set to “30 wpm”.

void callback2( GtkWidget *widget, gpointer data ) {
 int wpm;
 wpm = atoi( g_strndup((char *) data, 2) );
 set_cw_speed(wpm);
 g_print ("%s was toggled \n", (char *) data);
}

The callback routine is almost the same as before. No need to check the suffix of “wpm” here.

/* main() */
    char *strwpm[] = {"10 wpm", "15 wpm", "20 wpm", "25 wpm", "30 wpm", "35 wpm", "40 wpm"};

    for(int i=0;i<7;i++) {
     if(i == 0) {
      button = gtk_radio_button_new_with_label(NULL, strwpm[i]);
     } else {
      button = gtk_radio_button_new_with_label(gtk_radio_button_group (GTK_RADIO_BUTTON (button)), strwpm[i]);
     }
     if(i == 4) gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
     gtk_signal_connect (GTK_OBJECT (button), "toggled", GTK_SIGNAL_FUNC (callback2), (gpointer) strwpm[i]);
     gtk_box_pack_start (GTK_BOX (box2), button, TRUE, TRUE, 0);
     gtk_widget_show (button);
    }

Initially, the fourth button (30 wpm) is depressed. (Yes, we count from the number zero.)

% ./a.out
10 wpm was toggled <-- before I touch no buttons.

This is not what I expected, but it should not be a big matter, because I will need some initialization for IC-7410 anyway.

Leave a Reply

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