#!/usr/bin/python
#coding: utf-8
#       DESCRIPTION:    display module for install  (tk)
#
#       SCRIPT NAME:    ri_inst_tk.py
#
#       MENTOR:         Li Zhi
#
#       AUTHOR:         Ling Fen
#
#       EMAIL:          fling@linx-info.com
#
#       DATE:           2010-09-20
#
#       HISTORY:
#       REVISOR         DATE                    MODIFICATION
#       Ling Fen        2010-09-04              create
#

from Tkinter import *
import tkMessageBox
import os
from ri_oper import language, Rate

def set_task(task_name):
    lab_operation.configure(text=task_name)
    lab_operation.update()

def set_sub_task(sub_task):
    txt_suboperation.insert(END,sub_task)
    txt_suboperation.see(END)

def set_task_scale():
    scl_progress.configure(state='normal')
    scl_progress.set(Rate.value)
    scl_progress.update()
    scl_progress.configure(state='disable')

def set_task_over():
    ret = tkMessageBox.askokcancel(title="Linx",message="%s"%(language=='chinese' and "凝思磐石系统安装完成，请重新启动系统"or "Rocky system install completed,plase reboot")) 
    return ret

def root_destroy():
    root.destroy()

def error(oper, ret):
    if language == 'chinese':
        tkMessageBox.showerror('Linx',u"%s:\n 错误值: %d\n %s"%(oper.chinese_name, ret, oper.return_value[ret][1]))
    else:
        tkMessageBox.showerror('Linx',"%s:\n Error number: %d\n %s"%(oper.english_name, ret, oper.return_value[ret][0]))

def start(func):
    root.protocol('WM_TAKE_FOCUS', func)
    root.mainloop()

#root widget
root = Tk()
root.geometry("%sx%s+0+0" %(root.winfo_screenwidth(),root.winfo_screenheight()))
root.title('Linx')

# root subwidget
stringvar_bar=StringVar()

#label
lab_task=Label(root,text='%s:'%(language=="chinese" and u"任务" or "Task"))
lab_progress_bar=Label(root,text='%s:'%(language=="chinese" and u"进度"\
        or 'Progress bar'))
lab_operation=Label(root,text="")
lab_linx=Label(root,text="Linx")

txt_suboperation=Text(root,width=100,height=10)

#operation lable and taskname
lab_task.grid        (row=1, column=0, sticky='E')
lab_operation.grid   (row=1, column=1)
txt_suboperation.grid(row=2, column=1)
lab_progress_bar.grid(row=3, column=0, sticky='E') 
lab_linx.grid        (row=4, column=1)

#logo
photo_bm = PhotoImage(file="%s/../data/linxlogo.gif"\
        %os.path.split(os.path.realpath(__file__))[0])
logo_label=Label(root,image=photo_bm)
logo_label.grid(row=0,column=0,padx=50, pady=50, sticky='NW')

#progress bar
scl_progress=Scale(root,orient=HORIZONTAL,resolution=0.01,digits=4,from_=0,to=100,variable=stringvar_bar,label='%')
scl_progress.grid(row=3,column=1,padx=50, sticky='EW')

#root
root.rowconfigure(0,weight=1)
root.rowconfigure(1,weight=1)
root.rowconfigure(3,weight=1)
root.rowconfigure(4,weight=1)
root.columnconfigure(1,weight=1)
