#!/usr/bin/python
#-*-coding:utf-8-*-
from Tkinter import * 
import tkMessageBox
import tkFont
from w import *
from calendar import *

class Application(Frame):
	def __init__(self, master=None):
		Frame.__init__(self, master)
		self.createWidgets()
		self.pack()

	def testButtons(self):
		#print 'this is a test!'
		tkMessageBox.showinfo("Hello","This is a test")

	def showWeatherReport(self):
		#tkMessageBox.showinfo("Weather",getWeatherReport())
		weaInfo = getWeatherInfo2()
		weaText = "发布时间: "+ weaInfo['date_y'].encode('utf-8')+" "+weaInfo['fchh'].encode('utf-8')
		for i in range(1,7): 
			weaText += "\r\n"+"第"+str(i)+"天: "+weaInfo['temp'+str(i)].encode('utf-8')+";"+weaInfo['weather'+str(i)].encode('utf-8')+"; "+weaInfo['wind'+str(i)].encode('utf-8')
		self.label.config(text=weaText)
		#nothing for now

	def updateCalendar(self):
		updateDate(self.leftFrame)

	def showCalendar(self):
		self.label.config(text="")
		#AppCal = Calendar()
		displayCalendar(self.leftFrame)
		#self.leftFrame.pack()

	def createWidgets(self):

		#TODO: get retrieve form size
		self.mainbg = Canvas(self,bg='white',height=600,width=800)
		self.mainbg.create_rectangle(0,0,150,600,fill='green')
		self.mainbg.create_rectangle(150,0,800,600,fill='grey')
		self.leftFrame = Frame(self,width=500,height=550,relief=GROOVE)
		self.leftFrame.place(relx=0.3,rely=0.05)
 
		btnFT = tkFont.Font(family='Fixdsys',size=16,weight=tkFont.BOLD)	
		self.wButton = Button(self.mainbg,text="天气",font=btnFT,command=self.showWeatherReport)
		self.wButton.place(height=40,width=120,relx=0.01,rely=0.05)

		self.cButton = Button(self.mainbg,text="日历",font=btnFT,command=self.showCalendar)
		self.cButton.place(height=40,width=120,relx=0.01,rely=0.15)

		self.tButton = Button(self.mainbg,text="定时",font=btnFT)
		self.tButton.place(height=40,width=120,relx=0.01,rely=0.25)

		self.fButton = Button(self.mainbg,text="美食",font=btnFT)
		self.fButton.place(height=40,width=120,relx=0.01,rely=0.35)

		self.qButton = Button(self.mainbg, text="退出",font=btnFT,command=self.quit )
		self.qButton.place(height=40,width=120,relx=0.01,rely=0.45)

		self.label = Label(self.mainbg,text='Waiting...',justify=LEFT, compound='right')
		self.label.place(height=500,width=400,relx=0.2,rely=0.1)
		
		self.mainbg.pack()

#tkMessageBox.showinfo("Weather",getWeatherReport())
		
app = Application()
app.master.geometry('800x600')
app.master.title("Sanil (v0.1)")
app.mainloop()
