tags:

views:

346

answers:

1

Hi

I have a glade gui, and I want to insert another object using a glade file as well.

When I do it as bellow (this is essentially what I am doing) the whole app hangs and the self.show() and maxes out the CPU at 100%. If I replace the first line of one's init() with self.builder = gtk.Builder() then the app runs, I can set widgets, ie: set contents of entry's, set and change the values of comboboxes. But I cant respond to signals, button clicks never call the handler.

In the real code the object two is set as a page in a note book, and I have multiple other pages, the gtk.main() is in the object that owns the notebook. All these work as expected, it's just the object one that fails.

Any clues? I have tried calling self.builder.connect_signals() for every widget but it still fails to notice them.

class one(gtk.VBox):
 def __init__(self, builder):
        gtk.VBox.__init__(self)
        self.builder = builder  # if this is self.builder = gtk.Builder() app runs but widget signals go missing.
        self.builder.add_from_file("ui_for_one.glade")
     self.show()  # Endless loop here?

class two(object):  # This is the page in a notebook.   
 def __init__(self):
  self.builder = gtk.Builder()
  self.builder.add_from_file("ui_for_two.glade")
  self.some_container = self.builder.get_object("some_container")
  self.one = one(self.builder)
  self.some_container.pack_start(self.one, False, False)
+2  A: 

Is there a good reason for using the same gtk.Builder object in two classes?
This might be the cause of your problem. In your one class, you load a glade file but you never do anything with its widgets. Something like this should work:

class one(gtk.VBox):

  def __init__(self):
    gtk.VBox.__init__(self)
    self.builder = gtk.Builder()
    self.builder.add_from_file("ui_for_one.glade")
    some_widget = self.builder.get_object("some_widget")
    self.add(some_widget)
    self.builder.connect_signals(self)
    # No reason to call self.show() here, that should be done manually.

  #Your callback functions here

class two(object):  # This is the page in a notebook.   

  def __init__(self):
    self.builder = gtk.Builder()
    self.builder.add_from_file("ui_for_two.glade")
    self.some_container = self.builder.get_object("some_container")
    self.one = one()
    self.some_container.pack_start(self.one, False, False)
    self.some_container.show_all() #recursively show some_container and all its child widgets

    self.builder.connect_signals(self)

For more info, check out these Glade tutorials.

DoR
I had not tried self.builder.connect_signals(self) and that has fixed the problem. I have been using builder only for short while (using libglade before) and have not yet called builder.connect_signals(self) until now. Do you know how some things work with out calling it and others do not?
Rob
Well I can't see the rest of your code, but maybe you manually connected signals to some widgets but not the rest?
DoR
Ignore my comment, I had been calling it. In the real code class two base class calls it. Some where I had the idea in my head that gtk.Builder did this automagically. Cheers!
Rob