from tkinter import *
from subprocess import call
import os

root = Tk()

root.geometry('500x600')

root.title('题库v2.0工具面板')

def temp():
    pass

def generate_info(string):
    outputstring = "暂无信息"
    if string == "寻找空闲题号":
        outputstring = '功能: 在题库中列出所有空闲题号.\n1. 按"运行STEP1"按钮后等若干秒, 在终端查看结果.'
    elif string == "批量收录题目":
        outputstring = '功能: 在一个.tex文件中找到\\item开头的题目并收录到题库.\n'+'0. 选中菜单项后会打开一个编辑窗口, 在编辑窗口中设置\n\t(1) 初始编号;\n\t(2) 题目来源(文件中的%开头的注释行的内容会依次作为此后题目来源的后缀);\n\t(3) .tex文件名(完整路径);\n\t(4) 收录日期及编辑者;\n\t(5) 是否对题目进行编号.\n'+'1. 编辑完成后按"运行STEP1"按钮后等若干秒, 在终端查看结果.'
    return outputstring
    

def SetButton(string,numbuttons,openfilelist):
    commandname.set(string)
    LabelTool.config(text = string)
    LabelInfo.config(text = generate_info(string))
    button1.place(x = 10, y = 10)
    button1.configure(bg = "green")
    if numbuttons == 1:
        button2.place_forget()
    else:
        button2.place(x=10, y=50)
        button2.configure(bg = "red")
    for f in openfilelist:
        os.system("code "+f)

# 按钮STEP1执行的命令
def run_command1():
    selectedtool = commandname.get()
    if selectedtool == "题号选题pdf生成":
        call(["python","题号选题pdf生成.py"])
    elif selectedtool == "寻找空闲题号":
        call(["python","寻找空闲题号.py"])
    elif selectedtool == "批量收录题目":
        call(["python","批量收录题目.py"])
    elif selectedtool == "添加关联题目":
        call(["python","添加关联题目.py"])
        button2.configure(bg = "green")
    elif selectedtool == "修改题目数据库":
        call(["python","修改题目数据库.py"])
        button2.configure(bg = "green")
    elif selectedtool == "mathpix预处理":
        call(["python","../文本处理工具/剪贴板文本整理_mathpix.py"])
    elif selectedtool == "带圈数字处理":
        call(["python","../文本处理工具/带圈数字处理.py"])
    elif selectedtool == "试卷答案生成":
        call(["python","试卷答案生成.py"])
    elif selectedtool == "单元标记转换":
        call(["python","单元标记转换.py"])
    elif selectedtool == "目标清点及清单生成":
        call(["python","单元课时目标题目数据清点.py"])
    elif selectedtool == "目标表体生成":
        call(["python","根据范围提取课时目标.py"])
    elif selectedtool == "课时目标寻找题目":
        call(["python","课时目标寻找题目.py"])
    elif selectedtool == "关键字筛选题号":
        call(["python","关键字筛选题号.py"])
    elif selectedtool == "讲义生成":
        call(["python","讲义生成.py"])
    elif selectedtool == "课时目标划分信息汇总":
        call(["python","课时目标划分信息汇总.py"])
    elif selectedtool == "题号清单生成":
        call(["python","题号清单生成.py"]) 
    elif selectedtool == "已用题号剔除":
        call(["python","已用题号剔除.py"])
    elif selectedtool == "寻找未赋答案题目":
        call(["python","寻找未赋答案题目.py"]) 
    elif selectedtool == "识别题目类型":
        call(["python","识别题目类型.py"])
    elif selectedtool == "批量添加字段数据":
        call(["python","批量添加字段数据.py"])
    elif selectedtool == "目标挂钩清点":
        call(["python","目标挂钩清点.py"])
    elif selectedtool == "批量题号选题pdf生成":
        call(["python","批量生成题目pdf.py"])  
    elif selectedtool == "目标pdf生成":
        call(["python","课时目标pdf生成.py"])
    elif selectedtool == "剪贴板表格整理":
        call(["python","剪贴板表格整理.py"])
    elif selectedtool == "手动统计结果转换":
        call(["python","手动统计结果转换.py"])
    elif selectedtool == "新题相似相同比对":
        call(["python","新题相似相同比对.py"])
    elif selectedtool == "全局未标注相同题目检测":
        call(["python","全局未标注相同题目检测.py"])
    elif selectedtool == "局部相似题目检测":
        call(["python","局部相似题目检测.py"])
    elif selectedtool == "相同相似题目标注":
        call(["python","相同相似题目标注.py"])    
    elif selectedtool == "latex修改题目":
        call(["python","latex界面修改题目内容.py"])
        button2.configure(bg = "green")
    elif selectedtool == "答案metadata生成":
        call(["python","答案metadata生成.py"])
    elif selectedtool == "错题重做来源清点":
        call(["python","错题重做来源清点.py"])
    elif selectedtool == "统考数据导入":
        call(["python","统考数据导入.py"])
    LabelTool.config(text = selectedtool+"STEP1命令执行完毕")
    button1.place_forget()

# 按钮STEP2执行的命令

def run_command2():
    selectedtool = commandname.get()
    if selectedtool == "添加关联题目":
        call(["python","导入关联题目.py"])
    elif selectedtool == "修改题目数据库":
        call(["python","修改结果汇入.py"])
    elif selectedtool == "latex修改题目":
        call(["python","导入latex界面修改的题目内容.py"])
    LabelTool.config(text = selectedtool+ "STEP2命令执行完毕")
    button2.place_forget()

commandname = StringVar()
commandname.set("none")
LabelTool = Label(root, text = "请在菜单栏选择工具", height = 1, width = 40, anchor=NW)
LabelTool.place(x=10,y=100)
LabelInfo = Label(root, text = "工具提示信息", height = 20, width = 100, anchor = NW, justify = "left")
LabelInfo.place(x=10,y=140)

button1 = Button(root, text = "运行STEP1", command = run_command1)
button2 = Button(root, text = "运行STEP2", command = run_command2)
# button3 = Button(root, text = "运行STEP3")

menubar = Menu(root)

# 设置 录入 菜单项
ImportMenu = Menu(menubar, tearoff = False)
menubar.add_cascade(label = "录入", menu = ImportMenu)
ImportMenu.add_command(label = "寻找空闲题号", command = lambda: SetButton("寻找空闲题号",1,[]))
ImportMenu.add_separator()
ImportMenu.add_command(label = "批量收录题目", command = lambda: SetButton("批量收录题目",1,["批量收录题目.py"]))
ImportMenu.add_command(label = "添加关联题目", command = lambda: SetButton("添加关联题目",2,["添加关联题目.py"]))

# 设置 维护 菜单项
MaintainenceMenu = Menu(menubar, tearoff = False)
menubar.add_cascade(label = "维护", menu = MaintainenceMenu)
MaintainenceMenu.add_command(label = "批量添加字段数据", command = lambda: SetButton("批量添加字段数据",1,["文本文件/metadata.txt","批量添加字段数据.py"]))
MaintainenceMenu.add_command(label = "手动统计结果转换", command = lambda: SetButton("手动统计结果转换",1,["文本文件/metadata.txt","文本文件/手动统计结果.txt"]))
MaintainenceMenu.add_separator()
MaintainenceMenu.add_command(label = "LaTeX界面修改题目内容", command = lambda: SetButton("latex修改题目",2,["latex界面修改题目内容.py"]))
MaintainenceMenu.add_command(label = "修改题目综合信息", command = lambda: SetButton("修改题目数据库",2,["修改题目数据库.py"]))
MaintainenceMenu.add_command(label = "识别题目类型", command = lambda: SetButton("识别题目类型",1,[]))
MaintainenceMenu.add_separator()
MaintainenceMenu.add_command(label = "答案metadata生成", command = lambda: SetButton("答案metadata生成",1,["答案metadata生成.py"]))
MaintainenceMenu.add_separator()
MaintainenceMenu.add_command(label = "统考数据导入", command = lambda: SetButton("统考数据导入",1,["统考数据导入.py"]))


# 设置 使用 菜单项
UseMenu = Menu(menubar, tearoff = False)
menubar.add_cascade(label = "使用", menu = UseMenu)
UseMenu.add_command(label = "关键字筛选题号", command = lambda: SetButton("关键字筛选题号",1,["关键字筛选题号.py"]))
UseMenu.add_separator()
UseMenu.add_command(label = "讲义试卷生成", command = lambda: SetButton("讲义生成",1,["讲义生成.py"]))
UseMenu.add_command(label = "题号选题pdf生成", command = lambda: SetButton("题号选题pdf生成",1,["题号选题pdf生成.py"]))
UseMenu.add_command(label = "批量题号选题pdf生成", command = lambda: SetButton("批量题号选题pdf生成",1,["批量生成题目pdf.py"]))


# 设置 备课组 菜单项
BKZMenu = Menu(menubar, tearoff=False)
menubar.add_cascade(label = "备课组材料相关", menu = BKZMenu)
BKZMenu.add_command(label = "试卷答案生成", command = lambda: SetButton("试卷答案生成",1,["试卷答案生成.py"]))
BKZMenu.add_command(label = "题号清单生成", command = lambda: SetButton("题号清单生成",1,["题号清单生成.py"]))
BKZMenu.add_command(label = "已用题号剔除", command = lambda: SetButton("已用题号剔除",1,["已用题号剔除.py"]))
BKZMenu.add_command(label = "寻找未赋答案题目", command = lambda: SetButton("寻找未赋答案题目",1,["寻找未赋答案题目.py"]))
BKZMenu.add_command(label = "错题重做来源清点", command = lambda: SetButton("错题重做来源清点",1,["错题重做来源清点.py"]))

# 设置 目标及标签 菜单项
ObjTagMenu = Menu(menubar, tearoff = False)
menubar.add_cascade(label = "目标及标签", menu = ObjTagMenu)
ObjTagMenu.add_command(label = "单元标记转换", command = lambda: SetButton("单元标记转换",1,["单元标记转换.py"]))
ObjTagMenu.add_separator()
ObjTagMenu.add_command(label = "目标表体生成", command = lambda: SetButton("目标表体生成",1,["根据范围提取课时目标.py"]))
ObjTagMenu.add_command(label = "目标pdf生成", command = lambda: SetButton("目标pdf生成",1,["课时目标pdf生成.py"]))
ObjTagMenu.add_command(label = "课时目标寻找题目", command = lambda: SetButton("课时目标寻找题目",1,["课时目标寻找题目.py"]))
ObjTagMenu.add_command(label = "课时目标划分信息汇总", command = lambda: SetButton("课时目标划分信息汇总",1,[]))
ObjTagMenu.add_separator()
ObjTagMenu.add_command(label = "目标挂钩基础清点", command = lambda: SetButton("目标挂钩清点",1,[]))
ObjTagMenu.add_command(label = "目标清点及清单生成", command = lambda: SetButton("目标清点及清单生成",1,[]))

# 设置 相同相似比对 菜单项
SimRelMenu = Menu(menubar, tearoff= False)
menubar.add_cascade(label = "相同相似", menu = SimRelMenu)
SimRelMenu.add_command(label = "新题相似相同比对", command = lambda: SetButton("新题相似相同比对",1,["新题相似相同比对.py"]))
SimRelMenu.add_separator()
SimRelMenu.add_command(label = "局部相似题目检测", command = lambda: SetButton("局部相似题目检测",1,["局部相似题目检测.py"]))
SimRelMenu.add_command(label = "相同相似题目标注", command = lambda: SetButton("相同相似题目标注",1,["相同相似题目标注.py"]))
SimRelMenu.add_separator()
SimRelMenu.add_command(label = "全局未标注相同题目检测", command = lambda: SetButton("全局未标注相同题目检测",1,[]))



# 设置 其他 菜单项
OtherMenu = Menu(menubar, tearoff = False)
menubar.add_cascade(label = "其他", menu = OtherMenu)
OtherMenu.add_command(label = "剪贴板mathpix预处理", command = lambda: SetButton("mathpix预处理",1,[]))
OtherMenu.add_command(label = "剪贴板带圈数字处理", command = lambda: SetButton("带圈数字处理",1,[]))
OtherMenu.add_command(label = "剪贴板表格整理", command = lambda: SetButton("剪贴板表格整理",1,[]))


menubar.add_command(label = "退出", command = root.destroy)



root.config(menu = menubar)
root.attributes("-topmost",1)
root.iconbitmap("logo.ico")

root.mainloop()