51 lines
1.7 KiB
Python
51 lines
1.7 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.radioButton_latex.setChecked(True)
|
|
self.pushButton_exec.clicked.connect(self.exec)
|
|
def exec(self):
|
|
id_string = self.lineEdit_id.text()
|
|
editor = self.lineEdit_editor.text()
|
|
prodictpath = "../题库0.3/Problems.json"
|
|
pro_dict = load_dict(prodictpath)
|
|
obj_dict = load_dict("../题库0.3/LessonObj.json")
|
|
pro_dict_raw_string = ReadTextFile(prodictpath)
|
|
configjson = BuildFullScheme
|
|
if self.radioButton_latex.isChecked():
|
|
tempfilepath = "临时文件/problem_edit.tex"
|
|
edited = ModifyProblembyTeX(id_string,pro_dict,tempfilepath,editor)
|
|
else:
|
|
edited = jsonEditProblemMetadata(id_string,pro_dict,editor)
|
|
save_dict(pro_dict,prodictpath)
|
|
print(f"编辑过的题号: {edited}")
|
|
if edited != "无有效题号":
|
|
if not XeLaTeXTest(edited,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()
|
|
|