views:

1563

answers:

1

Hi,

I have a small project that uses libglade and use the following to load the xml file:

self.gladefile = "sdm.glade"
self.wTree = gtk.glade.XML(self.gladefile) 
self.window = self.wTree.get_widget("MainWindow")
if (self.window):
    self.window.connect("destroy", gtk.main_quit)
dic = { "on_button1_clicked" : self.button1_clicked, 
        "on_MainWindow_destroy" : gtk.main_quit}
self.wTree.signal_autoconnect(dic)

After converting my project in glade, what structural changes do I need to make? I'm on Ubuntu 9.04.

+5  A: 

You need to use gtk.Builder instead. This class can load any number of UI files, so you need to add them manually, either as files or as strings:

self.uifile = "sdm.ui"
self.wTree = gtk.Builder()
self.wTree.add_from_file(self.uifile)

Instead of get_widget, just use get_object on the builder class:

self.window = self.wTree.get_object("MainWindow")
if self.window:
    self.window.connect("destroy", gtk.main_quit)

To connect the signals, just use connect_signals, which also takes a dictionary:

dic = { "on_button1_clicked" : self.button1_clicked, 
    "on_MainWindow_destroy" : gtk.main_quit}
self.wTree.connect_signals(dic)

It used to be the case (at least in GTK+ 2.12, not sure if it's still the same) that you could call connect_signals only once, any signals which are not connected during the first invocation will never be connected. This was different in glade, so be careful if you relied on that feature before.

Torsten Marek