From a5712273e6c6d24d05816eab9bd43073d6d64bd4 Mon Sep 17 00:00:00 2001 From: "weiye.wang" Date: Thu, 25 Apr 2024 22:48:31 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=81=E7=A7=BB=20=E6=8F=90=E5=8F=96?= =?UTF-8?q?=E7=AD=94=E6=A1=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 工具v4/Ui_文件或文本框提取答案.py | 84 +++++++++++++++ 工具v4/tool_panel.py | 7 +- 工具v4/文件或文本框提取答案.py | 56 ++++++++++ 工具v4/文件或文本框提取答案.ui | 174 ++++++++++++++++++++++++++++++ 4 files changed, 320 insertions(+), 1 deletion(-) 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..37e38c5f --- /dev/null +++ b/工具v4/Ui_文件或文本框提取答案.py @@ -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 + diff --git a/工具v4/tool_panel.py b/工具v4/tool_panel.py index 98baf6a2..514b18b1 100644 --- a/工具v4/tool_panel.py +++ b/工具v4/tool_panel.py @@ -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) diff --git a/工具v4/文件或文本框提取答案.py b/工具v4/文件或文本框提取答案.py new file mode 100644 index 00000000..04294d09 --- /dev/null +++ b/工具v4/文件或文本框提取答案.py @@ -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() + diff --git a/工具v4/文件或文本框提取答案.ui b/工具v4/文件或文本框提取答案.ui new file mode 100644 index 00000000..0557da07 --- /dev/null +++ b/工具v4/文件或文本框提取答案.ui @@ -0,0 +1,174 @@ + + + Form + + + + 0 + 0 + 760 + 490 + + + + 文件或文本框提取答案 + + + + + 40 + 100 + 311 + 331 + + + + + + + 40 + 50 + 331 + 20 + + + + true + + + + + + 40 + 30 + 54 + 16 + + + + 文件路径 + + + + + + 40 + 80 + 101 + 16 + + + + 含答案的源代码 + + + + + + 492 + 50 + 211 + 20 + + + + 答案: \textcolor{blue}{ + + + + + + 490 + 30 + 54 + 16 + + + + 答案前缀 + + + + + + 610 + 90 + 95 + 20 + + + + 文本框生成 + + + + + + 610 + 120 + 95 + 20 + + + + 文件生成 + + + + + + 380 + 50 + 101 + 24 + + + + 选择文件路径 + + + + + + 360 + 80 + 91 + 16 + + + + 答案metadata + + + + + + 360 + 100 + 241 + 331 + + + + + + + 610 + 150 + 101 + 281 + + + + + true + + + + 提取答案 + + + + + +