from PySide6.QtWidgets import QWidget, QApplication, QFileDialog from Ui_文本转换处理 import Ui_Form from database_tools_2 import * class MyWindow_wbzh(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_mathpix.setChecked(True) self.pushButton_convert.clicked.connect(self.exec) def exec(self): raw_string = self.plainTextEdit_origin.toPlainText() self.mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = self.database_name) 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.mycursor = self.mydb.cursor() self.pro_dict = generateProDict(self.mycursor) dest_string = PaintRedAnswers(raw_string,self.pro_dict) self.plainTextEdit_dest.setPlainText(dest_string) self.mydb.close() if __name__ == '__main__': app = QApplication([]) windows = MyWindow() windows.show() app.exec()