State actions and Glade

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

State actions and Glade

Gtk+ - Apps Dev mailing list
I am trying to write an application using Glade where the tool bar contains
a set of radio tool buttons. Those radio tool buttons should not perform an
action when activated but rather just change the associated action's state.

For that I've set the 'Action Name' property for the tool buttons in Glade
as 'win.radio-state(0)' and 'win.radio-state(1)'.

Since the only thing that I am after is the action's state, I don't even
need a 'chage_state' handler in the action definition. Therefore, the
GActionEntry for the radio buttons is defined as:
    {"radio-state", NULL, "i", "0", NULL}

However, no matter what I do, the tool radio buttons are never 'sensitive'
and I can never click on them.

How should I be using state actions with Glade? It seems that I am doing
things as described by https://wiki.gnome.org/HowDoI/GAction but it still
does not work.

Thank you for your help.
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: State actions and Glade

Gtk+ - Apps Dev mailing list
Can someone please help me with some pointer?

Thank you.

On Tue, Sep 18, 2018 at 9:35 AM Mitko Haralanov <[hidden email]>
wrote:

> I am trying to write an application using Glade where the tool bar
> contains a set of radio tool buttons. Those radio tool buttons should not
> perform an action when activated but rather just change the associated
> action's state.
>
> For that I've set the 'Action Name' property for the tool buttons in Glade
> as 'win.radio-state(0)' and 'win.radio-state(1)'.
>
> Since the only thing that I am after is the action's state, I don't even
> need a 'chage_state' handler in the action definition. Therefore, the
> GActionEntry for the radio buttons is defined as:
>     {"radio-state", NULL, "i", "0", NULL}
>
> However, no matter what I do, the tool radio buttons are never 'sensitive'
> and I can never click on them.
>
> How should I be using state actions with Glade? It seems that I am doing
> things as described by https://wiki.gnome.org/HowDoI/GAction but it still
> does not work.
>
> Thank you for your help.
>
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: State actions and Glade

Gtk+ - Apps Dev mailing list
 
Hi Mitko,

The GtkToolbar doesn't implement the GAction interface so you are out of luck there.

You can use gtk_toggle_tool_button_get_active() to get the state of one of the GtkRadioToolButton's in the toolbar.

Eric


//gcc -Wall toolbar1.c -o toolbar1 `pkg-config --cflags --libs gtk+-3.0`

#include<gtk/gtk.h>

static void get_active_radio(GtkWidget *button, GtkToolItem **radios)
  {
    gint i=0;

    for(i=0;i<3;i++)
     {
       if(gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(radios[i])))
          {
            g_print("radio%i\n", i+1);
          }
     }
  }
int main(int argc, char **argv)
  {
    gtk_init(&argc, &argv);

    GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Toolbar");
    gtk_window_set_default_size(GTK_WINDOW(window), 300, 100);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

    GtkToolItem *radio1=gtk_radio_tool_button_new(NULL);
    gtk_tool_item_set_expand(radio1, TRUE);
    gtk_tool_button_set_label(GTK_TOOL_BUTTON(radio1), "radio1");
    GtkToolItem *radio2=gtk_radio_tool_button_new_from_widget(GTK_RADIO_TOOL_BUTTON(radio1));
    gtk_tool_item_set_expand(radio2, TRUE);
    gtk_tool_button_set_label(GTK_TOOL_BUTTON(radio2), "radio2"); 
    GtkToolItem *radio3=gtk_radio_tool_button_new_from_widget(GTK_RADIO_TOOL_BUTTON(radio1));
    gtk_tool_item_set_expand(radio3, TRUE);
    gtk_tool_button_set_label(GTK_TOOL_BUTTON(radio3), "radio3");

    GtkWidget *toolbar=gtk_toolbar_new();
    gtk_widget_set_hexpand(toolbar, TRUE);
    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), radio1, 0); 
    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), radio2, 1);
    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), radio3, 2);

    GtkWidget *button=gtk_button_new_with_label("Get Active Radio");
    gtk_widget_set_hexpand(button, TRUE);
    gtk_widget_set_vexpand(button, TRUE);
    GtkToolItem *radios[]={radio1, radio2, radio3};
    g_signal_connect(button, "clicked", G_CALLBACK(get_active_radio), radios);

    GtkWidget *grid1=gtk_grid_new();
    gtk_container_set_border_width(GTK_CONTAINER(grid1), 15);
    gtk_grid_set_row_spacing(GTK_GRID(grid1), 8);
    gtk_grid_attach(GTK_GRID(grid1), toolbar, 0, 0, 1, 1);
    gtk_grid_attach(GTK_GRID(grid1), button, 0, 1, 1, 1);

    gtk_container_add(GTK_CONTAINER(window), grid1);
   
    gtk_widget_show_all(window);

    gtk_widget_grab_focus(button);

    gtk_main();

    return 0; 
  }

_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: State actions and Glade

Gtk+ - Apps Dev mailing list
Hi,

Thank you for your reply. I am not sure what you mean by "GtkToolbar
doesn't implement the GAction interface". In Glade, I can define the
specify the "Action Name" for each individual widget in the Toolbar. Those
action names get automatically linked to the actions that I've defined in
the my GActionEntry array. The only thing that does not work are the Radio
button actions.

Thank you,
Mitko

On Tue, Oct 2, 2018 at 4:19 PM <[hidden email]> wrote:

>
> Hi Mitko,
>
> The GtkToolbar doesn't implement the GAction interface so you are out of
> luck there.
>
> You can use gtk_toggle_tool_button_get_active() to get the state of one of
> the GtkRadioToolButton's in the toolbar.
>
> Eric
>
>
> //gcc -Wall toolbar1.c -o toolbar1 `pkg-config --cflags --libs gtk+-3.0`
>
> #include<gtk/gtk.h>
>
> static void get_active_radio(GtkWidget *button, GtkToolItem **radios)
>   {
>     gint i=0;
>
>     for(i=0;i<3;i++)
>      {
>
> if(gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(radios[i])))
>           {
>             g_print("radio%i\n", i+1);
>           }
>      }
>   }
> int main(int argc, char **argv)
>   {
>     gtk_init(&argc, &argv);
>
>     GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
>     gtk_window_set_title(GTK_WINDOW(window), "Toolbar");
>     gtk_window_set_default_size(GTK_WINDOW(window), 300, 100);
>     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
>     g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
>
>     GtkToolItem *radio1=gtk_radio_tool_button_new(NULL);
>     gtk_tool_item_set_expand(radio1, TRUE);
>     gtk_tool_button_set_label(GTK_TOOL_BUTTON(radio1), "radio1");
>     GtkToolItem
> *radio2=gtk_radio_tool_button_new_from_widget(GTK_RADIO_TOOL_BUTTON(radio1));
>     gtk_tool_item_set_expand(radio2, TRUE);
>     gtk_tool_button_set_label(GTK_TOOL_BUTTON(radio2), "radio2");
>     GtkToolItem
> *radio3=gtk_radio_tool_button_new_from_widget(GTK_RADIO_TOOL_BUTTON(radio1));
>     gtk_tool_item_set_expand(radio3, TRUE);
>     gtk_tool_button_set_label(GTK_TOOL_BUTTON(radio3), "radio3");
>
>     GtkWidget *toolbar=gtk_toolbar_new();
>     gtk_widget_set_hexpand(toolbar, TRUE);
>     gtk_toolbar_insert(GTK_TOOLBAR(toolbar), radio1, 0);
>     gtk_toolbar_insert(GTK_TOOLBAR(toolbar), radio2, 1);
>     gtk_toolbar_insert(GTK_TOOLBAR(toolbar), radio3, 2);
>
>     GtkWidget *button=gtk_button_new_with_label("Get Active Radio");
>     gtk_widget_set_hexpand(button, TRUE);
>     gtk_widget_set_vexpand(button, TRUE);
>     GtkToolItem *radios[]={radio1, radio2, radio3};
>     g_signal_connect(button, "clicked", G_CALLBACK(get_active_radio),
> radios);
>
>     GtkWidget *grid1=gtk_grid_new();
>     gtk_container_set_border_width(GTK_CONTAINER(grid1), 15);
>     gtk_grid_set_row_spacing(GTK_GRID(grid1), 8);
>     gtk_grid_attach(GTK_GRID(grid1), toolbar, 0, 0, 1, 1);
>     gtk_grid_attach(GTK_GRID(grid1), button, 0, 1, 1, 1);
>
>     gtk_container_add(GTK_CONTAINER(window), grid1);
>
>     gtk_widget_show_all(window);
>
>     gtk_widget_grab_focus(button);
>
>     gtk_main();
>
>     return 0;
>   }
>
>
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: State actions and Glade

Gtk+ - Apps Dev mailing list
 
"I am not sure what you mean"

I don't have a good answer for this. I see that GtkRadioToolButton is in the list of Known Implementations for GtkActionable but doesn't use the GAction interface directly.

https://developer.gnome.org/gtk3/stable/GtkActionable.html#gtk-actionable-set-detailed-action-name

It looks like this allows you to set up your action groups and callbacks with GIO but I don't have experience with it. Maybe someone has an example of setting up widgets to use action callbacks?

Eric

_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: State actions and Glade

Gtk+ - Apps Dev mailing list
In reply to this post by Gtk+ - Apps Dev mailing list
 
I don't know if this is of any help. Another try at it. This one uses a GtkApplication. Setup an action on the button along with the standard "clicked" callback. A menu in there also.

Eric


//gcc -Wall toolbar2.c -o toolbar2 `pkg-config --cflags --libs gtk+-3.0`

#include<gtk/gtk.h>

static void quit_program(GSimpleAction *action, GVariant *parameter, gpointer user_data)
  {
    g_application_quit(G_APPLICATION(user_data));
  }
static void test1_callback(GSimpleAction *action, GVariant *parameter, gpointer user_data)
  {
    g_print("Test1 Callback\n");
  }
static void radio_test1(GtkWidget *button, GtkToolItem **radios)
  {
    gint i=0;

    for(i=0;i<3;i++)
     {
       if(gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(radios[i])))
          {
            g_print("test1 radio%i\n", i+1);
          }
     }
  }
static void radio_test2(GSimpleAction *action, GVariant *parameter, GtkToolItem **radios)
  {
    gint i=0;

     for(i=0;i<3;i++)
      {
        if(gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(radios[i])))
           {
             g_print("    test2 radio%i\n", i+1);
           }
      }
  }
static void app_startup(GtkApplication *app, gpointer user_data)
  {
    //Setup menu callbacks.
    GSimpleAction *test1=g_simple_action_new("test1", NULL);
    g_signal_connect(test1, "activate", G_CALLBACK(test1_callback), app);
    g_action_map_add_action(G_ACTION_MAP(app), G_ACTION(test1));
    g_object_unref(test1);
    GSimpleAction *quit=g_simple_action_new("quit", NULL);
    g_signal_connect(quit, "activate", G_CALLBACK(quit_program), app);
    g_action_map_add_action(G_ACTION_MAP(app), G_ACTION(quit));
    g_object_unref(quit);

    //Setup menu.
    GMenu *menu=g_menu_new();
    GMenu *submenu=g_menu_new();
    g_menu_append_submenu(menu, "Application", G_MENU_MODEL(submenu));
    GMenu *section=g_menu_new();
    g_menu_append_section(submenu, NULL, G_MENU_MODEL(section));
    g_menu_append(section, "Test1", "app.test1");
    g_menu_append(section, "Quit", "app.quit");
    g_object_unref(submenu);
    g_object_unref(section);

    gtk_application_set_menubar(GTK_APPLICATION(app), G_MENU_MODEL(menu));
    g_object_unref(menu);
  }
static void app_activate(GtkApplication *app, GtkToolItem **radios)
  {
    GtkWidget *window=gtk_application_window_new(GTK_APPLICATION(app));
    gtk_window_set_title(GTK_WINDOW(window), "Toolbar2");
    gtk_window_set_default_size(GTK_WINDOW(window), 300, 100);
    gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
    gtk_container_set_border_width(GTK_CONTAINER(window), 20);

    GtkToolItem *radio1=gtk_radio_tool_button_new(NULL);
    gtk_tool_item_set_expand(radio1, TRUE);
    gtk_tool_button_set_label(GTK_TOOL_BUTTON(radio1), "radio1");
    GtkToolItem *radio2=gtk_radio_tool_button_new_from_widget(GTK_RADIO_TOOL_BUTTON(radio1));
    gtk_tool_item_set_expand(radio2, TRUE);
    gtk_tool_button_set_label(GTK_TOOL_BUTTON(radio2), "radio2"); 
    GtkToolItem *radio3=gtk_radio_tool_button_new_from_widget(GTK_RADIO_TOOL_BUTTON(radio1));
    gtk_tool_item_set_expand(radio3, TRUE);
    gtk_tool_button_set_label(GTK_TOOL_BUTTON(radio3), "radio3");

    radios[0]=radio1;
    radios[1]=radio2;
    radios[2]=radio3;

    GtkWidget *toolbar=gtk_toolbar_new();
    gtk_widget_set_hexpand(toolbar, TRUE);
    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), radio1, 0); 
    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), radio2, 1);
    gtk_toolbar_insert(GTK_TOOLBAR(toolbar), radio3, 2);

    GtkWidget *button=gtk_button_new_with_label("Get Active Radio");
    gtk_widget_set_hexpand(button, TRUE);
    gtk_widget_set_vexpand(button, TRUE);
    g_signal_connect(button, "clicked", G_CALLBACK(radio_test1), radios);
 
    GSimpleAction *radio_action1=g_simple_action_new("radio_test2", NULL);
    g_action_map_add_action(G_ACTION_MAP(app), (GAction*)radio_action1);
    g_signal_connect(radio_action1, "activate", G_CALLBACK(radio_test2), radios);
    gtk_actionable_set_action_name(GTK_ACTIONABLE(button), "app.radio_test2");   
    g_object_unref(radio_action1);

    GtkWidget *grid1=gtk_grid_new();
    gtk_container_set_border_width(GTK_CONTAINER(grid1), 15);
    gtk_grid_set_row_spacing(GTK_GRID(grid1), 8);
    gtk_grid_attach(GTK_GRID(grid1), toolbar, 0, 0, 1, 1);
    gtk_grid_attach(GTK_GRID(grid1), button, 0, 1, 1, 1);
  
    gtk_container_add(GTK_CONTAINER(window), grid1);

    gtk_widget_show_all(window);

    gtk_widget_grab_focus(button);
  }
int main(int argc, char **argv)
  {
    GtkApplication *app;
    int status;
    GtkToolItem *radios[3];
    app=gtk_application_new("app.example", G_APPLICATION_FLAGS_NONE);
    g_signal_connect(app, "startup", G_CALLBACK(app_startup), NULL);
    g_signal_connect(app, "activate", G_CALLBACK(app_activate), radios);
    status=g_application_run(G_APPLICATION(app), argc, argv);
    g_object_unref(app);
    return(status);
  }
 

_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: State actions and Glade

Gtk+ - Apps Dev mailing list
Thanks for the example.

I played a bit more with Glade and I found that if the action is described
as a detailed action, i.e. "win.radio-action(0)", then the application acts
as if I haven't define such an action. It appears as if the buildable is
using the entire string as the action name and fails to parse the action
name vs. the action target.

If I remove the detailed portion. i.e. "win.radio-action", the the action
is "connected" but now complains that the parameter does not match.

If I remove the target from the action and just connect the "change-state"
signal without connecting the "activate" signal, the "change-state" signal
handler does not get called at all.

It just seems like there is something broken with Glade's or libglade's
handling of the detailed action.

On Fri, Oct 5, 2018 at 1:44 PM <[hidden email]> wrote:

>
> I don't know if this is of any help. Another try at it. This one uses a
> GtkApplication. Setup an action on the button along with the standard
> "clicked" callback. A menu in there also.
>
> Eric
>
>
> //gcc -Wall toolbar2.c -o toolbar2 `pkg-config --cflags --libs gtk+-3.0`
>
> #include<gtk/gtk.h>
>
> static void quit_program(GSimpleAction *action, GVariant *parameter,
> gpointer user_data)
>   {
>     g_application_quit(G_APPLICATION(user_data));
>   }
> static void test1_callback(GSimpleAction *action, GVariant *parameter,
> gpointer user_data)
>   {
>     g_print("Test1 Callback\n");
>   }
> static void radio_test1(GtkWidget *button, GtkToolItem **radios)
>   {
>     gint i=0;
>
>     for(i=0;i<3;i++)
>      {
>
> if(gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(radios[i])))
>           {
>             g_print("test1 radio%i\n", i+1);
>           }
>      }
>   }
> static void radio_test2(GSimpleAction *action, GVariant *parameter,
> GtkToolItem **radios)
>   {
>     gint i=0;
>
>      for(i=0;i<3;i++)
>       {
>
> if(gtk_toggle_tool_button_get_active(GTK_TOGGLE_TOOL_BUTTON(radios[i])))
>            {
>              g_print("    test2 radio%i\n", i+1);
>            }
>       }
>   }
> static void app_startup(GtkApplication *app, gpointer user_data)
>   {
>     //Setup menu callbacks.
>     GSimpleAction *test1=g_simple_action_new("test1", NULL);
>     g_signal_connect(test1, "activate", G_CALLBACK(test1_callback), app);
>     g_action_map_add_action(G_ACTION_MAP(app), G_ACTION(test1));
>     g_object_unref(test1);
>     GSimpleAction *quit=g_simple_action_new("quit", NULL);
>     g_signal_connect(quit, "activate", G_CALLBACK(quit_program), app);
>     g_action_map_add_action(G_ACTION_MAP(app), G_ACTION(quit));
>     g_object_unref(quit);
>
>     //Setup menu.
>     GMenu *menu=g_menu_new();
>     GMenu *submenu=g_menu_new();
>     g_menu_append_submenu(menu, "Application", G_MENU_MODEL(submenu));
>     GMenu *section=g_menu_new();
>     g_menu_append_section(submenu, NULL, G_MENU_MODEL(section));
>     g_menu_append(section, "Test1", "app.test1");
>     g_menu_append(section, "Quit", "app.quit");
>     g_object_unref(submenu);
>     g_object_unref(section);
>
>     gtk_application_set_menubar(GTK_APPLICATION(app), G_MENU_MODEL(menu));
>     g_object_unref(menu);
>   }
> static void app_activate(GtkApplication *app, GtkToolItem **radios)
>   {
>     GtkWidget *window=gtk_application_window_new(GTK_APPLICATION(app));
>     gtk_window_set_title(GTK_WINDOW(window), "Toolbar2");
>     gtk_window_set_default_size(GTK_WINDOW(window), 300, 100);
>     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
>     gtk_container_set_border_width(GTK_CONTAINER(window), 20);
>
>     GtkToolItem *radio1=gtk_radio_tool_button_new(NULL);
>     gtk_tool_item_set_expand(radio1, TRUE);
>     gtk_tool_button_set_label(GTK_TOOL_BUTTON(radio1), "radio1");
>     GtkToolItem
> *radio2=gtk_radio_tool_button_new_from_widget(GTK_RADIO_TOOL_BUTTON(radio1));
>     gtk_tool_item_set_expand(radio2, TRUE);
>     gtk_tool_button_set_label(GTK_TOOL_BUTTON(radio2), "radio2");
>     GtkToolItem
> *radio3=gtk_radio_tool_button_new_from_widget(GTK_RADIO_TOOL_BUTTON(radio1));
>     gtk_tool_item_set_expand(radio3, TRUE);
>     gtk_tool_button_set_label(GTK_TOOL_BUTTON(radio3), "radio3");
>
>     radios[0]=radio1;
>     radios[1]=radio2;
>     radios[2]=radio3;
>
>     GtkWidget *toolbar=gtk_toolbar_new();
>     gtk_widget_set_hexpand(toolbar, TRUE);
>     gtk_toolbar_insert(GTK_TOOLBAR(toolbar), radio1, 0);
>     gtk_toolbar_insert(GTK_TOOLBAR(toolbar), radio2, 1);
>     gtk_toolbar_insert(GTK_TOOLBAR(toolbar), radio3, 2);
>
>     GtkWidget *button=gtk_button_new_with_label("Get Active Radio");
>     gtk_widget_set_hexpand(button, TRUE);
>     gtk_widget_set_vexpand(button, TRUE);
>     g_signal_connect(button, "clicked", G_CALLBACK(radio_test1), radios);
>
>     GSimpleAction *radio_action1=g_simple_action_new("radio_test2", NULL);
>     g_action_map_add_action(G_ACTION_MAP(app), (GAction*)radio_action1);
>     g_signal_connect(radio_action1, "activate", G_CALLBACK(radio_test2),
> radios);
>     gtk_actionable_set_action_name(GTK_ACTIONABLE(button),
> "app.radio_test2");
>     g_object_unref(radio_action1);
>
>     GtkWidget *grid1=gtk_grid_new();
>     gtk_container_set_border_width(GTK_CONTAINER(grid1), 15);
>     gtk_grid_set_row_spacing(GTK_GRID(grid1), 8);
>     gtk_grid_attach(GTK_GRID(grid1), toolbar, 0, 0, 1, 1);
>     gtk_grid_attach(GTK_GRID(grid1), button, 0, 1, 1, 1);
>
>     gtk_container_add(GTK_CONTAINER(window), grid1);
>
>     gtk_widget_show_all(window);
>
>     gtk_widget_grab_focus(button);
>   }
> int main(int argc, char **argv)
>   {
>     GtkApplication *app;
>     int status;
>     GtkToolItem *radios[3];
>     app=gtk_application_new("app.example", G_APPLICATION_FLAGS_NONE);
>     g_signal_connect(app, "startup", G_CALLBACK(app_startup), NULL);
>     g_signal_connect(app, "activate", G_CALLBACK(app_activate), radios);
>     status=g_application_run(G_APPLICATION(app), argc, argv);
>     g_object_unref(app);
>     return(status);
>   }
>
>
>
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list