tags:

views:

346

answers:

2

About Gtk Dialog box Behavior...

I am using GtkBuilder +Glade to display a top level window and dialogs in it...

builder = gtk_builder_new();
gtk_builder_add_from_file( builder, "test.glade", NULL );
windowPtr = GTK_WIDGET( gtk_builder_get_object( m_builder, "window_main"));

on clicking on button i am opening one dialog box which is in other glade file.... after closing the dialog box control gets return to main window....

but when i click again on button to open dialog box.. it opens the dialog box but dialog box does not show any child widgets in it (it is just a empty window).. why this is happening?

I am not handling close event on dialog!

+2  A: 

In glade, set the callback for "delete-event" of your GtkDialog to gtk_widget_hide_on_delete. This will then hide your dialog instead of destroying it.

Also, you will need to add this line to your program:
gtk_builder_signals_connect( m_builder, NULL )

DoR
thanks very much, you saved my day... it worked !!!
PP
A: 

I have a same problem using glade and pygtk, here is my code:

class Sample:
def __init__ (self):
    self.builder = gtk.Builder()
    self.builder.add_from_file("../data/sample.glade")
    self.builder.connect_signals(self)

    self.window = self.builder.get_object("mywindow")
    self.window.set_modal(True)
    self.window.show_all()

def addDialog(self, sender):
    dialog = self.builder.get_object("dialog1")
    label = self.builder.get_object("label2")
    print label.get_text()
    print dialog.get_title()
    result = dialog.run()
    if result == 1 :
        print "ok!"
    else :
        print "no, thanks :D"
    dialog.destroy()

I have connected addDialog to the clicked event of a button on "mywindow".

The first time I click it, I can see "dialog1" which has "label2" inside. the next time I click that button, "dialog1" is opened but with no widgets inside! but in trminal the "label2" text and "dialog1" title is printed correctly, means that they are constructed but not visible.

I also connected "dialog1" delete-event to gtk_widget_hide in the glade file, but no changes happend.

goli