gtk-builder-convert 错误

gtk-builder-convert 错误

我正在按照链接中的教程进行操作http://www.micahcarrick.com/gtk-glade-tutorial-part-1.html

当我运行 gtk-builder-convert tutorial.glade tutorial.xml 时出现以下错误

    Traceback (most recent call last):
    File "/usr/bin/gtk-builder-convert", line 799, in <module>
    sys.exit(main(sys.argv))
    File "/usr/bin/gtk-builder-convert", line 787, in main
    conv.parse_file(input_filename)
    File "/usr/bin/gtk-builder-convert", line 162, in parse_file
    self._parse()
    File "/usr/bin/gtk-builder-convert", line 234, in _parse
    assert glade_iface, ("Badly formed XML, there is "

    AssertionError: Badly formed XML, there is no <glade-interface> tag.

林间空地文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<interface>
    <!-- interface-requires gtk+ 3.0 -->
    <object class="GtkWindow" id="window">
        <property name="can_focus">False</property>
        <property name="title" translatable="yes">GTK+ Text Editor</property>
        <signal name="destroy" handler="on_window_destroy" swapped="no"/>
        <child>
            <placeholder/>
        </child>
    </object>
</interface>

注意:glade 文件是在 ubuntu 12.10 中使用 Glade 3.14.0 生成的

答案1

上次我在 Glade/GTK 中编程时,不需要“gtk-builder-convert”。glade 提供的 .glade 文件本身就是您需要的 xml 文件。只需编写代码,就好像您已经将文件转换为 .xml 一样(顺便说一句,我使用的是 glade 3.12.1)。例如:

#include <gtk/gtk.h>

void on_window_destroy (GtkWidget *object, gpointer user_data) {
    gtk_main_quit();
}

int main (int argc, char *argv[]) {
    GtkBuilder *builder;
    GtkWidget *window;

    gtk_init (&argc, &argv);

    builder = gtk_builder_new ();
    gtk_builder_add_from_file (builder, "ui.glade", NULL);

    window = GTK_WIDGET (gtk_builder_get_object (builder, "window1"));
    g_signal_connect (window, "destroy", G_CALLBACK (on_window_destroy), NULL);

    gtk_widget_show (window);       
    gtk_main ();

    return 0;
}

相关内容