import tkinter
from tkinter import *
from tkinter.ttk import *
import json

from common.log import logger
from config import conf
import requests
from db.sop import sop_task_query, sop_task_create
from common.sql_lite import get_global_db_connection

class FrameTabsSop(Frame):
    def __init__(self, parent):
        super().__init__(parent)
        self.__frame()
        self.tk_table_sop_list = self.__tk_table_sop_list(self)
        self.tk_button_sync = self.__tk_button_sync(self)

    def __frame(self):
        self.place(x=0, y=0, width=675, height=510)

    def __tk_table_sop_list(self, parent):
        # 表头字段 表头宽度
        columns = {"SOP ID":50, "SOP名称": 111, "发送账号": 111, "状态": 111, "创建时间": 111, "类型": 111}
        # 初始化表格 表格是基于Treeview，tkinter本身没有表格。show="headings" 为隐藏首列。
        tk_table = Treeview(parent, show="headings", columns=list(columns))
        for text, width in columns.items():  # 批量设置列属性
            tk_table.heading(text, text=text, anchor='center')
            tk_table.column(text, anchor='center', width=width, stretch=False)  # stretch 不自动拉伸


        # 插入数据示例
        # data = [
        #     [1, "github", "https://github.com/iamxcd/tkinter-helper"],
        #     [2, "演示地址", "https://www.pytk.net/tkinter-helper"]
        # ]
        #
        # # 导入初始数据
        # for values in data:
        #     tk_table.insert('', END, values=values)

        tk_table.place(x=30, y=50, width=608, height=420)
        return tk_table

    def __tk_button_sync(self, parent):
        btn = Button(parent, text="同步SOP列表", takefocus=True, state=tkinter.NORMAL)
        btn.place(x=560, y=10, width=80, height=30)
        return btn
