From 12ffd17e282d4748b8d5e00131d9d2156ada12d9 Mon Sep 17 00:00:00 2001 From: wangweiye7840 Date: Thu, 25 Apr 2024 17:01:47 +0800 Subject: [PATCH] =?UTF-8?q?LaTeX=E4=BB=A3=E7=A0=81=E8=BD=AC=E6=8D=A2?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E8=BF=81=E7=A7=BB=E5=AE=8C=E6=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v4/Ui_文本转换处理.py | 96 ++++++++++++++++++++++++++ 工具v4/tool_panel.py | 15 ++-- 工具v4/文本转换处理.py | 43 ++++++++++++ 工具v4/文本转换处理.ui | 142 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 290 insertions(+), 6 deletions(-) create mode 100644 工具v4/Ui_文本转换处理.py create mode 100644 工具v4/文本转换处理.py create mode 100644 工具v4/文本转换处理.ui diff --git a/工具v4/Ui_文本转换处理.py b/工具v4/Ui_文本转换处理.py new file mode 100644 index 00000000..e83d1147 --- /dev/null +++ b/工具v4/Ui_文本转换处理.py @@ -0,0 +1,96 @@ +# -*- coding: utf-8 -*- + +################################################################################ +## Form generated from reading UI file '文本转换处理.ui' +## +## Created by: Qt User Interface Compiler version 6.6.2 +## +## WARNING! All changes made in this file will be lost when recompiling UI file! +################################################################################ + +from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale, + QMetaObject, QObject, QPoint, QRect, + QSize, QTime, QUrl, Qt) +from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor, + QFont, QFontDatabase, QGradient, QIcon, + QImage, QKeySequence, QLinearGradient, QPainter, + QPalette, QPixmap, QRadialGradient, QTransform) +from PySide6.QtWidgets import (QApplication, QLabel, QPlainTextEdit, QPushButton, + QRadioButton, QSizePolicy, QVBoxLayout, QWidget) + +class Ui_Form(object): + def setupUi(self, Form): + if not Form.objectName(): + Form.setObjectName(u"Form") + Form.resize(760, 490) + self.plainTextEdit_origin = QPlainTextEdit(Form) + self.plainTextEdit_origin.setObjectName(u"plainTextEdit_origin") + self.plainTextEdit_origin.setGeometry(QRect(10, 30, 310, 430)) + self.label = QLabel(Form) + self.label.setObjectName(u"label") + self.label.setGeometry(QRect(10, 10, 54, 16)) + self.label_2 = QLabel(Form) + self.label_2.setObjectName(u"label_2") + self.label_2.setGeometry(QRect(430, 10, 54, 16)) + self.plainTextEdit_dest = QPlainTextEdit(Form) + self.plainTextEdit_dest.setObjectName(u"plainTextEdit_dest") + self.plainTextEdit_dest.setGeometry(QRect(430, 30, 310, 430)) + self.plainTextEdit_dest.setAutoFillBackground(False) + self.plainTextEdit_dest.setReadOnly(True) + self.pushButton_convert = QPushButton(Form) + self.pushButton_convert.setObjectName(u"pushButton_convert") + self.pushButton_convert.setGeometry(QRect(330, 280, 91, 71)) + font = QFont() + font.setBold(True) + self.pushButton_convert.setFont(font) + self.layoutWidget = QWidget(Form) + self.layoutWidget.setObjectName(u"layoutWidget") + self.layoutWidget.setGeometry(QRect(330, 100, 97, 126)) + self.verticalLayout = QVBoxLayout(self.layoutWidget) + self.verticalLayout.setObjectName(u"verticalLayout") + self.verticalLayout.setContentsMargins(0, 0, 0, 0) + self.radioButton_mathpix = QRadioButton(self.layoutWidget) + self.radioButton_mathpix.setObjectName(u"radioButton_mathpix") + + self.verticalLayout.addWidget(self.radioButton_mathpix) + + self.radioButton_textcircled = QRadioButton(self.layoutWidget) + self.radioButton_textcircled.setObjectName(u"radioButton_textcircled") + + self.verticalLayout.addWidget(self.radioButton_textcircled) + + self.radioButton_multiple = QRadioButton(self.layoutWidget) + self.radioButton_multiple.setObjectName(u"radioButton_multiple") + + self.verticalLayout.addWidget(self.radioButton_multiple) + + self.radioButton_puctuations = QRadioButton(self.layoutWidget) + self.radioButton_puctuations.setObjectName(u"radioButton_puctuations") + + self.verticalLayout.addWidget(self.radioButton_puctuations) + + self.radioButton_answers = QRadioButton(self.layoutWidget) + self.radioButton_answers.setObjectName(u"radioButton_answers") + + self.verticalLayout.addWidget(self.radioButton_answers) + + + self.retranslateUi(Form) + + QMetaObject.connectSlotsByName(Form) + # setupUi + + def retranslateUi(self, Form): + Form.setWindowTitle(QCoreApplication.translate("Form", u"\u6587\u672c\u8f6c\u6362\u5904\u7406", None)) + self.plainTextEdit_origin.setPlaceholderText(QCoreApplication.translate("Form", u"\u5c06\u6e90\u6587\u672c \u7c98\u8d34 \u5728\u8fd9\u4e2a\u6587\u672c\u6846\u5185", None)) + self.label.setText(QCoreApplication.translate("Form", u"\u6e90\u6587\u672c", None)) + self.label_2.setText(QCoreApplication.translate("Form", u"\u76ee\u6807\u6587\u672c", None)) + self.plainTextEdit_dest.setPlaceholderText(QCoreApplication.translate("Form", u"\u6309 \u8f6c\u6362 \u4ee5\u83b7\u5f97\u76ee\u6807\u6587\u672c", None)) + self.pushButton_convert.setText(QCoreApplication.translate("Form", u"\u8f6c\u6362", None)) + self.radioButton_mathpix.setText(QCoreApplication.translate("Form", u"Mathpix", None)) + self.radioButton_textcircled.setText(QCoreApplication.translate("Form", u"\u5706\u5708\u6570\u5b57", None)) + self.radioButton_multiple.setText(QCoreApplication.translate("Form", u"\u591a\u9009\u8f6c\u586b\u7a7a", None)) + self.radioButton_puctuations.setText(QCoreApplication.translate("Form", u"\u6807\u70b9\u8f6c\u534a\u89d2", None)) + self.radioButton_answers.setText(QCoreApplication.translate("Form", u"\u5df2\u6709\u7b54\u6848\u6807\u7ea2", None)) + # retranslateUi + diff --git a/工具v4/tool_panel.py b/工具v4/tool_panel.py index 87b1cb65..a364f6cb 100644 --- a/工具v4/tool_panel.py +++ b/工具v4/tool_panel.py @@ -3,6 +3,7 @@ from Ui_tool_panel import Ui_MainWindow from PySide6.QtCore import Signal from 寻找空闲题号 import MyWindow_kxth from 生成直方图代码 import MyWindow_hist +from 文本转换处理 import MyWindow_wbzh from database_tools_2 import * class MyWindow(QMainWindow,Ui_MainWindow): @@ -19,20 +20,22 @@ class MyWindow(QMainWindow,Ui_MainWindow): self.pushButton_tikutest.clicked.connect(self.SelectTIKUTEST) #以上为设置当前数据库的两个按钮 self.layout_kxth = QVBoxLayout(self.tab_kxth) - self.tab_kxth = MyWindow_kxth(self.database) - self.layout_kxth.addWidget(self.tab_kxth) #以上三行为初始化“空闲题号”tab + self.kxth = MyWindow_kxth(self.database) + self.layout_kxth.addWidget(self.kxth) #以上三行为初始化“空闲题号”tab - + self.layout_wbzh = QVBoxLayout(self.tab_wbzh) + self.wbzh = MyWindow_wbzh() + self.layout_wbzh.addWidget(self.wbzh) #以上三行为初始化“LaTeX代码转换”tab self.layout_hist = QVBoxLayout(self.tab_hist) - self.tab_hist = MyWindow_hist() - self.layout_hist.addWidget(self.tab_hist) #以上三行为初始化“生成直方图代码”tab + self.hist = MyWindow_hist() + self.layout_hist.addWidget(self.hist) #以上三行为初始化“生成直方图代码”tab for func in [ - self.tab_kxth.setdbname + self.kxth.setdbname ]: #在列表中的tab里传送数据库名的连接 self.sendDBname.connect(func) def sendValue(self): diff --git a/工具v4/文本转换处理.py b/工具v4/文本转换处理.py new file mode 100644 index 00000000..d44ab4ac --- /dev/null +++ b/工具v4/文本转换处理.py @@ -0,0 +1,43 @@ +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): + 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() + diff --git a/工具v4/文本转换处理.ui b/工具v4/文本转换处理.ui new file mode 100644 index 00000000..a96ec25e --- /dev/null +++ b/工具v4/文本转换处理.ui @@ -0,0 +1,142 @@ + + + Form + + + + 0 + 0 + 760 + 490 + + + + 文本转换处理 + + + + + 10 + 30 + 310 + 430 + + + + 将源文本 粘贴 在这个文本框内 + + + + + + 10 + 10 + 54 + 16 + + + + 源文本 + + + + + + 430 + 10 + 54 + 16 + + + + 目标文本 + + + + + + 430 + 30 + 310 + 430 + + + + false + + + true + + + 按 转换 以获得目标文本 + + + + + + 330 + 280 + 91 + 71 + + + + + true + + + + 转换 + + + + + + 330 + 100 + 97 + 126 + + + + + + + Mathpix + + + + + + + 圆圈数字 + + + + + + + 多选转填空 + + + + + + + 标点转半角 + + + + + + + 已有答案标红 + + + + + + + + +