Question

i want to populate a gtk.notebook on-the-fly. everytime a user opens a file, a new notebook-tab is generated. pretty straight forward. my problem is, that i use glade to build the ui and the notebook-tab should have a child widget tree (scrolledwindow->viewport-> alignment->frame). in my glade-file, i have a template notebook-tab, which i want to use multiple times, so that i dont have to code the whole tree in plain gtk. with libglade, you could reuse a widget tree as explained in the pygtk faq here: http://faq.pygtk.org/index.py?file=faq22.011.htp&req=show . How do i do this with GtkBuilder?

thanks in advance,

Arthur

Was it helpful?

Solution

Do it this way with GtkBuilder:

builder = gtk.Builder()
builder.add_from_file("GUI.xml")
builder.connect_signals(self)
self.window1 = builder.get_object("window1")
self.window1.show()

edit:

I was initially wrong, it seems that gtkbuilder does instantiate objects when it adds. So the ideal way to do this would be to add the widget in manually via a string

builder.add_from_string("""
<interface>
  <object class="GtkWindow" id="window1">
    <child>
      <object class="GtkComboBox" id="combobox1">
        <property name="model">liststore1</property>
      </object>
    </child>
  </object>
</interface>""")

self.window1 = builder.get_object("window1")

Hopefully this works!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top