修改界面

This commit is contained in:
2025-05-20 02:59:58 +08:00
parent 83b3790e8b
commit 9ca61d5092
13 changed files with 394 additions and 499 deletions

View File

@@ -22,6 +22,17 @@ class Question:
questions.append(Question(*line.strip('\n').split(',')))
return questions
@staticmethod
def load_from_xls(path: str) -> list['Question']:
questions = []
wb = load_workbook(path, read_only=True)
ws = wb.active
for row in ws.iter_rows(min_col=2, max_col=3, min_row=2, values_only=True):
if row[0] is None and row[1] is None:
break
questions.append(Question(*row))
return questions
@property
def no(self) -> str:
return self._no
@@ -112,4 +123,4 @@ class Course:
if __name__ == '__main__':
...
...

44
module/worker.py Normal file
View File

@@ -0,0 +1,44 @@
import os
from pathlib import Path
from PySide6.QtCore import QObject, Signal
from module.doc import DocPaper
from module.schema import Course, Student, Question
from utils.function import resource_path
class DTGWorker(QObject):
progress = Signal(int)
finished = Signal()
def __init__(
self,
input_student_filepath: str,
input_question_filepath: str,
output_filepath: str,
output_filename: str
):
super().__init__()
self.input_filepath = input_student_filepath
self.input_question_filepath = input_question_filepath
self.output_filepath = output_filepath
self.output_filename = output_filename
def run(self):
course = Course.load_from_xls(self.input_filepath)
students = Student.load_from_xls(self.input_filepath)
questions = Question.load_from_xls(self.input_question_filepath)
d = DocPaper(self.output_filename, template_path=resource_path("template/template.docx"))
for index, student in enumerate(students):
if (p := int((index + 1) / len(students) * 100)) != 100:
self.progress.emit(p)
else:
self.progress.emit(99)
student.pick_question(questions)
d.add_paper(course, student)
d.save(self.output_filepath)
self.progress.emit(100)
os.startfile(Path(self.output_filepath) / f"{self.output_filename}.docx")
self.finished.emit()