import Blender
from Blender import *
from Blender.BGL import *
from Blender.Draw import *


# Have to declare inital values for strings, toggle buttons and number sliders
SomeString = Create('String')
Tog = Create(0)	# 0 = off, 1 = on
Num = Create(0)

def draw():
	# Declare variables
	global SomeString, Tog, Num
	
	# Background colour RGBA values
	glClearColor(0.753, 0.753, 0.753, 0.0)
	glClear(GL_COLOR_BUFFER_BIT)

	# Text colour RGB values
	glColor3f(0.0, 0.000, 0.000)
	glRasterPos2i(20, 700)			  # x,y position
	Text(' Here is some text.')


	# Create the GUI 
	
	# Push button
	# Label, event number, x position, y position, xwidth, ywidth, tooltip 
	Button('Button',1,20,650,100,35,'Example button')

	# String
	# Label, event number, x position, y position, xwdith, ywidth, variable name,
	# max no. character (hard maximum is 399), tooltip
	# SomeString.val is a string varaible, normal python string operations can be used.	
	SomeString = String('Enter :', 2, 20, 600, 100, 35, SomeString.val, 399, 'Enter a string')

	# Toggle
	# Label, event number, x position, y position, xwdith, ywidth, variable name, tooltip	
	# Toggle.val is an integer, 0=off, 1=on
	Tog = Toggle('Toggle',3,20,550,100,35,Tog.val,'Toggle button')
	
	# Integer number slider
	# Label, event number, x position, y position, xwdith, ywidth, variable name, minimum
	# value, maximum value, tooltip
	# Num.val is an integer which can only be between specified values
	# User can use LMB+drag to set values, or shift+LMB to type numbers. If they enter a value
	# outside the specified range, the value is automatically corrected.
	Num = Number('Num :',4,20,500,100,35, Num.val, 0,1000, 'Number slider')



def event(evt, val):
	# Quit GUI if Q pressed
	if (evt== QKEY and not val): Exit()

def bevent(evt):
	
	if evt==1:
		print 'Button pressed'
	
	# Simply typing in the string box counts as an event
	if evt==2:
		print SomeString.val
		
	# Alternatively, the button can be used
	if evt==1:
		print 'You entered :',SomeString.val
			
	# Similarly, using the toggle button counts as an event, or the push-button can use the toggle
	if evt==3:
		print 'You pushed the toggle button !'
		
	if evt==1:
		if Tog.val==0:
			print 'You pushed the button and the toggle was OFF'
		if Tog.val==1:
			print 'You pushed the button and the toggle was ON'
	
	# Same for number slider	
	if evt==4:
		print Num.val
	


Register(draw, event, bevent)