增加备课讨论稿生成功能并加入工具面板

This commit is contained in:
weiye.wang 2023-06-09 22:35:18 +08:00
parent 38ea2e6ea7
commit 25a62ae4ac
4 changed files with 192 additions and 1 deletions

View File

@ -13,7 +13,7 @@ problems = "15:30"
template_file = "模板文件/备课草稿模板.txt" #设置模板文件名
exec_list = [("标题替换",lessonid+title)] #设置讲义标题
destination_file = "临时文件/"+lessonid+title # 设置输出文件名
destination_file = "临时文件/"+lessonid+title+"草稿" # 设置输出文件名

View File

@ -0,0 +1,96 @@
import os,re,json,time,sys
"""---设置目标及题块编号---"""
lessonid = "K0103"
title = "集合的关系"
problems = ["15:30","1:3","40:45"]
"""---设置结束---"""
template_file = "模板文件/备课讨论稿模板.txt" #设置模板文件名
exec_list = [("标题替换",lessonid+title)] #设置讲义标题
destination_file = "临时文件/"+lessonid+title+"讨论稿" # 设置输出文件名
#生成数码列表, 逗号分隔每个区块, 区块内部用:表示整数闭区间
def generate_number_set(string):
string = re.sub(r"[\n\s]","",string)
string_list = string.split(",")
numbers_list = []
for s in string_list:
if not ":" in s:
numbers_list.append(s.zfill(6))
else:
start,end = s.split(":")
for ind in range(int(start),int(end)+1):
numbers_list.append(str(ind).zfill(6))
return numbers_list
#读取题库json文件并转化为字典
with open(r"../题库0.3/Problems.json","r",encoding = "utf8") as f:
database = f.read()
pro_dict = json.loads(database)
#读取目标数据库json并转化为字典
with open(r"../题库0.3/LessonObj.json","r",encoding = "utf8") as f:
database = f.read()
obj_dict = json.loads(database)
#读取系统日期
current_time = time.localtime()
time_string = "_"+str(current_time.tm_year).zfill(4)+str(current_time.tm_mon).zfill(2)+str(current_time.tm_mday).zfill(2)
#生成目标文件名和目标文件目录
latex_file = destination_file + time_string + ".tex"
d = re.search("/[^/]*$",destination_file).span()[0]
destination_dir = destination_file[:d]
#读取模板
with open(template_file,"r",encoding="utf8") as f:
latex_raw = f.read()
#识别操作系统
if sys.platform != "win32":
latex_raw = re.sub(r"fontset[\s]*=[\s]*none","fontset = fandol",latex_raw)
latex_raw = re.sub(r"\\setCJKmainfont",r"% \\setCJKmainfont",latex_raw)
#预处理
for command in exec_list:
latex_raw = re.sub(command[0],command[1],latex_raw)
data_output = latex_raw
obj_data = ""
for id in obj_dict:
if lessonid in id:
obj_data += "\n\\item %s: %s\n"%(id,obj_dict[id]["content"])
problems_data = []
for plist in problems:
current_data = ""
for id in generate_number_set(plist):
if id in pro_dict:
current_data += "\n\\item (%s) %s\\\\\n来源: %s\\\\\n参考答案: %s\\\\\n关联目标: %s\\\\\n"%(id,pro_dict[id]["content"],pro_dict[id]["origin"],pro_dict[id]["ans"],",".join(pro_dict[id]["objs"]))
problems_data.append(current_data)
data_output = data_output.replace("目标待替换",obj_data)
print("目标生成完毕.")
for i in range(len(problems)):
data_output = data_output.replace("待替换"+str(i+1),problems_data[i])
print("题目生成完毕.")
#保存和编译latex文件
with open(latex_file,"w",encoding = "utf8") as f:
f.write(data_output)
print("开始编译pdf文件: ", latex_file)
os.system("xelatex -interaction=batchmode -output-directory=" + destination_dir + " "+ latex_file)
print(os.system("xelatex -interaction=batchmode -output-directory=" + destination_dir + " "+ latex_file))

View File

@ -114,6 +114,8 @@ def run_command1():
call(["python","分类题号字典生成.py"])
elif selectedtool == "备课草稿生成":
call(["python","备课草稿生成.py"])
elif selectedtool == "备课讨论稿生成":
call(["python","备课讨论稿生成.py"])
LabelTool.config(text = selectedtool+"STEP1命令执行完毕")
button1.place_forget()
@ -189,6 +191,8 @@ BKZMenu.add_command(label = "寻找未赋答案题目", command = lambda: SetBut
BKZMenu.add_command(label = "错题重做来源清点", command = lambda: SetButton("错题重做来源清点",1,["错题重做来源清点.py"]))
BKZMenu.add_separator()
BKZMenu.add_command(label = "备课草稿生成", command = lambda: SetButton("备课草稿生成",1,["备课草稿生成.py"]))
BKZMenu.add_command(label = "备课讨论稿生成", command = lambda: SetButton("备课讨论稿生成",1,["备课讨论稿生成.py"]))
# 设置 目标及标签 菜单项
ObjTagMenu = Menu(menubar, tearoff = False)

View File

@ -0,0 +1,91 @@
\documentclass[10pt,a4paper,twoside]{article}
\usepackage[UTF8, fontset = none, heading = true]{ctex}
\setCJKmainfont[BoldFont=黑体,ItalicFont=楷体]{华文中宋}
\usepackage{amssymb,amsmath,amsfonts,amsthm,mathrsfs,dsfont,graphicx}
\usepackage{ifthen,indentfirst,enumerate,color,lastpage}
\usepackage{tikz}
\usepackage{multicol}
\usepackage{multirow}
\usepackage{makecell}
\usepackage{longtable}
\usepackage{diagbox}
\usepackage[top=1in, bottom=1in,left=0.8in,right=0.8in]{geometry}
\usepackage{fancyhdr}
\fancyhf{}
\rhead{--\ \thepage\ of \pageref{LastPage} \ --}
\pagestyle{fancy}
\ctexset{section={
name={},
number=\chinese{section},
}}
\CTEXsetup[format={\bfseries\raggedright}]{section}
\usetikzlibrary{arrows,calc,intersections,patterns,decorations.pathreplacing,3d,angles,quotes,positioning,shapes.geometric}
\renewcommand{\baselinestretch}{1.5}
\newtheorem{defi}{定义~}
\newtheorem{eg}{例~}
\newtheorem{ex}{~}
\newtheorem{rem}{注~}
\newtheorem{thm}{定理~}
\newtheorem{coro}{推论~}
\newtheorem{axiom}{公理~}
\newtheorem{prop}{性质~}
\newcommand{\blank}[1]{\underline{\hbox to #1pt{}}}
\newcommand{\bracket}[1]{(\hbox to #1pt{})}
\newcommand{\onech}[4]{\par\begin{tabular}{p{.9\linewidth}}
A.~#1\\
B.~#2\\
C.~#3\\
D.~#4
\end{tabular}}
\newcommand{\twoch}[4]{\par\begin{tabular}{p{.46\linewidth}p{.46\linewidth}}
A.~#1& B.~#2\\
C.~#3& D.~#4
\end{tabular}}
\newcommand{\vartwoch}[4]{\par\begin{tabular}{p{.46\linewidth}p{.46\linewidth}}
(1)~#1& (2)~#2\\
(3)~#3& (4)~#4
\end{tabular}}
\newcommand{\fourch}[4]{\par\begin{tabular}{p{.23\linewidth}p{.23\linewidth}p{.23\linewidth}p{.23\linewidth}}
A.~#1 &B.~#2& C.~#3& D.~#4
\end{tabular}}
\newcommand{\varfourch}[4]{\par\begin{tabular}{p{.23\linewidth}p{.23\linewidth}p{.23\linewidth}p{.23\linewidth}}
(1)~#1 &(2)~#2& (3)~#3& (4)~#4
\end{tabular}}
\newcommand{\papername}{标题替换}
\begin{document}
\begin{center}
{\bf\large \papername}\\
\today{}
\end{center}
\section{学习目标}
\begin{enumerate}[1.]
目标待替换
\end{enumerate}
\section{教学流程}
\begin{enumerate}[例1.]
待替换1
\end{enumerate}
\section{课堂练习}
\begin{enumerate}[练习1.]
待替换2
\end{enumerate}
\section{课后作业}
\begin{enumerate}[1.]
待替换3
\end{enumerate}
\section{备注}
\end{document}