from Tkinter import *
import main
import time
import threading

diction={}
host='10.6.15.118'
uname='abhiroyg'
passwd='praveen7'
networkPart='10.6.15'
startHost='1'
endHost='200'
count = 0

class App:
    def __init__ (self, master):
        frame = Frame(master, bg = "blue", height = 100, width=1000)
        #frame.pack(fill=X, expand=True)
        
        #self.button1 = Button(master, text = "Button1", fg = "blue", command = self.custom)
        #self.button1.pack(side = LEFT)
        #self.button1.place(x = 100, y = 200)

        l1 = Label(master, text = "Range")
        l1. grid(row = 0 , column = 0, sticky = N)

        #maybe there are grids in frame and also 
        var = StringVar()
        var.set("Select")
        optionMenu = OptionMenu(root, var, "10.6.16", "10.6.15", command = self.ping_all)
        optionMenu. grid(row =  1, column = 0, sticky = W)
        Label(master, text = "startAddr").grid(row = 2, column = 0, sticky = W)
        Label(master, text = "endAddr").grid(row = 3, column = 0, sticky = W)
        startAddr = Entry(master, width = 3)
        endAddr = Entry(master, width = 3)
        startAddr.grid(row = 2, column = 1, sticky = W)
        endAddr.grid(row = 3, column = 1, sticky = W)

        #3 invisible labels to get padding between (range, sender); (sender, peacock); (Password box, Go! Button)
        Label(master, text = "", width = 20, height = 1).grid(row = 0, column = 2, sticky = N)
        #Label(master, text = "", width = 20, height = 1).grid(row = 0, column = 5, sticky = N)
        Label(master, text = "", width = 30, height = 2).grid(row = 3, column = 5, sticky = W)

        #Special "PASSWORD" text field, inquire in Tkinter...

        #DCF User name and Password

        l2 = Label(master, text = "Network Account")
        l2. grid(row = 0 , column = 3, sticky = N)

        l3 = Label(master, text = "User name")
        l3. grid(row = 1, column = 3, sticky = W, rowspan = 2)
        l4 = Label(master, text = "Password")
        l4. grid(row = 2, column = 3, sticky = W, rowspan = 2)

        e1 = Entry(master) 
        e2 = Entry(master, show = '*')
        e1.grid(row = 1, column=4, sticky = W, rowspan = 2) 
        e2.grid(row = 2, column=4, sticky = W, rowspan = 2)

        #Sender's Gmail User name and password
        l2 = Label(master, text = "Sender")
        l2. grid(row = 0 , column = 6, sticky = N)

        l3 = Label(master, text = "User name")
        l3. grid(row = 1, column = 6, sticky = W, rowspan = 2)
        l4 = Label(master, text = "Password")
        l4. grid(row = 2, column = 6, sticky = W, rowspan = 2)

        e1 = Entry(master) 
        e2 = Entry(master, show = '*')
        e1.grid(row = 1, column=7, sticky = W, rowspan = 2) 
        e2.grid(row = 2, column=7, sticky = W, rowspan = 2)

        #Admin@Peacock's username...
        l5 = Label(master, text = "Peacock's Email ID")
        l5. grid(row = 0, column = 9, sticky = N, rowspan = 2)
        e3 = Entry(master)
        e3. grid(row = 1, column = 9, sticky = E+W, rowspan = 2)


        RWidth=(root.winfo_screenwidth()-20)/2
        RHeight=(root.winfo_screenheight()-40)/2
        self.button1 = Button(master, text = "Go!",width = 8, height = 1, command = self.startAll)
        self.button1. grid(row = 4, column = 4, columnspan = 1, sticky = "NESW")
        #Fix the button's co-ordinates at the end of making the GUI.
        #self.button1.place(x = RWidth, y = RHeight)
        separator = Frame(height=10, bd=100, relief=SUNKEN)
        #separator.grid(row = 5, column = 0, columnspan = 5, sticky = "W", padx = 20, pady = 20)

        #to fill up the entire cell use the sticky value NSEW
        #we means the widget will be stretched to stick to the corners west and east
        #ttk::frame .c.f -borderwidth 5 -relief sunken -width 200 -height 100

        #put widgets in the bottom frame

        frame = Frame(master, relief = SUNKEN, borderwidth = 5, bg = "mint cream", height = 800)
        frame.grid(row = 6, column = 0, columnspan = 9, sticky = "NSEW")

        #************FRAME2 BEGIN****************#

        frame2 = Frame(frame, bg = "mint cream", height = 500, width = 700)
        frame2.grid(row = 0, column = 0)
        #listbox height = 30 is equivalent to frame's height = 500
        #add a label on the top of the scroll bar...
        Label(frame2, text = "List of Alive Systems").grid(row = 0, column = 0, sticky = W, columnspan = 2)
        scrollbar = Scrollbar(frame2)
        scrollbar. grid(row = 1, column = 1, sticky = "NWES")
        self.listbox = Listbox(frame2, yscrollcommand = scrollbar.set, height = 30, width = 30)
        self.listbox.grid(row = 1, column = 0, sticky = W)
        scrollbar.config(command = self.listbox.yview)

        #format of entries in the list box can be like, 
        #1. 10.6.15.112
        #2. 10.6.16.23 i.e, S.No and comp's IP address
        #for i in range(100):
            #self.listbox.insert(END, str(i))
        #*************END of frame2***************#

        #*************FRAME3 BEGIN***************#
        frame3 = Frame(frame, bg = "mint cream", height = 500, width = 1400)    #have 2 columns split here...
        frame3.grid(row = 0, column = 1)
        Label(frame3, text = "Systems with disk nearly full").grid(row = 0, column = 0, sticky = W, columnspan = 2)
        Label(frame3, text = "Corresponding disk spaces").grid(row = 0, column = 1, sticky = W, columnspan = 2)
                
        scrollbar1 = Scrollbar(frame3)
        scrollbar1. grid(row = 1, column = 1, sticky = "NWES")
                
        scrollbar2 = Scrollbar(frame3)
        scrollbar2. grid(row = 1, column = 3, sticky = "NWES")
                
        listbox1 = Listbox(frame3, yscrollcommand = scrollbar1.set, height = 30, width = 30)
        listbox1.grid(row = 1, column = 0, sticky = W)
                
        listbox2 = Listbox(frame3, yscrollcommand = scrollbar2.set, height = 30, width = 30)
        listbox2.grid(row = 1, column = 2, sticky = W)
                
        scrollbar1.config(command=listbox1.yview)
        scrollbar2.config(command=listbox2.yview)
                
        for i in range(100):
            listbox1.insert(END, str(i))
            listbox2.insert(END, str(i))

        
        for i in range(int(startHost), 1+int(endHost)):
            diction[networkPart +'.'+ str(i)]= {}
        
        print "initialization ended"
            

        #************END of frame3****************#
        


    def startAll(self):
        #Invoke all other programs here...
        #Fill all the lists from here..

        
        
        thread1 = threading.Thread(target = main.mainFunction(host, uname, passwd, networkPart, startHost, endHost, diction))
        print "how are you, what are you doing"
        thread1.start()
        
                #while(1):
                #time.sleep(100)

        print "Custom command"

    def ping_all(self):
        print "Pinging computers..."

root = Tk()
app = App(root)
#root.geometry("%dx%d%+d%+d" % (600,400, 0, 0))
root.wm_title("System@Peacock")
RWidth=root.winfo_screenwidth()-40
RHeight=root.winfo_screenheight()-40
root.geometry(("%dx%d")%(RWidth,RHeight))
root.mainloop()
