diff --git a/工具v4/Ui_添加关联题目.py b/工具v4/Ui_添加关联题目.py new file mode 100644 index 00000000..61590250 --- /dev/null +++ b/工具v4/Ui_添加关联题目.py @@ -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 + diff --git a/工具v4/database_tools_2.py b/工具v4/database_tools_2.py index 9dbc80a6..35b4bdcc 100644 --- a/工具v4/database_tools_2.py +++ b/工具v4/database_tools_2.py @@ -398,7 +398,7 @@ def NextSpareIDBlock(num,database): #返回adict中下一个空闲的题号块 mycursor = mydb.cursor() mycursor.execute("SELECT ID FROM problems;") 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] if larger_ID_list == []: end = 999999 diff --git a/工具v4/tool_panel.py b/工具v4/tool_panel.py index 406c7c91..e1adba6f 100644 --- a/工具v4/tool_panel.py +++ b/工具v4/tool_panel.py @@ -12,6 +12,7 @@ from 单一题号转为图片 import MyWindow_sctp from 指定题号编译pdf import MyWindow_xtby from 根据正确率选择题号 import MyWindow_ndsx from 关键字筛选题号 import MyWindow_sxth +from 添加关联题目 import MyWindow_tjgl from database_tools_2 import * class MyWindow(QMainWindow,Ui_MainWindow): @@ -27,6 +28,14 @@ class MyWindow(QMainWindow,Ui_MainWindow): self.pushButton_tiku.clicked.connect(self.SelectTIKU) 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.sxth = MyWindow_sxth(self.database) @@ -44,10 +53,6 @@ class MyWindow(QMainWindow,Ui_MainWindow): self.sctp = MyWindow_sctp(self.database) 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.hqth = MyWindow_hqth() self.layout_hqth.addWidget(self.hqth) #以上三行为初始化“获取题号”tab @@ -80,7 +85,8 @@ class MyWindow(QMainWindow,Ui_MainWindow): self.sctp.setdbname, self.xtby.setdbname, self.ndsx.setdbname, - self.sxth.setdbname + self.sxth.setdbname, + self.tjgl.setdbname ]: #在列表中的tab里传送数据库名的连接 self.sendDBname.connect(func) def sendValue(self): diff --git a/工具v4/添加关联题目.py b/工具v4/添加关联题目.py new file mode 100644 index 00000000..6b277df6 --- /dev/null +++ b/工具v4/添加关联题目.py @@ -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() + diff --git a/工具v4/添加关联题目.ui b/工具v4/添加关联题目.ui new file mode 100644 index 00000000..66f5e8d0 --- /dev/null +++ b/工具v4/添加关联题目.ui @@ -0,0 +1,103 @@ + + + Form + + + + 0 + 0 + 760 + 490 + + + + 添加关联题目 + + + + + 460 + 120 + 81 + 81 + + + + + true + + + + 添加关联题目 + + + + + + 250 + 120 + 196 + 80 + + + + + + + + + + 60 + 0 + + + + 旧题号 + + + + + + + + + + + + + + 新起始题号 + + + + + + + + + + + + + + + 60 + 0 + + + + 编辑者 + + + + + + + + + + + + + +