#! /usr/bin/env python
#  -*- coding: utf-8 -*-
#
# GUI module generated by PAGE version 4.26
#  in conjunction with Tcl version 8.6
#    Apr 22, 2020 06:32:46 PM +0300  platform: Windows NT


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 tomdownload_support


has_files_been_passed = True
# Var that lets program know there is a value in a list that should be passed
return_values = False
entry_values = []


def vp_start_gui(first_time=False):
    '''Starting point when module is the main routine.'''
    global val, w, root
    global return_values
    global entry_values
    return_values = []
    entry_values = []
    root = tk.Tk()
    top = Toplevel1(root)
    tomdownload_support.init(root, top)
    # Gets list of files in the cloud through socket. gives socket back
    s, var = tomdownload_support.insert_bots()
    if not var:
        print("destroyed")
        return "empty", s
    # Keep alive while user selects
    while not return_values:
        try:
            root.update()
        except:
            return
    if first_time:
        root.destroy()
    else:
        root.destroy()
    print('OUT')
    # VAR RESET
    return_values = False
    print(entry_values[0] + " ---> SELECTION")
    # Pass back
    return entry_values[0], s


w = None


def update_root():
    global val, w, root
    try:
        root.update()
    except:
        return


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


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


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'
        font11 = "-family Bahnschrift -size 13 -weight normal -slant roman "  \
            "-underline 0 -overstrike 0"

        top.geometry("487x500+450+171")
        top.minsize(120, 1)
        top.maxsize(1364, 749)
        top.resizable(1, 1)
        top.title("Filecloud")
        top.configure(borderwidth="3")
        top.configure(background="#0A3252")
        top.configure(highlightbackground="#d9d9d9")
        top.configure(highlightcolor="black")

        self.Label1 = tk.Label(top)
        self.Label1.place(relx=-0.062, rely=0.0, height=71, width=544)
        self.Label1.configure(activebackground="#2d3436")
        self.Label1.configure(activeforeground="white")
        self.Label1.configure(activeforeground="#2d3436")
        self.Label1.configure(background="#0A3252")
        self.Label1.configure(disabledforeground="#a3a3a3")
        self.Label1.configure(font="-family {Bahnschrift Light} -size 48")
        self.Label1.configure(foreground="#ffffff")
        self.Label1.configure(highlightbackground="#d9d9d9")
        self.Label1.configure(highlightcolor="black")
        self.Label1.configure(text='''Download a file''')

        self.Button1_1 = tk.Button(top)
        self.Button1_1.place(relx=0.283, rely=0.86, height=54, width=207)
        self.Button1_1.configure(activebackground="#ececec")
        self.Button1_1.configure(activeforeground="#000000")
        self.Button1_1.configure(background="#EA9A19")
        self.Button1_1.configure(disabledforeground="#a3a3a3")
        self.Button1_1.configure(font="-family {Verdana} -size 24")
        self.Button1_1.configure(foreground="#ffffff")
        self.Button1_1.configure(highlightbackground="#d9d9d9")
        self.Button1_1.configure(highlightcolor="black")
        self.Button1_1.configure(overrelief="flat")
        self.Button1_1.configure(pady="0")
        self.Button1_1.configure(relief="flat")
        self.Button1_1.configure(text='''DOWNLOAD''')
        self.Button1_1.configure(command=lambda:return_selected_file(self.Listbox1))

        self.Label2 = tk.Label(top)
        self.Label2.place(relx=0.045, rely=0.14, height=31, width=434)
        self.Label2.configure(activebackground="#f9f9f9")
        self.Label2.configure(activeforeground="black")
        self.Label2.configure(background="#0A3252")
        self.Label2.configure(disabledforeground="#a3a3a3")
        self.Label2.configure(font="-family {System} -size 10 -weight bold")
        self.Label2.configure(foreground="#ffffff")
        self.Label2.configure(highlightbackground="#d9d9d9")
        self.Label2.configure(highlightcolor="black")
        self.Label2.configure(text='''Select a file to download from the cloud by clicking on it''')

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

        self.Listbox1 = tk.Listbox(top)
        self.Listbox1.place(relx=0.226, rely=0.22, relheight=0.604
                , relwidth=0.542)

        self.Listbox1.configure(background="#0d3d64")
        self.Listbox1.configure(borderwidth="3")
        self.Listbox1.configure(cursor="fleur")
        self.Listbox1.configure(disabledforeground="#a3a3a3")
        self.Listbox1.configure(font=font11)
        self.Listbox1.configure(foreground="#ffffff")
        self.Listbox1.configure(relief="flat")
        self.Listbox1.configure(selectbackground="#114e80")

    def insert_bots(self, SERVER_FILES_PASSED):
        self.Listbox1.delete(0, 'end')
        for item in SERVER_FILES_PASSED:
            self.Listbox1.insert('end', item)
        update_root()


def return_selected_file(listbox):
    # Take selected file from list and pass back through list
    # RUNS WHEN CLICKED ON SUBMIT
    global entry_values
    global return_values
    # If no ne selected exit
    if not listbox.curselection():
        return
    # Passing to list
    entry_values.append(listbox.get(listbox.curselection()))
    return_values = True


if __name__ == '__main__':
    vp_start_gui()





