#! /usr/bin/env python
#  -*- coding: utf-8 -*-
#
# GUI module generated by PAGE version 6.0.1
#  in conjunction with Tcl version 8.6
#    Feb 19, 2021 03:29:04 PM +08  platform: Linux

import sys
from tkinter import messagebox
from svm import gen_image, pred, conf_mat, class_report
import webbrowser
from PIL import Image, ImageTk

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

import pingus_support

def vp_start_gui():
    '''Starting point when module is the main routine.'''
    global val, w, root
    root = tk.Tk()
    top = Window_Title (root)
    pingus_support.init(root, top)
    root.mainloop()

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

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

class Window_Title:
    def __init__(self, top=None):

        ##Button functions
        def test_performance():
            self.anotherWindow = tk.Toplevel()
            self.anotherWindow.geometry("600x300+625+275")
            self.anotherWindow.minsize(1, 1)
            self.anotherWindow.maxsize(3825, 1050)
            self.anotherWindow.resizable(False, False)
            self.anotherWindow.title("Performance Evaluation")

            self.PerformanceEvalLabelTitle = tk.Label(self.anotherWindow)
            self.PerformanceEvalLabelTitle.place(relx=0.033, rely=0.044, height=19, width=566)
            self.PerformanceEvalLabelTitle.configure(activebackground="#f9f9f9")
            self.PerformanceEvalLabelTitle.configure(font="-family {Arial} -size 15")
            self.PerformanceEvalLabelTitle.configure(text='''Performance Evaluation''')

            self.menubar = tk.Menu(self.anotherWindow,font="TkMenuFont",bg=_bgcolor,fg=_fgcolor)
            top.configure(menu = self.menubar)

            # self.Label1 = tk.Label(self.anotherWindow)
            # self.Label1.place(relx=0.033, rely=0.133, height=309, width=566)
            # self.Label1.configure(activebackground="#f9f9f9")
            # self.Label1.configure(text=class_report())

            self.Text1 = tk.Text(self.anotherWindow)
            self.Text1.place(relx=0.133, rely=0.163, height=150, width=450)
            self.Text1.insert('6.0',class_report())

            self.ConfMatrixButton = tk.Button(self.anotherWindow)
            self.ConfMatrixButton.place(relx=0.333, rely=0.809, height=29, width=210)
            self.ConfMatrixButton.configure(activebackground="#f9f9f9")
            self.ConfMatrixButton.configure(text='''Confusion Matrix''')
            self.ConfMatrixButton.configure(command=conf_mat)

            
        def predict():
            img_num = self.imgnum
            predicted_label = pred(img_num)
            
            bank_dict = {
                1: ['Hong Leong Bank', '9:15am to 4:00pm', 'www.hlb.com.my', '03-7626 8899'], 
                2: ['HSBC', '9:30am to 4:00pm', 'www.hsbc.com.my', '1300-88-1388'],
                3: ['Maybank', '9:15am to 4:00pm', 'www.maybank2u.com.my', '1300-88-6688'], 
                4: ['RHB', '9:15am to 4:15pm', 'www.rhb.com.my', '03-9206 8118']
            }
            self.BankLabel['text'] = str(bank_dict[predicted_label][0])
            self.OpHrLabel['text'] = str(bank_dict[predicted_label][1])
            self.WebLabel['text'] = str(bank_dict[predicted_label][2])
            self.WebLabel_1['text'] = str(bank_dict[predicted_label][3])

        def goto_web():
            if self.WebLabel['text'] != '-':
                webbrowser.open_new(self.WebLabel['text'])
            else:
                messagebox.showinfo('Error', 'There is no URL')

        def generate():
            self.img, self.imgnum = gen_image()
            self.Labelframe1['image'] = self.img
            
            
            

        '''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'

        top.geometry("600x439+644+180")
        top.minsize(1, 1)
        top.maxsize(3825, 1050)
        top.resizable(False, False)
        top.title("Bank Building Recognition System")
        top.configure(highlightcolor="black")

        self.Title = tk.Label(top)
        self.Title.place(relx=0.017, rely=0.023, height=38, width=576)
        self.Title.configure(activebackground="#f9f9f9")
        self.Title.configure(font="-family {Arial} -size 18")
        self.Title.configure(text='''Bank Building Recognition System''')

        self.Labelframe1 = tk.Label(top)
        self.Labelframe1.place(relx=0.167, rely=0.132, relheight=0.433
                , relwidth=0.667)
        # self.Labelframe1.configure(relief='groove')

        self.Test_Performance = tk.Button(top, command = test_performance)
        self.Test_Performance.place(relx=0.017, rely=0.911, height=29, width=159)

        self.Test_Performance.configure(activebackground="#f9f9f9")
        self.Test_Performance.configure(text='''Test Performance''')

        self.Predict = tk.Button(top, command = predict)
        self.Predict.place(relx=0.767, rely=0.911, height=29, width=129)
        self.Predict.configure(activebackground="#f9f9f9")
        self.Predict.configure(text='''Predict''')

        self.Label1 = tk.Label(top)
        self.Label1.place(relx=0.15, rely=0.592, height=19, width=196)
        self.Label1.configure(anchor='w')
        self.Label1.configure(text='''Bank Name:''')

        self.Label2 = tk.Label(top)
        self.Label2.place(relx=0.15, rely=0.661, height=19, width=136)
        self.Label2.configure(anchor='w')
        self.Label2.configure(text='''Operating Hours:''')

        self.Label3 = tk.Label(top)
        self.Label3.place(relx=0.15, rely=0.729, height=19, width=116)
        self.Label3.configure(anchor='w')
        self.Label3.configure(cursor="fleur")
        self.Label3.configure(text='''Website:''')

        self.Label4 = tk.Label(top)
        self.Label4.place(relx=0.15, rely=0.797, height=19, width=146)
        self.Label4.configure(anchor='w')
        self.Label4.configure(text='''Contact Information:''')

        self.Button1 = tk.Button(top, command = goto_web)
        self.Button1.place(relx=0.683, rely=0.706, height=29, width=89)
        self.Button1.configure(text='''Go To Web''')

        self.BankLabel = tk.Label(top)
        self.BankLabel.place(relx=0.283, rely=0.592, height=19, width=326)
        self.BankLabel.configure(anchor='w')
        self.BankLabel.configure(text='''-''')

        self.menubar = tk.Menu(top,font="TkMenuFont",bg=_bgcolor,fg=_fgcolor)
        top.configure(menu = self.menubar)

        self.OpHrLabel = tk.Label(top)
        self.OpHrLabel.place(relx=0.333, rely=0.661, height=19, width=296)
        self.OpHrLabel.configure(activebackground="#f9f9f9")
        self.OpHrLabel.configure(anchor='w')
        self.OpHrLabel.configure(text='''-''')

        self.WebLabel = tk.Label(top)
        self.WebLabel.place(relx=0.25, rely=0.729, height=19, width=246)
        self.WebLabel.configure(activebackground="#f9f9f9")
        self.WebLabel.configure(anchor='w')
        self.WebLabel.configure(cursor="fleur")
        self.WebLabel.configure(text='''-''')

        ## Contact information label
        self.WebLabel_1 = tk.Label(top)
        self.WebLabel_1.place(relx=0.367, rely=0.797, height=19, width=276)
        self.WebLabel_1.configure(activebackground="#f9f9f9")
        self.WebLabel_1.configure(anchor='w')
        self.WebLabel_1.configure(text='''-''')

        self.Generate = tk.Button(top, command = generate)
        self.Generate.place(relx=0.433, rely=0.911, height=29, width=109)
        self.Generate.configure(text='''Generate''')

        

if __name__ == '__main__':
    vp_start_gui()





