完成编辑题目(latex,json)的Qt widget并在Qt面板, 工具面板上更新

This commit is contained in:
weiye.wang 2024-03-02 20:52:04 +08:00
parent 42ff59127a
commit de216100a0
7 changed files with 261 additions and 31 deletions

View File

@ -30,8 +30,7 @@ class MyWindow(QMainWindow,Ui_MainWindow):
self.action_plsl.triggered.connect(lambda: run_command("批量收录题目",[]))
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"]))
self.action_bjtm.triggered.connect(lambda: run_command("编辑题目信息",[]))
self.action_xxdr.triggered.connect(lambda: run_command("获取小闲平台使用数据",[]))
self.action_sddr.triggered.connect(lambda: run_command("手动统计结果导入",["临时文件/手动统计结果.txt"]))
self.action_tkdr.triggered.connect(lambda: run_command("统考数据导入",["统考数据导入.py"]))

View File

@ -38,16 +38,9 @@
<property name="title">
<string>维护</string>
</property>
<widget class="QMenu" name="menu">
<property name="title">
<string>编辑题目</string>
</property>
<addaction name="action_LaTeXedit"/>
<addaction name="action_jsonedit"/>
</widget>
<addaction name="action_tjzd"/>
<addaction name="separator"/>
<addaction name="menu"/>
<addaction name="action_bjtm"/>
<addaction name="separator"/>
<addaction name="action_xxdr"/>
<addaction name="action_sddr"/>
@ -213,14 +206,9 @@
<string>多选转填空</string>
</property>
</action>
<action name="action_LaTeXedit">
<action name="action_bjtm">
<property name="text">
<string>LaTeX</string>
</property>
</action>
<action name="action_jsonedit">
<property name="text">
<string>json</string>
<string>编辑题目</string>
</property>
</action>
</widget>

View File

@ -68,10 +68,8 @@ class Ui_MainWindow(object):
self.action_dqsz.setObjectName(u"action_dqsz")
self.action_dxtk = QAction(MainWindow)
self.action_dxtk.setObjectName(u"action_dxtk")
self.action_LaTeXedit = QAction(MainWindow)
self.action_LaTeXedit.setObjectName(u"action_LaTeXedit")
self.action_jsonedit = QAction(MainWindow)
self.action_jsonedit.setObjectName(u"action_jsonedit")
self.action_bjtm = QAction(MainWindow)
self.action_bjtm.setObjectName(u"action_bjtm")
self.centralwidget = QWidget(MainWindow)
self.centralwidget.setObjectName(u"centralwidget")
MainWindow.setCentralWidget(self.centralwidget)
@ -82,8 +80,6 @@ class Ui_MainWindow(object):
self.menu_luru.setObjectName(u"menu_luru")
self.menu_weihu = QMenu(self.menubar)
self.menu_weihu.setObjectName(u"menu_weihu")
self.menu = QMenu(self.menu_weihu)
self.menu.setObjectName(u"menu")
self.menu_shiyong = QMenu(self.menubar)
self.menu_shiyong.setObjectName(u"menu_shiyong")
self.menu_beikezu = QMenu(self.menubar)
@ -111,7 +107,7 @@ class Ui_MainWindow(object):
self.menu_luru.addAction(self.action_tjgl)
self.menu_weihu.addAction(self.action_tjzd)
self.menu_weihu.addSeparator()
self.menu_weihu.addAction(self.menu.menuAction())
self.menu_weihu.addAction(self.action_bjtm)
self.menu_weihu.addSeparator()
self.menu_weihu.addAction(self.action_xxdr)
self.menu_weihu.addAction(self.action_sddr)
@ -124,8 +120,6 @@ class Ui_MainWindow(object):
self.menu_weihu.addAction(self.action_hbsy)
self.menu_weihu.addSeparator()
self.menu_weihu.addAction(self.action_tjjc)
self.menu.addAction(self.action_LaTeXedit)
self.menu.addAction(self.action_jsonedit)
self.menu_shiyong.addAction(self.action_sxth)
self.menu_shiyong.addSeparator()
self.menu_shiyong.addAction(self.action_xtby)
@ -170,11 +164,9 @@ class Ui_MainWindow(object):
self.action_mtpx.setText(QCoreApplication.translate("MainWindow", u"mathpix\u9884\u5904\u7406", None))
self.action_dqsz.setText(QCoreApplication.translate("MainWindow", u"\u62ec\u53f7\u6570\u5b57\u53d8\u4e3a\u5e26\u5708\u6570\u5b57", None))
self.action_dxtk.setText(QCoreApplication.translate("MainWindow", u"\u591a\u9009\u8f6c\u586b\u7a7a", None))
self.action_LaTeXedit.setText(QCoreApplication.translate("MainWindow", u"LaTeX", None))
self.action_jsonedit.setText(QCoreApplication.translate("MainWindow", u"json", None))
self.action_bjtm.setText(QCoreApplication.translate("MainWindow", u"\u7f16\u8f91\u9898\u76ee", None))
self.menu_luru.setTitle(QCoreApplication.translate("MainWindow", u"\u5f55\u5165", None))
self.menu_weihu.setTitle(QCoreApplication.translate("MainWindow", u"\u7ef4\u62a4", None))
self.menu.setTitle(QCoreApplication.translate("MainWindow", u"\u7f16\u8f91\u9898\u76ee", None))
self.menu_shiyong.setTitle(QCoreApplication.translate("MainWindow", u"\u4f7f\u7528", None))
self.menu_beikezu.setTitle(QCoreApplication.translate("MainWindow", u"\u5907\u8bfe\u7ec4", None))
self.menu_latex.setTitle(QCoreApplication.translate("MainWindow", u"LaTeX\u4ee3\u7801\u76f8\u5173", None))

View File

@ -0,0 +1,103 @@
# -*- 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, QRadioButton, QSizePolicy, QVBoxLayout,
QWidget)
class Ui_Form(object):
def setupUi(self, Form):
if not Form.objectName():
Form.setObjectName(u"Form")
Form.resize(390, 72)
self.pushButton_exec = QPushButton(Form)
self.pushButton_exec.setObjectName(u"pushButton_exec")
self.pushButton_exec.setGeometry(QRect(310, 10, 71, 51))
font = QFont()
font.setBold(True)
self.pushButton_exec.setFont(font)
self.widget = QWidget(Form)
self.widget.setObjectName(u"widget")
self.widget.setGeometry(QRect(10, 10, 292, 54))
self.horizontalLayout_3 = QHBoxLayout(self.widget)
self.horizontalLayout_3.setObjectName(u"horizontalLayout_3")
self.horizontalLayout_3.setContentsMargins(0, 0, 0, 0)
self.verticalLayout_2 = QVBoxLayout()
self.verticalLayout_2.setObjectName(u"verticalLayout_2")
self.horizontalLayout = QHBoxLayout()
self.horizontalLayout.setObjectName(u"horizontalLayout")
self.label = QLabel(self.widget)
self.label.setObjectName(u"label")
self.horizontalLayout.addWidget(self.label)
self.lineEdit_id = QLineEdit(self.widget)
self.lineEdit_id.setObjectName(u"lineEdit_id")
self.horizontalLayout.addWidget(self.lineEdit_id)
self.verticalLayout_2.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_editor = QLineEdit(self.widget)
self.lineEdit_editor.setObjectName(u"lineEdit_editor")
self.horizontalLayout_2.addWidget(self.lineEdit_editor)
self.verticalLayout_2.addLayout(self.horizontalLayout_2)
self.horizontalLayout_3.addLayout(self.verticalLayout_2)
self.verticalLayout = QVBoxLayout()
self.verticalLayout.setObjectName(u"verticalLayout")
self.radioButton_latex = QRadioButton(self.widget)
self.radioButton_latex.setObjectName(u"radioButton_latex")
self.verticalLayout.addWidget(self.radioButton_latex)
self.radioButton_json = QRadioButton(self.widget)
self.radioButton_json.setObjectName(u"radioButton_json")
self.verticalLayout.addWidget(self.radioButton_json)
self.horizontalLayout_3.addLayout(self.verticalLayout)
self.retranslateUi(Form)
QMetaObject.connectSlotsByName(Form)
# setupUi
def retranslateUi(self, Form):
Form.setWindowTitle(QCoreApplication.translate("Form", u"\u7f16\u8f91\u9898\u76ee\u4fe1\u606f", None))
self.pushButton_exec.setText(QCoreApplication.translate("Form", u"\u5f00\u59cb\u7f16\u8f91", None))
self.label.setText(QCoreApplication.translate("Form", u"\u5f85\u4fee\u6539ID", None))
self.label_2.setText(QCoreApplication.translate("Form", u"\u7f16\u8f91\u8005", None))
self.radioButton_latex.setText(QCoreApplication.translate("Form", u"LaTeX\u6a21\u5f0f", None))
self.radioButton_json.setText(QCoreApplication.translate("Form", u"json\u6a21\u5f0f", None))
# retranslateUi

View File

@ -81,8 +81,7 @@ MaintainenceMenu = Menu(menubar, tearoff = False)
menubar.add_cascade(label = "维护", menu = MaintainenceMenu)
MaintainenceMenu.add_command(label = "批量添加字段数据", command = lambda: SetButton("修改metadata",["文本文件/metadata.txt"]))
MaintainenceMenu.add_separator()
MaintainenceMenu.add_command(label = "LaTeX编辑题目答案及提示", command = lambda: SetButton("LaTeX编辑题目答案及提示",["latex编辑题目答案及提示.py"]))
MaintainenceMenu.add_command(label = "json编辑题目综合信息", command = lambda: SetButton("json编辑题目综合信息",["json编辑题目综合信息.py"]))
MaintainenceMenu.add_command(label = "编辑题目", command = lambda: SetButton("编辑题目信息",[]))
MaintainenceMenu.add_separator()
MaintainenceMenu.add_command(label = "合并使用记录并排序", command = lambda: SetButton("合并使用记录并排序",[]))
MaintainenceMenu.add_separator()

View File

@ -0,0 +1,50 @@
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
from Ui_编辑题目信息 import Ui_Form
from database_tools import *
class MyWindow(QWidget,Ui_Form):
def __init__(self):
super().__init__()
self.setupUi(self)
self.bind()
def bind(self):
self.radioButton_latex.setChecked(True)
self.pushButton_exec.clicked.connect(self.exec)
def exec(self):
id_string = self.lineEdit_id.text()
editor = self.lineEdit_editor.text()
prodictpath = "../题库0.3/Problems.json"
pro_dict = load_dict(prodictpath)
obj_dict = load_dict("../题库0.3/LessonObj.json")
pro_dict_raw_string = ReadTextFile(prodictpath)
configjson = BuildFullScheme
if self.radioButton_latex.isChecked():
tempfilepath = "临时文件/problem_edit.tex"
edited = ModifyProblembyTeX(id_string,pro_dict,tempfilepath,editor)
else:
edited = jsonEditProblemMetadata(id_string,pro_dict,editor)
save_dict(pro_dict,prodictpath)
print(f"编辑过的题号: {edited}")
if edited != "无有效题号":
if not XeLaTeXTest(edited,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,99 @@
<?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>390</width>
<height>72</height>
</rect>
</property>
<property name="windowTitle">
<string>编辑题目信息</string>
</property>
<widget class="QPushButton" name="pushButton_exec">
<property name="geometry">
<rect>
<x>310</x>
<y>10</y>
<width>71</width>
<height>51</height>
</rect>
</property>
<property name="font">
<font>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>开始编辑</string>
</property>
</widget>
<widget class="QWidget" name="layoutWidget">
<property name="geometry">
<rect>
<x>10</x>
<y>10</y>
<width>292</width>
<height>54</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<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_id"/>
</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_editor"/>
</item>
</layout>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QRadioButton" name="radioButton_latex">
<property name="text">
<string>LaTeX模式</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="radioButton_json">
<property name="text">
<string>json模式</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
<resources/>
<connections/>
</ui>