from functools import partial
import os
from upload_pic import UploadPic  # 假设 UploadPic 类在 upload_pic 模块中
from run_main import RunMain

class HandleDetail():

    def __int__(self):
        self.run_main = RunMain(windows=self)

    def deal_run_end_sign(self, config_data: dict):
        if config_data["sign_text"] == "开始抠图":
            # 先做整体校验
            self.run_main.check_for_cutout_image_first_call_back(return_data=self.run_main.check_before_cutout,
                                                                 config_data=config_data)

        print(config_data)
        if config_data["sign_text"] == "已结束抠图处理":
            if config_data["detail_is_enable"]:
                # 先做整体校验
                # temp_name=self.last_temp, temp_name_list=self.temp_list
                func = partial(self.run_main.check_before_detail, config_data=config_data)
                self.do_thread_run(func=func,
                                   call_back=self.run_main.check_for_detail_first_call_back,
                                   time_out=30,
                                   is_show_mask=False)
            else:
                self.set_state(state_value=2)

        if config_data["sign_text"] == "已结束详情处理":
            if config_data["upload_is_enable"]:
                to_deal_dir = "{}/软件-详情图生成".format(config_data["image_dir"])
                print("to_deal_dir", to_deal_dir)
                if os.path.exists(to_deal_dir):
                    self.upload_pic = UploadPic(windows=self, to_deal_dir=to_deal_dir, config_data=config_data)
                    self.upload_pic.run_end_sign.connect(self.deal_run_end_sign)
                    self.upload_pic.show_progress_detail_sign.connect(self.show_progress_detail)
                    self.upload_pic.run()
                    # threading.Thread(target=self.upload_pic.run_by_thread, args=()).start()
                else:
                    self.set_state(state_value=2)
            else:
                self.set_state(state_value=2)

        if config_data["sign_text"] == "结束":
            self.set_state(state_value=2)
