[pygtk] Dialog Lifecycle?

Neil Dugan pygtk at butterflystitches.com.au
Sun Mar 23 10:10:24 WST 2008


Darren Hart wrote:
> On 3/19/08, Neil Dugan <pygtk at butterflystitches.com.au> wrote:
> 
>>Darren Hart wrote:
>>
>>>I'm trying to add a dialog bound to a menu item.  I created the UI in
>>>glade.  I use the glade.XML.get_widget() to get the dialog, and then
>>
>>show()
>>
>>>it from the menuitem action handler.  Then I hide it when the dialog
>>>response handler receives RESPONSE_OK.  If I CLOSE the dialog however
>>
>>(from
>>
>>>the window manager X button) I see gtk.RESPONSE_DELETE_EVENT, and after
>>
>>that
>>
>>>I can no longer use glade.XML.get_widget() to retrieve my dialog.  It
>>
>>has
>>
>>>been destroyed.
>>>
>>>1) Is it really necessary to destroy and recreate the dialolg, rather
>>
>>than
>>
>>>just show/hide?
>>>2) If so, is the only way to recreate the dialog to re-read the glade
>>
>>file,
>>
>>>passing it the dialog name as the third param?
>>>
>>>Also, the dialog is visible by default, so part of my start -up sequence
>>
>>is
>>
>>>to hide it.... but you can see the wm animation... so I don't think that
>>
>>is
>>
>>>the right way either.
>>>
>>>I get the feeling I'm swimming upstream here, so if someone can set me
>>>straight on how to properly use dialog boxes, I would be most
>>
>>appreciative.
>>
>>>Thanks,
>>>
>>>
>>
>>
>>Hi Darren,
>>
>>The way I do it is, I have a function like.
>>
>>def hide(self, dialog, event) :
>>        dialog.hide()
>>        return True
>>
>>And in the init I use the command
>>        dialog.connect('delete_event', self.hide)
>>
>>I am not using glade thou, but this should work.
> 
> 
> 
> 
> OK, the key being to return True so that other handlers (such the built-in
> one that destroys it) don't get run?
> 
> How do you ensure the dialog isn't visible when the application starts?

I don't use glade. When I build the requester (in my init code) I just 
don't do a dialog.show() call.  That is done latter when I want to see 
the requester.

One thing to remember is the dialog variable needs to stay valid for 
the entire time the program is running (e.g. a global).

But as far as I remember when you start your glade app, it shouldn't 
auto show the dialogs ether.

> 
> Thanks,
> 
> Darren
> 
> 
> Regards Neil.
> 


More information about the pygtk mailing list