1

I have the following XML code that I use to generate a GtkMenuBar by means of GtkBuilder:

<?xml version="1.0"?>
<interface>
  <menu id="menubar">
    <submenu id="submenu">
      <attribute name="label">test</attribute>
      <section>
        <item>
          <attribute name="label">random item</attribute>
        </item>
      </section>
    </submenu>
  </menu>
</interface>

Both the menu as well as the submenu allow for an id attribute with which I can use in a call to gtk_builder_get_object, when I ever need to refer to them in my program, and this works just fine.

However, for the item, such an id attribute is impossible, i.e. changing <item> to <item id="myitem"> will result in the error

Gtk-ERROR **: failed to add UI: attribute 'id' invalid for element 'item'

However, I need to change this menu item's label at runtime and had hoped to do this in the way I described above. How can I accomplish this instead?

1 Answers1

0

This is a simple menu bar, with one menu item (_File), one submenu which has 3 Menu items (2x ImageMenuItem and a SeparatorMenuItem). The following was done with Glade 3.19 (Fedora 23) and after parsing your file, glade complains it is targeted for Gtk+ 2.12 even when there is no version reference on the file. As you can see the syntax differs.

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.19.0 -->
<interface>
  <requires lib="gtk+" version="3.16"/>
  <object class="GtkMenuBar" id="menubar1">
    <property name="visible">True</property>
    <property name="can_focus">False</property>
    <child>
      <object class="GtkMenuItem" id="menuitem1">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <property name="label" translatable="yes">_File</property>
        <property name="use_underline">True</property>
        <child type="submenu">
          <object class="GtkMenu" id="menu1">
            <property name="visible">True</property>
            <property name="can_focus">False</property>
            <child>
              <object class="GtkImageMenuItem" id="imagemenuitem1">
                <property name="label">gtk-new</property>
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="use_underline">True</property>
                <property name="use_stock">True</property>
              </object>
            </child>
            <child>
              <object class="GtkSeparatorMenuItem" id="separatormenuitem1">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
              </object>
            </child>
            <child>
              <object class="GtkImageMenuItem" id="imagemenuitem2">
                <property name="label">gtk-quit</property>
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="use_underline">True</property>
                <property name="use_stock">True</property>
              </object>
            </child>
          </object>
        </child>
      </object>
    </child>
  </object>
</interface>

Can you inform a bit more on your setup and dependencies? Anyway, it is recommended to upgrade to Gtk+ 3.

José Fonte
  • 4,016
  • 2
  • 16
  • 28