From ba68505c18b80b2e229098effa678171b802b258 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Thu, 29 Dec 2022 15:08:57 -0800 Subject: [PATCH] Flash around border on exceptions in Scene.embed --- manimlib/scene/scene.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/manimlib/scene/scene.py b/manimlib/scene/scene.py index 66d1d529..55b8c37d 100644 --- a/manimlib/scene/scene.py +++ b/manimlib/scene/scene.py @@ -16,15 +16,18 @@ import numpy as np from tqdm import tqdm as ProgressDisplay from manimlib.animation.animation import prepare_animation +from manimlib.animation.fading import VFadeInThenOut from manimlib.camera.camera import Camera from manimlib.config import get_module from manimlib.constants import ARROW_SYMBOLS from manimlib.constants import DEFAULT_WAIT_TIME from manimlib.constants import COMMAND_MODIFIER from manimlib.constants import SHIFT_MODIFIER +from manimlib.constants import RED from manimlib.event_handler import EVENT_DISPATCHER from manimlib.event_handler.event_type import EventType from manimlib.logger import log +from manimlib.mobject.frame import FullScreenRectangle from manimlib.mobject.mobject import _AnimationBuilder from manimlib.mobject.mobject import Group from manimlib.mobject.mobject import Mobject @@ -34,7 +37,6 @@ from manimlib.mobject.types.vectorized_mobject import VMobject from manimlib.scene.scene_file_writer import SceneFileWriter from manimlib.utils.family_ops import extract_mobject_family_members from manimlib.utils.family_ops import recursive_mobject_remove -from manimlib.utils.iterables import list_difference_update from typing import TYPE_CHECKING @@ -253,14 +255,18 @@ class Scene(object): shell.events.register("post_run_cell", post_cell_func) - if self.embed_error_sound: - # Play sound after any Exceptions - def custom_exc(shell, etype, evalue, tb, tb_offset=None): - # still show the error don't just swallow it - shell.showtraceback((etype, evalue, tb), tb_offset=tb_offset) + # Flash border, and potentially play sound, on exceptions + def custom_exc(shell, etype, evalue, tb, tb_offset=None): + # still show the error don't just swallow it + shell.showtraceback((etype, evalue, tb), tb_offset=tb_offset) + if self.embed_error_sound: os.system("printf '\a'") + self.play(VFadeInThenOut( + FullScreenRectangle().set_stroke(RED, 30).set_fill(opacity=0), + run_time=0.5, + )) - shell.set_custom_exc((Exception,), custom_exc) + shell.set_custom_exc((Exception,), custom_exc) # Set desired exception mode shell.magic(f"xmode {self.embed_exception_mode}")