迁移 添加关联题目
This commit is contained in:
parent
fe29401dc3
commit
62b401554e
|
|
@ -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(760, 490)
|
||||||
|
self.pushButton_exec = QPushButton(Form)
|
||||||
|
self.pushButton_exec.setObjectName(u"pushButton_exec")
|
||||||
|
self.pushButton_exec.setGeometry(QRect(460, 120, 81, 81))
|
||||||
|
font = QFont()
|
||||||
|
font.setBold(True)
|
||||||
|
self.pushButton_exec.setFont(font)
|
||||||
|
self.layoutWidget = QWidget(Form)
|
||||||
|
self.layoutWidget.setObjectName(u"layoutWidget")
|
||||||
|
self.layoutWidget.setGeometry(QRect(250, 120, 196, 80))
|
||||||
|
self.verticalLayout = QVBoxLayout(self.layoutWidget)
|
||||||
|
self.verticalLayout.setObjectName(u"verticalLayout")
|
||||||
|
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
|
||||||
|
self.horizontalLayout = QHBoxLayout()
|
||||||
|
self.horizontalLayout.setObjectName(u"horizontalLayout")
|
||||||
|
self.label = QLabel(self.layoutWidget)
|
||||||
|
self.label.setObjectName(u"label")
|
||||||
|
self.label.setMinimumSize(QSize(60, 0))
|
||||||
|
|
||||||
|
self.horizontalLayout.addWidget(self.label)
|
||||||
|
|
||||||
|
self.lineEdit_oldids = QLineEdit(self.layoutWidget)
|
||||||
|
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.layoutWidget)
|
||||||
|
self.label_2.setObjectName(u"label_2")
|
||||||
|
|
||||||
|
self.horizontalLayout_2.addWidget(self.label_2)
|
||||||
|
|
||||||
|
self.lineEdit_newid = QLineEdit(self.layoutWidget)
|
||||||
|
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.layoutWidget)
|
||||||
|
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.layoutWidget)
|
||||||
|
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
|
||||||
|
|
||||||
|
|
@ -398,7 +398,7 @@ def NextSpareIDBlock(num,database): #返回adict中下一个空闲的题号块
|
||||||
mycursor = mydb.cursor()
|
mycursor = mydb.cursor()
|
||||||
mycursor.execute("SELECT ID FROM problems;")
|
mycursor.execute("SELECT ID FROM problems;")
|
||||||
idlist = [ret[0] for ret in mycursor.fetchall()]
|
idlist = [ret[0] for ret in mycursor.fetchall()]
|
||||||
start = NextSpareID(num)
|
start = NextSpareID(num,database)
|
||||||
larger_ID_list = [int(id) for id in idlist if int(id)>start]
|
larger_ID_list = [int(id) for id in idlist if int(id)>start]
|
||||||
if larger_ID_list == []:
|
if larger_ID_list == []:
|
||||||
end = 999999
|
end = 999999
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ from 单一题号转为图片 import MyWindow_sctp
|
||||||
from 指定题号编译pdf import MyWindow_xtby
|
from 指定题号编译pdf import MyWindow_xtby
|
||||||
from 根据正确率选择题号 import MyWindow_ndsx
|
from 根据正确率选择题号 import MyWindow_ndsx
|
||||||
from 关键字筛选题号 import MyWindow_sxth
|
from 关键字筛选题号 import MyWindow_sxth
|
||||||
|
from 添加关联题目 import MyWindow_tjgl
|
||||||
from database_tools_2 import *
|
from database_tools_2 import *
|
||||||
|
|
||||||
class MyWindow(QMainWindow,Ui_MainWindow):
|
class MyWindow(QMainWindow,Ui_MainWindow):
|
||||||
|
|
@ -27,6 +28,14 @@ class MyWindow(QMainWindow,Ui_MainWindow):
|
||||||
self.pushButton_tiku.clicked.connect(self.SelectTIKU)
|
self.pushButton_tiku.clicked.connect(self.SelectTIKU)
|
||||||
self.pushButton_tikutest.clicked.connect(self.SelectTIKUTEST) #以上为设置当前数据库的两个按钮
|
self.pushButton_tikutest.clicked.connect(self.SelectTIKUTEST) #以上为设置当前数据库的两个按钮
|
||||||
|
|
||||||
|
self.layout_kxth = QVBoxLayout(self.tab_kxth)
|
||||||
|
self.kxth = MyWindow_kxth(self.database)
|
||||||
|
self.layout_kxth.addWidget(self.kxth) #以上三行为初始化“空闲题号”tab
|
||||||
|
|
||||||
|
self.layout_tjgl = QVBoxLayout(self.tab_tjgl)
|
||||||
|
self.tjgl = MyWindow_tjgl(self.database)
|
||||||
|
self.layout_tjgl.addWidget(self.tjgl) #以上三行为初始化“添加关联”tab
|
||||||
|
|
||||||
|
|
||||||
self.layout_sxth = QVBoxLayout(self.tab_sxth)
|
self.layout_sxth = QVBoxLayout(self.tab_sxth)
|
||||||
self.sxth = MyWindow_sxth(self.database)
|
self.sxth = MyWindow_sxth(self.database)
|
||||||
|
|
@ -44,10 +53,6 @@ class MyWindow(QMainWindow,Ui_MainWindow):
|
||||||
self.sctp = MyWindow_sctp(self.database)
|
self.sctp = MyWindow_sctp(self.database)
|
||||||
self.layout_sctp.addWidget(self.sctp) #以上三行为初始化“生成图片”tab
|
self.layout_sctp.addWidget(self.sctp) #以上三行为初始化“生成图片”tab
|
||||||
|
|
||||||
self.layout_kxth = QVBoxLayout(self.tab_kxth)
|
|
||||||
self.kxth = MyWindow_kxth(self.database)
|
|
||||||
self.layout_kxth.addWidget(self.kxth) #以上三行为初始化“空闲题号”tab
|
|
||||||
|
|
||||||
self.layout_hqth = QVBoxLayout(self.tab_hqth)
|
self.layout_hqth = QVBoxLayout(self.tab_hqth)
|
||||||
self.hqth = MyWindow_hqth()
|
self.hqth = MyWindow_hqth()
|
||||||
self.layout_hqth.addWidget(self.hqth) #以上三行为初始化“获取题号”tab
|
self.layout_hqth.addWidget(self.hqth) #以上三行为初始化“获取题号”tab
|
||||||
|
|
@ -80,7 +85,8 @@ class MyWindow(QMainWindow,Ui_MainWindow):
|
||||||
self.sctp.setdbname,
|
self.sctp.setdbname,
|
||||||
self.xtby.setdbname,
|
self.xtby.setdbname,
|
||||||
self.ndsx.setdbname,
|
self.ndsx.setdbname,
|
||||||
self.sxth.setdbname
|
self.sxth.setdbname,
|
||||||
|
self.tjgl.setdbname
|
||||||
]: #在列表中的tab里传送数据库名的连接
|
]: #在列表中的tab里传送数据库名的连接
|
||||||
self.sendDBname.connect(func)
|
self.sendDBname.connect(func)
|
||||||
def sendValue(self):
|
def sendValue(self):
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
|
||||||
|
from Ui_添加关联题目 import Ui_Form
|
||||||
|
from database_tools_2 import *
|
||||||
|
|
||||||
|
class MyWindow_tjgl(QWidget,Ui_Form):
|
||||||
|
def __init__(self,database_name):
|
||||||
|
super().__init__()
|
||||||
|
self.database_name = database_name
|
||||||
|
self.setupUi(self)
|
||||||
|
self.bind()
|
||||||
|
def setdbname(self,string):
|
||||||
|
self.database_name = string
|
||||||
|
# print(self.database_name)
|
||||||
|
def bind(self):
|
||||||
|
self.pushButton_exec.clicked.connect(self.exec)
|
||||||
|
|
||||||
|
def exec(self):
|
||||||
|
old_ids = RefinePunctuations(self.lineEdit_oldids.text()).strip() # 需要添加关联题目的id字符串
|
||||||
|
starting_id = self.lineEdit_newid.text().strip() # 目的地的id字符串从这个位置后的首个空闲开始, 其中空闲位置需不少于old_ids中的题目数量 20240124修改
|
||||||
|
editor = self.lineEdit_editor.text().strip() # 修改人姓名
|
||||||
|
new_ids = NextSpareIDBlock(starting_id,self.database_name)
|
||||||
|
links = CreateIDLinks(generate_number_set(old_ids),generate_number_set(new_ids))
|
||||||
|
bodydata = CreateRelatedProblems(links,self.database_name)
|
||||||
|
tempfilepath = "临时文件/problem_edit.tex"
|
||||||
|
latextemplate = "模板文件/题目编辑.txt"
|
||||||
|
latexdata = ReadTextFile(latextemplate)
|
||||||
|
latexdata = StringSubstitute("<<待替换>>",latexdata,(bodydata,))
|
||||||
|
SaveTextFile(latexdata,tempfilepath)
|
||||||
|
print("编辑完毕后, 保存关闭文件继续.")
|
||||||
|
os.system(f"code -w -g {tempfilepath}") #-w表示关闭窗口后继续下一步
|
||||||
|
if XeLaTeXCompile("临时文件",tempfilepath,times=1):
|
||||||
|
problems = GenerateProblemListFromString2024(ReadTextFile(tempfilepath))
|
||||||
|
for problem in problems:
|
||||||
|
id_and_content = problem[0]
|
||||||
|
oid = re.findall(r"^\((\d{6})->",id_and_content)[0]
|
||||||
|
id = re.findall(r"^\(\d{6}->(\d{6})\)",id_and_content)[0]
|
||||||
|
content = re.findall(r"->\d{6}\)([\S\s]*)$",id_and_content)[0].strip()
|
||||||
|
print(id,content)
|
||||||
|
AddRelatedProblemToDB(id,content,oid,editor,self.database_name)
|
||||||
|
print("编译成功, 已汇入题库")
|
||||||
|
else:
|
||||||
|
print("编译失败, 未汇入题库")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
app = QApplication([])
|
||||||
|
windows = MyWindow()
|
||||||
|
windows.show()
|
||||||
|
app.exec()
|
||||||
|
|
||||||
|
|
@ -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>760</width>
|
||||||
|
<height>490</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>添加关联题目</string>
|
||||||
|
</property>
|
||||||
|
<widget class="QPushButton" name="pushButton_exec">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>460</x>
|
||||||
|
<y>120</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="layoutWidget">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>250</x>
|
||||||
|
<y>120</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>
|
||||||
Reference in New Issue