4

I am using Glade to design a Box with widgets and then load these widgets into my UI at run-time. To create each Box with widgets at run-time, I create a new GtkBuilder, call add_from_string passing in the text from the .ui file Glade creates, and then use the object returned from get_object("box1") in the UI. I know I could create the widgets with code, but for now, I'd like to use the .ui files Glade creates. It seems inefficient though to instantiate a new GtkBuilder object and the wasted Window object for every Box I want to create. Is there a more efficient method to load .ui files without creating a new GtkWidget object and wasted Window object?

Thanks, Vance

2 Answers 2

2

If you want to fill up your GUI with new widgets while your app is running, it is completely wrong to create a bunch of separate .ui files and GtkBuilders for them. It is very easy to create a single widget from withing the code.

I assume you use Python, since you've tagged your question as pygtk.

Have a look at a simple example:

from gi.repository import Gtk

and:

my_window = Gtk.Window()
my_button = Gtk.Button()
my_window.add(my_button)
my_window.show_all()

Well, it won't really work on it's own, but that's how you can create new widgets. For details on particular widgets, head to this elegant tutorial/docs: http://python-gtk-3-tutorial.readthedocs.org/

2
  • Thanks rafalcieslak. Yes, I am using Python. I am loading data from an internet api and displaying the data in widgets. Thus I need to generate the widgets at runtime. I would like to use Glade as it makes positioning and setting attributes of widgets easy; but why is this use "wrong"?
    – Vance T
    Jul 2, 2012 at 1:11
  • @user72943: While glade is meant to make designing easy, it's good only for static interfaces, where nothing changes at runtime. This is because GtkBuilder (as you have noticed) will not work efficiently, if you will ask it to process a .ui file each time you need a new widget... Glade may be helpful here to test widgets layout and work on design - yet it you want your application to work efficiently (especially if you need to do many GUI changes at runtime), you will have to create widgets the "classic way". Luckily. it's very simple and you shouldn't have trouble with it. Jul 2, 2012 at 11:25
2

If you want different chunks shoved in different areas at run-time, you can build one glade file with loads of windows and re-parent them. For an example check what I did for this other question.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .