mirror of
https://github.com/3b1b/manim.git
synced 2025-04-13 09:47:07 +00:00
Move reload out of Scene, instead have it directly update the global run configuration
This commit is contained in:
parent
07bb34793e
commit
1d67768a13
3 changed files with 33 additions and 42 deletions
|
@ -27,13 +27,6 @@ class ReloadManager:
|
|||
|
||||
window = None
|
||||
is_reload = False
|
||||
embed_line = None
|
||||
|
||||
def set_new_start_at_line(self, start_at_line):
|
||||
"""
|
||||
Sets/Updates the line number to load the scene from when reloading.
|
||||
"""
|
||||
self.embed_line = start_at_line
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
|
@ -65,10 +58,7 @@ class ReloadManager:
|
|||
scene_config = global_config["scene"]
|
||||
run_config = global_config["run"]
|
||||
|
||||
scene_config.update(reload_manager=self)
|
||||
run_config.update(is_reload=self.is_reload)
|
||||
if self.embed_line:
|
||||
run_config.update(embed_line=self.embed_line)
|
||||
|
||||
# Create or reuse window
|
||||
if run_config["show_in_window"] and not self.window:
|
||||
|
|
|
@ -47,7 +47,6 @@ if TYPE_CHECKING:
|
|||
|
||||
from PIL.Image import Image
|
||||
|
||||
from manimlib.reload_manager import ReloadManager
|
||||
from manimlib.animation.animation import Animation
|
||||
|
||||
|
||||
|
@ -72,7 +71,6 @@ class Scene(object):
|
|||
def __init__(
|
||||
self,
|
||||
window: Optional[Window] = None,
|
||||
reload_manager: Optional[ReloadManager] = None,
|
||||
camera_config: dict = dict(),
|
||||
file_writer_config: dict = dict(),
|
||||
skip_animations: bool = False,
|
||||
|
@ -90,7 +88,6 @@ class Scene(object):
|
|||
self.leave_progress_bars = leave_progress_bars
|
||||
self.presenter_mode = presenter_mode
|
||||
self.show_animation_progress = show_animation_progress
|
||||
self.reload_manager = reload_manager
|
||||
|
||||
self.camera_config = merge_dicts_recursively(
|
||||
get_camera_config(), # Global default
|
||||
|
@ -861,34 +858,6 @@ class Scene(object):
|
|||
def on_close(self) -> None:
|
||||
pass
|
||||
|
||||
def reload(self, start_at_line: int | None = None) -> None:
|
||||
"""
|
||||
Reloads the scene just like the `manimgl` command would do with the
|
||||
same arguments that were provided for the initial startup. This allows
|
||||
for quick iteration during scene development since we don't have to exit
|
||||
the IPython kernel and re-run the `manimgl` command again. The GUI stays
|
||||
open during the reload.
|
||||
|
||||
If `start_at_line` is provided, the scene will be reloaded at that line
|
||||
number. This corresponds to the `linemarker` param of the
|
||||
`extract_scene.insert_embed_line_to_module()` method.
|
||||
|
||||
Before reload, the scene is cleared and the entire state is reset, such
|
||||
that we can start from a clean slate. This is taken care of by the
|
||||
ReloadManager, which will catch the error raised by the `exit_raise`
|
||||
magic command that we invoke here.
|
||||
|
||||
Note that we cannot define a custom exception class for this error,
|
||||
since the IPython kernel will swallow any exception. While we can catch
|
||||
such an exception in our custom exception handler registered with the
|
||||
`set_custom_exc` method, we cannot break out of the IPython shell by
|
||||
this means.
|
||||
"""
|
||||
self.reload_manager.set_new_start_at_line(start_at_line)
|
||||
shell = get_ipython()
|
||||
if shell:
|
||||
shell.run_line_magic("exit_raise", "")
|
||||
|
||||
def focus(self) -> None:
|
||||
"""
|
||||
Puts focus on the ManimGL window.
|
||||
|
|
|
@ -61,12 +61,12 @@ def get_shortcuts(scene):
|
|||
clear=scene.clear,
|
||||
focus=scene.focus,
|
||||
save_state=scene.save_state,
|
||||
reload=scene.reload,
|
||||
undo=scene.undo,
|
||||
redo=scene.redo,
|
||||
i2g=scene.i2g,
|
||||
i2m=scene.i2m,
|
||||
checkpoint_paste=scene.checkpoint_paste,
|
||||
reload=reload_scene # Defined below
|
||||
)
|
||||
|
||||
|
||||
|
@ -104,6 +104,38 @@ def ensure_flash_on_error(shell, scene):
|
|||
shell.set_custom_exc((Exception,), custom_exc)
|
||||
|
||||
|
||||
def reload_scene(embed_line: int | None = None) -> None:
|
||||
"""
|
||||
Reloads the scene just like the `manimgl` command would do with the
|
||||
same arguments that were provided for the initial startup. This allows
|
||||
for quick iteration during scene development since we don't have to exit
|
||||
the IPython kernel and re-run the `manimgl` command again. The GUI stays
|
||||
open during the reload.
|
||||
|
||||
If `embed_line` is provided, the scene will be reloaded at that line
|
||||
number. This corresponds to the `linemarker` param of the
|
||||
`extract_scene.insert_embed_line_to_module()` method.
|
||||
|
||||
Before reload, the scene is cleared and the entire state is reset, such
|
||||
that we can start from a clean slate. This is taken care of by the
|
||||
ReloadManager, which will catch the error raised by the `exit_raise`
|
||||
magic command that we invoke here.
|
||||
|
||||
Note that we cannot define a custom exception class for this error,
|
||||
since the IPython kernel will swallow any exception. While we can catch
|
||||
such an exception in our custom exception handler registered with the
|
||||
`set_custom_exc` method, we cannot break out of the IPython shell by
|
||||
this means.
|
||||
"""
|
||||
if embed_line:
|
||||
global_config = get_global_config()
|
||||
global_config["run"]["embed_line"] = embed_line
|
||||
|
||||
shell = get_ipython()
|
||||
if shell:
|
||||
shell.run_line_magic("exit_raise", "")
|
||||
|
||||
|
||||
class CheckpointManager:
|
||||
checkpoint_states: dict[str, list[tuple[Mobject, Mobject]]] = dict()
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue