158 lines
7.1 KiB
Python
158 lines
7.1 KiB
Python
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
|
|
from Ui_系列讲义生成 import Ui_Form
|
|
from database_tools import *
|
|
import os
|
|
|
|
class MyWindow(QWidget,Ui_Form):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.setupUi(self)
|
|
self.bind()
|
|
|
|
def bind(self):
|
|
self.outputpath = os.path.join(os.getcwd(),"临时文件")
|
|
self.lineEdit_path.setText(self.outputpath)
|
|
self.TeachersCheckBoxList = [self.checkBox_ans,self.checkBox_objs,self.checkBox_tags,self.checkBox_solution,self.checkBox_usages,self.checkBox_origin,self.checkBox_remark]
|
|
self.StudentsCheckBoxList = [self.checkBox_space,self.checkBox_ans]
|
|
self.ContnetCheckBoxList = [self.checkBox_ans,self.checkBox_objs,self.checkBox_tags,self.checkBox_solution,self.checkBox_usages,self.checkBox_origin,self.checkBox_remark,self.checkBox_space]
|
|
for widget in self.ContnetCheckBoxList:
|
|
widget.setDisabled(True)
|
|
self.studentlayout()
|
|
self.disableusagessetting()
|
|
self.radioButton_teacher.clicked.connect(self.teacherlayout)
|
|
self.radioButton_student.clicked.connect(self.studentlayout)
|
|
self.checkBox_usages.clicked.connect(self.toggleusagessetting)
|
|
self.radioButton_student.clicked.connect(self.toggleusagessetting)
|
|
self.radioButton_teacher.clicked.connect(self.toggleusagessetting)
|
|
self.pushButton_exec.clicked.connect(self.saveandbuild)
|
|
self.pushButton_SelectPath.clicked.connect(self.selectpath)
|
|
|
|
|
|
|
|
def disableusagessetting(self):
|
|
self.lineEdit_high.setDisabled(True)
|
|
self.lineEdit_low.setDisabled(True)
|
|
self.lineEdit_grades.setDisabled(True)
|
|
def enableusagessetting(self):
|
|
self.lineEdit_high.setEnabled(True)
|
|
self.lineEdit_low.setEnabled(True)
|
|
self.lineEdit_grades.setEnabled(True)
|
|
def toggleusagessetting(self):
|
|
if self.checkBox_usages.isChecked() and self.radioButton_teacher.isChecked():
|
|
self.enableusagessetting()
|
|
else:
|
|
self.disableusagessetting()
|
|
|
|
def studentlayout(self):
|
|
for widget in self.TeachersCheckBoxList:
|
|
widget.setDisabled(True)
|
|
for widget in self.StudentsCheckBoxList:
|
|
widget.setEnabled(True)
|
|
|
|
def selectpath(self):
|
|
self.outputpath = QFileDialog.getExistingDirectory(None, "选择文件夹")
|
|
self.lineEdit_path.setText(self.outputpath)
|
|
|
|
def teacherlayout(self):
|
|
for widget in self.StudentsCheckBoxList:
|
|
widget.setDisabled(True)
|
|
for widget in self.TeachersCheckBoxList:
|
|
widget.setEnabled(True)
|
|
def generate_usages(self):
|
|
high = self.lineEdit_high.text().strip()
|
|
low = self.lineEdit_low.text().strip()
|
|
if self.checkBox_usages.isChecked() == False:
|
|
return [-2,-2]
|
|
elif self.checkBox_usages.isChecked() and high == "" and low == "":
|
|
return [-1,-1]
|
|
else:
|
|
if high == "":
|
|
high = "0"
|
|
if low == "":
|
|
low = "0"
|
|
return [int(high),int(low)]
|
|
|
|
def saveandbuild(self):
|
|
patterns = self.lineEdit_regex.text().strip().split(",")
|
|
jsonpath = "../备课组" #有json文件的根目录, 文件名需为"校本材料.json"
|
|
jsondicts = []
|
|
for loc,dirs,files in os.walk(jsonpath):
|
|
if "校本材料.json" in files:
|
|
jsondicts.append(load_dict(os.path.join(loc,"校本材料.json")))
|
|
|
|
|
|
raw_pro_dict = load_dict("../题库0.3/Problems.json")
|
|
obj_dict = load_dict("../题库0.3/LessonObj.json")
|
|
basicknowledge_dict = load_dict("../题库0.3/BasicKnowledge.json")
|
|
if self.radioButton_teacher.isChecked() and self.checkBox_usages.isChecked() and not self.lineEdit_grades.text().strip() == "":
|
|
grades = self.lineEdit_grades.text().strip().split(",")
|
|
else:
|
|
grades = []
|
|
pro_dict = select_grade_from_pro_dict(raw_pro_dict,grades)
|
|
# dictionaries = {} #合并字典
|
|
# for t in (obj_dict,basicknowledge_dict,pro_dict):
|
|
# dictionaries.update(t)
|
|
configjson = {
|
|
"教师版": self.radioButton_teacher.isChecked(),
|
|
"字段显示设置": {
|
|
"题后空间": self.checkBox_space.isChecked(),
|
|
"课时目标": self.checkBox_objs.isChecked(),
|
|
"题目标签": self.checkBox_tags.isChecked(),
|
|
"答案": self.checkBox_ans.isChecked(),
|
|
"解答与提示": self.checkBox_solution.isChecked(),
|
|
"使用记录": self.generate_usages(),
|
|
"来源": self.checkBox_origin.isChecked(),
|
|
"备注": self.checkBox_remark.isChecked(),
|
|
"届别": grades
|
|
},
|
|
"编译单个文件": self.checkBox_singlenote.isChecked(),
|
|
"编译合集": self.checkBox_seriesnote.isChecked()
|
|
}
|
|
papernames = []
|
|
multitexdata = []
|
|
for notes_dict in jsondicts:
|
|
for lessonid in notes_dict["notes"]:
|
|
coincideflag = False
|
|
for lessonpattern in patterns:
|
|
if re.findall(lessonpattern,lessonid) != []:
|
|
coincideflag = True
|
|
break
|
|
if coincideflag:
|
|
filename = notes_dict["notes"][lessonid]["id"]+notes_dict["notes"][lessonid]["filename"]+".tex"
|
|
papertype = lessonid[0]
|
|
consecutivenumbering = notes_dict["structures"][papertype]["consecutivenumbering"]
|
|
texdata = GenerateSingleLessonNote2024(id = lessonid,notesdict=notes_dict,pro_dict=pro_dict,obj_dict=obj_dict,bk_dict=basicknowledge_dict,templatepath=".\模板文件\讲义模板.txt",outputfilepath = os.path.join(self.outputpath,filename),misc=configjson,consecutivenumbering = consecutivenumbering)
|
|
papernames.append(notes_dict["notes"][lessonid]["id"]+" \\ "+notes_dict["notes"][lessonid]["name"])
|
|
multitexdata.append(re.findall(r"\\begin{center}\n{\\bf\\large \\papername}\n\\end{center}([\s\S]*\\end\{enumerate\})",texdata)[0])
|
|
# print(lessonid)
|
|
# print(configjson)
|
|
# print("\n".join(patterns))
|
|
merged = ""
|
|
for i in range(len(papernames)):
|
|
merged += "\n\n\\chapter{"+papernames[i]+"}\n\n\n"
|
|
merged += multitexdata[i]
|
|
|
|
mergedtext = StringSubstitute(r"<<待替换[\d]+>>",ReadTextFile("./模板文件/合集模板.txt"),[merged])
|
|
|
|
SaveTextFile(mergedtext,os.path.join(self.outputpath,f"合集{GetDate()}.tex"))
|
|
|
|
if not "编译合集" in configjson or configjson["编译合集"] == False:
|
|
tocompile = input("需要编译合集吗?(Y/[N]):")
|
|
if configjson["编译合集"] == True or tocompile[0].upper() == "Y":
|
|
XeLaTeXCompile(self.outputpath,f"合集{GetDate()}.tex")
|
|
os.startfile(self.outputpath)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app = QApplication([])
|
|
windows = MyWindow()
|
|
windows.show()
|
|
app.exec()
|
|
|