批量收录题目功能用Qt重写
This commit is contained in:
parent
bacd1efec7
commit
6b11f0f74e
|
|
@ -27,7 +27,7 @@ class MyWindow(QMainWindow,Ui_MainWindow):
|
|||
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("批量收录题目",["批量收录题目.py"]))
|
||||
self.action_plsl.triggered.connect(lambda: run_command("批量收录题目",[]))
|
||||
self.action_tjgl.triggered.connect(lambda: run_command("添加关联题目",["添加关联题目.py"]))
|
||||
self.action_tjzd.triggered.connect(lambda: run_command("修改metadata",["文本文件/metadata.txt"]))
|
||||
self.action_LaTeXedit.triggered.connect(lambda: run_command("LaTeX编辑题目答案及提示",["latex编辑题目答案及提示.py"]))
|
||||
|
|
|
|||
|
|
@ -0,0 +1,131 @@
|
|||
# -*- 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, QCheckBox, QHBoxLayout, QLabel,
|
||||
QLineEdit, QPushButton, QSizePolicy, QSplitter,
|
||||
QWidget)
|
||||
|
||||
class Ui_Form(object):
|
||||
def setupUi(self, Form):
|
||||
if not Form.objectName():
|
||||
Form.setObjectName(u"Form")
|
||||
Form.resize(342, 109)
|
||||
self.pushButton_exec = QPushButton(Form)
|
||||
self.pushButton_exec.setObjectName(u"pushButton_exec")
|
||||
self.pushButton_exec.setGeometry(QRect(260, 10, 71, 91))
|
||||
font = QFont()
|
||||
font.setBold(True)
|
||||
self.pushButton_exec.setFont(font)
|
||||
self.splitter = QSplitter(Form)
|
||||
self.splitter.setObjectName(u"splitter")
|
||||
self.splitter.setGeometry(QRect(10, 10, 241, 88))
|
||||
self.splitter.setOrientation(Qt.Vertical)
|
||||
self.widget = QWidget(self.splitter)
|
||||
self.widget.setObjectName(u"widget")
|
||||
self.horizontalLayout = QHBoxLayout(self.widget)
|
||||
self.horizontalLayout.setObjectName(u"horizontalLayout")
|
||||
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
|
||||
self.label = QLabel(self.widget)
|
||||
self.label.setObjectName(u"label")
|
||||
|
||||
self.horizontalLayout.addWidget(self.label)
|
||||
|
||||
self.lineEdit_startingid = QLineEdit(self.widget)
|
||||
self.lineEdit_startingid.setObjectName(u"lineEdit_startingid")
|
||||
self.lineEdit_startingid.setDragEnabled(False)
|
||||
self.lineEdit_startingid.setReadOnly(False)
|
||||
|
||||
self.horizontalLayout.addWidget(self.lineEdit_startingid)
|
||||
|
||||
self.splitter.addWidget(self.widget)
|
||||
self.layoutWidget = QWidget(self.splitter)
|
||||
self.layoutWidget.setObjectName(u"layoutWidget")
|
||||
self.horizontalLayout_2 = QHBoxLayout(self.layoutWidget)
|
||||
self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
|
||||
self.horizontalLayout_2.setContentsMargins(0, 0, 0, 0)
|
||||
self.label_2 = QLabel(self.layoutWidget)
|
||||
self.label_2.setObjectName(u"label_2")
|
||||
|
||||
self.horizontalLayout_2.addWidget(self.label_2)
|
||||
|
||||
self.lineEdit_editor = QLineEdit(self.layoutWidget)
|
||||
self.lineEdit_editor.setObjectName(u"lineEdit_editor")
|
||||
|
||||
self.horizontalLayout_2.addWidget(self.lineEdit_editor)
|
||||
|
||||
self.splitter.addWidget(self.layoutWidget)
|
||||
self.layoutWidget_2 = QWidget(self.splitter)
|
||||
self.layoutWidget_2.setObjectName(u"layoutWidget_2")
|
||||
self.horizontalLayout_3 = QHBoxLayout(self.layoutWidget_2)
|
||||
self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
|
||||
self.horizontalLayout_3.setContentsMargins(0, 0, 0, 0)
|
||||
self.label_3 = QLabel(self.layoutWidget_2)
|
||||
self.label_3.setObjectName(u"label_3")
|
||||
|
||||
self.horizontalLayout_3.addWidget(self.label_3)
|
||||
|
||||
self.lineEdit_origin = QLineEdit(self.layoutWidget_2)
|
||||
self.lineEdit_origin.setObjectName(u"lineEdit_origin")
|
||||
|
||||
self.horizontalLayout_3.addWidget(self.lineEdit_origin)
|
||||
|
||||
self.splitter.addWidget(self.layoutWidget_2)
|
||||
self.layoutWidget_3 = QWidget(self.splitter)
|
||||
self.layoutWidget_3.setObjectName(u"layoutWidget_3")
|
||||
self.horizontalLayout_4 = QHBoxLayout(self.layoutWidget_3)
|
||||
self.horizontalLayout_4.setObjectName(u"horizontalLayout_4")
|
||||
self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0)
|
||||
self.label_4 = QLabel(self.layoutWidget_3)
|
||||
self.label_4.setObjectName(u"label_4")
|
||||
|
||||
self.horizontalLayout_4.addWidget(self.label_4)
|
||||
|
||||
self.lineEdit_suffix = QLineEdit(self.layoutWidget_3)
|
||||
self.lineEdit_suffix.setObjectName(u"lineEdit_suffix")
|
||||
self.lineEdit_suffix.setEnabled(False)
|
||||
|
||||
self.horizontalLayout_4.addWidget(self.lineEdit_suffix)
|
||||
|
||||
self.checkBox_suffix = QCheckBox(self.layoutWidget_3)
|
||||
self.checkBox_suffix.setObjectName(u"checkBox_suffix")
|
||||
|
||||
self.horizontalLayout_4.addWidget(self.checkBox_suffix)
|
||||
|
||||
self.splitter.addWidget(self.layoutWidget_3)
|
||||
|
||||
self.retranslateUi(Form)
|
||||
|
||||
QMetaObject.connectSlotsByName(Form)
|
||||
# setupUi
|
||||
|
||||
def retranslateUi(self, Form):
|
||||
Form.setWindowTitle(QCoreApplication.translate("Form", u"\u6279\u91cf\u6536\u5f55\u65b0\u9898", None))
|
||||
self.pushButton_exec.setText(QCoreApplication.translate("Form", u"\u6536\u5f55\u65b0\u9898", None))
|
||||
self.label.setText(QCoreApplication.translate("Form", u"\u8d77\u59cbID", None))
|
||||
self.lineEdit_startingid.setInputMask("")
|
||||
self.lineEdit_startingid.setPlaceholderText(QCoreApplication.translate("Form", u"\u6570\u5b57\u9898\u53f7(\u901a\u5e38\u662f10000n+1)", None))
|
||||
self.label_2.setText(QCoreApplication.translate("Form", u"\u7f16\u8f91\u8005", None))
|
||||
self.lineEdit_editor.setPlaceholderText(QCoreApplication.translate("Form", u"\u7f16\u8f91\u8005\u59d3\u540d", None))
|
||||
self.label_3.setText(QCoreApplication.translate("Form", u"\u6765\u6e90", None))
|
||||
self.lineEdit_origin.setText(QCoreApplication.translate("Form", u"\u81ea\u62df\u9898\u76ee", None))
|
||||
self.lineEdit_origin.setPlaceholderText(QCoreApplication.translate("Form", u"\u9898\u76ee\u6765\u6e90, \u901a\u5e38\u4e3a \u81ea\u62df\u9898\u76ee", None))
|
||||
self.label_4.setText(QCoreApplication.translate("Form", u"\u540e\u7f00", None))
|
||||
self.lineEdit_suffix.setText(QCoreApplication.translate("Form", u"\u8bd5\u9898", None))
|
||||
self.lineEdit_suffix.setPlaceholderText(QCoreApplication.translate("Form", u"\u901a\u5e38\u4e3a \u8bd5\u9898", None))
|
||||
self.checkBox_suffix.setText(QCoreApplication.translate("Form", u"\u4f7f\u7528\u540e\u7f00", None))
|
||||
# retranslateUi
|
||||
|
||||
|
|
@ -1,20 +1,51 @@
|
|||
#修改起始id,出处,文件名
|
||||
starting_id = 30001 #起始id设置, 从这一个题号后的第一个空闲题号开始添加 20040124修改
|
||||
raworigin = "自拟题目" #题目来源的前缀(中缀在.tex文件中)
|
||||
filename = r"临时文件\新题比对.tex" #题目的来源.tex文件
|
||||
editor = "毛培菁" #编辑者姓名
|
||||
IndexDescription = "" #设置是否使用后缀, 留空("")则不用后缀, 不留空则以所设字符串作为后缀起始词, 按.tex文件中的顺序编号
|
||||
idlistpath = r"文本文件\新题收录列表.txt"
|
||||
|
||||
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
|
||||
from Ui_批量收录题目 import Ui_Form
|
||||
from database_tools import *
|
||||
|
||||
problems = GenerateProblemListFromString2024(ReadTextFile(filename))
|
||||
pro_dict = load_dict(r"../题库0.3/Problems.json")
|
||||
idlist = AddProblemstoDict2024(NextSpareID(starting_id,pro_dict),raworigin,problems,editor,IndexDescription,pro_dict)
|
||||
save_dict(SortDict(pro_dict),r"../题库0.3/Problems.json")
|
||||
AppendTextFile(f"{GetDate()}-{GetTime()}\n{generate_exp(idlist)}",idlistpath)
|
||||
os.system(f"code {idlistpath}")
|
||||
class MyWindow(QWidget,Ui_Form):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setupUi(self)
|
||||
self.bind()
|
||||
|
||||
def bind(self):
|
||||
self.suffix_checked = True
|
||||
self.checkBox_suffix.toggled.connect(self.togglesuffix)
|
||||
self.pushButton_exec.clicked.connect(self.exec)
|
||||
def togglesuffix(self):
|
||||
self.suffix_checked = self.checkBox_suffix.isChecked()
|
||||
if self.suffix_checked:
|
||||
self.lineEdit_suffix.setEnabled(True)
|
||||
else:
|
||||
self.lineEdit_suffix.setDisabled(True)
|
||||
def exec(self):
|
||||
starting_id = self.lineEdit_startingid.text().strip().zfill(6)
|
||||
raworigin = self.lineEdit_origin.text().strip()
|
||||
filename = "临时文件/新题比对.tex" #题目的来源.tex文件
|
||||
editor = self.lineEdit_editor.text().strip()
|
||||
if self.checkBox_suffix.isChecked():
|
||||
IndexDescription = self.lineEdit_suffix.text().strip()
|
||||
else:
|
||||
IndexDescription = ""
|
||||
idlistpath = "文本文件/新题收录列表.txt"
|
||||
problems = GenerateProblemListFromString2024(ReadTextFile(filename))
|
||||
pro_dict = load_dict("../题库0.3/Problems.json")
|
||||
idlist = AddProblemstoDict2024(NextSpareID(starting_id,pro_dict),raworigin,problems,editor,IndexDescription,pro_dict)
|
||||
save_dict(SortDict(pro_dict),r"../题库0.3/Problems.json")
|
||||
AppendTextFile(f"{GetDate()}-{GetTime()}\n{generate_exp(idlist)}",idlistpath)
|
||||
os.system(f"code {idlistpath}")
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = QApplication([])
|
||||
windows = MyWindow()
|
||||
windows.show()
|
||||
app.exec()
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,147 @@
|
|||
<?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>342</width>
|
||||
<height>109</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>批量收录新题</string>
|
||||
</property>
|
||||
<widget class="QPushButton" name="pushButton_exec">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>260</x>
|
||||
<y>10</y>
|
||||
<width>71</width>
|
||||
<height>91</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>收录新题</string>
|
||||
</property>
|
||||
</widget>
|
||||
<widget class="QSplitter" name="splitter">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>10</y>
|
||||
<width>241</width>
|
||||
<height>88</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<widget class="QWidget" name="">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>起始ID</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_startingid">
|
||||
<property name="inputMask">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="dragEnabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>数字题号(通常是10000n+1)</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>编辑者</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_editor">
|
||||
<property name="placeholderText">
|
||||
<string>编辑者姓名</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="layoutWidget_2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>来源</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_origin">
|
||||
<property name="text">
|
||||
<string>自拟题目</string>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>题目来源, 通常为 自拟题目</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="layoutWidget_3">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>后缀</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="lineEdit_suffix">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>试题</string>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>通常为 试题</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkBox_suffix">
|
||||
<property name="text">
|
||||
<string>使用后缀</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
#修改起始id,出处,文件名
|
||||
starting_id = 30001 #起始id设置, 从这一个题号后的第一个空闲题号开始添加 20040124修改
|
||||
raworigin = "自拟题目" #题目来源的前缀(中缀在.tex文件中)
|
||||
filename = r"临时文件\新题比对.tex" #题目的来源.tex文件
|
||||
editor = "毛培菁" #编辑者姓名
|
||||
IndexDescription = "" #设置是否使用后缀, 留空("")则不用后缀, 不留空则以所设字符串作为后缀起始词, 按.tex文件中的顺序编号
|
||||
idlistpath = r"文本文件\新题收录列表.txt"
|
||||
|
||||
from database_tools import *
|
||||
|
||||
problems = GenerateProblemListFromString2024(ReadTextFile(filename))
|
||||
pro_dict = load_dict(r"../题库0.3/Problems.json")
|
||||
idlist = AddProblemstoDict2024(NextSpareID(starting_id,pro_dict),raworigin,problems,editor,IndexDescription,pro_dict)
|
||||
save_dict(SortDict(pro_dict),r"../题库0.3/Problems.json")
|
||||
AppendTextFile(f"{GetDate()}-{GetTime()}\n{generate_exp(idlist)}",idlistpath)
|
||||
os.system(f"code {idlistpath}")
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue