Stephen Diehl
Stephen Diehl

Reputation: 8439

Window management with pygtk

I'm having an issue with PyGTK and GTK Builder windows. Here's a simplified version of my code.

class GUI:
def __init__(self,parent):
    builder_file = "./ui/window.builder"
    self.builder = gtk.Builder()
    self.builder.add_from_file(builder_file)

    self.window = self.builder.get_object('main')
    self.builder.connect_signals( self )
    self.populate_window()
    self.window.show()

def populate_window(self):
    hbox = self.builder.get_object('hbox')
    hbox.pack_start( somewidgets )

def on_destroy(self):
    self.window.destroy()

The gtk builder file just contains a toplevel window with a horizontal packing box and signal to the destroy. This appears to work and the window is created and populated just fine, but if I try to destroy the window that has been populated with any other widgets python segfaults.

I'm thinking this it's some issue with packing new widgets that aren't in the builder file so pygtk doesn't know how to destory them, but I'm not sure though.

Thanks for any help.

Upvotes: 0

Views: 578

Answers (2)

linkmaster03
linkmaster03

Reputation: 4358

Use gtk.main_quit().

def on_destroy(self):
    gtk.main_quit()

Upvotes: 1

ntd
ntd

Reputation: 7434

Your "destroy" handler is called when the window is yet in destruction, so this code fragment:

def on_destroy(self):
    self.window.destroy()

will generate an infinite recursive call. In other terms, you are destroying something that is yet being destroyed.

This has nothing to do with GtkBuilder or hand-coded widgets, but I suspect I'm missing something because I don't know why you need to connect something to GtkWindow::destroy.

Upvotes: 0

Related Questions