#!/usr/bin/env python
# -*-python-*-
# Geoffrey Furnish
#
# A Python/Tk script to interactively run the various Python demos.

from Tkinter import *

from plplot import *
from plplot_widget import *

import Plframe
from Plframe import *

import x01
import x02
import x03
import x04
import x05
import x06
import x07
import x08
##import x09
import x10
import x11
import x12
import x13
##import x14
##import x15
import x16
##import x17
##import x18
##import x19

class DemoApp(Frame):

    def __init__( s, master=None ):
	Frame.__init__( s, master )
	print "Building the Python Tk demo application main window."

	s.create_widgets()
	s.pack( expand=1, fill=BOTH )

	#plspause(1)

    def create_widgets(s):
	s.f = Frame(s)
	s.make_demo_bar( s.f )

        print "Time to register the plframe with the interp..."
        Pltk_init( s.tk.interpaddr() );

	s.plf = PlXframe(s, width="17c", height="17c" )

	s.f2 = Frame(s)
	s.f2.clone = Button( s.f2, text="Clone", command=s.clone )
	s.f2.clone.pack( side=LEFT, expand=1, fill=X )
	s.f2.reload = Button( s.f2, text="Reload", command=s.reload )
	s.f2.reload.pack( side=LEFT, expand=1, fill=X )
	s.f2.quit = Button( s.f2, text="Dismiss", command=s.master.destroy )
	s.f2.quit.pack( side=LEFT, expand=1, fill=X )
	s.f2.pack( side=BOTTOM, fill=X )

	s.f.pack( side=LEFT )
	s.plf.pack( side=RIGHT, expand=1, fill=BOTH )

    def make_demo_bar( s, f ):
	f.x01 = Button( f, text="Example 1", command=s.demo_x01 )
	f.x01.pack( expand=1, fill=X )
	f.x02 = Button( f, text="Example 2", command=s.demo_x02 )
	f.x02.pack( expand=1, fill=X )
	f.x03 = Button( f, text="Example 3", command=s.demo_x03 )
	f.x03.pack( expand=1, fill=X )
	f.x04 = Button( f, text="Example 4", command=s.demo_x04 )
	f.x04.pack( expand=1, fill=X )
	f.x05 = Button( f, text="Example 5", command=s.demo_x05 )
	f.x05.pack( expand=1, fill=X )
	f.x06 = Button( f, text="Example 6", command=s.demo_x06 )
	f.x06.pack( expand=1, fill=X )
	f.x07 = Button( f, text="Example 7", command=s.demo_x07 )
	f.x07.pack( expand=1, fill=X )
	f.x08 = Button( f, text="Example 8", command=s.demo_x08 )
	f.x08.pack( expand=1, fill=X )
	f.x09 = Button( f, text="Example 9", command=s.demo_x09,
			state='disabled' )
	f.x09.pack( expand=1, fill=X )
	f.x10 = Button( f, text="Example 10", command=s.demo_x10 )
	f.x10.pack( expand=1, fill=X )
	f.x11 = Button( f, text="Example 11", command=s.demo_x11 )
	f.x11.pack( expand=1, fill=X )
	f.x12 = Button( f, text="Example 12", command=s.demo_x12 )
	f.x12.pack( expand=1, fill=X )
	f.x13 = Button( f, text="Example 13", command=s.demo_x13 )
	f.x13.pack( expand=1, fill=X )
	f.x14 = Button( f, text="Example 14", command=s.demo_x14,
			state='disabled' )
	f.x14.pack( expand=1, fill=X )
	f.x15 = Button( f, text="Example 15", command=s.demo_x15,
			state='disabled' )
	f.x15.pack( expand=1, fill=X )
	f.x16 = Button( f, text="Example 16", command=s.demo_x16 )
	f.x16.pack( expand=1, fill=X )
	f.x17 = Button( f, text="Example 17", command=s.demo_x17,
			state='disabled' )
	f.x17.pack( expand=1, fill=X )
	f.x18 = Button( f, text="Example 18", command=s.demo_x18,
			state='disabled' )
	f.x18.pack( expand=1, fill=X )
	f.x19 = Button( f, text="Example 19", command=s.demo_x19,
			state='disabled' )
	f.x19.pack( expand=1, fill=X )

	# Others here.

##	f.quit = Button( f, text="Quit", command=f.quit )
##	f.quit.pack( expand=1, fill=X )

## A nice addition would be for these functions to not only call the
## demos, but to also stuff their source code into a text widget, so
## the user can easily see the correspondence between the source and
## the visual effects.

    def demo_x01(s):
	x01.main( s.plf )
    def demo_x02(s):
	x02.main( s.plf )
    def demo_x03(s):
	x03.main( s.plf )
    def demo_x04(s):
	x04.main( s.plf )
    def demo_x05(s):
	x05.main( s.plf )
    def demo_x06(s):
	x06.main( s.plf )
    def demo_x07(s):
	x07.main( s.plf )
    def demo_x08(s):
	x08.main( s.plf )
    def demo_x09(s):
	x09.main( s.plf )
    def demo_x10(s):
	x10.main( s.plf )
    def demo_x11(s):
	x11.main( s.plf )
    def demo_x12(s):
	x12.main( s.plf )
    def demo_x13(s):
	x13.main( s.plf )
    def demo_x14(s):
	x14.main( s.plf )
    def demo_x15(s):
	x15.main( s.plf )
    def demo_x16(s):
	x16.main( s.plf )
    def demo_x17(s):
	x17.main( s.plf )
    def demo_x18(s):
	x18.main( s.plf )
    def demo_x19(s):
	x19.main( s.plf )

    def clone(s):
	"Make a new instance of this demo megawidget."

	take2 = DemoApp( Toplevel() )
	pass

    def reload(s):
	"""Reload all the demo modules.  

	Facilitates modification of the demos, which is most useful
	during hte period of implementing the demos in Python."""

	reload( x01 )
	reload( x02 )
	reload( x03 )
	reload( x04 )
	reload( x05 )
	reload( x06 )
	reload( x07 )
	reload( x08 )
##	reload( x09 )
	reload( x10 )
	reload( x11 )
	reload( x12 )
	reload( x13 )
##	reload( x14 )
##	reload( x15 )
	reload( x16 )
##	reload( x17 )
##	reload( x18 )
##	reload( x19 )

	# Let's also reload the Plframe module, so we can hack on that
	# freely too.

	#reload( Plframe )
	# Doesn't work, don't know why.  Grrr.

demo = DemoApp()
demo.mainloop()
