diff --git a/工具v2/database_tools.py b/工具v2/database_tools.py index bd03fe70..c7de4008 100644 --- a/工具v2/database_tools.py +++ b/工具v2/database_tools.py @@ -1198,7 +1198,13 @@ def GenerateSingleLessonPreparation(lessonid, outputdir, adict, prodict, objdict return latex_data # 返回有错误的latex源代码 - +def getlineindex(string,filepath): #返回字符串在文本文件中第一次出现的行数, 若未出现则返回1 + with open(filepath,"r",encoding = "u8") as f: + lines = f.readlines() + for l in lines: + if string in l: + return lines.index(l)+1 + return 1 def getCopy(): # 获取剪切板内容 wc.OpenClipboard() diff --git a/工具v2/工具面板.py b/工具v2/工具面板.py index 78a8eaa4..35f3cd8a 100644 --- a/工具v2/工具面板.py +++ b/工具v2/工具面板.py @@ -1,6 +1,7 @@ from tkinter import * from subprocess import call import os +from database_tools import * root = Tk() @@ -26,8 +27,14 @@ def SetButton(string,openfilelist): LabelInfo.config(text = generate_info(string)) button1.place(x = 10, y = 10) button1.configure(bg = "green") + configjson = load_dict("文本文件/config.json") for f in openfilelist: - os.system("code -w "+f) + if not f in configjson: + os.system("code -w "+f) + else: + lineindex = getlineindex(f,"文本文件/config.json") + os.system(f"code -w -g 文本文件/config.json:{lineindex}") + # 按钮STEP1执行的命令 def run_command1(): diff --git a/工具v2/批量讲义生成.py b/工具v2/批量讲义生成.py index 156d735b..f25d0446 100644 --- a/工具v2/批量讲义生成.py +++ b/工具v2/批量讲义生成.py @@ -1,13 +1,20 @@ -problems_dict = { - "第一讲": "1:20", - "第二讲": "50:60,70:80" -} #题号字典, 每一项的key表示标题, 内容字符串表示题号 -notetitle = "测试批量讲义" #讲义标题, 也是文件标题 -answered = True #是否展示答案, True表示展示答案, False表示不展示答案 - +# problems_dict = { +# "第一讲": "1:20", +# "第二讲": "50:60,70:80" +# } #题号字典, 每一项的key表示标题, 内容字符串表示题号 +# notetitle = "测试批量讲义" #讲义标题, 也是文件标题 +# answered = True #是否展示答案, True表示展示答案, False表示不展示答案 from database_tools import * + +configjson = load_dict("文本文件/config.json")["批量讲义生成.py"] + +problems_dict = configjson["标题与题号"] +notetitle = configjson["pdf标题"] +answered = configjson["提供答案"] + + prodictpath = "../题库0.3/problems.json" pro_dict = load_dict(prodictpath) diff --git a/工具v2/文本文件/config.json b/工具v2/文本文件/config.json new file mode 100644 index 00000000..b7183056 --- /dev/null +++ b/工具v2/文本文件/config.json @@ -0,0 +1,11 @@ +{ + "说明": "程序的设置文件, 用于工具v2中各程序的主要变量赋值等", + "批量讲义生成.py": { + "标题与题号": { + "第一讲": "1:5", + "第二讲": "50:60,70:80" + }, + "pdf标题": "测试批量讲义", + "提供答案": true + } +} \ No newline at end of file