103 lines
4.4 KiB
Python
103 lines
4.4 KiB
Python
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
|
|
from Ui_讲义结构与内容录入 import Ui_Form
|
|
from database_tools_2 import *
|
|
|
|
class MyWindow(QWidget,Ui_Form):
|
|
def __init__(self):
|
|
super().__init__()
|
|
self.setupUi(self)
|
|
self.bind()
|
|
def bind(self):
|
|
self.pushButton_exec.clicked.connect(self.exec)
|
|
def exec(self):
|
|
if not len(self.lineEdit_structure.text()) == 1:
|
|
pass
|
|
print("首字母有误")
|
|
else:
|
|
self.prefix = self.lineEdit_structure.text().upper()+self.comboBox_grade.currentText()+self.comboBox_semester.currentText()
|
|
jsonfile = f"../备课组/{self.prefix[3:5]}届/校本材料.json"
|
|
notes_dict = load_dict(jsonfile)
|
|
|
|
# print(len(notes_dict))
|
|
if not self.prefix[0] in notes_dict["structures"]:
|
|
AddNew = input("此类型不在列表中, 新增(A)/退出(Q):")
|
|
if AddNew[0].upper() == "A":
|
|
descr = input("类型描述:")
|
|
cn = input("编号是否连续(T/F):")
|
|
if cn[0].upper() == "T":
|
|
cn = True
|
|
else:
|
|
cn = False
|
|
partscount = int(input("分为多少个部分:"))
|
|
new_struct_dict = {
|
|
"description": descr,
|
|
"consecutivenumbering": cn,
|
|
"structure": {}
|
|
}
|
|
for i in range(partscount):
|
|
partid = input(f"第 {i+1} 部分的代号:")
|
|
partname = input(f"部分 {partid} 的名称:")
|
|
spaceflag = input(f"部分 {partid}: {partname} 中是否要在题目后留空格(T/F):")
|
|
if spaceflag[0].upper() == "T":
|
|
spaceflag = True
|
|
else:
|
|
spaceflag = False
|
|
new_struct_dict["structure"][partid] = {
|
|
"name": partname,
|
|
"spaceflag": spaceflag
|
|
}
|
|
notes_dict["structures"][self.prefix[0]] = new_struct_dict.copy()
|
|
save_dict(notes_dict,jsonfile)
|
|
else:
|
|
pass
|
|
else:
|
|
numberlist = []
|
|
for id in notes_dict["notes"]:
|
|
if self.prefix in id:
|
|
numberlist.append(id[-2:])
|
|
print("该分类下已有材料编号: "+generate_exp(numberlist))
|
|
pid = self.prefix + input("请输入新材料编号(两位数):")
|
|
while pid in notes_dict["notes"]:
|
|
print("编号重复, 请重新输入.")
|
|
pid = self.prefix + input("请输入新材料编号(两位数):")
|
|
name = input("请输入材料名称:")
|
|
filenameraw = input("生成的文件名和材料名称是否一致?([Y]/如果不一致请输入文件名):")
|
|
if filenameraw.upper() == "Y":
|
|
filename = name
|
|
else:
|
|
filename = filenameraw
|
|
new_note_dict = {
|
|
"id": pid,
|
|
"name": name,
|
|
"filename": filename
|
|
}
|
|
structure = notes_dict['structures'][self.prefix[0]]['structure']
|
|
print(f"此类材料共有 {len(structure)} 个部分, 分别是:")
|
|
for p in structure:
|
|
print(f"{p}: {structure[p]['name']}")
|
|
new_note_dict[p] = []
|
|
for p in structure:
|
|
rawdata = input(f"现在输入 {p}: {structure[p]['name']} 部分的内容编号:")
|
|
rawdata = re.sub(r"[^BXK\d:,]","",rawdata)
|
|
if re.findall(r"\d",rawdata) == []:
|
|
new_note_dict[p] = []
|
|
else:
|
|
new_note_dict[p] = generate_id_set(rawdata)
|
|
print(f"{p}: {new_note_dict[p]}")
|
|
notes_dict["notes"][pid] = new_note_dict.copy()
|
|
notes_dict["notes"] = SortDict(notes_dict["notes"])
|
|
save_dict(notes_dict,jsonfile)
|
|
print("处理完成")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
app = QApplication([])
|
|
windows = MyWindow()
|
|
windows.show()
|
|
app.exec()
|
|
|