from tkinter import *
from tkinter import ttk
from Parser import *
from checker import *
from Area import *

#global Map_File
def map_file_open(): 
    global Map_File
    #Map_File = open('sydney250m.txt','r').read()
    Map_File = filedialog.askopenfile(mode='r').read()
    print("File Load: Done!")
    pass#return Map_File

def map_go():
    #SL = sealevel_entry.get()
    SL = SL_entry.get()
    print(SL)
    map_check(Map_File)
    print("Map checked")
    print(map_approx_area(float(SL), Map_File))
    pass

app = Tk() #Initializing the GUI
app.title("Pymap 1730")

frame = ttk.Frame(app, padding="12 12 12 12") ##Create a program frame, give it some padding
frame.grid(column=0, row=0, sticky=(N, W, E, S)) #Put a grid in it, sticky the grid to the frame edges
frame.columnconfigure(0, weight=1) #Resizing stuff
frame.rowconfigure(0, weight=1) #More resizing


sealevel_entry= StringVar() #Variable initializing for GUI
return_path = StringVar()

SL_entry = ttk.Entry(frame, width=7, textvariable='sealevel_entry')  #Creating an entry field
SL_entry.grid(column=2, row=1, sticky=(W, E))

ttk.Label(frame, textvariable=return_path).grid(column=2, row=2, sticky=(W, E)) #Text label

ttk.Button(frame, text="Browse Files", command=map_file_open).grid(column=1, row=1, sticky=W) #Button to do file_open()
ttk.Button(frame, text="Do stuff!", command=map_go).grid(column=1, row=2, columnspan = 3)  #Button to do map_go()
ttk.Label(frame, text="Sea Level").grid(column=3, row=1, sticky=W) #Text labels


for child in frame.winfo_children(): child.grid_configure(padx=5, pady=5) #Pads everything

SL_entry.focus() #Program starts with entry box selected - type without clicking it
app.mainloop() #Don't remove this.
