迁移 提取答案

This commit is contained in:
weiye.wang 2024-04-25 22:48:31 +08:00
parent 9e33772912
commit a5712273e6
4 changed files with 320 additions and 1 deletions

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, QLineEdit, QPlainTextEdit,
QPushButton, QRadioButton, QSizePolicy, QWidget)
class Ui_Form(object):
def setupUi(self, Form):
if not Form.objectName():
Form.setObjectName(u"Form")
Form.resize(760, 490)
self.plainTextEdit_rawString = QPlainTextEdit(Form)
self.plainTextEdit_rawString.setObjectName(u"plainTextEdit_rawString")
self.plainTextEdit_rawString.setGeometry(QRect(40, 100, 311, 331))
self.lineEdit_filepath = QLineEdit(Form)
self.lineEdit_filepath.setObjectName(u"lineEdit_filepath")
self.lineEdit_filepath.setGeometry(QRect(40, 50, 331, 20))
self.lineEdit_filepath.setReadOnly(True)
self.label = QLabel(Form)
self.label.setObjectName(u"label")
self.label.setGeometry(QRect(40, 30, 54, 16))
self.label_2 = QLabel(Form)
self.label_2.setObjectName(u"label_2")
self.label_2.setGeometry(QRect(40, 80, 101, 16))
self.lineEdit_2 = QLineEdit(Form)
self.lineEdit_2.setObjectName(u"lineEdit_2")
self.lineEdit_2.setGeometry(QRect(492, 50, 211, 20))
self.label_3 = QLabel(Form)
self.label_3.setObjectName(u"label_3")
self.label_3.setGeometry(QRect(490, 30, 54, 16))
self.radioButton_text = QRadioButton(Form)
self.radioButton_text.setObjectName(u"radioButton_text")
self.radioButton_text.setGeometry(QRect(610, 90, 95, 20))
self.radioButton_file = QRadioButton(Form)
self.radioButton_file.setObjectName(u"radioButton_file")
self.radioButton_file.setGeometry(QRect(610, 120, 95, 20))
self.pushButton_selectfilepath = QPushButton(Form)
self.pushButton_selectfilepath.setObjectName(u"pushButton_selectfilepath")
self.pushButton_selectfilepath.setGeometry(QRect(380, 50, 101, 24))
self.label_4 = QLabel(Form)
self.label_4.setObjectName(u"label_4")
self.label_4.setGeometry(QRect(360, 80, 91, 16))
self.plainTextEdit_ans = QPlainTextEdit(Form)
self.plainTextEdit_ans.setObjectName(u"plainTextEdit_ans")
self.plainTextEdit_ans.setGeometry(QRect(360, 100, 241, 331))
self.pushButton_exec = QPushButton(Form)
self.pushButton_exec.setObjectName(u"pushButton_exec")
self.pushButton_exec.setGeometry(QRect(610, 150, 101, 281))
font = QFont()
font.setBold(True)
self.pushButton_exec.setFont(font)
self.retranslateUi(Form)
QMetaObject.connectSlotsByName(Form)
# setupUi
def retranslateUi(self, Form):
Form.setWindowTitle(QCoreApplication.translate("Form", u"\u6587\u4ef6\u6216\u6587\u672c\u6846\u63d0\u53d6\u7b54\u6848", None))
self.label.setText(QCoreApplication.translate("Form", u"\u6587\u4ef6\u8def\u5f84", None))
self.label_2.setText(QCoreApplication.translate("Form", u"\u542b\u7b54\u6848\u7684\u6e90\u4ee3\u7801", None))
self.lineEdit_2.setText(QCoreApplication.translate("Form", u"\u7b54\u6848: \\textcolor{blue}{", None))
self.label_3.setText(QCoreApplication.translate("Form", u"\u7b54\u6848\u524d\u7f00", None))
self.radioButton_text.setText(QCoreApplication.translate("Form", u"\u6587\u672c\u6846\u751f\u6210", None))
self.radioButton_file.setText(QCoreApplication.translate("Form", u"\u6587\u4ef6\u751f\u6210", None))
self.pushButton_selectfilepath.setText(QCoreApplication.translate("Form", u"\u9009\u62e9\u6587\u4ef6\u8def\u5f84", None))
self.label_4.setText(QCoreApplication.translate("Form", u"\u7b54\u6848metadata", None))
self.pushButton_exec.setText(QCoreApplication.translate("Form", u"\u63d0\u53d6\u7b54\u6848", None))
# retranslateUi

View File

@ -17,6 +17,7 @@ from 批量收录新题 import MyWindow_bdsl
from 下载小闲答题数据 import MyWindow_xxxz
from 新增基础知识梳理 import MyWindow_tjjc
from 共享使用记录 import MyWindow_gxsy
from 文件或文本框提取答案 import MyWindow_tqda
from database_tools_2 import *
class MyWindow(QMainWindow,Ui_MainWindow):
@ -44,9 +45,13 @@ class MyWindow(QMainWindow,Ui_MainWindow):
self.tjgl = MyWindow_tjgl(self.database)
self.layout_tjgl.addWidget(self.tjgl) #以上三行为初始化“添加关联”tab
self.layout_tqda = QVBoxLayout(self.tab_tqda)
self.tqda = MyWindow_tqda()
self.layout_tqda.addWidget(self.tqda) #以上三行为初始化“提取答案”tab
self.layout_gxsy = QVBoxLayout(self.tab_gxsy)
self.gxsy = MyWindow_gxsy(self.database)
self.layout_gxsy.addWidget(self.gxsy) #以上三行为初始化“新增基础知识梳理”tab
self.layout_gxsy.addWidget(self.gxsy) #以上三行为初始化“共享使用数据”tab
self.layout_tjjc = QVBoxLayout(self.tab_tjjc)
self.tjjc = MyWindow_tjjc(self.database)

View File

@ -0,0 +1,56 @@
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
from Ui_文件或文本框提取答案 import Ui_Form
import os
from database_tools_2 import *
class MyWindow_tqda(QWidget,Ui_Form):
def __init__(self):
super().__init__()
self.setupUi(self)
self.bind()
def bind(self):
self.radioButton_text.setChecked(True)
self.textlayout()
self.radioButton_text.clicked.connect(self.textlayout)
self.radioButton_file.clicked.connect(self.filelayout)
self.pushButton_selectfilepath.clicked.connect(self.selectfilepath)
self.pushButton_exec.clicked.connect(self.exec)
def textlayout(self):
self.pushButton_selectfilepath.setDisabled(True)
self.lineEdit_filepath.setDisabled(True)
self.plainTextEdit_rawString.setEnabled(True)
def filelayout(self):
self.pushButton_selectfilepath.setEnabled(True)
self.lineEdit_filepath.setEnabled(True)
self.plainTextEdit_rawString.setDisabled(True)
def selectfilepath(self):
self.filepath = QFileDialog.getOpenFileName(self,"选择.tex文件",os.getcwd(),"tex文件(*.tex);;所有文件(*)")[0]
self.lineEdit_filepath.setText(self.filepath)
def exec(self):
if self.radioButton_text.isChecked():
data = self.plainTextEdit_rawString.toPlainText()
else:
data = ReadTextFile(self.filepath)
print(self.lineEdit_2.text())
anslist = generateAnswerList(data,self.lineEdit_2.text())
output = "ans\n\n"
for id,ans in anslist:
if not ans == "暂无答案":
output += f"{id}\n{ans}\n\n"
self.plainTextEdit_ans.setPlainText(output)
if __name__ == '__main__':
app = QApplication([])
windows = MyWindow_tqda()
windows.show()
app.exec()

View File

@ -0,0 +1,174 @@
<?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>760</width>
<height>490</height>
</rect>
</property>
<property name="windowTitle">
<string>文件或文本框提取答案</string>
</property>
<widget class="QPlainTextEdit" name="plainTextEdit_rawString">
<property name="geometry">
<rect>
<x>40</x>
<y>100</y>
<width>311</width>
<height>331</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_filepath">
<property name="geometry">
<rect>
<x>40</x>
<y>50</y>
<width>331</width>
<height>20</height>
</rect>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>40</x>
<y>30</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>40</x>
<y>80</y>
<width>101</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>含答案的源代码</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_2">
<property name="geometry">
<rect>
<x>492</x>
<y>50</y>
<width>211</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>答案: \textcolor{blue}{</string>
</property>
</widget>
<widget class="QLabel" name="label_3">
<property name="geometry">
<rect>
<x>490</x>
<y>30</y>
<width>54</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>答案前缀</string>
</property>
</widget>
<widget class="QRadioButton" name="radioButton_text">
<property name="geometry">
<rect>
<x>610</x>
<y>90</y>
<width>95</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>文本框生成</string>
</property>
</widget>
<widget class="QRadioButton" name="radioButton_file">
<property name="geometry">
<rect>
<x>610</x>
<y>120</y>
<width>95</width>
<height>20</height>
</rect>
</property>
<property name="text">
<string>文件生成</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_selectfilepath">
<property name="geometry">
<rect>
<x>380</x>
<y>50</y>
<width>101</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>选择文件路径</string>
</property>
</widget>
<widget class="QLabel" name="label_4">
<property name="geometry">
<rect>
<x>360</x>
<y>80</y>
<width>91</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>答案metadata</string>
</property>
</widget>
<widget class="QPlainTextEdit" name="plainTextEdit_ans">
<property name="geometry">
<rect>
<x>360</x>
<y>100</y>
<width>241</width>
<height>331</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton_exec">
<property name="geometry">
<rect>
<x>610</x>
<y>150</y>
<width>101</width>
<height>281</height>
</rect>
</property>
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>提取答案</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>