diff --git a/molecularnodes/scene/base.py b/molecularnodes/scene/base.py index e2653e41..52f25086 100644 --- a/molecularnodes/scene/base.py +++ b/molecularnodes/scene/base.py @@ -1,9 +1,13 @@ import bpy from ..entities import Molecule import tempfile -from IPython.display import Image, display from pathlib import Path +try: + from IPython.display import Image, display +except ImportError: + Image = None + display = None IS_EEVEE_NEXT = bpy.app.version[0] == 4 and bpy.app.version[1] >= 2 @@ -247,4 +251,11 @@ def snapshot(self, path: str | Path | None = None) -> None: tmp_path = Path(tmpdir) / "snapshot.png" bpy.context.scene.render.filepath = str(tmp_path) bpy.ops.render.render(write_still=True, animation=False) - display(Image(tmp_path)) + if display and Image: + display(Image(tmp_path)) + else: + # Alternative handling like saving to disk + if path: + import shutil + + shutil.copy(tmp_path, path) diff --git a/pyproject.toml b/pyproject.toml index 052922cf..3066f986 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -20,6 +20,7 @@ Documentation = "https://bradyajohnston.github.io/MolecularNodes" [project.optional-dependencies] bpy = ["bpy>=4.2"] +jupyter = ["jupyter", "IPython"] dev = ["pytest", "pytest-cov", "syrupy", "scipy", "fake-bpy-module", "IPython"] test = ["pytest", "pytest-cov", "syrupy", "scipy", "IPython"] docs = ["quartodoc", "tomlkit", "nodepad", "jupyter", "IPython"]