Skip to content

Commit 98641a2

Browse files
Add --preview_command cli flag (#3615)
* Add preview_command cli flag * Edit help for --preview_command * Change back from subprocess.run * Remove old comment * Bug with timg stopped happening with sp.run * Fix docstring * Revert "Fix docstring" This reverts commit d2c00fc. * Actually fix docstring * Change help for option Co-authored-by: Benjamin Hackl <[email protected]> --------- Co-authored-by: Benjamin Hackl <[email protected]>
1 parent a3d584b commit 98641a2

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

manim/_config/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ class MyScene(Scene): ...
318318
"zero_pad",
319319
"force_window",
320320
"no_latex_cleanup",
321+
"preview_command",
321322
}
322323

323324
def __init__(self) -> None:
@@ -767,6 +768,7 @@ def digest_args(self, args: argparse.Namespace) -> Self:
767768
"force_window",
768769
"dry_run",
769770
"no_latex_cleanup",
771+
"preview_command",
770772
]:
771773
if hasattr(args, key):
772774
attr = getattr(args, key)
@@ -1016,6 +1018,14 @@ def no_latex_cleanup(self) -> bool:
10161018
def no_latex_cleanup(self, value: bool) -> None:
10171019
self._set_boolean("no_latex_cleanup", value)
10181020

1021+
@property
1022+
def preview_command(self) -> str:
1023+
return self._d["preview_command"]
1024+
1025+
@preview_command.setter
1026+
def preview_command(self, value: str) -> None:
1027+
self._set_str("preview_command", value)
1028+
10191029
@property
10201030
def verbosity(self) -> str:
10211031
"""Logger verbosity; "DEBUG", "INFO", "WARNING", "ERROR", or "CRITICAL" (-v)."""

manim/cli/render/global_options.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,9 @@ def validate_gui_location(ctx, param, value):
105105
help="Prevents deletion of .aux, .dvi, and .log files produced by Tex and MathTex.",
106106
default=False,
107107
),
108+
option(
109+
"--preview_command",
110+
help="The command used to preview the output file (for example vlc for video files)",
111+
default="",
112+
),
108113
)

manim/utils/file_ops.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
from manim import __version__, config, logger
3434

35-
from .. import console
35+
from .. import config, console
3636

3737

3838
def is_mp4_format() -> bool:
@@ -204,8 +204,12 @@ def open_file(file_path, in_browser=False):
204204
commands = ["open"] if not in_browser else ["open", "-R"]
205205
else:
206206
raise OSError("Unable to identify your operating system...")
207+
208+
# check after so that file path is set correctly
209+
if config.preview_command:
210+
commands = [config.preview_command]
207211
commands.append(file_path)
208-
sp.Popen(commands)
212+
sp.run(commands)
209213

210214

211215
def open_media_file(file_writer: SceneFileWriter) -> None:

0 commit comments

Comments
 (0)