Re: State actions and Glade

2018-10-05 Thread Eric Cashon via gtk-app-devel-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

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

Re: State actions and Glade

2018-10-04 Thread Eric Cashon via gtk-app-devel-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
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: State actions and Glade

2018-10-04 Thread Mitko Haralanov via gtk-app-devel-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  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
>
> 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(, );
>
> 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
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: State actions and Glade

2018-10-02 Thread Eric Cashon via gtk-app-devel-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

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(, );

    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
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: State actions and Glade

2018-10-02 Thread Mitko Haralanov via gtk-app-devel-list
Can someone please help me with some pointer?

Thank you.

On Tue, Sep 18, 2018 at 9:35 AM Mitko Haralanov 
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
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list