mirror of
https://github.com/3b1b/manim.git
synced 2025-08-02 11:03:03 +08:00

Since the reload logic no longer relies on any state, the relevant loop is simple enough that it feels clearest to include it in the main entry point file.
68 lines
1.7 KiB
Python
68 lines
1.7 KiB
Python
#!/usr/bin/env python
|
|
from manimlib import __version__
|
|
from manimlib.config import get_global_config
|
|
from manimlib.config import parse_cli
|
|
import manimlib.logger
|
|
import manimlib.utils.init_config
|
|
import manimlib.extract_scene
|
|
from manimlib.window import Window
|
|
|
|
|
|
from IPython.terminal.embed import KillEmbedded
|
|
|
|
|
|
from typing import TYPE_CHECKING
|
|
if TYPE_CHECKING:
|
|
from argparse import Namespace
|
|
|
|
|
|
def run_scenes():
|
|
"""
|
|
Runs the scenes in a loop and detects when a scene reload is requested.
|
|
"""
|
|
global_config = get_global_config()
|
|
scene_config = global_config["scene"]
|
|
run_config = global_config["run"]
|
|
|
|
if run_config["show_in_window"]:
|
|
# Create a reusable window
|
|
window = Window(**global_config["window"])
|
|
scene_config.update(window=window)
|
|
|
|
while True:
|
|
try:
|
|
# Blocking call since a scene may init an IPython shell()
|
|
scenes = manimlib.extract_scene.main(scene_config, run_config)
|
|
for scene in scenes:
|
|
scene.run()
|
|
return
|
|
except KillEmbedded:
|
|
# Requested via the `exit_raise` IPython runline magic
|
|
# by means of the reload_scene() command
|
|
pass
|
|
except KeyboardInterrupt:
|
|
break
|
|
|
|
|
|
def main():
|
|
"""
|
|
Main entry point for ManimGL.
|
|
"""
|
|
print(f"ManimGL \033[32mv{__version__}\033[0m")
|
|
|
|
args = parse_cli()
|
|
if args.version and args.file is None:
|
|
return
|
|
if args.log_level:
|
|
manimlib.logger.log.setLevel(args.log_level)
|
|
|
|
if args.config:
|
|
manimlib.utils.init_config.init_customization()
|
|
return
|
|
|
|
run_scenes()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|