From 5a4f00c243f6652aeb8cb311c3e1694d1c76f7fb Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Thu, 29 Feb 2024 22:49:53 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B3=BB=E5=88=97=E8=AE=B2=E4=B9=89=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=8A=9F=E8=83=BD=E5=B7=B2=E7=94=A8qt=E9=9D=A2?= =?UTF-8?q?=E6=9D=BF=E9=87=8D=E5=86=99,=20=E5=B9=B6=E5=8A=A0=E5=85=A5?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E9=9D=A2=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v2/Qt基础框架.py | 4 +- 工具v2/Ui_系列讲义生成.py | 229 +++++++++++++++++++++++++++ 工具v2/工具面板.py | 2 +- 工具v2/系列讲义生成.py | 198 +++++++++++++++++------ 工具v2/系列讲义生成.ui | 322 ++++++++++++++++++++++++++++++++++++++ 工具v2/系列讲义生成old.py | 60 +++++++ 6 files changed, 761 insertions(+), 54 deletions(-) create mode 100644 工具v2/Ui_系列讲义生成.py create mode 100644 工具v2/系列讲义生成.ui create mode 100644 工具v2/系列讲义生成old.py diff --git a/工具v2/Qt基础框架.py b/工具v2/Qt基础框架.py index 671c9597..40164b13 100644 --- a/工具v2/Qt基础框架.py +++ b/工具v2/Qt基础框架.py @@ -1,8 +1,8 @@ from PySide6.QtWidgets import QWidget, QApplication, QFileDialog -import Ui_寻找空闲题号 +import Ui_test -class MyWindow(QWidget,Ui_寻找空闲题号.Ui_Form): +class MyWindow(QWidget,Ui_test.Ui_Form): def __init__(self): super().__init__() self.setupUi(self) diff --git a/工具v2/Ui_系列讲义生成.py b/工具v2/Ui_系列讲义生成.py new file mode 100644 index 00000000..56e670ec --- /dev/null +++ b/工具v2/Ui_系列讲义生成.py @@ -0,0 +1,229 @@ +# -*- coding: utf-8 -*- + +################################################################################ +## Form generated from reading UI file '系列讲义生成.ui' +## +## Created by: Qt User Interface Compiler version 6.6.2 +## +## WARNING! All changes made in this file will be lost when recompiling UI file! +################################################################################ + +from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, + QMetaObject, QObject, QPoint, QRect, + QSize, QTime, QUrl, Qt) +from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, + QFont, QFontDatabase, QGradient, QIcon, + QImage, QKeySequence, QLinearGradient, QPainter, + QPalette, QPixmap, QRadialGradient, QTransform) +from PySide6.QtWidgets import (QApplication, QCheckBox, QHBoxLayout, QLabel, + QLineEdit, QPushButton, QRadioButton, QSizePolicy, + QVBoxLayout, QWidget) + +class Ui_Form(object): + def setupUi(self, Form): + if not Form.objectName(): + Form.setObjectName(u"Form") + Form.resize(511, 394) + self.lineEdit_regex = QLineEdit(Form) + self.lineEdit_regex.setObjectName(u"lineEdit_regex") + self.lineEdit_regex.setGeometry(QRect(100, 20, 231, 20)) + self.label = QLabel(Form) + self.label.setObjectName(u"label") + self.label.setGeometry(QRect(10, 20, 91, 16)) + self.label_2 = QLabel(Form) + self.label_2.setObjectName(u"label_2") + self.label_2.setGeometry(QRect(340, 20, 171, 16)) + self.pushButton_exec = QPushButton(Form) + self.pushButton_exec.setObjectName(u"pushButton_exec") + self.pushButton_exec.setGeometry(QRect(280, 250, 221, 131)) + font = QFont() + font.setBold(True) + self.pushButton_exec.setFont(font) + self.label_3 = QLabel(Form) + self.label_3.setObjectName(u"label_3") + self.label_3.setGeometry(QRect(10, 50, 61, 16)) + self.lineEdit_path = QLineEdit(Form) + self.lineEdit_path.setObjectName(u"lineEdit_path") + self.lineEdit_path.setGeometry(QRect(10, 70, 491, 20)) + self.pushButton_SelectPath = QPushButton(Form) + self.pushButton_SelectPath.setObjectName(u"pushButton_SelectPath") + self.pushButton_SelectPath.setGeometry(QRect(430, 40, 75, 24)) + self.verticalLayoutWidget = QWidget(Form) + self.verticalLayoutWidget.setObjectName(u"verticalLayoutWidget") + self.verticalLayoutWidget.setGeometry(QRect(10, 110, 81, 111)) + self.verticalLayout = QVBoxLayout(self.verticalLayoutWidget) + self.verticalLayout.setObjectName(u"verticalLayout") + self.verticalLayout.setContentsMargins(0, 0, 0, 0) + self.label_4 = QLabel(self.verticalLayoutWidget) + self.label_4.setObjectName(u"label_4") + self.label_4.setAlignment(Qt.AlignLeading|Qt.AlignLeft|Qt.AlignVCenter) + + self.verticalLayout.addWidget(self.label_4) + + self.radioButton_student = QRadioButton(self.verticalLayoutWidget) + self.radioButton_student.setObjectName(u"radioButton_student") + self.radioButton_student.setChecked(True) + + self.verticalLayout.addWidget(self.radioButton_student) + + self.radioButton_teacher = QRadioButton(self.verticalLayoutWidget) + self.radioButton_teacher.setObjectName(u"radioButton_teacher") + + self.verticalLayout.addWidget(self.radioButton_teacher) + + self.verticalLayoutWidget_2 = QWidget(Form) + self.verticalLayoutWidget_2.setObjectName(u"verticalLayoutWidget_2") + self.verticalLayoutWidget_2.setGeometry(QRect(110, 110, 151, 271)) + self.verticalLayout_2 = QVBoxLayout(self.verticalLayoutWidget_2) + self.verticalLayout_2.setObjectName(u"verticalLayout_2") + self.verticalLayout_2.setContentsMargins(0, 0, 0, 0) + self.label_5 = QLabel(self.verticalLayoutWidget_2) + self.label_5.setObjectName(u"label_5") + + self.verticalLayout_2.addWidget(self.label_5) + + self.checkBox_space = QCheckBox(self.verticalLayoutWidget_2) + self.checkBox_space.setObjectName(u"checkBox_space") + + self.verticalLayout_2.addWidget(self.checkBox_space) + + self.checkBox_ans = QCheckBox(self.verticalLayoutWidget_2) + self.checkBox_ans.setObjectName(u"checkBox_ans") + + self.verticalLayout_2.addWidget(self.checkBox_ans) + + self.checkBox_objs = QCheckBox(self.verticalLayoutWidget_2) + self.checkBox_objs.setObjectName(u"checkBox_objs") + self.checkBox_objs.setCheckable(True) + self.checkBox_objs.setTristate(False) + + self.verticalLayout_2.addWidget(self.checkBox_objs) + + self.checkBox_tags = QCheckBox(self.verticalLayoutWidget_2) + self.checkBox_tags.setObjectName(u"checkBox_tags") + + self.verticalLayout_2.addWidget(self.checkBox_tags) + + self.checkBox_solution = QCheckBox(self.verticalLayoutWidget_2) + self.checkBox_solution.setObjectName(u"checkBox_solution") + + self.verticalLayout_2.addWidget(self.checkBox_solution) + + self.checkBox_usages = QCheckBox(self.verticalLayoutWidget_2) + self.checkBox_usages.setObjectName(u"checkBox_usages") + + self.verticalLayout_2.addWidget(self.checkBox_usages) + + self.checkBox_origin = QCheckBox(self.verticalLayoutWidget_2) + self.checkBox_origin.setObjectName(u"checkBox_origin") + + self.verticalLayout_2.addWidget(self.checkBox_origin) + + self.checkBox_remark = QCheckBox(self.verticalLayoutWidget_2) + self.checkBox_remark.setObjectName(u"checkBox_remark") + + self.verticalLayout_2.addWidget(self.checkBox_remark) + + self.verticalLayoutWidget_3 = QWidget(Form) + self.verticalLayoutWidget_3.setObjectName(u"verticalLayoutWidget_3") + self.verticalLayoutWidget_3.setGeometry(QRect(280, 110, 222, 121)) + self.verticalLayout_usagepanel = QVBoxLayout(self.verticalLayoutWidget_3) + self.verticalLayout_usagepanel.setObjectName(u"verticalLayout_usagepanel") + self.verticalLayout_usagepanel.setContentsMargins(0, 0, 0, 0) + self.label_6 = QLabel(self.verticalLayoutWidget_3) + self.label_6.setObjectName(u"label_6") + + self.verticalLayout_usagepanel.addWidget(self.label_6) + + self.horizontalLayout = QHBoxLayout() + self.horizontalLayout.setObjectName(u"horizontalLayout") + self.label_9 = QLabel(self.verticalLayoutWidget_3) + self.label_9.setObjectName(u"label_9") + + self.horizontalLayout.addWidget(self.label_9) + + self.lineEdit_high = QLineEdit(self.verticalLayoutWidget_3) + self.lineEdit_high.setObjectName(u"lineEdit_high") + self.lineEdit_high.setEnabled(True) + + self.horizontalLayout.addWidget(self.lineEdit_high) + + self.label_10 = QLabel(self.verticalLayoutWidget_3) + self.label_10.setObjectName(u"label_10") + + self.horizontalLayout.addWidget(self.label_10) + + self.lineEdit_low = QLineEdit(self.verticalLayoutWidget_3) + self.lineEdit_low.setObjectName(u"lineEdit_low") + + self.horizontalLayout.addWidget(self.lineEdit_low) + + + self.verticalLayout_usagepanel.addLayout(self.horizontalLayout) + + self.label_7 = QLabel(self.verticalLayoutWidget_3) + self.label_7.setObjectName(u"label_7") + + self.verticalLayout_usagepanel.addWidget(self.label_7) + + self.lineEdit_grades = QLineEdit(self.verticalLayoutWidget_3) + self.lineEdit_grades.setObjectName(u"lineEdit_grades") + + self.verticalLayout_usagepanel.addWidget(self.lineEdit_grades) + + self.verticalLayoutWidget_4 = QWidget(Form) + self.verticalLayoutWidget_4.setObjectName(u"verticalLayoutWidget_4") + self.verticalLayoutWidget_4.setGeometry(QRect(10, 240, 81, 141)) + self.verticalLayout_3 = QVBoxLayout(self.verticalLayoutWidget_4) + self.verticalLayout_3.setObjectName(u"verticalLayout_3") + self.verticalLayout_3.setContentsMargins(0, 0, 0, 0) + self.label_8 = QLabel(self.verticalLayoutWidget_4) + self.label_8.setObjectName(u"label_8") + + self.verticalLayout_3.addWidget(self.label_8) + + self.checkBox_singlenote = QCheckBox(self.verticalLayoutWidget_4) + self.checkBox_singlenote.setObjectName(u"checkBox_singlenote") + + self.verticalLayout_3.addWidget(self.checkBox_singlenote) + + self.checkBox_seriesnote = QCheckBox(self.verticalLayoutWidget_4) + self.checkBox_seriesnote.setObjectName(u"checkBox_seriesnote") + self.checkBox_seriesnote.setChecked(True) + + self.verticalLayout_3.addWidget(self.checkBox_seriesnote) + + + self.retranslateUi(Form) + + QMetaObject.connectSlotsByName(Form) + # setupUi + + def retranslateUi(self, Form): + Form.setWindowTitle(QCoreApplication.translate("Form", u"\u7cfb\u5217\u8bb2\u4e49\u751f\u6210", None)) + self.label.setText(QCoreApplication.translate("Form", u"\u8bb2\u4e49\u7f16\u53f7\u8868\u8fbe\u5f0f", None)) + self.label_2.setText(QCoreApplication.translate("Form", u"\u7528 \",\" \u5206\u9694\u7684\u4e00\u7cfb\u5217\u6b63\u5219\u8868\u8fbe\u5f0f", None)) + self.pushButton_exec.setText(QCoreApplication.translate("Form", u"\u5f00\u59cb\u751f\u6210\u4e0e\u7f16\u8bd1", None)) + self.label_3.setText(QCoreApplication.translate("Form", u"\u6587\u4ef6\u8def\u5f84", None)) + self.pushButton_SelectPath.setText(QCoreApplication.translate("Form", u"\u9009\u62e9\u8def\u5f84", None)) + self.label_4.setText(QCoreApplication.translate("Form", u"\u7248\u5f0f\u9009\u62e9", None)) + self.radioButton_student.setText(QCoreApplication.translate("Form", u"\u5b66\u751f\u7248", None)) + self.radioButton_teacher.setText(QCoreApplication.translate("Form", u"\u6559\u5e08\u7248", None)) + self.label_5.setText(QCoreApplication.translate("Form", u"\u5185\u5bb9\u9009\u9879", None)) + self.checkBox_space.setText(QCoreApplication.translate("Form", u"\u9898\u540e\u7a7a\u95f4", None)) + self.checkBox_ans.setText(QCoreApplication.translate("Form", u"\u7b54\u6848", None)) + self.checkBox_objs.setText(QCoreApplication.translate("Form", u"\u8bfe\u65f6\u76ee\u6807", None)) + self.checkBox_tags.setText(QCoreApplication.translate("Form", u"\u9898\u76ee\u6807\u7b7e", None)) + self.checkBox_solution.setText(QCoreApplication.translate("Form", u"\u89e3\u7b54\u4e0e\u63d0\u793a", None)) + self.checkBox_usages.setText(QCoreApplication.translate("Form", u"\u4f7f\u7528\u8bb0\u5f55", None)) + self.checkBox_origin.setText(QCoreApplication.translate("Form", u"\u6765\u6e90", None)) + self.checkBox_remark.setText(QCoreApplication.translate("Form", u"\u5907\u6ce8", None)) + self.label_6.setText(QCoreApplication.translate("Form", u"\u4f7f\u7528\u8bb0\u5f55\u9009\u62e9(\u90fd\u7559\u7a7a\u4e3a\u5168\u663e\u793a)", None)) + self.label_9.setText(QCoreApplication.translate("Form", u"\u9ad8", None)) + self.label_10.setText(QCoreApplication.translate("Form", u"\u4f4e", None)) + self.label_7.setText(QCoreApplication.translate("Form", u"\u5c4a\u522b\u9009\u62e9(\u7528 \",\" \u5206\u9694, \u7559\u7a7a\u4e3a\u5168\u663e\u793a)", None)) + self.label_8.setText(QCoreApplication.translate("Form", u"\u7f16\u8bd1\u9009\u9879", None)) + self.checkBox_singlenote.setText(QCoreApplication.translate("Form", u"\u5355\u5f20\u7f16\u8bd1", None)) + self.checkBox_seriesnote.setText(QCoreApplication.translate("Form", u"\u5408\u96c6\u7f16\u8bd1", None)) + # retranslateUi + diff --git a/工具v2/工具面板.py b/工具v2/工具面板.py index ee54b05d..ad550da1 100644 --- a/工具v2/工具面板.py +++ b/工具v2/工具面板.py @@ -135,7 +135,7 @@ BKMenu.add_command(label = "讲义结构编号录入", command = lambda: SetButt BKMenu.add_command(label = "在.tex或.pdf文件中获取题号", command = lambda: SetButton("在.tex或.pdf文件中获取题号",["在.tex或.pdf文件中获取题号.py"])) 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_command(label = "系列讲义生成", command = lambda: SetButton("系列讲义生成",[])) BKMenu.add_separator() BKMenu.add_command(label = "添加基础知识梳理", command = lambda: SetButton("添加基础知识梳理",["添加基础知识梳理.py"])) # BKMenu.add_command(label = "题号清单生成", command = lambda: SetButton("题号清单生成",1,["题号清单生成.py"])) diff --git a/工具v2/系列讲义生成.py b/工具v2/系列讲义生成.py index 949a807b..05104e6b 100644 --- a/工具v2/系列讲义生成.py +++ b/工具v2/系列讲义生成.py @@ -1,60 +1,156 @@ -# lessonpattern = r"U20240501" # 正则表达式, 数据库中讲义的编号([A-Z][0-9]{4}[(01)|(02)][[0-9]{2}), 字母表示类型, 四位数字表示届别, 2位数字表示学期及其他, 2位数字表示序号 -# outputdir = "d:/temp/26届材料" # 输出文件夹, 不建议修改 -# answered = True # 设置是否编译答案 - +from PySide6.QtWidgets import QWidget, QApplication, QFileDialog +from Ui_系列讲义生成 import Ui_Form from database_tools import * +import os -configjson = load_dict("文本文件/config.json")["系列讲义生成.py"] +class MyWindow(QWidget,Ui_Form): + def __init__(self): + super().__init__() + self.setupUi(self) + self.bind() -lessonpattern = configjson["讲义标题格式"] # 正则表达式, 数据库中讲义的编号([A-Z][0-9]{4}[(01)|(02)][[0-9]{2}), 字母表示类型, 四位数字表示届别, 2位数字表示学期及其他, 2位数字表示序号 -outputdir = configjson["输出路径"] # 输出文件夹, 不建议修改 -# answered = configjson["提供答案"] # 设置是否编译答案 + 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.pushButton_exec.clicked.connect(self.saveandbuild) + self.pushButton_SelectPath.clicked.connect(self.selectpath) + - -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") -grades = configjson["字段显示设置"]["届别"] -pro_dict = select_grade_from_pro_dict(raw_pro_dict,grades) - - -dictionaries = {} #合并字典 -for t in (obj_dict,basicknowledge_dict,pro_dict): - dictionaries.update(t) - -papernames = [] -multitexdata = [] - -for notes_dict in jsondicts: - for lessonid in notes_dict["notes"]: - if re.findall(lessonpattern,lessonid) != []: - 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(outputdir,filename),misc=configjson,consecutivenumbering = consecutivenumbering) - # texdata = GenerateSingleLessonNote(id = lessonid,notesdict = notes_dict, metadict = dictionaries, templatepath = ".\模板文件\讲义模板.txt", outputfilepath = os.path.join(outputdir,filename),consecutivenumbering=consecutivenumbering,answered=answered) - 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]) - + + 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) -merged = "" -for i in range(len(papernames)): - merged += "\n\n\\chapter{"+papernames[i]+"}\n\n\n" - merged += multitexdata[i] + 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"))) -mergedtext = StringSubstitute(r"<<待替换[\d]+>>",ReadTextFile("./模板文件/合集模板.txt"),[merged]) -SaveTextFile(mergedtext,os.path.join(outputdir,f"合集{GetDate()}.tex")) + 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] -if not "编译合集" in configjson or configjson["编译合集"] == False: - tocompile = input("需要编译合集吗?(Y/[N]):") -if configjson["编译合集"] == True or tocompile[0].upper() == "Y": - XeLaTeXCompile(outputdir,f"合集{GetDate()}.tex") + 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") + + + + + + + + + +if __name__ == '__main__': + app = QApplication([]) + windows = MyWindow() + windows.show() + app.exec() diff --git a/工具v2/系列讲义生成.ui b/工具v2/系列讲义生成.ui new file mode 100644 index 00000000..0818d459 --- /dev/null +++ b/工具v2/系列讲义生成.ui @@ -0,0 +1,322 @@ + + + Form + + + + 0 + 0 + 511 + 394 + + + + 系列讲义生成 + + + + + 100 + 20 + 231 + 20 + + + + + + + 10 + 20 + 91 + 16 + + + + 讲义编号表达式 + + + + + + 340 + 20 + 171 + 16 + + + + 用 "," 分隔的一系列正则表达式 + + + + + + 280 + 250 + 221 + 131 + + + + + true + + + + 开始生成与编译 + + + + + + 10 + 50 + 61 + 16 + + + + 文件路径 + + + + + + 10 + 70 + 491 + 20 + + + + + + + 430 + 40 + 75 + 24 + + + + 选择路径 + + + + + + 10 + 110 + 81 + 111 + + + + + + + 版式选择 + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + 学生版 + + + true + + + + + + + 教师版 + + + + + + + + + 110 + 110 + 151 + 271 + + + + + + + 内容选项 + + + + + + + 题后空间 + + + + + + + 答案 + + + + + + + 课时目标 + + + true + + + false + + + + + + + 题目标签 + + + + + + + 解答与提示 + + + + + + + 使用记录 + + + + + + + 来源 + + + + + + + 备注 + + + + + + + + + 280 + 110 + 222 + 121 + + + + + + + 使用记录选择(都留空为全显示) + + + + + + + + + + + + + + + + true + + + + + + + + + + + + + + + + + + + 届别选择(用 "," 分隔, 留空为全显示) + + + + + + + + + + + + 10 + 240 + 81 + 141 + + + + + + + 编译选项 + + + + + + + 单张编译 + + + + + + + 合集编译 + + + true + + + + + + + + + diff --git a/工具v2/系列讲义生成old.py b/工具v2/系列讲义生成old.py new file mode 100644 index 00000000..949a807b --- /dev/null +++ b/工具v2/系列讲义生成old.py @@ -0,0 +1,60 @@ +# lessonpattern = r"U20240501" # 正则表达式, 数据库中讲义的编号([A-Z][0-9]{4}[(01)|(02)][[0-9]{2}), 字母表示类型, 四位数字表示届别, 2位数字表示学期及其他, 2位数字表示序号 +# outputdir = "d:/temp/26届材料" # 输出文件夹, 不建议修改 +# answered = True # 设置是否编译答案 + +from database_tools import * + +configjson = load_dict("文本文件/config.json")["系列讲义生成.py"] + +lessonpattern = configjson["讲义标题格式"] # 正则表达式, 数据库中讲义的编号([A-Z][0-9]{4}[(01)|(02)][[0-9]{2}), 字母表示类型, 四位数字表示届别, 2位数字表示学期及其他, 2位数字表示序号 +outputdir = configjson["输出路径"] # 输出文件夹, 不建议修改 +# answered = configjson["提供答案"] # 设置是否编译答案 + + +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") +grades = configjson["字段显示设置"]["届别"] +pro_dict = select_grade_from_pro_dict(raw_pro_dict,grades) + + +dictionaries = {} #合并字典 +for t in (obj_dict,basicknowledge_dict,pro_dict): + dictionaries.update(t) + +papernames = [] +multitexdata = [] + +for notes_dict in jsondicts: + for lessonid in notes_dict["notes"]: + if re.findall(lessonpattern,lessonid) != []: + 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(outputdir,filename),misc=configjson,consecutivenumbering = consecutivenumbering) + # texdata = GenerateSingleLessonNote(id = lessonid,notesdict = notes_dict, metadict = dictionaries, templatepath = ".\模板文件\讲义模板.txt", outputfilepath = os.path.join(outputdir,filename),consecutivenumbering=consecutivenumbering,answered=answered) + 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]) + + +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(outputdir,f"合集{GetDate()}.tex")) + +if not "编译合集" in configjson or configjson["编译合集"] == False: + tocompile = input("需要编译合集吗?(Y/[N]):") +if configjson["编译合集"] == True or tocompile[0].upper() == "Y": + XeLaTeXCompile(outputdir,f"合集{GetDate()}.tex") +