用Qt重写 新增基础知识梳理 功能, 并加入两个面板

This commit is contained in:
weiye.wang 2024-03-03 17:42:45 +08:00
parent 6ae64f025a
commit c21a75fb3f
5 changed files with 211 additions and 2 deletions

View File

@ -37,7 +37,7 @@ class MyWindow(QMainWindow,Ui_MainWindow):
self.action_dygg.triggered.connect(lambda: run_command("单元挂钩",["单元挂钩.py"]))
self.action_tqda.triggered.connect(lambda: run_command("文件或文本框提取答案",[]))#已完成
self.action_hbsy.triggered.connect(lambda: run_command("合并使用记录并排序",[]))#已完成
self.action_tjjc.triggered.connect(lambda: run_command("添加基础知识梳理",["添加基础知识梳理.py"]))
self.action_tjjc.triggered.connect(lambda: run_command("新增基础知识梳理",[]))#已完成
self.action_sxth.triggered.connect(lambda: run_command("关键字筛选题号",[]))#已完成
self.action_xtby.triggered.connect(lambda: run_command("指定题号编译pdf",[]))#已完成
self.action_sctp.triggered.connect(lambda: run_command("单一题号转为图片",[]))#已完成

View File

@ -0,0 +1,60 @@
# -*- 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, QPushButton,
QSizePolicy, QWidget)
class Ui_Form(object):
def setupUi(self, Form):
if not Form.objectName():
Form.setObjectName(u"Form")
Form.resize(400, 129)
self.label = QLabel(Form)
self.label.setObjectName(u"label")
self.label.setGeometry(QRect(10, 20, 91, 16))
self.lineEdit_filepath = QLineEdit(Form)
self.lineEdit_filepath.setObjectName(u"lineEdit_filepath")
self.lineEdit_filepath.setGeometry(QRect(10, 40, 381, 20))
self.lineEdit_filepath.setReadOnly(True)
self.pushButton_selectfilepath = QPushButton(Form)
self.pushButton_selectfilepath.setObjectName(u"pushButton_selectfilepath")
self.pushButton_selectfilepath.setGeometry(QRect(304, 10, 91, 24))
self.label_2 = QLabel(Form)
self.label_2.setObjectName(u"label_2")
self.label_2.setGeometry(QRect(10, 70, 291, 51))
self.pushButton_exec = QPushButton(Form)
self.pushButton_exec.setObjectName(u"pushButton_exec")
self.pushButton_exec.setGeometry(QRect(310, 70, 81, 51))
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"\u65b0\u589e\u57fa\u7840\u77e5\u8bc6\u68b3\u7406", None))
self.label.setText(QCoreApplication.translate("Form", u"LaTeX\u6587\u4ef6\u4f4d\u7f6e", None))
self.pushButton_selectfilepath.setText(QCoreApplication.translate("Form", u"\u9009\u62e9\u6587\u4ef6", None))
self.label_2.setText(QCoreApplication.translate("Form", u"LaTeX\u6587\u4ef6\u4e2d\u6709\u4e00\u4e2aenumerate\u73af\u5883.\n"
"\u6bcf\u4e00\u4e2aitem\u540e\u9762\u6709\u4e00\u4e2a\u4e2d\u62ec\u53f7\u5305\u56f4\u7684\u4fe1\u606f, \u4e4b\u540e\u662f\u5185\u5bb9.\n"
"\u4f8b\u5982: \\item [K0101/K0101001B,K0101002B] \u5185\u5bb9", None))
self.pushButton_exec.setText(QCoreApplication.translate("Form", u"\u6dfb\u52a0\u57fa\u7840\u77e5\u8bc6", None))
# retranslateUi

View File

@ -132,7 +132,7 @@ BKMenu.add_command(label = "录入答题纸对应信息", command = lambda: SetB
BKMenu.add_command(label = "讲义生成", command = lambda: SetButton("讲义生成",["讲义生成.py"]))
BKMenu.add_command(label = "系列讲义生成", command = lambda: SetButton("系列讲义生成",[]))
BKMenu.add_separator()
BKMenu.add_command(label = "添加基础知识梳理", command = lambda: SetButton("添加基础知识梳理",["添加基础知识梳理.py"]))
BKMenu.add_command(label = "添加基础知识梳理", command = lambda: SetButton("新增基础知识梳理",[]))
# BKMenu.add_command(label = "题号清单生成", command = lambda: SetButton("题号清单生成",1,["题号清单生成.py"]))
# BKMenu.add_command(label = "已用题号剔除", command = lambda: SetButton("已用题号剔除",1,["已用题号剔除.py"]))
# BKMenu.add_command(label = "寻找未赋答案题目", command = lambda: SetButton("寻找未赋答案题目",1,["寻找未赋答案题目.py"]))

View File

@ -0,0 +1,58 @@
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
from Ui_新增基础知识梳理 import Ui_Form
import os
from database_tools import *
class MyWindow(QWidget,Ui_Form):
def __init__(self):
super().__init__()
self.setupUi(self)
self.bind()
def bind(self):
self.pushButton_exec.setDisabled(True)
self.pushButton_selectfilepath.clicked.connect(self.selectfilepath)
self.pushButton_exec.clicked.connect(self.exec)
def selectfilepath(self):
self.filepath = QFileDialog.getOpenFileName(self,"选择.tex文件",os.getcwd(),"tex文件(*.tex);;所有文件(*)")[0]
self.lineEdit_filepath.setText(self.filepath)
self.pushButton_exec.setEnabled(True)
def exec(self):
bkdatajsonpath = r"../题库0.3/BasicKnowledge.json" # 知识梳理数据库路径
basicknowledge_dict = load_dict(bkdatajsonpath)
bkdata_raw = ReadTextFile(self.filepath)
bkdatabody = re.findall(r"\\begin\{enumerate\}([\s\S]*?)\\end\{enumerate\}",bkdata_raw)[0].strip().split("\\item")
bkdata = [line.strip() for line in bkdatabody if "[" in line and "]" in line]
currentid = int(max(basicknowledge_dict)[1:])+1
for line in bkdata:
if not line.strip() == "":
id = "B" + str(currentid).zfill(5)
pos = line.index("]")
head = line[1:pos]
content = line[pos+1:].strip()
lesson,objs = head.split("/")
obj_list = objs.split(",")
print(lesson,obj_list,content)
basicknowledge_dict[id] = {}
basicknowledge_dict[id]["lesson"] = lesson
basicknowledge_dict[id]["objs"] = obj_list
basicknowledge_dict[id]["content"] = content
currentid += 1
save_dict(basicknowledge_dict,bkdatajsonpath)
print("已录入完成")
if __name__ == '__main__':
app = QApplication([])
windows = MyWindow()
windows.show()
app.exec()

View File

@ -0,0 +1,91 @@
<?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>400</width>
<height>129</height>
</rect>
</property>
<property name="windowTitle">
<string>新增基础知识梳理</string>
</property>
<widget class="QLabel" name="label">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>91</width>
<height>16</height>
</rect>
</property>
<property name="text">
<string>LaTeX文件位置</string>
</property>
</widget>
<widget class="QLineEdit" name="lineEdit_filepath">
<property name="geometry">
<rect>
<x>10</x>
<y>40</y>
<width>381</width>
<height>20</height>
</rect>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
<widget class="QPushButton" name="pushButton_selectfilepath">
<property name="geometry">
<rect>
<x>304</x>
<y>10</y>
<width>91</width>
<height>24</height>
</rect>
</property>
<property name="text">
<string>选择文件</string>
</property>
</widget>
<widget class="QLabel" name="label_2">
<property name="geometry">
<rect>
<x>10</x>
<y>70</y>
<width>291</width>
<height>51</height>
</rect>
</property>
<property name="text">
<string>LaTeX文件中有一个enumerate环境.
每一个item后面有一个中括号包围的信息, 之后是内容.
例如: \item [K0101/K0101001B,K0101002B] 内容</string>
</property>
</widget>
<widget class="QPushButton" name="pushButton_exec">
<property name="geometry">
<rect>
<x>310</x>
<y>70</y>
<width>81</width>
<height>51</height>
</rect>
</property>
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>添加基础知识</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
</ui>