from PySide6.QtWidgets import QWidget, QApplication, QLineEdit from Ui_题号筛选器 import Ui_Form from database_tools import * import time,os class MyWindow(QWidget,Ui_Form): def __init__(self): super().__init__() self.setupUi(self) self.conditions = [] self.pro_dict = load_dict("../题库0.3/Problems.json") self.lcdNumber_resCount.display(len(self.pro_dict)) self.bind() def bind(self): self.pushButton_content.clicked.connect(lambda: self.add_content("content")) self.pushButton_obj.clicked.connect(lambda: self.add_content("objs")) self.pushButton_tag.clicked.connect(lambda: self.add_content("tags")) self.pushButton_usage.clicked.connect(lambda: self.add_content("usages")) self.pushButton_origin.clicked.connect(lambda: self.add_content("origin")) self.pushButton_genre.clicked.connect(lambda: self.add_content("genre")) self.pushButton_ans.clicked.connect(lambda: self.add_content("ans")) self.pushButton_solution.clicked.connect(lambda: self.add_content("solution")) self.pushButton_same.clicked.connect(lambda: self.add_content("same")) self.pushButton_related.clicked.connect(lambda: self.add_content("related")) 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) def add_content(self,field): self.conditions.append((field,self.checkBox_not.isChecked(),self.lineEdit_SingleCondition.text())) self.showConditions() def undolast(self): self.conditions = self.conditions[:-1].copy() self.showConditions() def clearConditions(self): self.conditions = [] self.showConditions() def showConditions(self): text = "" for cond in self.conditions: 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) try: AppendTextFile(f"\n{time.ctime()}\n{exp}\n","临时文件/题号筛选.txt") except: SaveTextFile(f"{time.ctime()}\n{exp}\n","临时文件/题号筛选.txt") prodictpath = "../题库0.3/Problems.json" objdictpath = "../题库0.3/LessonObj.json" raw_pro_dict = load_dict(prodictpath) configjson_detailed = { "pdf标题": "筛选题目编译", "教师版": True, "字段显示设置": { "题后空间": True, "课时目标": True, "题目标签": True, "答案": True, "解答与提示": True, "使用记录": [3,-1], "使用记录说明": "[a,b]表示显示最好的a个和最差b个, 有-2表示不显示, 无-2但有-1表示全部显示", "来源": True, "备注": True, "届别": [] } } configjson_simple = { "pdf标题": "筛选题目编译", "教师版": False, "字段显示设置": { "题后空间": True, "课时目标": True, "题目标签": True, "答案": True, "解答与提示": True, "使用记录": [3,-1], "使用记录说明": "[a,b]表示显示最好的a个和最差b个, 有-2表示不显示, 无-2但有-1表示全部显示", "来源": True, "备注": True, "届别": [] } } if self.checkBox_Detailed.isChecked(): configjson = configjson_detailed else: configjson = configjson_simple 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}秒") os.system("code 临时文件/题号筛选.txt") os.startfile("临时文件") if __name__ == '__main__': app = QApplication([]) windows = MyWindow() windows.show() app.exec()