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


try:
    import Tkinter as tk
except ImportError:
    import tkinter as tk
import socket
import config
try:
    import ttk
    py3 = False
except ImportError:
    import tkinter.ttk as ttk
    py3 = True
    
value = []
HOST = config.HOST
port = config.PORT


def init(top, gui):
    global w, top_level, root
    w = gui
    top_level = top
    root = top


def destroy_window():
    # Function which closes the window.
    global top_level
    top_level.destroy()
    top_level = None


def insert_bots():
    print('entered insert bots')
    global w, root
    file_arr, s = server_get_file_list()
    if file_arr == []:
        return s, False
    w.insert_bots(file_arr)
    return s, True


def server_get_file_list():
    print("emtered get file list")
    s = socket.socket()
    try:
        s.connect((HOST, port))
    except IOError:
        print("connection aborted")
        exit()
    s.send('d'.encode())
    print("sent")
    data = s.recv(2048).decode()
    print("check one")
    if data == "empty":
        print("received no file")
        return [], s
    print(data)
    data = data.split(':')
    return data, s


if __name__ == '__main__':
    import tomdownload
    tomdownload.vp_start_gui()




