from PySide6.QtWidgets import QWidget, QApplication, QFileDialog from Ui_答题纸对应 import Ui_Form from database_tools_2 import * def getindices(string): indices_list = [] notesjsonpath = f"../备课组/{string[3:5]}届/校本材料.json" try: notesjson = load_dict(notesjsonpath) for id in notesjson["notes"]: if id.startswith(string): indices_list.append(id[-2:]) return indices_list except: return [] class MyWindow(QWidget,Ui_Form): def __init__(self): super().__init__() self.setupUi(self) self.bind() def bind(self): self.comboBox_grade.activated.connect(self.setindex) self.comboBox_semester.activated.connect(self.setindex) self.lineEdit_structure.textChanged.connect(self.setindex) self.comboBox_index.activated.connect(self.activateexec) self.pushButton_exec.clicked.connect(self.exec) def setindex(self): self.comboBox_index.clear() self.structure = self.lineEdit_structure.text().upper() self.grade = self.comboBox_grade.currentText() self.semester = self.comboBox_semester.currentText() self.initialstring = f"{self.structure}{self.grade}{self.semester}" self.indices = getindices(self.initialstring) self.comboBox_index.addItems(self.indices) if self.indices == []: self.pushButton_exec.setDisabled(True) else: self.pushButton_exec.setEnabled(True) def activateexec(self): self.pushButton_exec.setEnabled(True) def exec(self): pid = f"{self.structure}{self.grade}{self.semester}{self.comboBox_index.currentText()}" answersheetjson = f"../备课组/{self.grade[-2:]}届/答题纸对应.json" notesjson = f"../备课组/{self.grade[-2:]}届/校本材料.json" marks_list = re.findall(r"(?:(?:^)|(?:\n))(\d+)分",self.plainTextEdit_marks.toPlainText()) marks_list = [int(mark) for mark in marks_list] answersheet_dict = load_dict(answersheetjson) notes_dict = load_dict(notesjson) new_dict = {} if not pid in notes_dict["notes"]: print("讲义编号有误.") else: new_dict["id"] = pid corresponding_method = input("用何种方式对应? 题号(I)/章节标题(P):") if corresponding_method[0].upper() == "I": new_dict["idlist"] = [] count = 1 id = input(f"输入第 {count} 题的题号(S表示跳过, E表示结束):") while len(re.findall(r"[Ss\d,:]",id)) == len(id): if "S" in id.upper(): new_dict["idlist"].append("999999") count += 1 else: new_id_list = generate_number_set(id) new_dict["idlist"] += [i.zfill(6) for i in new_id_list] count += len(new_id_list) id = input(f"输入第 {count} 题的题号(S表示跳过, E表示结束):") elif corresponding_method[0].upper() == "P": structure = notes_dict["structures"][pid[0]]["structure"] count = 1 partslist = [] for key in structure: print(f"{count}. {key}: {structure[key]['name']}") count += 1 partslist.append(key) parts_selected_string = input("使用哪些部分(输入数字编号, 用';'分隔):") parts_selected_index = parts_selected_string.strip().split(";") parts_selected = [] for i in parts_selected_index: parts_selected.append(partslist[int(i)-1]) new_dict["parts"] = parts_selected.copy() if marks_list == []: marksflag = input("是否为每个结果赋分(Y/N):") if marksflag[0].upper() == "Y": new_dict["marks"] = [] count = 1 mark = input(f"依次输入分数, 非自然数作为结束(第 {count} 个位置):") while len(re.findall(r"\d",mark)) == len(mark): new_dict["marks"].append(int(mark)) count += 1 mark = input(f"依次输入分数, 非自然数作为结束(第 {count} 个位置):") else: new_dict["marks"] = marks_list.copy() answersheet_dict[self.lineEdit_xiaoxianid.text()] = new_dict.copy() save_dict(answersheet_dict,answersheetjson) print("设置完成") if __name__ == '__main__': app = QApplication([]) windows = MyWindow() windows.show() app.exec()