8

The following code is from listing 9-11 of Foundations of GTK+ Development. Through this book, I've been attempting to migrate any GTK2 specific stuff (or any depreciated code for that matter) to learn what's relevant at the present moment. That said, this generated a lot of warnings on compile.

#define NUM_ENTRIES 13 static GtkActionEntry entries[] = { { "File", NULL, "_File", NULL, NULL, NULL }, { "Open", GTK_STOCK_OPEN, NULL, NULL, "Open an existing file", G_CALLBACK(open) }, { "Save", GTK_STOCK_SAVE, NULL, NULL, "Save the document to a file", G_CALLBACK(save) }, { "Quit", GTK_STOCK_QUIT, NULL, NULL, "Quit the application", G_CALLBACK(quit) }, { "Edit", NULL, "_Edit", NULL, NULL, NULL }, { "Cut", GTK_STOCK_CUT, NULL, NULL, "Cut the selection to the clipboard", G_CALLBACK(cut) }, { "Copy", GTK_STOCK_COPY, NULL, NULL, "Copy the selection to the clipboard", G_CALLBACK(copy) }, { "Paste", GTK_STOCK_PASTE, NULL, NULL, "Paste from the clipboard", G_CALLBACK(paste) }, { "SelectAll", GTK_STOCK_SELECT_ALL, NULL, NULL, "Select all the text", G_CALLBACK(selectall) }, { "Deselect", NULL, "_Deselect", NULL, "Deselect text", G_CALLBACK(deselect) }, { "Help", NULL, "_Help", NULL, NULL, NULL }, { "Contents", GTK_STOCK_HELP, NULL, NULL, "Get help using the application", G_CALLBACK(help) }, { "About", GTK_STOCK_ABOUT, NULL, NULL, "More information about the application", G_CALLBACK(about) } }; int main(int argc, char *argv[]) { GtkWidget *window, *menubar, *toolbar, *vbox; GtkActionGroup *group; GtkUIManager *uimanager; gtk_init(&argc, &argv); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(window), "UI Manager"); gtk_widget_set_size_request(window, 250, -1); g_signal_connect(window, "destroy", gtk_main_quit, NULL); group = gtk_action_group_new("MainActionGroup"); gtk_action_group_add_actions(group, entries, NUM_ENTRIES, NULL); uimanager = gtk_ui_manager_new(); gtk_ui_manager_insert_action_group(uimanager, group, 0); gtk_ui_manager_add_ui_from_file(uimanager, "menu.ui", NULL); gtk_ui_manager_add_ui_from_file(uimanager, "toolbar.ui", NULL); menubar = gtk_ui_manager_get_widget(uimanager, "/MenuBar"); toolbar = gtk_ui_manager_get_widget(uimanager, "/Toolbar"); gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS); gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(uimanager)); vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0); gtk_container_add(GTK_CONTAINER(window), vbox); gtk_widget_show_all(window); gtk_main(); return 0; } 

Specifically:

uimanager.c: At top level: uimanager.c:18:3: warning: ‘GtkStock’ is deprecated [-Wdeprecated-declarations] { "Open", GTK_STOCK_OPEN, NULL, NULL, "Open an existing file", G_CALLBACK(open) }, ^ ... uimanager.c: In function ‘main’: uimanager.c:45:2: warning: ‘gtk_action_group_new’ is deprecated (declared at /usr/include/gtk-3.0/gtk/deprecated/gtkactiongroup.h:175) [-Wdeprecated-declarations] group = gtk_action_group_new("MainActionGroup"); ^ uimanager.c:46:2: warning: ‘gtk_action_group_add_actions’ is deprecated (declared at /usr/include/gtk-3.0/gtk/deprecated/gtkactiongroup.h:210) [-Wdeprecated-declarations] gtk_action_group_add_actions(group, entries, NUM_ENTRIES, NULL); ^ uimanager.c:48:2: warning: ‘gtk_ui_manager_new’ is deprecated (declared at /usr/include/gtk-3.0/gtk/deprecated/gtkuimanager.h:130) [-Wdeprecated-declarations] uimanager = gtk_ui_manager_new(); ^ uimanager.c:49:2: warning: ‘gtk_ui_manager_insert_action_group’ is deprecated (declared at /usr/include/gtk-3.0/gtk/deprecated/gtkuimanager.h:138) [-Wdeprecated-declarations] gtk_ui_manager_insert_action_group(uimanager, group, 0); ^ uimanager.c:50:2: warning: ‘gtk_ui_manager_add_ui_from_file’ is deprecated (declared at /usr/include/gtk-3.0/gtk/deprecated/gtkuimanager.h:163) [-Wdeprecated-declarations] gtk_ui_manager_add_ui_from_file(uimanager, "menu.ui", NULL); ^ uimanager.c:51:2: warning: ‘gtk_ui_manager_add_ui_from_file’ is deprecated (declared at /usr/include/gtk-3.0/gtk/deprecated/gtkuimanager.h:163) [-Wdeprecated-declarations] gtk_ui_manager_add_ui_from_file(uimanager, "toolbar.ui", NULL); ^ uimanager.c:53:2: warning: ‘gtk_ui_manager_get_widget’ is deprecated (declared at /usr/include/gtk-3.0/gtk/deprecated/gtkuimanager.h:149) [-Wdeprecated-declarations] menubar = gtk_ui_manager_get_widget(uimanager, "/MenuBar"); ^ uimanager.c:54:2: warning: ‘gtk_ui_manager_get_widget’ is deprecated (declared at /usr/include/gtk-3.0/gtk/deprecated/gtkuimanager.h:149) [-Wdeprecated-declarations] toolbar = gtk_ui_manager_get_widget(uimanager, "/Toolbar"); ^ uimanager.c:56:2: warning: ‘gtk_ui_manager_get_accel_group’ is deprecated (declared at /usr/include/gtk-3.0/gtk/deprecated/gtkuimanager.h:147) [-Wdeprecated-declarations] gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(uimanager)); ^ 

For whatever reason, I've yet to find proper guidance on what to do instead of using GtkStock items, though I've managed to work around them in every other tutorial. However, the same now goes for action groups, UI managers, and the lot of warnings in that second section. The docs just say they're depreciated and not to be used. If so, what should any of these items be replaced with?

1
  • No reason to downvote, information about what to use instead is scattered all over the gtk docs, mailinglist and rfc, at least I could not find a migration guide which stated clearly what to use instead from a top down perspective. Commented Jul 25, 2014 at 19:09

2 Answers 2

18
  1. Gtk.ActionGroup is deprecated, use GLib.SimpleActionGroup
  2. Gtk.Action is deprecated, use GLib.SimpleAction
  3. If you creating a menu, use Gtk.menu_new_with_model (better approach)
  4. Gtk.UIManager is deprecated, use Gtk.Builder instead
  5. Gtk.Stock is deprecated, use "set_icon_name" property instead if applicable. For example, read Gtk.ToolButton doc. In menu, unfortunately, Gtk3 drop the use of icon in menu.
Sign up to request clarification or add additional context in comments.

11 Comments

Thank you, that was complete and very specific. =) May I ask where (if anywhere) the information about what to use instead of the depreciated features is published?
you have to read the Gtk Documentation. If you offline install libgtk3.0-doc or you can find it in developer.gnome.org/gtk3/stable
I've definitely been reading the documentation, but I still haven't found the things you said specifically written down.
what version of gtk you are using ?
sorry to take a long time to get back to you, i was ill. as @jku said, it does contain hint of where those deprecation things being replaced with. for your case, the Gtk.ActionGroup is deprecated but it doesn't say how to replace. Reading further than that, Gtk.Action is actually related to Gtk.ActionGroup, is also deprecated. But it does say how to replace it, with GLib.Action. From there, just read bit more,before you get to the GLib.ActionGroup. Also, maybe this is an off topic, but, every Gtk's underlying mechanism is using GLib or GIO except for drawing part which is cairo
|
1

Thus there is no complete guide step by step on how to do things

for GtkStock, there is that document: https://docs.google.com/document/d/1KCVPoYQBqMbDP11tHPpjW6uaEHrvLUmcDPqKAppCY8o/pub

For GtkUiManager and other there is some code example available when you downlod the source code, into the exemple directory action-namespace.c

At last gtk-demo provide some code examples as well.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.