#!/usr/bin/python
# 
#  hdraw
# 
#  Author            :  Jak Kirman
#  Attributions      :  
#  Date              : 13 May 1995
#  Last modification : 21 Dec 1996
#  $Id$

# Drawing program for young children.
# HTML version, 20 May 1995
# Moving the mouse draws lines.
# Clicking the left mouse button changes the color randomly.
# Clicking the middle mouse button changes the thickness of the lines
#   randomly.
# Typing 'q' quits.
# Typing 'p' prints the image in Postscript form.

import Tkinter, sys, os, Pencil
from Tkinter import Widget

if os.environ.has_key ('REMOTE_HOST'):
  env = '-d %s:0.0' % sys.environ['REMOTE_HOST']
  html = 1
else:
  html = 0
    
if html:
    print '''\
Content-type: text/html
<html><head><title>Hayley Kirman's hdraw program</title></head>
<body>
    
<h1>Hdraw: a very simple drawing program for children</h1>
    
Just move the mouse to draw.  Clicking the left button randomly 
changes the color; clicking the middle button changes the thickness 
of the line.
<p> Type p to get a Postscript version of the image.
<p> Type q to quit the program.
'''

frame =       Tkinter.Frame (None)
width, height = frame.winfo_screenwidth()-50, frame.winfo_screenheight()-50
canvas =          Tkinter.Canvas (frame, width=width, height=height,
                                  background="white")
pencil =              Pencil.Pencil (canvas, html=html)
Widget.bind (canvas, "<Motion>", pencil.moving, pencil)
Widget.bind (canvas, "<Enter>", pencil.enter, pencil);
Widget.bind (canvas, "<ButtonPress-1>", pencil.changeColor, pencil)
Widget.bind (canvas, "<ButtonPress-2>", pencil.changeLineWidth, pencil)
Widget.bind (canvas, "<ButtonPress-3>", pencil.changeLineWidth, pencil)

buttonFrame =     Tkinter.Frame (frame)
printButton =         Tkinter.Button (buttonFrame, text="Print",
                                      command=pencil.printPS)
clearButton =         Tkinter.Button (buttonFrame, text = "Clear",
                                      command=pencil.clear)
quitButton =          Tkinter.Button (buttonFrame, text="Quit",
                                      command=pencil.done)
frame.pack()
buttonFrame.pack (side='top', fill="x")
for button in [printButton, clearButton, quitButton]:
  button.pack(side='left', fill='x', expand=1)
canvas.pack(side='top')

canvas.mainloop()


