[pygtk] closing dialog box

Samuel Cormier-Iijima sciyoshi at gmail.com
Tue Aug 29 13:26:08 WST 2006


If you want a dialog box, you should probably subclass gtk.Dialog,
which has a convenient 'run' interface. If you really need your own
window, the reason it's closing is because you're calling
gtk.main_quit(). What you should really do is just hide the dialog
when it's done (I think the Python garbage collector will call
g_object_unref() later, but I could be wrong...)

Cheers,
Samuel

On 8/28/06, Christopher Spears <cspears2002 at yahoo.com> wrote:
> I wrote a script that creates a window with a button.
> If the button is pressed, a dialog box is launched.
> Here is the script:
>
> #!/usr/bin/python
>
> import pygtk
> pygtk.require('2.0')
>
> import gtk, gtk.glade
>
> class HelloWorldDialog:
>         """A Dialog Box"""
>         def on_hello_world_dialog_delete(self, widget,
> event):
>                 gtk.main_quit()
>
>         def close_dialog(self, widget):
>                 print "I clicked the close button!"
>                 gtk.main_quit()
>
>         def main(self):
>                 gtk.main()
>
>         def __init__(self):
>
>                 self.gladefile = "launch_dialog_box.glade"
>                 self.wTree = gtk.glade.XML(self.gladefile,
> "hello_world_dialog")
>
>                 closebutton1 = self.wTree.get_widget("closebutton1")
>
>                 dic = { "on_hello_world_dialog_delete_event" :
> self.on_hello_world_dialog_delete,
>                         "on_closebutton1_clicked" : self.close_dialog }
>
>                 self.wTree.signal_autoconnect(dic)
>
>
> class MainWindow:
>         """This application creates a window that can launch
> a dialog box"""
>
>         def on_mainWindow_delete(self, widget, event):
>                 gtk.main_quit()
>
>         def launch_dialog(self, widget):
>                 hwd = HelloWorldDialog()
>                 #hwd.main()
>
>         def main(self):
>                 gtk.main()
>
>         def __init__(self):
>
>                 self.gladefile = "launch_dialog_box.glade"
>                 self.wTree = gtk.glade.XML(self.gladefile,
> "mainWindow")
>
>                 launch_button =
> self.wTree.get_widget("launch_button")
>
>                 dic = { "on_mainWindow_delete_event" :
> self.on_mainWindow_delete,
>                         "on_launch_button_clicked" : self.launch_dialog }
>
>                 self.wTree.signal_autoconnect(dic)
>
> if __name__ == "__main__":
>         mw = MainWindow()
>         mw.main()
>
> My problem is closing the dialog box closes the main
> window as well.  I tried to solve this by giving the
> dialog box its own main loop.  Unfortunately, that did
> not work.  The only change was that I had to click the
> "Close" button twice in order for to close everything.
>  Any hints?
>
>
> _______________________________________________
> pygtk mailing list   pygtk at daa.com.au
> http://www.daa.com.au/mailman/listinfo/pygtk
> Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/
>


More information about the pygtk mailing list