44 lines
1.7 KiB
Python
44 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_mathpix.setChecked(True)
|
|
self.pushButton_convert.clicked.connect(self.exec)
|
|
def exec(self):
|
|
raw_string = self.plainTextEdit_origin.toPlainText()
|
|
if self.radioButton_mathpix.isChecked():
|
|
dest_string = RefineMathpix(raw_string)
|
|
elif self.radioButton_textcircled.isChecked():
|
|
dest_string = re.sub(r"\((\d)\)",lambda x: "\\textcircled{"+x.group(1)+"}",raw_string) #替换所有的小括号包围的单个数字为圆圈包围的
|
|
dest_string = re.sub(r"\$\\textcircled\{\\scriptsize\{(\d)\}\}",lambda x: "\\textcircled{"+x.group(1)+"}$",dest_string)
|
|
dest_string = re.sub(r"\\textcircled\{\\scriptsize\{(\d)\}\}",lambda x: "\\textcircled{"+x.group(1)+"}",dest_string)
|
|
elif self.radioButton_multiple.isChecked():
|
|
try:
|
|
dest_string = MultiplechoicetoBlankFilling(raw_string)
|
|
except:
|
|
dest_string = "转换失败"
|
|
elif self.radioButton_puctuations.isChecked():
|
|
dest_string = RefinePunctuations(raw_string)
|
|
elif self.radioButton_answers.isChecked():
|
|
self.pro_dict = load_dict("../题库0.3/Problems.json")
|
|
dest_string = PaintRedAnswers(raw_string,self.pro_dict)
|
|
self.plainTextEdit_dest.setPlainText(dest_string)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app = QApplication([])
|
|
windows = MyWindow()
|
|
windows.show()
|
|
app.exec()
|
|
|