diff --git a/工具v4/Ui_题号筛选器.py b/工具v4/Ui_题号筛选器.py new file mode 100644 index 00000000..0e0454c8 --- /dev/null +++ b/工具v4/Ui_题号筛选器.py @@ -0,0 +1,136 @@ +# -*- 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, QCheckBox, QFrame, QLCDNumber, + QLabel, QLineEdit, QPushButton, QSizePolicy, + QWidget) + +class Ui_Form(object): + def setupUi(self, Form): + if not Form.objectName(): + Form.setObjectName(u"Form") + Form.resize(760, 490) + Form.setWindowOpacity(1.000000000000000) + self.pushButton_content = QPushButton(Form) + self.pushButton_content.setObjectName(u"pushButton_content") + self.pushButton_content.setGeometry(QRect(120, 30, 75, 24)) + self.pushButton_obj = QPushButton(Form) + self.pushButton_obj.setObjectName(u"pushButton_obj") + self.pushButton_obj.setGeometry(QRect(120, 60, 75, 24)) + self.pushButton_tag = QPushButton(Form) + self.pushButton_tag.setObjectName(u"pushButton_tag") + self.pushButton_tag.setGeometry(QRect(120, 90, 75, 24)) + self.pushButton_usage = QPushButton(Form) + self.pushButton_usage.setObjectName(u"pushButton_usage") + self.pushButton_usage.setGeometry(QRect(120, 120, 75, 24)) + self.pushButton_origin = QPushButton(Form) + self.pushButton_origin.setObjectName(u"pushButton_origin") + self.pushButton_origin.setGeometry(QRect(120, 150, 75, 24)) + self.pushButton_genre = QPushButton(Form) + self.pushButton_genre.setObjectName(u"pushButton_genre") + self.pushButton_genre.setGeometry(QRect(120, 180, 75, 24)) + self.pushButton_ans = QPushButton(Form) + self.pushButton_ans.setObjectName(u"pushButton_ans") + self.pushButton_ans.setGeometry(QRect(120, 210, 75, 24)) + self.pushButton_solution = QPushButton(Form) + self.pushButton_solution.setObjectName(u"pushButton_solution") + self.pushButton_solution.setGeometry(QRect(120, 240, 75, 24)) + self.pushButton_same = QPushButton(Form) + self.pushButton_same.setObjectName(u"pushButton_same") + self.pushButton_same.setGeometry(QRect(120, 270, 75, 24)) + self.pushButton_related = QPushButton(Form) + self.pushButton_related.setObjectName(u"pushButton_related") + self.pushButton_related.setGeometry(QRect(120, 300, 75, 24)) + self.pushButton_remark = QPushButton(Form) + self.pushButton_remark.setObjectName(u"pushButton_remark") + self.pushButton_remark.setGeometry(QRect(120, 330, 75, 24)) + self.pushButton_exec = QPushButton(Form) + self.pushButton_exec.setObjectName(u"pushButton_exec") + self.pushButton_exec.setGeometry(QRect(490, 110, 161, 91)) + font = QFont() + font.setBold(True) + self.pushButton_exec.setFont(font) + self.pushButton_undo = QPushButton(Form) + self.pushButton_undo.setObjectName(u"pushButton_undo") + self.pushButton_undo.setGeometry(QRect(120, 380, 75, 24)) + self.pushButton_clearAll = QPushButton(Form) + self.pushButton_clearAll.setObjectName(u"pushButton_clearAll") + self.pushButton_clearAll.setGeometry(QRect(120, 410, 75, 24)) + self.label_conditions = QLabel(Form) + self.label_conditions.setObjectName(u"label_conditions") + self.label_conditions.setGeometry(QRect(220, 110, 261, 331)) + self.label_conditions.setFrameShape(QFrame.StyledPanel) + self.label_conditions.setAlignment(Qt.AlignLeading|Qt.AlignLeft|Qt.AlignTop) + self.label_conditions.setWordWrap(False) + self.label = QLabel(Form) + self.label.setObjectName(u"label") + self.label.setGeometry(QRect(220, 90, 71, 16)) + self.checkBox_not = QCheckBox(Form) + self.checkBox_not.setObjectName(u"checkBox_not") + self.checkBox_not.setGeometry(QRect(380, 30, 111, 20)) + self.lineEdit_SingleCondition = QLineEdit(Form) + self.lineEdit_SingleCondition.setObjectName(u"lineEdit_SingleCondition") + self.lineEdit_SingleCondition.setGeometry(QRect(220, 60, 261, 20)) + self.label_2 = QLabel(Form) + self.label_2.setObjectName(u"label_2") + self.label_2.setGeometry(QRect(220, 30, 151, 16)) + self.label_3 = QLabel(Form) + self.label_3.setObjectName(u"label_3") + self.label_3.setGeometry(QRect(490, 30, 91, 16)) + self.lcdNumber_resCount = QLCDNumber(Form) + self.lcdNumber_resCount.setObjectName(u"lcdNumber_resCount") + self.lcdNumber_resCount.setGeometry(QRect(490, 50, 161, 51)) + self.lcdNumber_resCount.setDigitCount(6) + self.lcdNumber_resCount.setProperty("value", 0.000000000000000) + self.pushButton_savebuild = QPushButton(Form) + self.pushButton_savebuild.setObjectName(u"pushButton_savebuild") + self.pushButton_savebuild.setGeometry(QRect(490, 240, 161, 201)) + self.pushButton_savebuild.setFont(font) + self.checkBox_Detailed = QCheckBox(Form) + self.checkBox_Detailed.setObjectName(u"checkBox_Detailed") + self.checkBox_Detailed.setGeometry(QRect(490, 210, 79, 20)) + + self.retranslateUi(Form) + + QMetaObject.connectSlotsByName(Form) + # setupUi + + def retranslateUi(self, Form): + Form.setWindowTitle(QCoreApplication.translate("Form", u"\u9898\u53f7\u7b5b\u9009\u5668", None)) + self.pushButton_content.setText(QCoreApplication.translate("Form", u"\u5185\u5bb9", None)) + self.pushButton_obj.setText(QCoreApplication.translate("Form", u"\u76ee\u6807\u7f16\u53f7", None)) + self.pushButton_tag.setText(QCoreApplication.translate("Form", u"\u6807\u7b7e", None)) + self.pushButton_usage.setText(QCoreApplication.translate("Form", u"\u4f7f\u7528\u8bb0\u5f55", None)) + self.pushButton_origin.setText(QCoreApplication.translate("Form", u"\u51fa\u5904", None)) + self.pushButton_genre.setText(QCoreApplication.translate("Form", u"\u9898\u76ee\u7c7b\u578b", None)) + self.pushButton_ans.setText(QCoreApplication.translate("Form", u"\u7b54\u6848", None)) + self.pushButton_solution.setText(QCoreApplication.translate("Form", u"\u89e3\u7b54\u4e0e\u63d0\u793a", None)) + self.pushButton_same.setText(QCoreApplication.translate("Form", u"\u76f8\u540c\u9898\u53f7", None)) + self.pushButton_related.setText(QCoreApplication.translate("Form", u"\u76f8\u5173\u9898\u53f7", None)) + self.pushButton_remark.setText(QCoreApplication.translate("Form", u"\u5907\u6ce8", None)) + self.pushButton_exec.setText(QCoreApplication.translate("Form", u"\u8fd0\u884c", None)) + self.pushButton_undo.setText(QCoreApplication.translate("Form", u"\u64a4\u9500\u4e0a\u4e00\u4e2a", None)) + self.pushButton_clearAll.setText(QCoreApplication.translate("Form", u"\u6e05\u9664", None)) + self.label_conditions.setText("") + self.label.setText(QCoreApplication.translate("Form", u"\u5f53\u524d\u6761\u4ef6:", None)) + self.checkBox_not.setText(QCoreApplication.translate("Form", u"\u9009\u4e2d\u8868\u793a\u4e0d\u5305\u542b", None)) + self.label_2.setText(QCoreApplication.translate("Form", u"\u8f93\u5165\u6761\u4ef6, \u7528\",\"\u5206\u9694\u8868\u793a\"\u6216\"", None)) + self.label_3.setText(QCoreApplication.translate("Form", u"\u7b5b\u9009\u7ed3\u679c\u6570\u76ee:", None)) + self.pushButton_savebuild.setText(QCoreApplication.translate("Form", u"\u4fdd\u5b58\u548c\u7f16\u8bd1", None)) + self.checkBox_Detailed.setText(QCoreApplication.translate("Form", u"\u8be6\u7ec6\u4fe1\u606f", None)) + # retranslateUi + diff --git a/工具v4/tool_panel.py b/工具v4/tool_panel.py index aab5ebf3..406c7c91 100644 --- a/工具v4/tool_panel.py +++ b/工具v4/tool_panel.py @@ -11,6 +11,7 @@ from 获取题号 import MyWindow_hqth from 单一题号转为图片 import MyWindow_sctp from 指定题号编译pdf import MyWindow_xtby from 根据正确率选择题号 import MyWindow_ndsx +from 关键字筛选题号 import MyWindow_sxth from database_tools_2 import * class MyWindow(QMainWindow,Ui_MainWindow): @@ -26,9 +27,14 @@ class MyWindow(QMainWindow,Ui_MainWindow): self.pushButton_tiku.clicked.connect(self.SelectTIKU) self.pushButton_tikutest.clicked.connect(self.SelectTIKUTEST) #以上为设置当前数据库的两个按钮 + + self.layout_sxth = QVBoxLayout(self.tab_sxth) + self.sxth = MyWindow_sxth(self.database) + self.layout_sxth.addWidget(self.sxth) #以上三行为初始化“关键字筛选”tab + self.layout_ndsx = QVBoxLayout(self.tab_ndsx) self.ndsx = MyWindow_ndsx(self.database) - self.layout_ndsx.addWidget(self.ndsx) #以上三行为初始化“选题编译”tab + self.layout_ndsx.addWidget(self.ndsx) #以上三行为初始化“按难度筛选”tab self.layout_xtby = QVBoxLayout(self.tab_xtby) self.xtby = MyWindow_xtby(self.database) @@ -73,7 +79,8 @@ class MyWindow(QMainWindow,Ui_MainWindow): self.jysc.setdbname, self.sctp.setdbname, self.xtby.setdbname, - self.ndsx.setdbname + self.ndsx.setdbname, + self.sxth.setdbname ]: #在列表中的tab里传送数据库名的连接 self.sendDBname.connect(func) def sendValue(self): diff --git a/工具v4/关键字筛选题号.py b/工具v4/关键字筛选题号.py new file mode 100644 index 00000000..c843da18 --- /dev/null +++ b/工具v4/关键字筛选题号.py @@ -0,0 +1,148 @@ +from PySide6.QtWidgets import QWidget, QApplication, QLineEdit +from Ui_题号筛选器 import Ui_Form +from database_tools_2 import * +import time,os + +class MyWindow_sxth(QWidget,Ui_Form): + def __init__(self,database_name): + super().__init__() + self.database_name = database_name + self.setupUi(self) + self.conditions = [] + mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = self.database_name) + mycursor = mydb.cursor() + mycursor.execute("SELECT count(*) FROM problems WHERE NOT content REGEXP 'OBS';") + self.lcdNumber_resCount.display(mycursor.fetchall()[0][0]) + self.bind() + def setdbname(self,string): + self.database_name = string + print(self.database_name) + def bind(self): + self.pushButton_content.clicked.connect(lambda: self.add_content("content")) + self.pushButton_obj.clicked.connect(lambda: self.add_content("objs")) + self.pushButton_tag.clicked.connect(lambda: self.add_content("tags")) + self.pushButton_usage.clicked.connect(lambda: self.add_content("usages")) + self.pushButton_origin.clicked.connect(lambda: self.add_content("origin")) + self.pushButton_genre.clicked.connect(lambda: self.add_content("genre")) + self.pushButton_ans.clicked.connect(lambda: self.add_content("ans")) + self.pushButton_solution.clicked.connect(lambda: self.add_content("solution")) + self.pushButton_same.clicked.connect(lambda: self.add_content("same")) + self.pushButton_related.clicked.connect(lambda: self.add_content("related")) + self.pushButton_remark.clicked.connect(lambda: self.add_content("remark")) + self.pushButton_undo.clicked.connect(self.undolast) + self.pushButton_clearAll.clicked.connect(self.clearConditions) + self.pushButton_exec.clicked.connect(self.exec) + self.pushButton_savebuild.clicked.connect(self.build) + + + + def add_content(self,field): + self.conditions.append((field,self.checkBox_not.isChecked(),self.lineEdit_SingleCondition.text())) + self.showConditions() + def undolast(self): + self.conditions = self.conditions[:-1].copy() + self.showConditions() + def clearConditions(self): + self.conditions = [] + self.showConditions() + def showConditions(self): + text = "" + for cond in self.conditions: + field, flag_not, matchexp = cond + text += f"字段 {field} 中{'没有' if flag_not else '有 '}{' 或 '.join([t.strip() for t in matchexp.split(',')])}\n" + self.label_conditions.setText(text) + def exec(self): + self.matchlist = MatchConditioninMariaDB(self.conditions,self.database_name) + self.lcdNumber_resCount.display(len(self.matchlist)) + + def build(self): + idlist = sorted(list(self.matchlist)) + exp = generate_exp(idlist) + try: + AppendTextFile(f"\n{time.ctime()}\n{exp}\n","临时文件/题号筛选.txt") + except: + SaveTextFile(f"{time.ctime()}\n{exp}\n","临时文件/题号筛选.txt") + configjson_detailed = { + "pdf标题": "筛选题目编译", + "教师版": True, + "字段显示设置": { + "题后空间": True, + "课时目标": True, + "题目标签": True, + "答案": True, + "解答与提示": True, + "使用记录": [3,-1], + "使用记录说明": "[a,b]表示显示最好的a个和最差b个, 有-2表示不显示, 无-2但有-1表示全部显示", + "来源": True, + "备注": True, + "届别": [] + } + } + configjson_simple = { + "pdf标题": "筛选题目编译", + "教师版": False, + "字段显示设置": { + "题后空间": True, + "课时目标": True, + "题目标签": True, + "答案": True, + "解答与提示": True, + "使用记录": [3,-1], + "使用记录说明": "[a,b]表示显示最好的a个和最差b个, 有-2表示不显示, 无-2但有-1表示全部显示", + "来源": True, + "备注": True, + "届别": [] + } + } + + if self.checkBox_Detailed.isChecked(): + configjson = configjson_detailed + else: + configjson = configjson_simple + + + notetitle = configjson["pdf标题"] + outputdir = "临时文件" #输出文件的目录 + outputfilepath = os.path.join(outputdir,notetitle+".tex") + print("输出文件目录: %s\n输出文件名: %s"%(os.path.join(os.getcwd(),outputdir),notetitle+".tex")) + + latex_raw = ReadTextFile("模板文件/讲义模板.txt") + if configjson["教师版"] == True: + latex_raw = latex_raw.replace(r"学号\blank{50} \ 姓名\blank{80}","上海市控江中学") + + if sys.platform != "win32": #非win系统用默认字体 + latex_raw = re.sub(r"fontset[\s]*=[\s]*none","fontset = fandol",latex_raw) + latex_raw = re.sub(r"\\setCJKmainfont",r"% \\setCJKmainfont",latex_raw) + starttime = time.time() + mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = self.database_name) + mycursor = mydb.cursor() + bodystring = "\\begin{enumerate}\n\n" + for id in generate_number_set(exp): + bodystring += generateLaTeXBodyContentfromMariaDB(mycursor,id,configjson) + bodystring += "\\end{enumerate}\n\n" + + midtime = time.time() + print(f"生成LaTeX文件所花时间: {midtime-starttime:.3f}秒") + + latex_data = StringSubstitute(r"<<[\s\S]*?待替换[\s\S]*?>>",latex_raw,(notetitle,bodystring)) #替换标题和bodystring + SaveTextFile(latex_data,outputfilepath) #保存.tex文件 + + if XeLaTeXCompile(outputdir,notetitle+".tex"): + print("编译成功") + else: + print("编译失败") + + endtime = time.time() + print(f"生成pdf文件所花时间: {endtime-midtime:.3f}秒") + os.system("code 临时文件/题号筛选.txt") + startfile("临时文件") + + + + +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..ae0d78a0 --- /dev/null +++ b/工具v4/题号筛选器.ui @@ -0,0 +1,340 @@ + + + Form + + + + 0 + 0 + 760 + 490 + + + + 题号筛选器 + + + 1.000000000000000 + + + + + 120 + 30 + 75 + 24 + + + + 内容 + + + + + + 120 + 60 + 75 + 24 + + + + 目标编号 + + + + + + 120 + 90 + 75 + 24 + + + + 标签 + + + + + + 120 + 120 + 75 + 24 + + + + 使用记录 + + + + + + 120 + 150 + 75 + 24 + + + + 出处 + + + + + + 120 + 180 + 75 + 24 + + + + 题目类型 + + + + + + 120 + 210 + 75 + 24 + + + + 答案 + + + + + + 120 + 240 + 75 + 24 + + + + 解答与提示 + + + + + + 120 + 270 + 75 + 24 + + + + 相同题号 + + + + + + 120 + 300 + 75 + 24 + + + + 相关题号 + + + + + + 120 + 330 + 75 + 24 + + + + 备注 + + + + + + 490 + 110 + 161 + 91 + + + + + true + + + + 运行 + + + + + + 120 + 380 + 75 + 24 + + + + 撤销上一个 + + + + + + 120 + 410 + 75 + 24 + + + + 清除 + + + + + + 220 + 110 + 261 + 331 + + + + QFrame::StyledPanel + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + false + + + + + + 220 + 90 + 71 + 16 + + + + 当前条件: + + + + + + 380 + 30 + 111 + 20 + + + + 选中表示不包含 + + + + + + 220 + 60 + 261 + 20 + + + + + + + 220 + 30 + 151 + 16 + + + + 输入条件, 用","分隔表示"或" + + + + + + 490 + 30 + 91 + 16 + + + + 筛选结果数目: + + + + + + 490 + 50 + 161 + 51 + + + + 6 + + + 0.000000000000000 + + + + + + 490 + 240 + 161 + 201 + + + + + true + + + + 保存和编译 + + + + + + 490 + 210 + 79 + 20 + + + + 详细信息 + + + + + +