from PySide6.QtWidgets import QWidget, QApplication, QFileDialog from Ui_添加关联题目 import Ui_Form from database_tools_2 import * class MyWindow_tjgl(QWidget,Ui_Form): def __init__(self,database_name): super().__init__() self.database_name = database_name self.setupUi(self) self.bind() def setdbname(self,string): self.database_name = string # print(self.database_name) def bind(self): self.pushButton_exec.clicked.connect(self.exec) def exec(self): old_ids = RefinePunctuations(self.lineEdit_oldids.text()).strip() # 需要添加关联题目的id字符串 starting_id = self.lineEdit_newid.text().strip() # 目的地的id字符串从这个位置后的首个空闲开始, 其中空闲位置需不少于old_ids中的题目数量 20240124修改 editor = self.lineEdit_editor.text().strip() # 修改人姓名 new_ids = NextSpareIDBlock(starting_id,self.database_name) links = CreateIDLinks(generate_number_set(old_ids),generate_number_set(new_ids)) bodydata = CreateRelatedProblems(links,self.database_name) tempfilepath = "临时文件/problem_edit.tex" latextemplate = "模板文件/题目编辑.txt" latexdata = ReadTextFile(latextemplate) latexdata = StringSubstitute("<<待替换>>",latexdata,(bodydata,)) SaveTextFile(latexdata,tempfilepath) print("编辑完毕后, 保存关闭文件继续.") os.system(f"code -w -g {tempfilepath}") #-w表示关闭窗口后继续下一步 if XeLaTeXCompile("临时文件",tempfilepath,times=1): problems = GenerateProblemListFromString2024(ReadTextFile(tempfilepath)) for problem in problems: id_and_content = problem[0] oid = re.findall(r"^\((\d{6})->",id_and_content)[0] id = re.findall(r"^\(\d{6}->(\d{6})\)",id_and_content)[0] content = re.findall(r"->\d{6}\)([\S\s]*)$",id_and_content)[0].strip() print(id,content) AddRelatedProblemToDB(id,content,oid,editor,self.database_name) print("编译成功, 已汇入题库") else: print("编译失败, 未汇入题库") if __name__ == '__main__': app = QApplication([]) windows = MyWindow() windows.show() app.exec()