整合mathpix处理, 转为带圈数字, 多选改填空. 改写为Qt widget 并加入Qt面板

This commit is contained in:
weiye.wang 2024-03-03 00:25:23 +08:00
parent a23cd7c3b5
commit 8508b45e59
6 changed files with 271 additions and 42 deletions

View File

@ -25,29 +25,28 @@ class MyWindow(QMainWindow,Ui_MainWindow):
self.bind()
def bind(self):
self.action_kxth.triggered.connect(lambda: run_command("寻找空闲题号",[]))
self.action_xtbd.triggered.connect(lambda: run_command("新题比对",[]))
self.action_plsl.triggered.connect(lambda: run_command("批量收录题目",[]))
self.action_tjgl.triggered.connect(lambda: run_command("添加关联题目",[]))
self.action_tjzd.triggered.connect(lambda: run_command("修改metadata",["文本文件/metadata.txt"]))
self.action_bjtm.triggered.connect(lambda: run_command("编辑题目信息",[]))
self.action_xxdr.triggered.connect(lambda: run_command("获取小闲平台使用数据",[]))
self.action_sddr.triggered.connect(lambda: run_command("手动统计结果导入",["临时文件/手动统计结果.txt"]))
self.action_tkdr.triggered.connect(lambda: run_command("统考数据导入",[]))
self.action_kxth.triggered.connect(lambda: run_command("寻找空闲题号",[]))#已完成
self.action_xtbd.triggered.connect(lambda: run_command("新题比对",[]))#已完成
self.action_plsl.triggered.connect(lambda: run_command("批量收录题目",[]))#已完成
self.action_tjgl.triggered.connect(lambda: run_command("添加关联题目",[]))#已完成
self.action_tjzd.triggered.connect(lambda: run_command("修改metadata",["文本文件/metadata.txt"]))#已完成
self.action_bjtm.triggered.connect(lambda: run_command("编辑题目信息",[]))#已完成
self.action_xxdr.triggered.connect(lambda: run_command("获取小闲平台使用数据",[]))#已完成
self.action_sddr.triggered.connect(lambda: run_command("手动统计结果导入",["临时文件/手动统计结果.txt"]))#已完成
self.action_tkdr.triggered.connect(lambda: run_command("统考数据导入",[]))#已完成
self.action_dygg.triggered.connect(lambda: run_command("单元挂钩",["单元挂钩.py"]))
self.action_tqda.triggered.connect(lambda: run_command("文件或剪贴板提取答案",["文件或剪贴板提取答案.py"]))
self.action_hbsy.triggered.connect(lambda: run_command("合并使用记录并排序",[]))
self.action_hbsy.triggered.connect(lambda: run_command("合并使用记录并排序",[]))#已完成
self.action_tjjc.triggered.connect(lambda: run_command("添加基础知识梳理",["添加基础知识梳理.py"]))
self.action_sxth.triggered.connect(lambda: run_command("关键字筛选题号",[]))
self.action_sxth.triggered.connect(lambda: run_command("关键字筛选题号",[]))#已完成
self.action_xtby.triggered.connect(lambda: run_command("多种题目生成",["多种题目生成.py"]))
self.action_sctp.triggered.connect(lambda: run_command("单一题目转成图片文件",["单一题目转成图片文件.py"]))
self.action_hqth.triggered.connect(lambda: run_command("在.tex或.pdf文件中获取题号",["在.tex或.pdf文件中获取题号.py"]))
self.action_jglr.triggered.connect(lambda: run_command("讲义结构编号录入",["讲义结构编号录入.py"]))
self.action_dtdy.triggered.connect(lambda: run_command("录入答题纸对应信息",["录入答题纸对应信息.py"]))
self.action_jysc.triggered.connect(lambda: run_command("系列讲义生成",[]))
self.action_mtpx.triggered.connect(lambda: run_command("mathpix识别文本预处理",[]))
self.action_dqsz.triggered.connect(lambda: run_command("修改为带圈数字",[]))
self.action_dxtk.triggered.connect(lambda: run_command("多选题转为填空题",[]))
self.action_jysc.triggered.connect(lambda: run_command("系列讲义生成",[]))#已完成
self.action_wbzh.triggered.connect(lambda: run_command("文本转换处理",[]))#已完成

View File

@ -79,9 +79,7 @@
<property name="title">
<string>LaTeX代码相关</string>
</property>
<addaction name="action_mtpx"/>
<addaction name="action_dqsz"/>
<addaction name="action_dxtk"/>
<addaction name="action_wbzh"/>
</widget>
<widget class="QMenu" name="menu_exit">
<property name="title">
@ -191,19 +189,9 @@
<string>获取题号</string>
</property>
</action>
<action name="action_mtpx">
<action name="action_wbzh">
<property name="text">
<string>mathpix预处理</string>
</property>
</action>
<action name="action_dqsz">
<property name="text">
<string>括号数字变为带圈数字</string>
</property>
</action>
<action name="action_dxtk">
<property name="text">
<string>多选转填空</string>
<string>文本转换处理</string>
</property>
</action>
<action name="action_bjtm">

View File

@ -62,12 +62,8 @@ class Ui_MainWindow(object):
self.action_jysc.setObjectName(u"action_jysc")
self.action_hqth = QAction(MainWindow)
self.action_hqth.setObjectName(u"action_hqth")
self.action_mtpx = QAction(MainWindow)
self.action_mtpx.setObjectName(u"action_mtpx")
self.action_dqsz = QAction(MainWindow)
self.action_dqsz.setObjectName(u"action_dqsz")
self.action_dxtk = QAction(MainWindow)
self.action_dxtk.setObjectName(u"action_dxtk")
self.action_wbzh = QAction(MainWindow)
self.action_wbzh.setObjectName(u"action_wbzh")
self.action_bjtm = QAction(MainWindow)
self.action_bjtm.setObjectName(u"action_bjtm")
self.centralwidget = QWidget(MainWindow)
@ -131,9 +127,7 @@ class Ui_MainWindow(object):
self.menu_beikezu.addAction(self.action_dtdy)
self.menu_beikezu.addSeparator()
self.menu_beikezu.addAction(self.action_jysc)
self.menu_latex.addAction(self.action_mtpx)
self.menu_latex.addAction(self.action_dqsz)
self.menu_latex.addAction(self.action_dxtk)
self.menu_latex.addAction(self.action_wbzh)
self.retranslateUi(MainWindow)
@ -161,9 +155,7 @@ class Ui_MainWindow(object):
self.action_dtdy.setText(QCoreApplication.translate("MainWindow", u"\u5f55\u5165\u7b54\u9898\u7eb8\u5bf9\u5e94\u4fe1\u606f", None))
self.action_jysc.setText(QCoreApplication.translate("MainWindow", u"\u7cfb\u5217\u8bb2\u4e49\u751f\u6210", None))
self.action_hqth.setText(QCoreApplication.translate("MainWindow", u"\u83b7\u53d6\u9898\u53f7", None))
self.action_mtpx.setText(QCoreApplication.translate("MainWindow", u"mathpix\u9884\u5904\u7406", None))
self.action_dqsz.setText(QCoreApplication.translate("MainWindow", u"\u62ec\u53f7\u6570\u5b57\u53d8\u4e3a\u5e26\u5708\u6570\u5b57", None))
self.action_dxtk.setText(QCoreApplication.translate("MainWindow", u"\u591a\u9009\u8f6c\u586b\u7a7a", None))
self.action_wbzh.setText(QCoreApplication.translate("MainWindow", u"\u6587\u672c\u8f6c\u6362\u5904\u7406", None))
self.action_bjtm.setText(QCoreApplication.translate("MainWindow", u"\u7f16\u8f91\u9898\u76ee", None))
self.menu_luru.setTitle(QCoreApplication.translate("MainWindow", u"\u5f55\u5165", None))
self.menu_weihu.setTitle(QCoreApplication.translate("MainWindow", u"\u7ef4\u62a4", None))

View File

@ -0,0 +1,84 @@
# -*- 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(720, 401)
self.plainTextEdit_origin = QPlainTextEdit(Form)
self.plainTextEdit_origin.setObjectName(u"plainTextEdit_origin")
self.plainTextEdit_origin.setGeometry(QRect(10, 30, 291, 361))
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(390, 10, 54, 16))
self.plainTextEdit_dest = QPlainTextEdit(Form)
self.plainTextEdit_dest.setObjectName(u"plainTextEdit_dest")
self.plainTextEdit_dest.setGeometry(QRect(430, 30, 281, 361))
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(310, 210, 111, 71))
font = QFont()
font.setBold(True)
self.pushButton_convert.setFont(font)
self.widget = QWidget(Form)
self.widget.setObjectName(u"widget")
self.widget.setGeometry(QRect(320, 120, 97, 74))
self.verticalLayout = QVBoxLayout(self.widget)
self.verticalLayout.setObjectName(u"verticalLayout")
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.radioButton_mathpix = QRadioButton(self.widget)
self.radioButton_mathpix.setObjectName(u"radioButton_mathpix")
self.verticalLayout.addWidget(self.radioButton_mathpix)
self.radioButton_textcircled = QRadioButton(self.widget)
self.radioButton_textcircled.setObjectName(u"radioButton_textcircled")
self.verticalLayout.addWidget(self.radioButton_textcircled)
self.radioButton_multiple = QRadioButton(self.widget)
self.radioButton_multiple.setObjectName(u"radioButton_multiple")
self.verticalLayout.addWidget(self.radioButton_multiple)
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))
# retranslateUi

View File

@ -0,0 +1,38 @@
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)
else:
try:
dest_string = MultiplechoicetoBlankFilling(raw_string)
except:
dest_string = "转换失败"
self.plainTextEdit_dest.setPlainText(dest_string)
if __name__ == '__main__':
app = QApplication([])
windows = MyWindow()
windows.show()
app.exec()

View File

@ -0,0 +1,128 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>720</width>
<height>401</height>
</rect>
</property>
<property name="windowTitle">
<string>文本转换处理</string>
</property>
<widget class="QPlainTextEdit" name="plainTextEdit_origin">
<property name="geometry">
<rect>
<x>10</x>
<y>30</y>
<width>291</width>
<height>361</height>
</rect>
</property>
<property name="placeholderText">
<string>将源文本 粘贴 在这个文本框内</string>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>54</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>源文本</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>390</x>
<y>10</y>
<width>54</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>目标文本</string>
</property>
</widget>
<widget class="QPlainTextEdit" name="plainTextEdit_dest">
<property name="geometry">
<rect>
<x>430</x>
<y>30</y>
<width>281</width>
<height>361</height>
</rect>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>按 转换 以获得目标文本</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_convert">
<property name="geometry">
<rect>
<x>310</x>
<y>210</y>
<width>111</width>
<height>71</height>
</rect>
</property>
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>转换</string>
</property>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>320</x>
<y>120</y>
<width>97</width>
<height>74</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QRadioButton" name="radioButton_mathpix">
<property name="text">
<string>Mathpix</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_textcircled">
<property name="text">
<string>圆圈数字</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_multiple">
<property name="text">
<string>多选转填空</string>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>