On Fri, 2009-05-22 at 19:00 +0200, Alberto Garcia wrote:
> Well, that's what looks better in the Fremantle UI style. So even
> if you use gtk radio buttons directly (i.e, without gtk actions) I
> suggest you to do something like this:
> 
> gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (radio_button), FALSE);

To be honest, I also like the _look_ of the toggle button more then the
look of the radio button. But I think we really should use radio buttons
where it is semantically correct/needed.
If the user can only select one single option he should see a radio
button group and not something else. Imaging an app menu with two radio
button groups with three options each. Now if we would use toggle
buttons there the user wouldn't get any clue which combinations he can
select. It would be pure try & error.

So why not just change the visual representation of a GtkRadioButton to
something more pleasing?

> Of course you can still use the traditional radio button look if you
> want, see the attached example (it might help you with the keyboard
> accelerators too).

Thanks a lot for the code example. I didn't look at the accelerators
code yet, but I checked the radio button / action stuff.

I attached a slightly extended version of your example, which uses
gtk_radio_action_set_current_value() the way I'm using it in my code.
Sadly it's not working. So maybe I'm just doing it all wrong. Please
check my small modifications.

Here is a small diff to give you a quick glance of what I changed:

> GtkRadioAction *radioaction = NULL;
> 
13c15,28
<     g_debug ("Button clicked: %s", gtk_action_get_name (action));
---
>     const gchar *name = gtk_action_get_name (action);
>     g_debug ("Button clicked: %s", name);
> 
>     if (strcmp(name, "Action one") == 0) {
>       g_debug("Activating Radio One");
>       gtk_radio_action_set_current_value(radioaction, 0);
>     } else if (strcmp(name, "Action two") == 0) {
>       g_debug("Activating Radio Two");
>       gtk_radio_action_set_current_value(radioaction, 1);
>     } else if (strcmp(name, "Action three") == 0) {
>       g_debug("Activating Radio Three");
>       gtk_radio_action_set_current_value(radioaction, 2);
>     }
> 
68d82
<     GtkRadioAction *radioaction;


So long!
Conny


#include                                        <hildon/hildon.h>

GtkRadioAction *radioaction = NULL;

static void
radio_action_changed                            (GtkAction *action,
                                                 GtkAction *current)
{
    g_debug ("Radio action changed: %s", gtk_action_get_name (current));
}

static void
action_activated                                (GtkAction *action)
{
    const gchar *name = gtk_action_get_name (action);
    g_debug ("Button clicked: %s", name);

    if (strcmp(name, "Action one") == 0) {
    	g_debug("Activating Radio One");
    	gtk_radio_action_set_current_value(radioaction, 0);
    } else if (strcmp(name, "Action two") == 0) {
    	g_debug("Activating Radio Two");
    	gtk_radio_action_set_current_value(radioaction, 1);
    } else if (strcmp(name, "Action three") == 0) {
    	g_debug("Activating Radio Three");
    	gtk_radio_action_set_current_value(radioaction, 2);
    }

}

static GtkAction *
create_action                                   (const gchar *name,
                                                 const gchar *accel,
                                                 GtkActionGroup *actiongroup,
                                                 GtkAccelGroup *accelgroup)
{
    GtkAction *action = gtk_action_new (name, name, NULL, NULL);
    gtk_action_group_add_action_with_accel (actiongroup, action, accel);
    gtk_action_set_accel_group (action, accelgroup);
    gtk_action_connect_accelerator (action);
    g_signal_connect (action, "activate", G_CALLBACK (action_activated), NULL);
    return action;
}

static GtkButton *
create_item                                     (GtkAction *action)
{
    HildonSizeType buttonsize = HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH;
    GtkWidget *button = hildon_gtk_button_new (buttonsize);
    gtk_action_connect_proxy (action, button);
    return GTK_BUTTON (button);
}

static GtkRadioAction *
create_radio_action                             (const gchar *name,
                                                 GtkRadioAction *previous)
{
    static gint count = 0;
    GtkRadioAction *action = gtk_radio_action_new (name, name, NULL, NULL, count++);
    if (previous) {
        gtk_radio_action_set_group (action, gtk_radio_action_get_group (previous));
    }
    return action;
}

static GtkButton *
create_radio_item                               (GtkRadioAction *action)
{
    static GSList *group = NULL;
    HildonSizeType buttonsize = HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH;
    GtkWidget *button = hildon_gtk_radio_button_new (buttonsize, group);
    group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
    gtk_action_connect_proxy (GTK_ACTION (action), button);
    return GTK_BUTTON (button);
}

static HildonAppMenu *
create_menu                                     (GtkAccelGroup *accel)
{
    HildonAppMenu *menu = HILDON_APP_MENU (hildon_app_menu_new ());
    GtkActionGroup *group = gtk_action_group_new ("actiongroup");
    GtkAction *action;

    /* Items */
    action = create_action ("Action one", "<Ctrl>1", group, accel);
    hildon_app_menu_append (menu, create_item (action));

    action = create_action ("Action two", "<Ctrl>2", group, accel);
    hildon_app_menu_append (menu, create_item (action));

    action = create_action ("Action three", "<Ctrl>3", group, accel);
    hildon_app_menu_append (menu, create_item (action));

    action = create_action ("Action four", "<Ctrl>4", group, accel);
    hildon_app_menu_append (menu, create_item (action));

    /* Filters */
    radioaction = create_radio_action ("Radio one", NULL);
    g_signal_connect (radioaction, "changed", G_CALLBACK (radio_action_changed), NULL);
    gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (radioaction), TRUE);
    hildon_app_menu_add_filter (menu, create_radio_item (radioaction));

    radioaction = create_radio_action ("Radio two", radioaction);
    hildon_app_menu_add_filter (menu, create_radio_item (radioaction));

    radioaction = create_radio_action ("Radio three", radioaction);
    hildon_app_menu_add_filter (menu, create_radio_item (radioaction));

    gtk_widget_show_all (GTK_WIDGET (menu));

    return menu;
}

int
main                                            (int argc,
                                                 char **argv)
{
    GtkWidget *win;
    GtkWidget *label;
    HildonAppMenu *menu;
    GtkAccelGroup *accel;

    hildon_gtk_init (&argc, &argv);

    label = gtk_label_new ("This is an example of the\nHildonAppMenu widget.\n\n"
                           "Click on the titlebar\nto pop up the menu.");
    gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_CENTER);

    win = hildon_stackable_window_new ();

    accel = gtk_accel_group_new ();
    menu = create_menu (accel);
    hildon_window_set_app_menu (HILDON_WINDOW (win), menu);

    gtk_window_add_accel_group (GTK_WINDOW (win), accel);
    g_object_unref (accel);

    gtk_container_set_border_width (GTK_CONTAINER (win), 20);
    gtk_container_add (GTK_CONTAINER (win), label);

    g_signal_connect (win, "delete_event", G_CALLBACK (gtk_main_quit), NULL);

    gtk_widget_show_all (win);

    gtk_main ();

    return 0;
}
_______________________________________________
maemo-developers mailing list
maemo-developers@maemo.org
https://lists.maemo.org/mailman/listinfo/maemo-developers

Reply via email to