import pygtk
import gtk

class HelloFSUGAr(object):
	# A simple constructor for one Label
	def __init__(self):
		# Creating a new gtk window
		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
		
		self.lbl = gtk.Label("Hello FSUGAr")
		self.window.set_default_size(150,50)
		# We must add the control to the window
		self.window.add(self.lbl)

		# and show both
		self.lbl.show()
		self.window.show()

class MainClass(object):
	# two static (class) variable
	# n number of HelloFSUGAr window instanciated
	# list of HelloFSUGAr window instanciated
	__hellolist = []
	__quit = 0
	
	def __init__(self):
		self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
		
		self.buttonopen = gtk.Button("Hello FSUGAr !")
		
		self.buttonopen.connect ("clicked", self.newhellobutt, None)
		
		self.window.add(self.buttonopen)

		self.buttonopen.show()
		self.window.show()
		
	def main(self):
		gtk.main()

# ############################################################################

	def newhellobutt(self, widget, data=None):
		if len(MainClass.__hellolist) < 5 and not MainClass.__quit:
			print 'Fenetre ', len(MainClass.__hellolist), ' ajoutee'
			MainClass.__hellolist.append(HelloFSUGAr())
		else:
			i = 0;
			for obj in MainClass.__hellolist :
				i += 1
				obj.lbl.set_text("Window" + str(i))
			MainClass.__quit = 1
		if len(MainClass.__hellolist) == 0 and MainClass.__quit:
			self.destroy(self.window)
		elif MainClass.__quit:
			i = len(MainClass.__hellolist)
			print i
			obj.lbl.set_text(str(i))
			obj = MainClass.__hellolist.pop()

	def destroy (self, widget, data=None):
		gtk.main_quit()

# Main program
# ############################################################################
hello = MainClass()
hello.main()

