# -*-coding=utf-8-*-

# @Time : 2020/4/23 17:21
# @File : File.py
from PyQt5 import QtWidgets, QtCore, QtGui
import pyqtgraph as pg
import threading
import numpy as np
from t1k.resource.draw_real_ut import draw_bscan_from_csv
from t1k.resource.draw_ut import draw_bscan_from_csv as draw_bscan_from_csv_zoom
import time
from t1k.resource.langmap import get_lang_map
from t1k.resource.convertor import T1kConvertor
import io
from pathlib import PurePath
from t1k.resource.config import get_global_config
import cv2
from PyQt5.QtWidgets import QMenu, qApp, QAction
from t1k.resource.t1k_simple import RecordTestDesc
from t1k.resource.db_util import get_db_manager, headers, get_md5, CONFIRM, NOT_CONFIRM, CHANGED
import os

class File():
    def __init__(self):
        pass

    def open(self):
        fname = QtWidgets.QFileDialog.getOpenFileName(self, 'Open file', '', "T1k files (*.t1k)")
        if os.path.exists(fname[0]):
            self.clear_last()
            self.extractAction.setDisabled(True)
            self.clear_menu_method()
            self.t1k_file = fname[0]
            (csv_file, import_count, exception_count, normal_count, ui_str) = self.db.exists(self.t1k_file)
            if csv_file:
                csv_file_path = os.path.join(self.root, csv_file)
                if os.path.exists(csv_file_path):
                    self.run_csv_all_file(csv_file, import_count, exception_count, normal_count, ui_str)

            else:
                self.task = threading.Thread(target=self.run_t1k, args=(self.t1k_file,))
                # self.task = threading.Thread(target=lambda x: x.run_t1k(), args=(self,))
                self.stop_task = False
                self.task.start()
