#! /usr/bin/env python
#  -*- coding: utf-8 -*-
#
# GUI module generated by PAGE version 4.15
# In conjunction with Tcl version 8.6
#    Aug 22, 2018 06:49:45 PM

import sys
import dao
import carBooking

try:
    from Tkinter import *
    import tkMessageBox
except ImportError:
    from tkinter import *
    from tkinter import messagebox as tkMessageBox

try:
    import ttk

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

    py3 = True

import login_support


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


def get_root(r):
    global root
    root = r


w = None


def create_Login(root, *args, **kwargs):
    '''Starting point when module is imported by another program.'''
    global w, w_win, rt
    rt = root
    w = Toplevel(root)
    top = Login(w)
    login_support.init(w, top, *args, **kwargs)
    return (w, top)


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


def check_password(c_id, password):
    cursor = dao.give_login()
    isAvailable = 0
    for row in cursor:
        if (str(row[0]) == c_id and row[1] == password):
            isAvailable = 1
    return isAvailable


class Login:
    def onLogin(self):
        id = self.loginId.get()
        passw = self.password.get()
        if check_password(id, passw):
            tkMessageBox.showinfo("Login Page", "The login is successfull")
            carBooking.create_Book_Your_Car(root)
            carBooking.getId(id, root)
        else:
            tkMessageBox.showwarning("LoginPage", "The username or password is incorrect")

    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 = '#d9d9d9'  # X11 color: 'gray85'
        font11 = "-family Roboto -size 20 -weight normal -slant roman " \
                 "-underline 0 -overstrike 0"
        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)])

        top.geometry("735x477+632+156")
        top.title("Login")
        top.configure(background="#ffffff")

        self.TFrame1 = ttk.Frame(top)
        self.TFrame1.place(relx=0.0, rely=0.0, relheight=1.0, relwidth=1.0)
        self.TFrame1.configure(relief=GROOVE)
        self.TFrame1.configure(borderwidth="2")
        self.TFrame1.configure(relief=GROOVE)
        self.TFrame1.configure(width=735)

        self.loginLabel = ttk.Label(self.TFrame1)
        self.loginLabel.place(relx=0.15, rely=0.27, height=66, width=166)
        self.loginLabel.configure(background="#d9d9d9")
        self.loginLabel.configure(foreground="#000000")
        self.loginLabel.configure(font=font11)
        self.loginLabel.configure(relief=FLAT)
        self.loginLabel.configure(text='''Login Id''')
        self.loginLabel.configure(width=166)

        self.loginId = ttk.Entry(self.TFrame1)
        self.loginId.place(relx=0.44, rely=0.29, relheight=0.08, relwidth=0.33)
        self.loginId.configure(font=font11)
        self.loginId.configure(width=244)
        self.loginId.configure(takefocus="")
        self.loginId.configure(cursor="xterm")

        self.password = ttk.Entry(self.TFrame1)
        self.password.place(relx=0.44, rely=0.44, relheight=0.08, relwidth=0.33)
        self.password.configure(font=font11)
        self.password.configure(width=244)
        self.password.configure(takefocus="")
        self.password.configure(cursor="xterm")

        self.passwordLabel = ttk.Label(self.TFrame1)
        self.passwordLabel.place(relx=0.15, rely=0.44, height=46, width=176)
        self.passwordLabel.configure(background="#d9d9d9")
        self.passwordLabel.configure(foreground="#000000")
        self.passwordLabel.configure(font=font11)
        self.passwordLabel.configure(relief=FLAT)
        self.passwordLabel.configure(text='''Password''')
        self.passwordLabel.configure(width=176)

        self.loginButton = ttk.Button(self.TFrame1)
        self.loginButton.place(relx=0.37, rely=0.63, height=55, width=114)
        self.loginButton.configure(takefocus="")
        self.loginButton.configure(text='''Login''')
        self.loginButton.configure(width=114)
        self.loginButton.configure(command=self.onLogin)


if __name__ == '__main__':
    vp_start_gui()
