Beispiel #1
0
 def open(self):
     self.initial_number = 0
     self.count = 0
     self.table = TableSms()
     if self.application.mainloop:
         self.application.mainloop.on_init()
         self.application.mainloop.send = self.send
     else:
         print('conection received')
Beispiel #2
0
 def open(self):
     self.initial_number = 0
     self.count = 0
     self.table = TableSms()
     if self.application.mainloop:
         self.application.mainloop.on_init()
         self.application.mainloop.send = self.send
     else:
         print('conection received')
Beispiel #3
0
class websocketHandler(websocket.WebSocketHandler):

    def open(self):
        self.initial_number = 0
        self.count = 0
        self.table = TableSms()
        if self.application.mainloop:
            self.application.mainloop.on_init()
            self.application.mainloop.send = self.send
        else:
            print('conection received')

    def send(self, data):
        self.write_message(data)

    def on_message(self, msg):
        # # client.send(bytes(str(msg).encode()))
        data = json.loads(msg)

        if data["op"] == "initial_count":
            self.initial_number = int(data["data"])

        elif data["op"] == "init_data":
            self.count = len(self.table.display_name_list)
            self.table.add_entry(data["data"])
            if self.application.mainloop:
                self.application.mainloop.init_data("received " + str(self.count) + " out of " + str(self.initial_number) + " conversation")
            else:
                print("received " + str(self.count) + " out of " + str(self.initial_number) + " conversation")

        elif data["op"] == "done":

            if self.application.mainloop:
                # self.application.mainloop.done(self.sms_dict)
                self.application.mainloop.done()
            else:
                # print(self.sms_dict)
                # print("done")
                print("done")

        elif data["op"] == "sms_recv":
            if self.application.mainloop:
                thread_id = self.table.get_thread_id_by_number(data["data"]["number"])
                data["data"]["thread_id"] = thread_id
                self.application.mainloop.on_recv(data["data"])
                # client.send(bytes(str(data["data"]).encode()))
                # client.send(b'\n')
            else:
                print("sms received")
                print(data["data"])

        elif data["op"] == "sms_confirmation":
            if self.application.mainloop:
                # client.send(bytes(str(data["data"]).encode()))
                # client.send(b'\n')
                self.application.mainloop.on_send_confirmation(data)
            else:
                print("sms confirmation")
                print(data["data"])


    def on_close(self):
        if not self.application.mainloop:
            print("connection close")
Beispiel #4
0
class websocketHandler(websocket.WebSocketHandler):
    def open(self):
        self.initial_number = 0
        self.count = 0
        self.table = TableSms()
        if self.application.mainloop:
            self.application.mainloop.on_init()
            self.application.mainloop.send = self.send
        else:
            print('conection received')

    def send(self, data):
        self.write_message(data)

    def on_message(self, msg):
        # # client.send(bytes(str(msg).encode()))
        data = json.loads(msg)

        if data["op"] == "initial_count":
            self.initial_number = int(data["data"])

        elif data["op"] == "init_data":
            self.count = len(self.table.display_name_list)
            self.table.add_entry(data["data"])
            if self.application.mainloop:
                self.application.mainloop.init_data("received " +
                                                    str(self.count) +
                                                    " out of " +
                                                    str(self.initial_number) +
                                                    " conversation")
            else:
                print("received " + str(self.count) + " out of " +
                      str(self.initial_number) + " conversation")

        elif data["op"] == "done":

            if self.application.mainloop:
                # self.application.mainloop.done(self.sms_dict)
                self.application.mainloop.done()
            else:
                # print(self.sms_dict)
                # print("done")
                print("done")

        elif data["op"] == "sms_recv":
            if self.application.mainloop:
                thread_id = self.table.get_thread_id_by_number(
                    data["data"]["number"])
                data["data"]["thread_id"] = thread_id
                self.application.mainloop.on_recv(data["data"])
                # client.send(bytes(str(data["data"]).encode()))
                # client.send(b'\n')
            else:
                print("sms received")
                print(data["data"])

        elif data["op"] == "sms_confirmation":
            if self.application.mainloop:
                # client.send(bytes(str(data["data"]).encode()))
                # client.send(b'\n')
                self.application.mainloop.on_send_confirmation(data)
            else:
                print("sms confirmation")
                print(data["data"])

    def on_close(self):
        if not self.application.mainloop:
            print("connection close")