views:

743

answers:

4

I'm working on a PyGTK/glade application that currently has 16 windows/dialogs and is about 130KB, and will eventually have around 25 windows/dialogs and be around 200KB. Currently, I'm storing all the windows in one monolithic glade file. When I run a window I call it like...

self.wTree = gtk.glade.XML("interface.glade", "WindowXYZ")

I wonder if it would be a better idea to split each window into it's own glade file. Instead of one glade file with 25 windows/dialogs I'd have 25 glade files with one window/dialog each and call it like so:

self.wTree = gtk.glade.XML("windowxyz.glade")

What do you guys think is the best way to do this? Is one method more resource intensive than another? One thing that would be nice about going to individual glade files is that naming widgets would be easier. For example, I name all my OK buttons "windowxyz_ok", but I could change it to simply "ok" instead. Makes things simpler. The downside is that it may be a bit less convenient to make changes to different windows.

I'm open to any and all arguments. Thanks!

A: 

Did you take some timings to find out whether it makes a difference?

The problem is that, as far as I understand it, Glade always creates all widgets when it parses an XML file, so if you open the XML file and only read a single widget, you are wasting a lot of resources.

The other problem is that you need to re-read the file if you want to have another instance of that widget.

The way I did it before was to put all widgets that were created only once (like the about window, the main window etc) into one glade file, and separate glade files for widgets that needed to be created several times.

Torsten Marek
A: 

I use different glade files for different windows. But I keep dialog associated with a window in the same glade file. As you said, the naming problem is annoying.

Manuel Ceron
+5  A: 

In my projects, I always have one window per glade file. I'd recommend the same for your project.

The following are the two main reasons:

  • It will be faster and use less memory, since each call to gtk.glade.XML() parses the whole thing. Sure you can pass in the root argument to avoid creating the widget tree for all windows, but you'd still have to parse all the XML, even if you're not interested in it.
  • Conceptually its easier to understand if have one toplevel per window. You easily know which filename a given dialog/window is in just by looking at the filename.
Johan Dahlin
A: 

I have one glade file with 2 windows. It's about 450kb in size and I have not seen any slowdowns using libglademm with GTKmm.

Soo Wei Tan