title: repeatedly insert copies of same gtk objects generated from glade file
body: <p>I am rewriting parts of the interface of an old Python program written using glade and PyGTK.</p>
  
  <p>the program is rather complex, parts of the functionality is in plugins, so the original author has organized the interface definition in several glade files. also, some window define a generic interface, and then the specialization comes with its own widgets which fit in the generic GUI.</p>
  
  <p>I have a perplexity on how to do this correctly using </p>
  
  <pre><code>from gi.repository import Gtk
  builder = Gtk.Builder()
  </code></pre>
  
  <p>the builder, a global variable, holds all gtk objects defined in the glade files I pass it using its <code>add_from_file</code> method.</p>
  
  <p>now I want to add several expanders, showing one line of info when collapsed and a picture and more textual info when expanded.</p>
  
  <p>these expanders and the main window come all from the same <code>picture_expander.glade</code> file, which looks roughly like this:</p>
  
  <pre><code>&lt;interface&gt;
    &lt;object class="GtkWindow" id="picture_preview_window"&gt;
      &lt;child&gt;
        &lt;object class="GtkScrolledWindow" id="scrolledwindow2"&gt;
          &lt;child&gt;
            &lt;object class="GtkViewport" id="viewport1"&gt;
              &lt;child&gt;
                &lt;object class="GtkBox" id="notes_expander_box"&gt;
                  &lt;property name="orientation"&gt;vertical&lt;/property&gt;
                  &lt;child&gt;
                    &lt;placeholder/&gt;
                  &lt;/child&gt;
                &lt;/object&gt;
              &lt;/child&gt;
            &lt;/object&gt;
          &lt;/child&gt;
        &lt;/object&gt;
      &lt;/child&gt;
    &lt;/object&gt;
    &lt;object class="GtkBox" id="notes_box"&gt;
      &lt;property name="orientation"&gt;vertical&lt;/property&gt;
      &lt;child&gt;
        &lt;object class="GtkExpander" id="notes_expander"&gt;
          &lt;child&gt;
            &lt;object class="GtkBox" id="vbox2"&gt;
              &lt;property name="orientation"&gt;vertical&lt;/property&gt;
              &lt;child&gt;
                &lt;object class="GtkTable" id="table1"&gt;
                  &lt;property name="n_columns"&gt;2&lt;/property&gt;
                  &lt;child&gt;
                    &lt;object class="GtkLabel" id="label3"&gt;
                      &lt;property name="label" translatable="yes"&gt;User&lt;/property&gt;
                    &lt;/object&gt;
                    &lt;packing&gt;
                      &lt;property name="x_options"&gt;GTK_FILL&lt;/property&gt;
                      &lt;property name="y_options"/&gt;
                    &lt;/packing&gt;
                  &lt;/child&gt;
                &lt;/object&gt;
                &lt;packing&gt;
                &lt;/packing&gt;
              &lt;/child&gt;
              &lt;child&gt;
                &lt;object class="GtkBox" id="picture_frame"&gt;
                  &lt;property name="orientation"&gt;horizontal&lt;/property&gt;
                  &lt;child&gt;
                    &lt;placeholder/&gt;
                  &lt;/child&gt;
                &lt;/object&gt;
              &lt;/child&gt;
            &lt;/object&gt;
          &lt;/child&gt;
          &lt;child type="label"&gt;
            &lt;object class="GtkLabel" id="label1"&gt;
            &lt;/object&gt;
          &lt;/child&gt;
        &lt;/object&gt;
      &lt;/child&gt;
      &lt;child&gt;
        &lt;object class="GtkSeparator" id="hseparator2"&gt;
          &lt;property name="orientation"&gt;horizontal&lt;/property&gt;
        &lt;/object&gt;
      &lt;/child&gt;
    &lt;/object&gt;
  &lt;/interface&gt;
  </code></pre>
  
  <p>what is the correct way to do this?</p>
  
  <p>if I add the <code>picture_expander.glade</code> to the builder, no matter how many times I add it, the builder will create one object and not many copies of it. if I understand correctly, this is exactly the reason why the builder class was introduced. but this way I do not get different objects I can add to my <code>notes_expander_box</code> container.</p>
  
  <p>I see different options, but I don't know which is the safest and suggested.</p>
  
  <p>I might clone the object and its content, but how do I do that?
  and what happens with the IDs, how do I refer to the newly cloned objects?</p>
  
  <p>or, what I am doing now and works, for every expander I have to add to the <code>notes_expander_box</code> container, I create a new builder to which I pass the same file, and then ask the new builder to give me the object corresponding to the ID, so I end up with a new object and I can add it to my container.</p>
  
  <pre><code># -*- coding: utf-8 -*-
  #/usr/bin/env python
  
  from gi.repository import Gtk
  builder = Gtk.Builder()
  
  builder.add_from_file("picture_preview.glade")
  
  win = builder.get_object('picture_preview_window')
  
  ne = builder.get_object('notes_expander_box')
  for i in range(1, 4):
      tb = Gtk.Builder()
      tb.add_from_file("picture_preview.glade")
      box = tb.get_object('notes_box')
      ne.add(box)
  
  win.show_all()
  Gtk.main()
  </code></pre>
  
  <p>still, I don't think this is the way to go, as all the objects I am inserting all have the same ID.</p>
  
  <p>or should I try to have something like <code>Jinja2</code> generate the glade xml for me so that I can pass it to the global builder? with repetitions and unique IDs?</p>
  
  <p>the last option I see is to leave glade alone and do at least this part programmaticly.</p>