from tkinter import *
from subprocess import call
import os

root = Tk()

root.geometry('500x600')

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

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,openfilelist):
    commandname.set(string)
    LabelTool.config(text = string)
    LabelInfo.config(text = generate_info(string))
    button1.place(x = 10, y = 10)
    button1.configure(bg = "green")
    for f in openfilelist:
        os.system("code -w "+f)

# 按钮STEP1执行的命令
def run_command1():
    selectedtool = commandname.get()
    call(["python",selectedtool+".py"])
    LabelTool.config(text = selectedtool+"命令执行完毕")
    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 = "运行", 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("寻找空闲题号",[]))
ImportMenu.add_separator()
ImportMenu.add_command(label = "批量收录题目", command = lambda: SetButton("批量收录题目",["批量收录题目.py"]))
ImportMenu.add_command(label = "添加关联题目", command = lambda: SetButton("添加关联题目",["添加关联题目.py"]))



# 设置 维护 菜单项
MaintainenceMenu = Menu(menubar, tearoff = False)
menubar.add_cascade(label = "维护", menu = MaintainenceMenu)
MaintainenceMenu.add_command(label = "批量添加字段数据", command = lambda: SetButton("修改metadata",["文本文件/metadata.txt"]))
MaintainenceMenu.add_separator()
MaintainenceMenu.add_command(label = "LaTeX编辑题目答案及提示", command = lambda: SetButton("LaTeX编辑题目答案及提示",["latex编辑题目答案及提示.py"]))
MaintainenceMenu.add_command(label = "json编辑题目综合信息", command = lambda: SetButton("json编辑题目综合信息",["json编辑题目综合信息.py"]))
MaintainenceMenu.add_separator()
MaintainenceMenu.add_command(label = "合并使用记录并排序", command = lambda: SetButton("合并使用记录并排序",[]))
MaintainenceMenu.add_separator()
MaintainenceMenu.add_command(label = "统考数据导入", command = lambda: SetButton("统考数据导入",["统考数据导入.py"]))
MaintainenceMenu.add_command(label = "手动统计结果导入", command = lambda: SetButton("手动统计结果导入",["临时文件/手动统计结果.txt"]))
MaintainenceMenu.add_command(label = "转换手打答案至metadata", command = lambda: SetButton("转换手打答案至metadata",["转换手打答案至metadata.py"]))
MaintainenceMenu.add_separator()
MaintainenceMenu.add_command(label = "移除关联题号", command = lambda: SetButton("移除关联题号",["文本文件/metadata.txt"]))
MaintainenceMenu.add_separator()
MaintainenceMenu.add_command(label = "小闲平台使用数据导入", command = lambda: SetButton("小闲平台使用数据导入",["小闲平台使用数据导入.py"]))
MaintainenceMenu.add_command(label = "小闲平台大型考试数据导入", command = lambda: SetButton("小闲平台大型考试数据导入",["小闲平台大型考试数据导入.py"]))
MaintainenceMenu.add_separator()
MaintainenceMenu.add_command(label = "分类题号字典生成", command = lambda: SetButton("分类题号字典生成",["分类题号字典生成.py"]))



# 设置 使用 菜单项
UseMenu = Menu(menubar, tearoff = False)
menubar.add_cascade(label = "使用", menu = UseMenu)
UseMenu.add_command(label = "关键字筛选题号", command = lambda: SetButton("关键字筛选题号",["关键字筛选题号.py"]))
UseMenu.add_separator()
UseMenu.add_command(label = "学生讲义制作", command = lambda: SetButton("学生讲义制作",["学生讲义制作.py"]))
UseMenu.add_command(label = "教师讲义制作", command = lambda: SetButton("教师讲义制作",["教师讲义制作.py"]))
UseMenu.add_command(label = "批量讲义生成", command = lambda: SetButton("批量讲义生成",["批量讲义生成.py"]))
UseMenu.add_separator()
UseMenu.add_command(label = "文件夹题号清点", command = lambda: SetButton("文件夹题号清点",["文件夹题号清点.py"]))
UseMenu.add_command(label = "参考答案生成", command = lambda: SetButton("参考答案生成",["参考答案生成.py"]))
UseMenu.add_separator()
UseMenu.add_command(label = "文件题号提取", command = lambda: SetButton("文件题号提取",["文件题号提取.py"]))



# 设置 备课 菜单项
BKMenu = Menu(menubar, tearoff=False)
menubar.add_cascade(label = "备课", menu = BKMenu)
BKMenu.add_command(label = "新课备课所用题目草稿生成", command = lambda: SetButton("新课备课所用题目草稿生成",["新课备课所用题目草稿生成.py"]))
BKMenu.add_command(label = "新课备课稿合集生成", command = lambda: SetButton("新课备课稿合集生成",["新课备课稿合集生成.py"]))
BKMenu.add_command(label = "单课备课稿生成", command = lambda: SetButton("单课备课稿生成",["单课备课稿生成.py"]))
BKMenu.add_separator()
BKMenu.add_command(label = "添加基础知识梳理", command = lambda: SetButton("添加基础知识梳理",["添加基础知识梳理.py"]))
# BKMenu.add_command(label = "题号清单生成", command = lambda: SetButton("题号清单生成",1,["题号清单生成.py"]))
# BKMenu.add_command(label = "已用题号剔除", command = lambda: SetButton("已用题号剔除",1,["已用题号剔除.py"]))
# BKMenu.add_command(label = "寻找未赋答案题目", command = lambda: SetButton("寻找未赋答案题目",1,["寻找未赋答案题目.py"]))
# BKMenu.add_command(label = "错题重做来源清点", command = lambda: SetButton("错题重做来源清点",1,["错题重做来源清点.py"]))
# BKMenu.add_separator()
# BKMenu.add_command(label = "备课草稿生成", command = lambda: SetButton("备课草稿生成",1,["备课草稿生成.py"]))
# BKMenu.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("课时名和课时目标制作",["课时名和课时目标制作.py"]))
# 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识别文本预处理",[]))
OtherMenu.add_command(label = "修改为带圈数字", command = lambda: SetButton("修改为带圈数字",[]))
OtherMenu.add_command(label = "剪贴板生成表格", command = lambda: SetButton("剪贴板生成表格",[]))
# OtherMenu.add_command(label = "剪贴板带圈数字处理", command = lambda: SetButton("带圈数字处理",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()