diff --git a/app/common/display/result_display.py b/app/common/display/result_display.py index 6e6ce9c0..64309dc8 100644 --- a/app/common/display/result_display.py +++ b/app/common/display/result_display.py @@ -458,6 +458,11 @@ def create_student_label( 返回: list: 创建的标签列表 """ + # 检查 selected_students 是否为 None,避免后续的 len() 调用和迭代操作失败 + if selected_students is None: + logger.warning("create_student_label: selected_students 为 None,可能是未设置默认班级或抽取名单") + return [] + student_labels = [] # 内存优化:预分配列表容量 diff --git a/app/view/main/quick_draw_animation.py b/app/view/main/quick_draw_animation.py index 3be0b157..2ee15553 100644 --- a/app/view/main/quick_draw_animation.py +++ b/app/view/main/quick_draw_animation.py @@ -117,7 +117,13 @@ def stop_animation(self): ) # 动画完成后,更新浮窗通知并启动自动关闭定时器 - if self.final_selected_students and self.final_class_name: + # 确保 final_selected_students 不为 None 且不为空列表,final_class_name 不为 None + if ( + self.final_selected_students + and self.final_selected_students is not None + and len(self.final_selected_students) > 0 + and self.final_class_name + ): draw_count = readme_settings_async("quick_draw_settings", "draw_count") RollCallUtils.show_notification_if_enabled( class_name=self.final_class_name, @@ -134,6 +140,14 @@ def _animate_result(self): """动画过程中更新显示""" self.draw_random_students() + # 检查是否成功抽取到学生,如果没有则停止动画 + if not self.final_selected_students or self.final_selected_students is None: + logger.warning("_animate_result: 未抽取到学生,停止动画") + if self.animation_timer and self.animation_timer.isActive(): + self.animation_timer.stop() + self.stop_animation() + return + draw_count = readme_settings_async("quick_draw_settings", "draw_count") self.display_result_animated( self.final_selected_students, @@ -157,7 +171,14 @@ def draw_random_students(self): """独立的随机学生抽取逻辑,不依赖roll_call_widget的状态""" class_name = readme_settings_async("quick_draw_settings", "default_class") if not class_name: - logger.exception("draw_random_students: 未设置默认抽取名单") + # 未设置默认班级,初始化为空结果并停止动画 + logger.warning("draw_random_students: 未设置默认抽取名单,请在设置中配置默认班级") + self.final_selected_students = [] + self.final_class_name = None + # 停止动画计时器 + if self.animation_timer and self.animation_timer.isActive(): + self.animation_timer.stop() + self.stop_animation() return False group_index = 0