gpt4 book ai didi

c - gtk_action_group_new() 和 GtkStock - 用什么代替?

转载 作者:太空狗 更新时间:2023-10-29 14:54:03 26 4
gpt4 key购买 nike

以下代码来自 Foundations of GTK+ Development 的 list 9-11| .通过这本书,我一直在尝试迁移任何 GTK2 特定的东西(或与此相关的任何贬值代码)以了解当前相关的内容。也就是说,这会在编译时产生很多警告。

#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;
}

具体来说:

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));
^

无论出于何种原因,我还没有找到关于如何代替使用 GtkStock 项目的正确指导,尽管我已经在其他所有教程中设法解决了这些问题。但是,现在第二部分中的操作组、UI 管理器和大量警告也是如此。文档只是说它们已贬值并且不会被使用。如果是这样,这些项目中的任何一个应该被替换成什么?

最佳答案

  1. Gtk.ActionGroup 已弃用,请使用 GLib.SimpleActionGroup
  2. Gtk.Action 已弃用,请使用 GLib.SimpleAction
  3. 如果您创建菜单,请使用 Gtk.menu_new_with_model(更好的方法)
  4. Gtk.UIManager 已弃用,改用 Gtk.Builder
  5. Gtk.Stock 已弃用,如果适用,请改用“set_icon_name”属性。例如,阅读 Gtk.ToolButton 文档。不幸的是,在菜单中,Gtk3 放弃了在菜单中使用图标。

关于c - gtk_action_group_new() 和 GtkStock - 用什么代替?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24788045/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com