#! /usr/bin/env python
#  -*- coding: utf-8 -*-
#
# GUI module generated by PAGE version 5.0.2
#  in conjunction with Tcl version 8.6
#    Feb 26, 2020 11:26:17 PM CST  platform: Windows NT

#%%

# Importing the system
import sys

#Try-except is similar to if-else
#here, if the TRY component fails due to a type of error
#specified by the EXCEPT command, the EXCEPT portion is executed.
try:
    import Tkinter as tk
except ImportError:
    import tkinter as tk

try:
    import ttk
    py3 = False
except ImportError:
    import tkinter.ttk as ttk
    py3 = True

#This imports the support file generated from PAGE Builder
# All variabiles in this .py file can be used here since we have
#imported it already
import Sample1_support


#This function is ran if this program is ran on its own 
#(see last chunk below)
def vp_start_gui():
    '''Starting point when module is the main routine.'''
    global val, w, root
    root = tk.Tk()
    Sample1_support.set_Tk_var()
    top = Toplevel1 (root)
    Sample1_support.init(root, top)
    root.mainloop()

w = None
def create_Toplevel1(rt, *args, **kwargs):
    '''Starting point when module is imported by another module.
       Correct form of call: 'create_Toplevel1(root, *args, **kwargs)' .'''
    global w, w_win, root
    #rt = root
    root = rt
    w = tk.Toplevel (root)
    Sample1_support.set_Tk_var()
    top = Toplevel1 (w)
    Sample1_support.init(w, top, *args, **kwargs)
    return (w, top)

def destroy_Toplevel1():
    global w
    w.destroy()
    w = None

# The toplevel GUI is written as a class
class Toplevel1:
       
    def __init__(self, top=None):
        '''This class configures and populates the toplevel window.
           top is the toplevel containing window.'''
        _bgcolor = '#d9d9d9'  # X11 color: 'gray85'
        _fgcolor = '#000000'  # X11 color: 'black'
        _compcolor = '#d9d9d9' # X11 color: 'gray85'
        _ana1color = '#d9d9d9' # X11 color: 'gray85'
        _ana2color = '#ececec' # Closest X11 color: 'gray92'
        
        #Code to define attributes of the main window
        self.style = ttk.Style()
        if sys.platform == "win32":
            self.style.theme_use('winnative')
        self.style.configure('.',background=_bgcolor)
        self.style.configure('.',foreground=_fgcolor)
        self.style.configure('.',font="TkDefaultFont")
        self.style.map('.',background=
            [('selected', _compcolor), ('active',_ana2color)])
        
        #Code to define the attributes of the window title
        top.geometry("490x354+612+224")
        top.minsize(148, 1)
        top.maxsize(1924, 1055)
        top.resizable(1, 1)
        top.title("Simple Calculator of Things")
        top.configure(background="#d9d9d9")
        top.configure(highlightbackground="#d9d9d9")
        top.configure(highlightcolor="black")
        
        #Code for the attributes of the menubar
        self.menubar = tk.Menu(top,font="TkMenuFont",bg=_bgcolor,fg=_fgcolor)
        top.configure(menu = self.menubar)
        
        
        self.Entry1 = tk.Entry(top)
        self.Entry1.place(relx=0.327, rely=0.056,height=24, relwidth=0.253)
        self.Entry1.configure(background="white")
        self.Entry1.configure(disabledforeground="#a3a3a3")
        self.Entry1.configure(font="TkFixedFont")
        self.Entry1.configure(foreground="#000000")
        self.Entry1.configure(highlightbackground="#d9d9d9")
        self.Entry1.configure(highlightcolor="black")
        self.Entry1.configure(insertbackground="black")
        self.Entry1.configure(selectbackground="#c4c4c4")
        self.Entry1.configure(selectforeground="black")
        self.Entry1.configure(textvariable=Sample1_support.inputnumber)
        self.Entry1.focus()

        self.Label1 = tk.Label(top)
        self.Label1.place(relx=0.061, rely=0.056, height=26, width=122)
        self.Label1.configure(activebackground="#f9f9f9")
        self.Label1.configure(activeforeground="black")
        self.Label1.configure(background="#d9d9d9")
        self.Label1.configure(disabledforeground="#a3a3a3")
        self.Label1.configure(foreground="#000000")
        self.Label1.configure(highlightbackground="#d9d9d9")
        self.Label1.configure(highlightcolor="black")
        self.Label1.configure(text='''Input Number''')

        self.Radiobutton1 = tk.Radiobutton(top)
        self.Radiobutton1.place(relx=0.041, rely=0.198, relheight=0.088
                , relwidth=0.233)
        self.Radiobutton1.configure(activebackground="#ececec")
        self.Radiobutton1.configure(activeforeground="#000000")
        self.Radiobutton1.configure(background="#d9d9d9")
        self.Radiobutton1.configure(disabledforeground="#a3a3a3")
        self.Radiobutton1.configure(foreground="#000000")
        self.Radiobutton1.configure(highlightbackground="#d9d9d9")
        self.Radiobutton1.configure(highlightcolor="black")
        self.Radiobutton1.configure(justify='left')
        self.Radiobutton1.configure(text='''Temperature''')
        self.Radiobutton1.configure(value="1")
        self.Radiobutton1.configure(variable=Sample1_support.selectedButton)


        self.Radiobutton2 = tk.Radiobutton(top)
        self.Radiobutton2.place(relx=0.367, rely=0.198, relheight=0.088
                , relwidth=0.139)
        self.Radiobutton2.configure(activebackground="#ececec")
        self.Radiobutton2.configure(activeforeground="#000000")
        self.Radiobutton2.configure(background="#d9d9d9")
        self.Radiobutton2.configure(disabledforeground="#a3a3a3")
        self.Radiobutton2.configure(foreground="#000000")
        self.Radiobutton2.configure(highlightbackground="#d9d9d9")
        self.Radiobutton2.configure(highlightcolor="black")
        self.Radiobutton2.configure(justify='left')
        self.Radiobutton2.configure(text='''Power''')
        self.Radiobutton2.configure(value="2")
        self.Radiobutton2.configure(variable=Sample1_support.selectedButton)

        self.TCombobox1 = ttk.Combobox(top)
        self.TCombobox1.place(relx=0.041, rely=0.311, relheight=0.073
                , relwidth=0.239)
        self.value_list = ['F to C','C to F',]
        self.TCombobox1.configure(values=self.value_list)
        self.TCombobox1.configure(textvariable=Sample1_support.convert)
        self.TCombobox1.configure(takefocus="")

        self.Entry2 = tk.Entry(top)
        self.Entry2.place(relx=0.367, rely=0.311,height=24, relwidth=0.212)
        self.Entry2.configure(background="white")
        self.Entry2.configure(disabledforeground="#a3a3a3")
        self.Entry2.configure(font="TkFixedFont")
        self.Entry2.configure(foreground="#000000")
        self.Entry2.configure(insertbackground="black")
        self.Entry2.configure(textvariable=Sample1_support.exponent)

        self.Frame1 = tk.Frame(top)
        self.Frame1.place(relx=0.041, rely=0.678, relheight=0.212
                , relwidth=0.908)
        self.Frame1.configure(relief='groove')
        self.Frame1.configure(borderwidth="2")
        self.Frame1.configure(relief="groove")
        self.Frame1.configure(background="#d9d9d9")

        self.results = tk.Label(self.Frame1)
        self.results.place(relx=0.022, rely=0.133, height=56, width=432)
        self.results.configure(background="#d9d9d9")
        self.results.configure(disabledforeground="#a3a3a3")
        self.results.configure(foreground="#000000")
        self.results.configure(text='''Your Output Here''')

        self.Button1 = tk.Button(top)
        self.Button1.place(relx=0.122, rely=0.452, height=33, width=226)
        self.Button1.configure(activebackground="#ececec")
        self.Button1.configure(activeforeground="#000000")
        self.Button1.configure(background="#d9d9d9")
        self.Button1.configure(disabledforeground="#a3a3a3")
        self.Button1.configure(foreground="#000000")
        self.Button1.configure(highlightbackground="#d9d9d9")
        self.Button1.configure(highlightcolor="black")
        self.Button1.configure(pady="0")
        self.Button1.configure(text='''Calculate!''')


        '''ALL OTHER CODES AFTER THIS LINE'''

        def Rselect():
            if Sample1_support.selectedButton.get() == 1:
                self.TCombobox1.configure(state = "normal")
                self.Entry2.configure(state="disable")
            elif Sample1_support.selectedButton.get() == 2:
                self.Entry2.configure(state="normal")
                self.TCombobox1.configure(state = "disable")
        
        def ConvertTemperature(inputnum):
            if Sample1_support.convert.get() == 'F to C':
                #DO Calculations, fix it!
                converted = inputnum
            else:
                #DO Calculations, fix it!
                converted = inputnum
            return converted
        
        def ConvertPower(inputnum):
            power = float(Sample1_support.exponent.get())
            #DO CALCULATIONS, fix it!
            converted = inputnum**power
            return converted
        
        def Calculate():
            #this try-except chunk lets out an error prompt if the 
            #input value can't be converted to a numeric value
            try:
                a = float(Sample1_support.inputnumber.get())
            except ValueError:
                tk.messagebox.showerror("Error!", "Please enter a number.")
            
            labelvalue = 0
            if Sample1_support.selectedButton.get() == 1:
                labelvalue = ConvertTemperature(a)
            elif Sample1_support.selectedButton.get() == 2:
                labelvalue = ConvertPower(a)
            
            self.results.configure(text=f"The answer is {labelvalue}")
            
	    # f"" is called an f-string
            # In an f-string, you can easily show the value of a variable as string
            # by enclosing the variable name in {}
                

        self.Radiobutton1.configure(command=Rselect)
        self.Radiobutton2.configure(command=Rselect)
        
        self.Button1.configure(command=Calculate)

#This is the actual body of the code.
#if this program is ran by the main user (it was not called by another
#program), vp_start_gui is executed.
if __name__ == '__main__':
    vp_start_gui()





