[pygtk] closing dialog box

Christopher Spears cspears2002 at yahoo.com
Tue Aug 29 08:31:00 WST 2006


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?




More information about the pygtk mailing list