提取答案 迁移至 工具v3

This commit is contained in:
wangweiye7840 2024-04-16 11:50:37 +08:00
parent 640d59234d
commit e871c1f619
3 changed files with 314 additions and 0 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(690, 421)
self.plainTextEdit_rawString = QPlainTextEdit(Form)
self.plainTextEdit_rawString.setObjectName(u"plainTextEdit_rawString")
self.plainTextEdit_rawString.setGeometry(QRect(10, 80, 311, 331))
self.lineEdit_filepath = QLineEdit(Form)
self.lineEdit_filepath.setObjectName(u"lineEdit_filepath")
self.lineEdit_filepath.setGeometry(QRect(10, 30, 331, 20))
self.lineEdit_filepath.setReadOnly(True)
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(10, 60, 101, 16))
self.lineEdit_2 = QLineEdit(Form)
self.lineEdit_2.setObjectName(u"lineEdit_2")
self.lineEdit_2.setGeometry(QRect(462, 30, 211, 20))
self.label_3 = QLabel(Form)
self.label_3.setObjectName(u"label_3")
self.label_3.setGeometry(QRect(460, 10, 54, 16))
self.radioButton_text = QRadioButton(Form)
self.radioButton_text.setObjectName(u"radioButton_text")
self.radioButton_text.setGeometry(QRect(580, 70, 95, 20))
self.radioButton_file = QRadioButton(Form)
self.radioButton_file.setObjectName(u"radioButton_file")
self.radioButton_file.setGeometry(QRect(580, 100, 95, 20))
self.pushButton_selectfilepath = QPushButton(Form)
self.pushButton_selectfilepath.setObjectName(u"pushButton_selectfilepath")
self.pushButton_selectfilepath.setGeometry(QRect(350, 30, 101, 24))
self.label_4 = QLabel(Form)
self.label_4.setObjectName(u"label_4")
self.label_4.setGeometry(QRect(330, 60, 91, 16))
self.plainTextEdit_ans = QPlainTextEdit(Form)
self.plainTextEdit_ans.setObjectName(u"plainTextEdit_ans")
self.plainTextEdit_ans.setGeometry(QRect(330, 80, 241, 331))
self.pushButton_exec = QPushButton(Form)
self.pushButton_exec.setObjectName(u"pushButton_exec")
self.pushButton_exec.setGeometry(QRect(580, 130, 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

@ -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(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()
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>690</width>
<height>421</height>
</rect>
</property>
<property name="windowTitle">
<string>文件或文本框提取答案</string>
</property>
<widget class="QPlainTextEdit" name="plainTextEdit_rawString">
<property name="geometry">
<rect>
<x>10</x>
<y>80</y>
<width>311</width>
<height>331</height>
</rect>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_filepath">
<property name="geometry">
<rect>
<x>10</x>
<y>30</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>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>10</x>
<y>60</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>462</x>
<y>30</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>460</x>
<y>10</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>580</x>
<y>70</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>580</x>
<y>100</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>350</x>
<y>30</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>330</x>
<y>60</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>330</x>
<y>80</y>
<width>241</width>
<height>331</height>
</rect>
</property>
</widget>
<widget class="QPushButton" name="pushButton_exec">
<property name="geometry">
<rect>
<x>580</x>
<y>130</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>