from Tkinter import *
import time, threading, webbrowser#, winsound

def callback(event):
    webbrowser.open_new(r"http://www.webmd.com/fitness-exercise/20140407/sitting-disease-faq")

class Timer():
	root = Tk()
	frame = Frame(root)
	frame2 = Frame(root)
	frame3 = Frame(root)
	var = StringVar()
	var2 = StringVar()
	var3 = StringVar()
	label_1 = Label(frame, textvariable = var)
	label_2 = Label(frame, textvariable = var2)
	link = Label(frame3, text="Sitting is bad webmd", fg="blue", cursor="hand2")
	label_3 = Label(frame3, textvariable = var3)
	mins = 30
	secs = 0
	loop = 1
	

	def __init__(self):
		self.root.wm_title("Stand Timer")
		self.frame.pack()
		self.frame2.pack()
		self.frame3.pack()
		self.var.set('"Sitting is the new smoking"')
		self.label_1.pack(side=RIGHT)
		self.label_2.pack(side=LEFT)
		self.label_3.pack(side=RIGHT)
		looptext = "Loop: " + str(self.loop)
		self.var3.set(looptext)
		self.button_1 = Button(self.frame2, text="Start", command=self.start_cd)
		self.button_1.grid(row= 0, column=0)
		self.button_2 = Button(self.frame2, text="Exit", command=self.stop)
		self.button_2.grid(row= 0, column=2)
		self.link.pack(side=BOTTOM)
		self.link.bind("<Button-1>", callback)
		self.root.mainloop()

	def stop(self):
		exit()

	def start_cd(self):
		self.button_1.destroy()
		self.button_1 = Button(self.frame2, text="Reset", command=self.restart)
		self.button_1.grid(row= 0, column=1)
		self.var2.set("Stand up in:")
		self.var.set("30 minutes 00 seconds")
		t = threading.Thread(target=self.countdown)
		t.start()
		
	def restart(self):
		self.mins = 30
		self.secs = 0
		
	def countdown(self):
		while True:
			if self.secs <= 0:
				self.secs = 60
				self.mins -= 1
				if self.mins <= -1:
					self.loop += 1
					looptext = "Loop: " + str(self.loop)
					self.var3.set(looptext)
					self.mins = 30
					self.secs = 0
					top = Toplevel(master=self.root)
					top.title("Stand Up Dummy")
					top.attributes("-topmost", True)
					frame = Frame(top, height=600, width=1000, bg="Red")
					frame.pack()
					frame.pack_propagate(0)
					button = Button(frame, text='Dismiss', command=top.destroy)
					button.pack()
					label = Label(frame, fg="Yellow", text="STAND THE TRUCK UP YA GOOF!!!!!", height=75, bg="Red", font=("Helvetica", 32))
					label.pack()
					#top.lift()
					#winsound.Beep(800, 1500)
			time.sleep(1)
			self.secs -= 1
			if self.secs < 10:
				asec = '0' + str(self.secs) + " seconds"
			else:
				asec = str(self.secs) + " seconds"
			if self.mins < 10:
				amin = '0' + str(self.mins) + " minutes"
			else:
				amin = str(self.mins) + " minutes"
			tstring = amin + ' ' + asec
			self.var.set(tstring)

b = Timer()
#more soon