52 lines
2.1 KiB
Python
52 lines
2.1 KiB
Python
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
|
|
from Ui_添加关联题目 import Ui_Form
|
|
from database_tools_2 import *
|
|
|
|
class MyWindow(QWidget,Ui_Form):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.setupUi(self)
|
|
self.bind()
|
|
|
|
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)
|
|
links = CreateIDLinks(generate_number_set(old_ids),generate_number_set(new_ids))
|
|
bodydata = CreateRelatedProblems(links)
|
|
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)
|
|
print("编译成功, 已汇入题库")
|
|
else:
|
|
print("编译失败, 未汇入题库")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app = QApplication([])
|
|
windows = MyWindow()
|
|
windows.show()
|
|
app.exec()
|
|
|