#! /usr/bin/env python
#  -*- coding: utf-8 -*-
#
# GUI module generated by PAGE version 4.25.1
#  in conjunction with Tcl version 8.6
#    Dec 20, 2019 08:37:49 AM CST  platform: Windows NT

import sys
import NFCBackend

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 nfc_support
from tkinter import messagebox

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

w = None
def create_TopLevel(root, *args, **kwargs):
    '''Starting point when module is imported by another program.'''
    global w, w_win, rt
    rt = root
    w = tk.Toplevel (root)
    nfc_support.set_Tk_var()
    top = TopLevel (w)
    nfc_support.init(w, top, *args, **kwargs)
    return (w, top)

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

class TopLevel:
    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'
        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("250x180+409+113")
        top.title("Python NFC R/W")
        top.configure(background="#d9d9d9")
        top.configure(highlightbackground="#d9d9d9")
        top.configure(highlightcolor="black")

        self.EntryData = tk.Entry(top)
        self.EntryData.place(relx=0.16, rely=0.222,height=20, relwidth=0.656)
        self.EntryData.configure(background="white")
        self.EntryData.configure(disabledforeground="#a3a3a3")
        self.EntryData.configure(font="TkFixedFont")
        self.EntryData.configure(foreground="#000000")
        self.EntryData.configure(highlightbackground="#d9d9d9")
        self.EntryData.configure(highlightcolor="black")
        self.EntryData.configure(insertbackground="black")
        self.EntryData.configure(selectbackground="#c4c4c4")
        self.EntryData.configure(selectforeground="black")

        self.LabelData = tk.Label(top)
        self.LabelData.place(relx=0.36, rely=0.056, height=21, width=64)
        self.LabelData.configure(activebackground="#f9f9f9")
        self.LabelData.configure(activeforeground="black")
        self.LabelData.configure(background="#d9d9d9")
        self.LabelData.configure(disabledforeground="#a3a3a3")
        self.LabelData.configure(foreground="#000000")
        self.LabelData.configure(highlightbackground="#d9d9d9")
        self.LabelData.configure(highlightcolor="black")
        self.LabelData.configure(text='''Hex (Send)''')

        self.ButtonRead = tk.Button(top)
        self.ButtonRead.place(relx=0.28, rely=0.389, height=24, width=37)
        self.ButtonRead.configure(activebackground="#ececec")
        self.ButtonRead.configure(activeforeground="#000000")
        self.ButtonRead.configure(background="#d9d9d9")
        self.ButtonRead.configure(command=lambda: tk.messagebox.showinfo("Data from: S%sB%s" %(self.OptionSector.get(),self.OptionBlock.get()),NFCBackend.readsector(int(self.OptionSector.get()),int(self.OptionBlock.get()))))
        self.ButtonRead.configure(disabledforeground="#a3a3a3")
        self.ButtonRead.configure(foreground="#000000")
        self.ButtonRead.configure(highlightbackground="#d9d9d9")
        self.ButtonRead.configure(highlightcolor="black")
        self.ButtonRead.configure(pady="0")
        self.ButtonRead.configure(text='''Read''')

        self.ButtonWrite = tk.Button(top)
        self.ButtonWrite.place(relx=0.56, rely=0.389, height=24, width=39)
        self.ButtonWrite.configure(activebackground="#ececec")
        self.ButtonWrite.configure(activeforeground="#000000")
        self.ButtonWrite.configure(background="#d9d9d9")
        self.ButtonWrite.configure(command=lambda: tk.messagebox.showinfo("Data to: S%sB%s" %(self.OptionSector.get(),self.OptionBlock.get()),NFCBackend.writesector(int(self.OptionSector.get()),int(self.OptionBlock.get()),bytes(self.EntryData.get().encode('utf-8')))))
        self.ButtonWrite.configure(disabledforeground="#a3a3a3")
        self.ButtonWrite.configure(foreground="#000000")
        self.ButtonWrite.configure(highlightbackground="#d9d9d9")
        self.ButtonWrite.configure(highlightcolor="black")
        self.ButtonWrite.configure(pady="0")
        self.ButtonWrite.configure(text='''Write''')

        self.OptionSector = ttk.Combobox(top)
        self.OptionSector.place(relx=0.12, rely=0.722, relheight=0.117
                , relwidth=0.332)
        self.OptionSector.configure(textvariable=nfc_support.sectorlist)
        self.OptionSector.configure(takefocus="")
        self.OptionSector.configure(values=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15])

        self.OptionBlock = ttk.Combobox(top)
        self.OptionBlock.place(relx=0.54, rely=0.722, relheight=0.117
                , relwidth=0.332)
        self.OptionBlock.configure(textvariable=nfc_support.blocklist)
        self.OptionBlock.configure(takefocus="")
        self.OptionBlock.configure(values=[0,1,2,3])

        self.Label1 = tk.Label(top)
        self.Label1.place(relx=0.2, rely=0.583, height=21, width=39)
        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='''Sector''')

        self.Label2 = tk.Label(top)
        self.Label2.place(relx=0.64, rely=0.583, height=21, width=35)
        self.Label2.configure(activebackground="#f9f9f9")
        self.Label2.configure(activeforeground="black")
        self.Label2.configure(background="#d9d9d9")
        self.Label2.configure(disabledforeground="#a3a3a3")
        self.Label2.configure(foreground="#000000")
        self.Label2.configure(highlightbackground="#d9d9d9")
        self.Label2.configure(highlightcolor="black")
        self.Label2.configure(text='''Block''')

        self.SpeakerDisable = tk.Checkbutton(top)
        self.SpeakerDisable.place(relx=0.22, rely=0.861, relheight=0.139
                , relwidth=0.556)
        self.SpeakerDisable.configure(activebackground="#ececec")
        self.SpeakerDisable.configure(activeforeground="#000000")
        self.SpeakerDisable.configure(background="#d9d9d9")
        self.SpeakerDisable.configure(command=lambda: NFCBackend.beepControl())
        self.SpeakerDisable.configure(disabledforeground="#a3a3a3")
        self.SpeakerDisable.configure(foreground="#000000")
        self.SpeakerDisable.configure(highlightbackground="#d9d9d9")
        self.SpeakerDisable.configure(highlightcolor="black")
        self.SpeakerDisable.configure(justify='left')
        self.SpeakerDisable.configure(text='''Disable Speaker Beep''')
        self.SpeakerDisable.configure(variable=nfc_support.speaker)

if __name__ == '__main__':
    vp_start_gui()





