from random import randrange

from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.uix.button import Button

import socket
from connector import *
from scProcessor import *
from smartcard.util import toHexString

class Container(BoxLayout):
    def __init__(self):
        # self.scObj = sCard()
        self.conn = socket()

    def authorize(self):
        # Connects to the server

        HOST = '10.192.1.134'  # Symbolic name meaning all available interfaces
        PORT = 21077  # Arbitrary non-privileged port
        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
            s.bind((HOST, PORT))
            s.listen(1)
            conn, addr = s.accept()
            with conn:
                print('Connected by', addr)
                while True:
                    data = conn.recv(1024)
                    if not data: break
                    conn.sendall(data)
        #
        # # get atr for created obj
        # atr = self.scObj.getAtr()
        # self.change_inputlog(atr)
        # # send data to conn
        # self.conn.send_data()

    def change_inputlog(self, value):
        buffer = self.inputLog.text
        self.inputLog.text = buffer + '\n' + value

class kivyTca(App):
    def build(self):
        return Container()

if __name__ == '__main__':
    kivyTca().run()