This repository has been archived on 2024-06-23. You can view files and clone it, but cannot push or open issues or pull requests.
mathdeptv2/工具v4/单元挂钩.py

56 lines
2.1 KiB
Python

from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
from Ui_单元挂钩 import Ui_Form
from database_tools_2 import *
class MyWindow_dygg(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.radioButton_phase1.setChecked(True)
self.pushButton_exec.clicked.connect(self.exec)
def exec(self):
# pro_dict = load_dict("../题库0.3/Problems.json")
allids = getAllIDsExp(self.database_name)
all_same_list = generate_same_list(self.database_name)
all_related_list = generate_related_list(self.database_name)
if self.radioButton_phase1.isChecked():
idexp = self.lineEdit_ids.text()
if idexp.strip() == "":
idlist = unUnitted(allids,self.database_name)
else:
idlist = generate_number_set(idexp)
latex_body,tagrec = AutoAssignTagNotoLaTeX(idlist,all_same_list,all_related_list,self.database_name)
latex_raw = ReadTextFile("模板文件/讲义模板.txt")
latex_data = StringSubstitute(r"<<[\s\S]*?待替换[\s\S]*?>>",latex_raw,("待检查单元",latex_body))
SaveTextFile(tagrec,"临时文件/单元对应.txt")
SaveTextFile(latex_data,"临时文件/待检查单元.tex")
if XeLaTeXCompile("临时文件","待检查单元.tex") == True:
print("处理成功.")
os.system("code 临时文件/单元对应.txt 临时文件/待检查单元.pdf")
else:
print("处理失败.")
elif self.radioButton_phase2.isChecked():
output = UnitRectoMetadataText(ReadTextFile("临时文件/单元对应.txt"))
SaveTextFile(output,"./临时文件/metadata.txt")
os.system("code 临时文件/metadata.txt")
if __name__ == '__main__':
app = QApplication([])
windows = MyWindow_dygg()
windows.show()
app.exec()