Frédéric wrote:
> Le 19/12/2008, "John Finlay" <fin...@moeraki.com> a écrit:
>
>   
>> Frédéric wrote:
>>     
>>> It seems that all documentation related to that point refer to gtk.Window
>>> widgets, and it works fine. But if the main window opens a gtk.Dialog,
>>> then, it is impossible to avoid this dialog to be destroyed when hitting
>>> its X box: even if event-delete callback returns True, the signal is
>>> propagated, and the destroy signal is emited.
>>>       
>> Could you create a small, self-contained program to illustrate the
>> problem you are having?
>>     
>
> Sure:
>
> import gtk
>
> def delete(widget, event):
>     print "delete()"
>     return True # Should not propagate delete-event
>
> def destroy(widget):
>     print "destroy()"
>     return True
>
> def clicked(widget):
>     print "clicked()"
>     dialog = gtk.Dialog("My dialog", win,
>                          gtk.DIALOG_MODAL,
>                          (gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))
>     dialog.set_size_request(200, 50)
>     dialog.show()
>     dialog.connect("delete-event", delete)
>     dialog.connect("destroy", destroy)
>   
You probably mean to connect to the "destroy-event" signal in the above 
though it's not likely that you need to handle it.
>     dialog.run()
>     dialog.destroy()
>   
The above line is what is destroying your dialog - remove it.
> win = gtk.Window()
> win.set_size_request(200, 50)
> button = gtk.Button("Open dialog...")
> button.connect("clicked", clicked)
> win.add(button)
> win.connect("delete-event", gtk.main_quit)
> win.show_all()
> gtk.main()
>
>   
You are mixing the two ways of using a dialog - show() and run(). You 
should only use one of these ways. If you use the show() method then add 
a call in delete() to hide() the dialog when you are finished the delete 
processing. If you use the run() method then you don't need to handle 
the delete-event and you should retrieve the return response from the 
run() method to figure out what to do (you also don't need to make the 
dialog modal since run() blocks the UI until it returns).

John
_______________________________________________
pygtk mailing list   pygtk@daa.com.au
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/

Reply via email to