Skip to content

Commit

Permalink
Add --preview_command cli flag (#3615)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
JasonGrace2282 and behackl authored Apr 27, 2024
1 parent a3d584b commit 98641a2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
10 changes: 10 additions & 0 deletions manim/_config/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ class MyScene(Scene): ...
"zero_pad",
"force_window",
"no_latex_cleanup",
"preview_command",
}

def __init__(self) -> None:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)."""
Expand Down
5 changes: 5 additions & 0 deletions manim/cli/render/global_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="",
),
)
8 changes: 6 additions & 2 deletions manim/utils/file_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

from manim import __version__, config, logger

from .. import console
from .. import config, console


def is_mp4_format() -> bool:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 98641a2

Please sign in to comment.