diff --git a/manim/_config/utils.py b/manim/_config/utils.py index 7ced9c1101..a202d857cd 100644 --- a/manim/_config/utils.py +++ b/manim/_config/utils.py @@ -318,6 +318,7 @@ class MyScene(Scene): ... "zero_pad", "force_window", "no_latex_cleanup", + "preview_command", } def __init__(self) -> None: @@ -767,6 +768,7 @@ def digest_args(self, args: argparse.Namespace) -> Self: "force_window", "dry_run", "no_latex_cleanup", + "preview_command", ]: if hasattr(args, key): attr = getattr(args, key) @@ -1016,6 +1018,14 @@ def no_latex_cleanup(self) -> bool: def no_latex_cleanup(self, value: bool) -> None: self._set_boolean("no_latex_cleanup", value) + @property + def preview_command(self) -> str: + return self._d["preview_command"] + + @preview_command.setter + def preview_command(self, value: str) -> None: + self._set_str("preview_command", value) + @property def verbosity(self) -> str: """Logger verbosity; "DEBUG", "INFO", "WARNING", "ERROR", or "CRITICAL" (-v).""" diff --git a/manim/cli/render/global_options.py b/manim/cli/render/global_options.py index 42b61ae2d9..d7424dd1ee 100644 --- a/manim/cli/render/global_options.py +++ b/manim/cli/render/global_options.py @@ -105,4 +105,9 @@ def validate_gui_location(ctx, param, value): help="Prevents deletion of .aux, .dvi, and .log files produced by Tex and MathTex.", default=False, ), + option( + "--preview_command", + help="The command used to preview the output file (for example vlc for video files)", + default="", + ), ) diff --git a/manim/utils/file_ops.py b/manim/utils/file_ops.py index ae06561991..df505a60f3 100644 --- a/manim/utils/file_ops.py +++ b/manim/utils/file_ops.py @@ -32,7 +32,7 @@ from manim import __version__, config, logger -from .. import console +from .. import config, console def is_mp4_format() -> bool: @@ -204,8 +204,12 @@ def open_file(file_path, in_browser=False): commands = ["open"] if not in_browser else ["open", "-R"] else: raise OSError("Unable to identify your operating system...") + + # check after so that file path is set correctly + if config.preview_command: + commands = [config.preview_command] commands.append(file_path) - sp.Popen(commands) + sp.run(commands) def open_media_file(file_writer: SceneFileWriter) -> None: