56 lines
2.0 KiB
Python
56 lines
2.0 KiB
Python
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
|
||
from Ui_添加关联题目 import Ui_Form
|
||
from database_tools 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 = self.lineEdit_oldids.text().replace(",",",").replace(":",":").strip() # 需要添加关联题目的id字符串
|
||
starting_id = self.lineEdit_newid.text().strip() # 目的地的id字符串从这个位置后的首个空闲开始, 其中空闲位置需不少于old_ids中的题目数量 20040124修改
|
||
editor = self.lineEdit_editor.text().strip() # 修改人姓名
|
||
|
||
|
||
|
||
tempfilepath = "临时文件/problem_edit.json"
|
||
|
||
pro_dict = load_dict("../题库0.3/Problems.json")
|
||
obj_dict = load_dict("../题库0.3/LessonObj.json")
|
||
pro_dict_raw_string = ReadTextFile("../题库0.3/Problems.json")
|
||
configjson = BuildFullScheme
|
||
|
||
|
||
links = CreateIDLinks(generate_number_set(old_ids),generate_number_set(NextSpareIDBlock(starting_id,pro_dict)),pro_dict)
|
||
CreateRelatedProblems(links,pro_dict,tempfilepath,editor)
|
||
|
||
print("编辑完毕后, 保存关闭文件继续.")
|
||
os.system("code -w -g "+tempfilepath) #-w表示关闭窗口后继续下一步
|
||
|
||
editedid_list = ImportRelatedProblems(tempfilepath,"../题库0.3/Problems.json")
|
||
|
||
pro_dict = load_dict("../题库0.3/Problems.json")
|
||
|
||
if not XeLaTeXTest(editedid_list,pro_dict,obj_dict,configjson,templatepath="模板文件/讲义模板.txt",outdir = "临时文件",outfile = "problems_test.tex"):
|
||
SaveTextFile(pro_dict_raw_string,"../题库0.3/Problems.json")
|
||
print("编译失败, 题库文件退回原状")
|
||
else:
|
||
print("编译成功, 已汇入题库")
|
||
self.close()
|
||
|
||
|
||
|
||
|
||
|
||
if __name__ == '__main__':
|
||
app = QApplication([])
|
||
windows = MyWindow()
|
||
windows.show()
|
||
app.exec()
|
||
|