添加关联题目Qt重写, 并加入工具面板与Qt面板

This commit is contained in:
weiye.wang 2024-03-02 20:04:33 +08:00
parent e2d3d50252
commit 52fd239cb6
6 changed files with 294 additions and 23 deletions

View File

@ -28,7 +28,7 @@ class MyWindow(QMainWindow,Ui_MainWindow):
self.action_kxth.triggered.connect(lambda: run_command("寻找空闲题号",[]))
self.action_xtbd.triggered.connect(lambda: run_command("新题比对",[]))
self.action_plsl.triggered.connect(lambda: run_command("批量收录题目",[]))
self.action_tjgl.triggered.connect(lambda: run_command("添加关联题目",["添加关联题目.py"]))
self.action_tjgl.triggered.connect(lambda: run_command("添加关联题目",[]))
self.action_tjzd.triggered.connect(lambda: run_command("修改metadata",["文本文件/metadata.txt"]))
self.action_LaTeXedit.triggered.connect(lambda: run_command("LaTeX编辑题目答案及提示",["latex编辑题目答案及提示.py"]))
self.action_jsonedit.triggered.connect(lambda: run_command("json编辑题目综合信息",["json编辑题目综合信息.py"]))

View File

@ -0,0 +1,98 @@
# -*- 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, QHBoxLayout, QLabel, QLineEdit,
QPushButton, QSizePolicy, QVBoxLayout, QWidget)
class Ui_Form(object):
def setupUi(self, Form):
if not Form.objectName():
Form.setObjectName(u"Form")
Form.resize(351, 104)
self.pushButton_exec = QPushButton(Form)
self.pushButton_exec.setObjectName(u"pushButton_exec")
self.pushButton_exec.setGeometry(QRect(240, 10, 81, 81))
font = QFont()
font.setBold(True)
self.pushButton_exec.setFont(font)
self.widget = QWidget(Form)
self.widget.setObjectName(u"widget")
self.widget.setGeometry(QRect(30, 10, 196, 80))
self.verticalLayout = QVBoxLayout(self.widget)
self.verticalLayout.setObjectName(u"verticalLayout")
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout = QHBoxLayout()
self.horizontalLayout.setObjectName(u"horizontalLayout")
self.label = QLabel(self.widget)
self.label.setObjectName(u"label")
self.label.setMinimumSize(QSize(60, 0))
self.horizontalLayout.addWidget(self.label)
self.lineEdit_oldids = QLineEdit(self.widget)
self.lineEdit_oldids.setObjectName(u"lineEdit_oldids")
self.horizontalLayout.addWidget(self.lineEdit_oldids)
self.verticalLayout.addLayout(self.horizontalLayout)
self.horizontalLayout_2 = QHBoxLayout()
self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
self.label_2 = QLabel(self.widget)
self.label_2.setObjectName(u"label_2")
self.horizontalLayout_2.addWidget(self.label_2)
self.lineEdit_newid = QLineEdit(self.widget)
self.lineEdit_newid.setObjectName(u"lineEdit_newid")
self.horizontalLayout_2.addWidget(self.lineEdit_newid)
self.verticalLayout.addLayout(self.horizontalLayout_2)
self.horizontalLayout_3 = QHBoxLayout()
self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
self.label_3 = QLabel(self.widget)
self.label_3.setObjectName(u"label_3")
self.label_3.setMinimumSize(QSize(60, 0))
self.horizontalLayout_3.addWidget(self.label_3)
self.lineEdit_editor = QLineEdit(self.widget)
self.lineEdit_editor.setObjectName(u"lineEdit_editor")
self.horizontalLayout_3.addWidget(self.lineEdit_editor)
self.verticalLayout.addLayout(self.horizontalLayout_3)
self.retranslateUi(Form)
QMetaObject.connectSlotsByName(Form)
# setupUi
def retranslateUi(self, Form):
Form.setWindowTitle(QCoreApplication.translate("Form", u"\u6dfb\u52a0\u5173\u8054\u9898\u76ee", None))
self.pushButton_exec.setText(QCoreApplication.translate("Form", u"\u6dfb\u52a0\u5173\u8054\u9898\u76ee", None))
self.label.setText(QCoreApplication.translate("Form", u"\u65e7\u9898\u53f7", None))
self.label_2.setText(QCoreApplication.translate("Form", u"\u65b0\u8d77\u59cb\u9898\u53f7", None))
self.label_3.setText(QCoreApplication.translate("Form", u"\u7f16\u8f91\u8005", None))
# retranslateUi

View File

@ -71,7 +71,7 @@ menubar.add_cascade(label = "录入", menu = ImportMenu)
ImportMenu.add_command(label = "寻找空闲题号", command = lambda: SetButton("寻找空闲题号",[]))
ImportMenu.add_separator()
ImportMenu.add_command(label = "批量收录题目", command = lambda: SetButton("批量收录题目",[]))
ImportMenu.add_command(label = "添加关联题目", command = lambda: SetButton("添加关联题目",["添加关联题目.py"]))
ImportMenu.add_command(label = "添加关联题目", command = lambda: SetButton("添加关联题目",[]))
ImportMenu.add_separator()
ImportMenu.add_command(label = "新题比对", command = lambda: SetButton("新题比对",[]))

View File

@ -1,29 +1,70 @@
old_ids = "20462,20463" # 需要添加关联题目的id字符串
starting_id = "1" # 目的地的id字符串从这个位置后的首个空闲开始, 其中空闲位置需不少于old_ids中的题目数量 20040124修改
editor = "王伟叶" # 修改人姓名
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
from Ui_添加关联题目 import Ui_Form
from database_tools import *
tempfilepath = "临时文件/problem_edit.json"
pro_dict = load_dict("../题库0.3/problems.json")
obj_dict = load_dict("../题库0.3/LessonObj.json")
pro_dict_raw_string = ReadTextFile("../题库0.3/problems.json")
configjson = load_dict("文本文件/config.json")["默认完整编译题目模式"]
class MyWindow(QWidget,Ui_Form):
def __init__(self):
super().__init__()
self.setupUi(self)
self.bind()
def bind(self):
self.pushButton_exec.clicked.connect(self.exec)
def exec(self):
old_ids = self.lineEdit_oldids.text().replace("",",").replace("",":").strip() # 需要添加关联题目的id字符串
starting_id = self.lineEdit_newid.text().strip() # 目的地的id字符串从这个位置后的首个空闲开始, 其中空闲位置需不少于old_ids中的题目数量 20040124修改
editor = self.lineEdit_editor.text().strip() # 修改人姓名
links = CreateIDLinks(generate_number_set(old_ids),generate_number_set(NextSpareIDBlock(starting_id,pro_dict)),pro_dict)
CreateRelatedProblems(links,pro_dict,tempfilepath,editor)
print("编辑完毕后, 保存关闭文件继续.")
os.system("code -w -g "+tempfilepath) #-w表示关闭窗口后继续下一步
tempfilepath = "临时文件/problem_edit.json"
editedid_list = ImportRelatedProblems(tempfilepath,"../题库0.3/problems.json")
pro_dict = load_dict("../题库0.3/problems.json")
obj_dict = load_dict("../题库0.3/LessonObj.json")
pro_dict_raw_string = ReadTextFile("../题库0.3/problems.json")
configjson = {
"输出路径": "临时文件",
"教师版": True,
"字段显示设置": {
"题后空间": True,
"课时目标": True,
"题目标签": True,
"答案": True,
"解答与提示": True,
"使用记录": [3,-1],
"使用记录说明": "[a,b]表示显示最好的a个和最差b个, 有-2表示不显示, 无-2但有-1表示全部显示",
"来源": True,
"备注": True,
"届别": []
}
}
pro_dict = load_dict("../题库0.3/problems.json")
if not XeLaTeXTest(editedid_list,pro_dict,obj_dict,configjson,templatepath="模板文件/讲义模板.txt",outdir = "临时文件",outfile = "problems_test.tex"):
SaveTextFile(pro_dict_raw_string,"../题库0.3/Problems.json")
print("编译失败, 题库文件退回原状")
else:
print("编译成功, 已汇入题库")
links = CreateIDLinks(generate_number_set(old_ids),generate_number_set(NextSpareIDBlock(starting_id,pro_dict)),pro_dict)
CreateRelatedProblems(links,pro_dict,tempfilepath,editor)
print("编辑完毕后, 保存关闭文件继续.")
os.system("code -w -g "+tempfilepath) #-w表示关闭窗口后继续下一步
editedid_list = ImportRelatedProblems(tempfilepath,"../题库0.3/problems.json")
pro_dict = load_dict("../题库0.3/problems.json")
if not XeLaTeXTest(editedid_list,pro_dict,obj_dict,configjson,templatepath="模板文件/讲义模板.txt",outdir = "临时文件",outfile = "problems_test.tex"):
SaveTextFile(pro_dict_raw_string,"../题库0.3/Problems.json")
print("编译失败, 题库文件退回原状")
else:
print("编译成功, 已汇入题库")
self.close()
if __name__ == '__main__':
app = QApplication([])
windows = MyWindow()
windows.show()
app.exec()

View File

@ -0,0 +1,103 @@
<?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>351</width>
<height>104</height>
</rect>
</property>
<property name="windowTitle">
<string>添加关联题目</string>
</property>
<widget class="QPushButton" name="pushButton_exec">
<property name="geometry">
<rect>
<x>240</x>
<y>10</y>
<width>81</width>
<height>81</height>
</rect>
</property>
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>添加关联题目</string>
</property>
</widget>
<widget class="QWidget" name="">
<property name="geometry">
<rect>
<x>30</x>
<y>10</y>
<width>196</width>
<height>80</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label">
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>旧题号</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_oldids"/>
</item>
</layout>
</item>
<item>
<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_newid"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label_3">
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="text">
<string>编辑者</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="lineEdit_editor"/>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -0,0 +1,29 @@
old_ids = "20462,20463" # 需要添加关联题目的id字符串
starting_id = "1" # 目的地的id字符串从这个位置后的首个空闲开始, 其中空闲位置需不少于old_ids中的题目数量 20040124修改
editor = "王伟叶" # 修改人姓名
from database_tools import *
tempfilepath = "临时文件/problem_edit.json"
pro_dict = load_dict("../题库0.3/problems.json")
obj_dict = load_dict("../题库0.3/LessonObj.json")
pro_dict_raw_string = ReadTextFile("../题库0.3/problems.json")
configjson = load_dict("文本文件/config.json")["默认完整编译题目模式"]
links = CreateIDLinks(generate_number_set(old_ids),generate_number_set(NextSpareIDBlock(starting_id,pro_dict)),pro_dict)
CreateRelatedProblems(links,pro_dict,tempfilepath,editor)
print("编辑完毕后, 保存关闭文件继续.")
os.system("code -w -g "+tempfilepath) #-w表示关闭窗口后继续下一步
editedid_list = ImportRelatedProblems(tempfilepath,"../题库0.3/problems.json")
pro_dict = load_dict("../题库0.3/problems.json")
if not XeLaTeXTest(editedid_list,pro_dict,obj_dict,configjson,templatepath="模板文件/讲义模板.txt",outdir = "临时文件",outfile = "problems_test.tex"):
SaveTextFile(pro_dict_raw_string,"../题库0.3/Problems.json")
print("编译失败, 题库文件退回原状")
else:
print("编译成功, 已汇入题库")