Re: How to check if a radiobutton is activated?



Well with Glade/libglade, a function like this would
do the trick.  Radio buttons are checked and updated
like toggle_buttons

void SetRadioButton(char *name, int set)
{
  GtkWidget *widget;
  widget=glade_xml_get_widget(xml, name);
  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), set);
}

the char *name  is the name of the radio button widget as it will
check against your xml parsed by libglade (xml must be global
for this example function)
int set  is the radio button to be active, by numbers  0 is first
button, 1 is second button, etc...

-Brad

Patrice St-Gelais wrote:

Hi,

I don't know Glade, but maybe maybe if I describe how I use these
buttons it can give you some hints.

Usually a radio button would be matched with the content of a
user-defined variable.  You update the variable in the callback function
or functions connected to the buttons, using the "toggled" signal.  Each
button is connected separately.  The variable could be a global one or
an element of your callback data.

When you create the radio buttons, you toggle the one corresponding with
the value of the variable with :

 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);

If you don't, the default is the first button in the group.  You must
preset your user-defined variable accordingly.

One simple way to deal with the callbacks functions is to write one for
each button, hard-coding the update of your user-defined variable with a
different value in each function.

Another way is to check the content of the current button in a unique
callback function, connected to each button.  For instance:

void set_display_scale(GtkWidget *button, gpointer data) {
// Sets the display scale from the label of a radio button
 gchar *txt;
 my_struct *my_s;
 my_s = (my_struct *) data;
 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button)))
    // We are clicking another button, untoggling the current one
  return;
 gtk_label_get(GTK_LABEL(GTK_BIN(button)->child), &txt);
 if (!strcmp(SCALE_100, txt))
  my_s->display_scale = 0;
 else
 if (!strcmp(SCALE_50, txt))
  my_s->display_scale = 1;
....

As you can guess, if the user never clicks on any button before
committing the dialog ("OK'), you never know the actual button value
without presetting your variable.

There are probably other ways to know which button is currently
activated, for instance, by "digging" into the group containing the
buttons when "OK" is clicked, but it sounds to me rather unusual.

Hoping this helps.

Regards,

Patrice St-Gelais
__________________
Kent Nyberg a écrit :


Hello!
In my program (created with glade/libglade) i use a dialog
with some radiobuttons in it. When the user clicks 'ok' the
function connected to the 'ok'-button should check witch
radiobutton is activated.
I looked in the archives but could only find something about
GTK_TOGGLE_BUTTON(radiobutton)->active but that
always gives me '1' no matter what
radiobutton is active.

Can some one recomend a good example of how to check
radiobuttons? The GTK tutorial-examples does not cover my
problem, it only creates radiobuttons and leaves them. :(

If some one could help me i would be very glad!

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list




--
-----------------------------
Brad House
Sr. Developer
Main Street Softworks, Inc.

brad mainstreetsoftworks com
(352) 378-8228
-----------------------------




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]