Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Add ``--preview_command`` cli flag (#3615)

adeshpande98641a2f82af
diff --git a/manim/_config/utils.py b/manim/_config/utils.py
index 7ced9c110..a202d857c 100644
--- a/manim/_config/utils.py
+++ b/manim/_config/utils.py
@@ -318,6 +318,7 @@ class ManimConfig(MutableMapping):
"zero_pad",
"force_window",
"no_latex_cleanup",
+ "preview_command",
}
def __init__(self) -> None:
@@ -767,6 +768,7 @@ class ManimConfig(MutableMapping):
"force_window",
"dry_run",
"no_latex_cleanup",
+ "preview_command",
]:
if hasattr(args, key):
attr = getattr(args, key)
@@ -1016,6 +1018,14 @@ class ManimConfig(MutableMapping):
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 42b61ae2d..d7424dd1e 100644
--- a/manim/cli/render/global_options.py
+++ b/manim/cli/render/global_options.py
@@ -105,4 +105,9 @@ global_options = option_group(
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 ae0656199..df505a60f 100644
--- a/manim/utils/file_ops.py
+++ b/manim/utils/file_ops.py
@@ -32,7 +32,7 @@ if TYPE_CHECKING:
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: