Re: Accelerators for GtkNotebook to switch between pages
Oh no sorry. It not working. I had just defined the t accelerator in the activate function of the app. If I change it to e.g. b the accelerator doesn't work. Am 07.02.2018 um 23:19 schrieb Alexander Koeppe: > Hi infirit, > > crazy. I rebuilt the relevant parts in a demo app and there it's working > as expected. *argh*. > For completeness here's what I mean. > > The code that creates my GtkNotebook: > > /* notebook */ > notebook = gtk_notebook_new(); > gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_TOP); > gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), TRUE); > gtk_container_add(GTK_CONTAINER(frame), notebook); > > /* notebook page 1 */ > label = gtk_label_new("Tab1"); > gtk_widget_show(label); > page = gtk_frame_new("Content1"); > gtk_widget_show(page); > gtk_notebook_append_page(GTK_NOTEBOOK(notebook), page, label); > > /* notebook page 2 */ > label = gtk_label_new("Tab2"); > gtk_widget_show(label); > page = gtk_frame_new("Content2"); > gtk_widget_show(page); > gtk_notebook_append_page(GTK_NOTEBOOK(notebook), page, label); > > create_tab_menu(notebook); > > > > And this is the content of the create_tab_menu() function to create the > context menu of the tab, that actually contains the action to be > triggered by the accelerator: > > void create_tab_menu(GtkWidget *notebook) > { > GtkWidget *menu; > GtkBuilder *builder; > GSimpleActionGroup *actiongroup; > int i; > struct accel_map { > char *action; > const char * const accel[2]; > }; > > /* define actions */ > static GActionEntry tab_actions[] = { > {"test_action", test_cb, NULL, NULL, NULL, {}} > }; > > /* define accelerators */ > static struct accel_map tab_accels[] = { > {"tab.test_action", {"t", NULL}} > }; > > /* define menu structure */ > builder = gtk_builder_new(); > gtk_builder_add_from_string(builder, > "" > " " > " " > " " > " Test Action" > " tab.test_action" > " name='icon'>weather-clear-symbolic" > " " > " " > " " > "", -1, NULL); > > /* create actiongroup and map actions */ > actiongroup = g_simple_action_group_new(); > g_action_map_add_action_entries(G_ACTION_MAP(actiongroup), > tab_actions, > G_N_ELEMENTS(tab_actions), NULL); > > /* map accelerators to actions */ > for (i = 0; i < G_N_ELEMENTS(tab_accels); i++) > gtk_application_set_accels_for_action(GTK_APPLICATION(app), > tab_accels[i].action, tab_accels[i].accel); > > /* create new GtkMenu from GtkBuilder */ > menu = > gtk_menu_new_from_model(G_MENU_MODEL(gtk_builder_get_object(builder, > "tab-menu"))); > > /* insert action group into menu */ > gtk_widget_insert_action_group(menu, "tab", > G_ACTION_GROUP(actiongroup)); > > /* connect tab menu to right-click handler of notebook */ > g_signal_connect(G_OBJECT(notebook), "button-press-event", > G_CALLBACK(context_cb), menu); > > g_object_unref(builder); > > } > > > > > And for completeness the right-click handler: > > gboolean context_cb(GtkWidget *notebook, GdkEventButton *event, > gpointer data) > { > (void) notebook; > > if (event->button == 3) { > gtk_menu_popup_at_pointer(GTK_MENU(data), (GdkEvent*)event); > return TRUE; > } > > return FALSE; > } > > > > However, I'm afraid I'm back on my own and just have to find where it > goes wrong in my application. > > Thanks > ___ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Accelerators for GtkNotebook to switch between pages
Hi infirit, crazy. I rebuilt the relevant parts in a demo app and there it's working as expected. *argh*. For completeness here's what I mean. The code that creates my GtkNotebook: /* notebook */ notebook = gtk_notebook_new(); gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_TOP); gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), TRUE); gtk_container_add(GTK_CONTAINER(frame), notebook); /* notebook page 1 */ label = gtk_label_new("Tab1"); gtk_widget_show(label); page = gtk_frame_new("Content1"); gtk_widget_show(page); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), page, label); /* notebook page 2 */ label = gtk_label_new("Tab2"); gtk_widget_show(label); page = gtk_frame_new("Content2"); gtk_widget_show(page); gtk_notebook_append_page(GTK_NOTEBOOK(notebook), page, label); create_tab_menu(notebook); And this is the content of the create_tab_menu() function to create the context menu of the tab, that actually contains the action to be triggered by the accelerator: void create_tab_menu(GtkWidget *notebook) { GtkWidget *menu; GtkBuilder *builder; GSimpleActionGroup *actiongroup; int i; struct accel_map { char *action; const char * const accel[2]; }; /* define actions */ static GActionEntry tab_actions[] = { {"test_action", test_cb, NULL, NULL, NULL, {}} }; /* define accelerators */ static struct accel_map tab_accels[] = { {"tab.test_action", {"t", NULL}} }; /* define menu structure */ builder = gtk_builder_new(); gtk_builder_add_from_string(builder, "" " " " " " " " Test Action" " tab.test_action" " weather-clear-symbolic" " " " " " " "", -1, NULL); /* create actiongroup and map actions */ actiongroup = g_simple_action_group_new(); g_action_map_add_action_entries(G_ACTION_MAP(actiongroup), tab_actions, G_N_ELEMENTS(tab_actions), NULL); /* map accelerators to actions */ for (i = 0; i < G_N_ELEMENTS(tab_accels); i++) gtk_application_set_accels_for_action(GTK_APPLICATION(app), tab_accels[i].action, tab_accels[i].accel); /* create new GtkMenu from GtkBuilder */ menu = gtk_menu_new_from_model(G_MENU_MODEL(gtk_builder_get_object(builder, "tab-menu"))); /* insert action group into menu */ gtk_widget_insert_action_group(menu, "tab", G_ACTION_GROUP(actiongroup)); /* connect tab menu to right-click handler of notebook */ g_signal_connect(G_OBJECT(notebook), "button-press-event", G_CALLBACK(context_cb), menu); g_object_unref(builder); } And for completeness the right-click handler: gboolean context_cb(GtkWidget *notebook, GdkEventButton *event, gpointer data) { (void) notebook; if (event->button == 3) { gtk_menu_popup_at_pointer(GTK_MENU(data), (GdkEvent*)event); return TRUE; } return FALSE; } However, I'm afraid I'm back on my own and just have to find where it goes wrong in my application. Thanks ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: Accelerators for GtkNotebook to switch between pages
Op 02/02/2018 om 10:33 PM schreef Alexander Koeppe: > I'm looking for a way to switch between the pages of a GtkNotebook using > e.g. Left and Right. What have you tried so far, do you have a basic example, what part did you get stuck on? > I searched the documentation from different angels but didn't found a > obvious way how to accomplish that. I don't think adding accelerators to the labels is an option. Notebook pages are indexed from 0 and you can retrieve the index with gtk_notebook_get_current_page. Then de/increment with 1 and use gtk_notebook_set_current_page. Read up on [1] for the details on getting/settings notebook pages. ~infirit [1] https://developer.gnome.org/gtk3/stable/GtkNotebook.html ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Accelerators for GtkNotebook to switch between pages
Hi list, I'm looking for a way to switch between the pages of a GtkNotebook using e.g. Left and Right. I searched the documentation from different angels but didn't found a obvious way how to accomplish that. Does somebody have a hint for me pointing into the right direction? Thank you verymuch in advance. - Alex ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list