#!/usr/bin/env python

import sys
try:
	import pygtk
	pygtk.require("2.0")
except:
	pass
try:
	import gtk
	import gtk.glade
except:
	sys.exit(1)

def make_effective_dialog(window):
	"""Create all the widgets in here
	"""
	dialog=gtk.Dialog(title='Effective Dialog',parent=window,flags=gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT)

	#disable the separator
	
	#get the vbox
	vBox=dialog.vbox

	#create and entry
	label=gtk.Label("I'm afraid I can't do that, Dave")

	#add entry to vertical box
	vBox.pack_start(label,expand=True,fill=True,padding=10)

	window.show_all()
	label.show()

	if dialog.run():
		print True
	else:
		print False

	dialog.destroy()

def make_deffective_dialog(window):
	dialog=gtk.Dialog(title='Deffective Dialog',parent=window,flags=gtk.DIALOG_MODAL|gtk.DIALOG_DESTROY_WITH_PARENT)
	
	dialog.resize(300,300)

	fill_dialog(dialog)

	return dialog

def fill_dialog(dialog):
	"""Recursively create the widgets, starting from the vertical box
	"""
	#get vertical box
	vBox=dialog.vbox

	#add the drawing area and the menubar as left and right children	
	vBox.pack_start(create_da(),expand=True,fill=True,padding=0)
	
	create_buttons(dialog)

def create_da():
	"""Create the drawing area for this window
	"""
	#create the scrolled window
	outputWindowScrolledWindow=gtk.ScrolledWindow()

	#create the event box
	eventBox=gtk.EventBox()

	#set the events
	eventBox.set_events(gtk.gdk.POINTER_MOTION_MASK|gtk.gdk.BUTTON1_MOTION_MASK|gtk.gdk.BUTTON_PRESS_MASK|gtk.gdk.BUTTON_RELEASE_MASK|gtk.gdk.SCROLL_MASK)
	
	#create the drawing area and pixmap
	da=gtk.DrawingArea()
	
	#add da to eventbox
	eventBox.add(da)

	#minimum size of the drawing area
	da.set_size_request(1,1)

	#set the scrolled window policies
	outputWindowScrolledWindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)

	#first add the vBox to the scrolled windows
	outputWindowScrolledWindow.add_with_viewport(eventBox)

	#show all the widgets
	outputWindowScrolledWindow.show()
	da.show()
	eventBox.show()

	return outputWindowScrolledWindow
	
def create_buttons(dialog):
	"""Create the bar with the relevant information
	"""
	
	#get horizontal box
	hBox=gtk.HBox()
	dialog.vbox.pack_end(hBox)
#	hBox.set_homogeneous(True)

	playButton=create_button_with_image(gtk.STOCK_MEDIA_PLAY)
	pauseButton=create_button_with_image(gtk.STOCK_MEDIA_PAUSE)
	nextButton=create_button_with_image(gtk.STOCK_MEDIA_NEXT)
	stopButton=create_button_with_image(gtk.STOCK_MEDIA_STOP)
	iterationAdjustment=gtk.Adjustment(value=0,lower=0,upper=1000000,step_incr=1,page_incr=100,page_size=100)
	iterationSpinButton=gtk.SpinButton(iterationAdjustment)
	zoomAdjustment=gtk.Adjustment(value=1,lower=1,upper=10,step_incr=1,page_incr=1,page_size=1)
	zoomScrollbar=gtk.HScrollbar(zoomAdjustment)
	zoomScrollbar.set_increments(1,1)
	paddingAdjustment=gtk.Adjustment(value=1,lower=1,upper=100,step_incr=1,page_incr=1,page_size=1)
	paddingScrollbar=gtk.HScrollbar(paddingAdjustment)
	paddingScrollbar.set_increments(10,10)
	timeEntry=gtk.Entry()

	#add it to the horizontal box
	hBox.pack_start(playButton,expand=False,fill=False,padding=0)
	hBox.pack_start(pauseButton,expand=False,fill=False,padding=0)
	hBox.pack_start(nextButton,expand=False,fill=False,padding=0)
	hBox.pack_start(stopButton,expand=False,fill=False,padding=0)
	hBox.pack_start(iterationSpinButton,expand=False,fill=False,padding=5)
	hBox.pack_start(zoomScrollbar,expand=True,fill=True,padding=5)
	hBox.pack_start(paddingScrollbar,expand=True,fill=True,padding=5)
	hBox.pack_start(timeEntry,expand=False,fill=False,padding=5)
	hBox.show_all()

	#call show on the widgets
	playButton.show()
	pauseButton.show()
	nextButton.show()
	stopButton.show()
	iterationSpinButton.show()
	zoomScrollbar.show()
	paddingScrollbar.show()
	timeEntry.show()


def on_main_window_delete_event(widget,data=None):
	"""Return false so the window gets destroyed
	"""
	return False

def on_main_window_destroy(widget,data=None):
	"""Return false so the window gets destroyed
	"""
	gtk.main_quit()

def create_button_with_image(stock_name,label_text="",size=gtk.ICON_SIZE_BUTTON):
	# Create box for image and label
	box = gtk.HBox(False, 0)
	box.set_border_width(2)

	#create the button
	button=gtk.Button()

	# Now on to the image stuff
	image = gtk.Image()
	#image.set_from_file(image_filename)
	image.set_from_stock(stock_name,size)

	# Create a label for the button
	label = gtk.Label(label_text)

	# Pack the pixmap and label into the box
	box.pack_start(image, False, False, 3)
	box.pack_start(label, False, False, 3)

	#add the box to the button
	button.add(box)

	#call show on all the widgets
	image.show()
	label.show()
	box.show()
	button.show()

	#return the button to the calling widget
	return button

if __name__ == '__main__':

	try:
		window=gtk.Window()
		window.set_title("main")
		window.show()

		window.connect('destroy',on_main_window_destroy)
		window.connect('delete_event',on_main_window_delete_event)

		make_effective_dialog(window)
		d=make_deffective_dialog(window)
		d.run()


		gtk.main()
	except KeyboardInterrupt:
		sys.exit(1)








