From 02aa552a55b76da988cccd46d249422ab84f9971 Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Fri, 2 Feb 2024 20:36:06 -0500 Subject: [PATCH 1/9] Add preview_command cli flag --- manim/_config/utils.py | 10 ++++++++++ manim/cli/render/global_options.py | 5 +++++ manim/utils/file_ops.py | 8 ++++++-- 3 files changed, 21 insertions(+), 2 deletions(-) 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..7942f71035 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 to preview the video file (ex: xdg-open on linux)", + default="", + ), ) diff --git a/manim/utils/file_ops.py b/manim/utils/file_ops.py index ae06561991..c07cc84cc0 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) # Running in foreground prevents messing with output def open_media_file(file_writer: SceneFileWriter) -> None: From 1a7a7e19c63a77a1a91ee52e59ee705c6453ce1e Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Fri, 2 Feb 2024 20:44:29 -0500 Subject: [PATCH 2/9] Edit help for --preview_command --- manim/cli/render/global_options.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/cli/render/global_options.py b/manim/cli/render/global_options.py index 7942f71035..90322fee14 100644 --- a/manim/cli/render/global_options.py +++ b/manim/cli/render/global_options.py @@ -107,7 +107,7 @@ def validate_gui_location(ctx, param, value): ), option( "--preview_command", - help="The command to preview the video file (ex: xdg-open on linux)", + help="The command to preview the video file (ex: xdg-open on linux). Note that this does not have an effect on Windows", default="", ), ) From a89618591358dedfd1f72a2a085a1ef5f52c43da Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Fri, 2 Feb 2024 21:08:24 -0500 Subject: [PATCH 3/9] Change back from subprocess.run --- manim/utils/file_ops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/utils/file_ops.py b/manim/utils/file_ops.py index c07cc84cc0..a6f30cceab 100644 --- a/manim/utils/file_ops.py +++ b/manim/utils/file_ops.py @@ -209,7 +209,7 @@ def open_file(file_path, in_browser=False): if config.preview_command: commands = [config.preview_command] commands.append(file_path) - sp.run(commands) # Running in foreground prevents messing with output + sp.Popen(commands) # Running in foreground prevents messing with output def open_media_file(file_writer: SceneFileWriter) -> None: From f1f3198db19ee6bf7cce42a6fd9e025afefeec73 Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Fri, 2 Feb 2024 21:12:48 -0500 Subject: [PATCH 4/9] Remove old comment --- manim/utils/file_ops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/utils/file_ops.py b/manim/utils/file_ops.py index a6f30cceab..41b03e4930 100644 --- a/manim/utils/file_ops.py +++ b/manim/utils/file_ops.py @@ -209,7 +209,7 @@ def open_file(file_path, in_browser=False): if config.preview_command: commands = [config.preview_command] commands.append(file_path) - sp.Popen(commands) # Running in foreground prevents messing with output + sp.Popen(commands) def open_media_file(file_writer: SceneFileWriter) -> None: From 4b892eaa2ed42cafcf09f75cd7d00b28fdf4df3f Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Thu, 15 Feb 2024 13:13:27 -0500 Subject: [PATCH 5/9] Bug with timg stopped happening with sp.run --- manim/utils/file_ops.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/utils/file_ops.py b/manim/utils/file_ops.py index 41b03e4930..df505a60f3 100644 --- a/manim/utils/file_ops.py +++ b/manim/utils/file_ops.py @@ -209,7 +209,7 @@ def open_file(file_path, in_browser=False): 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: From 49775bab0badf58da51d87a15c6e3d275b9d72a7 Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Thu, 15 Feb 2024 13:26:14 -0500 Subject: [PATCH 6/9] Fix docstring --- manim/cli/render/global_options.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/manim/cli/render/global_options.py b/manim/cli/render/global_options.py index 90322fee14..0093a22692 100644 --- a/manim/cli/render/global_options.py +++ b/manim/cli/render/global_options.py @@ -102,12 +102,7 @@ def validate_gui_location(ctx, param, value): option( "--no_latex_cleanup", is_flag=True, - help="Prevents deletion of .aux, .dvi, and .log files produced by Tex and MathTex.", - default=False, - ), - option( - "--preview_command", - help="The command to preview the video file (ex: xdg-open on linux). Note that this does not have an effect on Windows", + help="Prevents deletion of .aux, .dvi, and .log files produced by Tex and MathTex", default="", ), ) From eceba84d0179409a204c54ec5ab92e2110b39078 Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Thu, 15 Feb 2024 13:27:18 -0500 Subject: [PATCH 7/9] Revert "Fix docstring" This reverts commit d2c00fc24dc46586f994237f1d2758528b78d6a3. --- manim/cli/render/global_options.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/manim/cli/render/global_options.py b/manim/cli/render/global_options.py index 0093a22692..90322fee14 100644 --- a/manim/cli/render/global_options.py +++ b/manim/cli/render/global_options.py @@ -102,7 +102,12 @@ def validate_gui_location(ctx, param, value): option( "--no_latex_cleanup", is_flag=True, - help="Prevents deletion of .aux, .dvi, and .log files produced by Tex and MathTex", + help="Prevents deletion of .aux, .dvi, and .log files produced by Tex and MathTex.", + default=False, + ), + option( + "--preview_command", + help="The command to preview the video file (ex: xdg-open on linux). Note that this does not have an effect on Windows", default="", ), ) From dd53471c270400813360612e2bb8ebd94ab4030f Mon Sep 17 00:00:00 2001 From: JasonGrace2282 Date: Thu, 15 Feb 2024 13:28:19 -0500 Subject: [PATCH 8/9] Actually fix docstring --- manim/cli/render/global_options.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/cli/render/global_options.py b/manim/cli/render/global_options.py index 90322fee14..7942f71035 100644 --- a/manim/cli/render/global_options.py +++ b/manim/cli/render/global_options.py @@ -107,7 +107,7 @@ def validate_gui_location(ctx, param, value): ), option( "--preview_command", - help="The command to preview the video file (ex: xdg-open on linux). Note that this does not have an effect on Windows", + help="The command to preview the video file (ex: xdg-open on linux)", default="", ), ) From 2c0c8c8dae3b26fac1f1326ac38bc2314cfd5ee5 Mon Sep 17 00:00:00 2001 From: adeshpande <110117391+JasonGrace2282@users.noreply.github.com> Date: Wed, 24 Apr 2024 22:37:05 -0400 Subject: [PATCH 9/9] Change help for option Co-authored-by: Benjamin Hackl --- manim/cli/render/global_options.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manim/cli/render/global_options.py b/manim/cli/render/global_options.py index 7942f71035..d7424dd1ee 100644 --- a/manim/cli/render/global_options.py +++ b/manim/cli/render/global_options.py @@ -107,7 +107,7 @@ def validate_gui_location(ctx, param, value): ), option( "--preview_command", - help="The command to preview the video file (ex: xdg-open on linux)", + help="The command used to preview the output file (for example vlc for video files)", default="", ), )