Flash around border on exceptions in Scene.embed

This commit is contained in:
Grant Sanderson 2022-12-29 15:08:57 -08:00
parent 71815fd7de
commit ba68505c18

View file

@ -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}")