import threading

import kivy
from kivy.app import App
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.floatlayout import FloatLayout
from server import Server

# Replace this with your
# current version
kivy.require('1.11.1')


# Defining a class
class MalwareServer(FloatLayout):

    # Function that returns
    # the root widget
    def __init__(self, **kwargs):
        super(MalwareServer, self).__init__(**kwargs)
        self.server = Server()
        t = threading.Thread(target=self.server.main)
        t.start()
        self.btn = Button(text="Push Me !",
                          font_size="20sp",
                          background_color=(1, 1, 1, 1),
                          color=(1, 1, 1, 1),
                          size_hint=(.3, .1),
                          pos_hint={'x': .1, 'y': .8})

        self.btn.bind(on_press=self.callback)
        self.status_label = Label(text=self.server.status,
                                  size_hint=(.3, .1),
                                  pos_hint={'x': .5, 'y': .8})

        self.info_label = Label(text=self.server.received_data,
                                size_hint=(.3, .1),
                                pos_hint={'x': 0.1, 'y': 0.4},
                                color=(1, 1, 0.5, 1))

        self.add_widget(self.btn)
        self.add_widget(self.status_label)
        self.add_widget(self.info_label)

    def callback(self, event):
        print(self.server.get_received_info())
        self.info_label.text = self.server.received_data
        self.status_label.text = self.server.status

class MalwareServerGUI(App):
    def build(self):
        return MalwareServer()


# and its run() method is called.
# This initializes and starts
# our Kivy application.

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