from PyQt6 import QtCore
from PyQt6.QtCore import QObject

from Functions.QtFunctions import ipcall
from .LogerinTxt import app_logger


class setlocalip(QObject):
    localipupdate = QtCore.pyqtSignal(str)

    def __init__(self, ip, thread):
        super().__init__()
        self.ip = ip
        self.thread = thread

    def run(self):
        # print("jjingruy1")
        try:
            if self.ip != None:
                try:
                    localcalltry = ipcall.searchinfo()
                    self.localtoken = localcalltry.start(self.ip)
                    # print("本地测试print(self.localtoken)")
                    # print(self.localtoken)
                except Exception as e:
                    self.localtoken = None
                    self.localtoken = None
                    app_logger.log_error(e)
            else:
                self.localtoken = None
            self.localipupdate.emit(self.localtoken)
            self.thread.quit()
        except Exception as e:
            app_logger.log_error(e)
            self.thread.quit()