import tkinter as tk

#Stack frame implementation provided by jonrsharpe on Stack overflow
#https://stackoverflow.com/questions/26213549/switching-between-frames-in-tkinter-menu

#Base Frame Template
class Base(tk.Frame):

	def __init__(self, parent, controller):
		tk.Frame.__init__(self, parent)
		self.controller = controller
		self.grid()
		self.create_widgets()

	def create_widgets(self):
		raise NotImplementedError
#Home
class HomePage(Base):

	def create_widgets(self):
		self.configure(background = "black")
		self.welcome= tk.Label(self, text="Welcome to Beaver!", fg="yellow", bg="black")
		self.welcome.configure(font=("Courier", 20))
		self.welcome.grid(row = 0, column = 2, stick=tk.E+tk.W)
		#Open button widget
		self.button1 = tk.Button(self, command=lambda: self.controller.show_frame(Open), text="Open", fg="yellow", bg="black")
		self.button1.grid(row=1, column=2, sticky=tk.E+tk.W, padx=20, pady=10, ipadx = 20)
		#Create Button Widget
		self.button2 = tk.Button(self, command=lambda: self.controller.show_frame(Create), padx=5, pady=5, text="Create", fg="yellow", bg="black")
		self.button2.grid(row=2, column=2, sticky=tk.E+tk.W, padx=5, pady=10)
		#Exit Button Widget
		self.button3 = tk.Button(self, text="Exit", fg="yellow", bg="black", command=self.quit)
		self.button3.grid(row=3, column=2, sticky=tk.E+tk.W, padx=5, pady=10)



class TextPage(Base):

	def create_widgets(self):
		self.configure(background="black")
#Open file widgets
class Open(Base):
	#def __init__(self, parent):
	#	self.parent = parent
	#	opFrame = tk.Frame(parent, bg="black")
	#	opFrame.grid()
	def create_widgets(self):

		self.configure(background = "black")

		#Filename label
		self.name = tk.Label(self, text="Filename:", fg="yellow", bg = "black")
		self.name.grid(row=0)
		#Password Label
		self.password = tk.Label(self, text="Password:", fg="yellow", bg="black")
		self.password.grid(row=1)
		#Entry widgets
		self.e1 = tk.Entry(self)
		self.e2 = tk.Entry(self)

		self.e1.grid(row=0, column=1)
		self.e2.grid(row=1, column=1)
		#Open File
		self.button1 = tk.Button(self, text="Open", command=self.controller.Text_Box)
		self.button1.grid(row=4, column=2, sticky=tk.E)
		#Return Home
		self.button2 = tk.Button(self, text="Cancel", command = lambda: self.controller.show_frame(HomePage))
		self.button2.grid(row=4, column=3, sticky=tk.W)

class Create(Base):

#	def __init__(self, parent):
#		self.parent = parent
#		logFrame = tk.Frame(parent, bg="black")
#		logFrame.grid()
	def create_widgets(self):

		self.configure(background = "black")

		#Create filename and password widgets
		self.name = tk.Label(self, text="Filename:", fg="yellow", bg="black")
		self.name.grid(row=0)

		self.password = tk.Label(self, text="Password:", fg="yellow", bg="black")
		self.password.grid(row=1)
		#Entry widgets
		self.e1 = tk.Entry(self)
		self.e2 = tk.Entry(self)

		self.e1.grid(row=0, column=1)
		self.e2.grid(row=1, column=1)

		#Create new file widget
		self.button1 = tk.Button(self, text="Create", command=self.controller.Text_Box)
		self.button1.grid(row=4, column=2, sticky=tk.E)

		self.button2 = tk.Button(self, text="Cancel", command=lambda: self.controller.show_frame(HomePage))
		self.button2.grid(row=4, column=3, sticky=tk.W)

	def close_box(self):
		self.parent.destroy()

class Control(tk.Tk):
	#"root" Control class inorder to switch frames and call toplevel windows
	def __init__(self):
		tk.Tk.__init__(self)
		self.title("Beaver")
		self.configure(background='black')
		self.geometry("500x400")
		self.create_widgets()
		self.resizable(0, 0)
		self.grid_rowconfigure(0, weight=1)
		self.grid_columnconfigure(0, weight=1)
		self.data = {}

	def create_widgets(self):
		#Initialize container
		self.container = tk.Frame(self, background="black")
		self.container.grid(row=0, column=0)
		self.container.grid_rowconfigure(0, weight=1)
		self.container.grid_columnconfigure(0, weight=1)

		self.frames = {}
		#For loop to iterate through frames
		for F in (HomePage, Open, Create):
			frame = F(self.container, self)
			frame.grid(row=0, column=0, sticky=tk.NW+tk.SE)
			self.frames[F] = frame
		self.show_frame(HomePage)

	def show_frame(self, cls):
		self.frames[cls].tkraise()
	#Toplevel text box
	def Text_Box(self):
		box = tk.Toplevel()
		box.title("Open File")
		box.configure(background='black')
		op = TextPage(box)

if __name__ == "__main__":
	app = Control()
	app.mainloop()
	exit()
