From 8d87bda99b5946c375b80b04caf69b4a6a05231b Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Fri, 23 Feb 2024 23:04:02 +0800 Subject: [PATCH] =?UTF-8?q?guipanel=E5=9F=BA=E6=9C=AC=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v2/Ui_题号筛选器.py | 10 +++++- 工具v2/guipanel.py | 78 +++++++++++++++++++++++++++++++++++++---- 工具v2/题号筛选器.ui | 25 ++++++++++++- 3 files changed, 105 insertions(+), 8 deletions(-) diff --git a/工具v2/Ui_题号筛选器.py b/工具v2/Ui_题号筛选器.py index f577ec62..16fb83b0 100644 --- a/工具v2/Ui_题号筛选器.py +++ b/工具v2/Ui_题号筛选器.py @@ -61,6 +61,9 @@ class Ui_Form(object): self.pushButton_exec = QPushButton(Form) self.pushButton_exec.setObjectName(u"pushButton_exec") self.pushButton_exec.setGeometry(QRect(20, 460, 75, 48)) + font = QFont() + font.setBold(True) + self.pushButton_exec.setFont(font) self.pushButton_undo = QPushButton(Form) self.pushButton_undo.setObjectName(u"pushButton_undo") self.pushButton_undo.setGeometry(QRect(20, 370, 75, 24)) @@ -90,9 +93,13 @@ class Ui_Form(object): self.label_3.setGeometry(QRect(120, 440, 91, 16)) self.lcdNumber_resCount = QLCDNumber(Form) self.lcdNumber_resCount.setObjectName(u"lcdNumber_resCount") - self.lcdNumber_resCount.setGeometry(QRect(220, 460, 161, 51)) + self.lcdNumber_resCount.setGeometry(QRect(120, 460, 161, 51)) self.lcdNumber_resCount.setDigitCount(6) self.lcdNumber_resCount.setProperty("value", 0.000000000000000) + self.pushButton_savebuild = QPushButton(Form) + self.pushButton_savebuild.setObjectName(u"pushButton_savebuild") + self.pushButton_savebuild.setGeometry(QRect(300, 440, 81, 71)) + self.pushButton_savebuild.setFont(font) self.retranslateUi(Form) @@ -120,5 +127,6 @@ class Ui_Form(object): self.checkBox_not.setText(QCoreApplication.translate("Form", u"\u9009\u4e2d\u8868\u793a\u4e0d\u5305\u542b", None)) self.label_2.setText(QCoreApplication.translate("Form", u"\u8f93\u5165\u6761\u4ef6, \u7528\",\"\u5206\u9694\u8868\u793a\"\u6216\"", None)) self.label_3.setText(QCoreApplication.translate("Form", u"\u7b5b\u9009\u7ed3\u679c\u6570\u76ee:", None)) + self.pushButton_savebuild.setText(QCoreApplication.translate("Form", u"\u4fdd\u5b58\u548c\u7f16\u8bd1", None)) # retranslateUi diff --git a/工具v2/guipanel.py b/工具v2/guipanel.py index 6ae1011e..f964c7a7 100644 --- a/工具v2/guipanel.py +++ b/工具v2/guipanel.py @@ -1,4 +1,4 @@ -from PySide6.QtWidgets import QWidget, QApplication, QLineEdit, QVBoxLayout +from PySide6.QtWidgets import QWidget, QApplication, QLineEdit from Ui_题号筛选器 import Ui_Form from database_tools import * @@ -7,8 +7,8 @@ class MyWindow(QWidget,Ui_Form): super().__init__() self.setupUi(self) self.conditions = [] - pro_dict = load_dict("../题库0.3/Problems.json") - self.lcdNumber_resCount.display(len(pro_dict)) + self.pro_dict = load_dict("../题库0.3/Problems.json") + self.lcdNumber_resCount.display(len(self.pro_dict)) self.bind() def bind(self): @@ -25,6 +25,8 @@ class MyWindow(QWidget,Ui_Form): self.pushButton_remark.clicked.connect(lambda: self.add_content("remark")) self.pushButton_undo.clicked.connect(self.undolast) self.pushButton_clearAll.clicked.connect(self.clearConditions) + self.pushButton_exec.clicked.connect(self.exec) + self.pushButton_savebuild.clicked.connect(self.build) @@ -43,8 +45,74 @@ class MyWindow(QWidget,Ui_Form): field, flag_not, matchexp = cond text += f"字段 {field} 中{'没有' if flag_not else '有 '}{' 或 '.join([t.strip() for t in matchexp.split(',')])}\n" self.label_conditions.setText(text) + def exec(self): + self.matchlist = [] + self.conditions.append(("content",True,"OBSOLETE")) + for id in self.pro_dict: + if MatchCondition2014(self.pro_dict[id],self.conditions): + self.matchlist.append(id) + self.conditions = self.conditions[:-1].copy() + self.lcdNumber_resCount.display(len(self.matchlist)) - + def build(self): + exp = generate_exp(self.matchlist) + SaveTextFile(exp,"临时文件/题号筛选.txt") + prodictpath = "../题库0.3/problems.json" + objdictpath = "../题库0.3/lessonobj.json" + raw_pro_dict = load_dict(prodictpath) + configjson = { + "pdf标题": "筛选题目编译", + "教师版": True, + "字段显示设置": { + "题后空间": True, + "课时目标": True, + "题目标签": True, + "答案": True, + "解答与提示": True, + "使用记录": [3,-1], + "使用记录说明": "[a,b]表示显示最好的a个和最差b个, 有-2表示不显示, 无-2但有-1表示全部显示", + "来源": True, + "备注": True, + "届别": [] + } + } + + grades = configjson["字段显示设置"]["届别"] + pro_dict = select_grade_from_pro_dict(raw_pro_dict,grades) + obj_dict = load_dict(objdictpath) + + notetitle = configjson["pdf标题"] + outputdir = "临时文件" #输出文件的目录 + outputfilepath = os.path.join(outputdir,notetitle+".tex") + print("输出文件目录: %s\n输出文件名: %s"%(os.path.join(os.getcwd(),outputdir),notetitle+".tex")) + + latex_raw = ReadTextFile("模板文件/讲义模板.txt") + if configjson["教师版"] == True: + latex_raw = latex_raw.replace(r"学号\blank{50} \ 姓名\blank{80}","上海市控江中学") + + if sys.platform != "win32": #非win系统用默认字体 + latex_raw = re.sub(r"fontset[\s]*=[\s]*none","fontset = fandol",latex_raw) + latex_raw = re.sub(r"\\setCJKmainfont",r"% \\setCJKmainfont",latex_raw) + starttime = time.time() + bodystring = "\\begin{enumerate}\n\n" + for id in generate_number_set(exp): + bodystring += generateLaTeXBodyContent(id,pro_dict,obj_dict,configjson) + bodystring += "\\end{enumerate}\n\n" + + midtime = time.time() + print(f"生成LaTeX文件所花时间: {midtime-starttime:.3f}秒") + + latex_data = StringSubstitute(r"<<[\s\S]*?待替换[\s\S]*?>>",latex_raw,(notetitle,bodystring)) #替换标题和bodystring + SaveTextFile(latex_data,outputfilepath) #保存.tex文件 + + if XeLaTeXCompile(outputdir,notetitle+".tex"): + print("编译成功") + else: + print("编译失败") + + endtime = time.time() + print(f"生成pdf文件所花时间: {endtime-midtime:.3f}秒") + if __name__ == '__main__': @@ -53,5 +121,3 @@ if __name__ == '__main__': windows.show() app.exec() - -#self.conditions.append(("content",True,"OBSOLETE")) \ No newline at end of file diff --git a/工具v2/题号筛选器.ui b/工具v2/题号筛选器.ui index 26bfda96..226969e0 100644 --- a/工具v2/题号筛选器.ui +++ b/工具v2/题号筛选器.ui @@ -168,6 +168,11 @@ 48 + + + true + + 运行 @@ -285,7 +290,7 @@ - 220 + 120 460 161 51 @@ -298,6 +303,24 @@ 0.000000000000000 + + + + 300 + 440 + 81 + 71 + + + + + true + + + + 保存和编译 + +