\n",
- " \n",
- " \n",
- " "
+ ""
],
"text/plain": [
""
@@ -135,7 +528,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
- "version": "3.8.13"
+ "version": "3.9.12"
}
},
"nbformat": 4,
diff --git a/jupyter_splitview/__init__.py b/jupyter_splitview/__init__.py
index 909a5d1e..7ccbf2f9 100644
--- a/jupyter_splitview/__init__.py
+++ b/jupyter_splitview/__init__.py
@@ -1,5 +1,9 @@
+from pathlib import Path
+
from .sw_cellmagic import SplitViewMagic
-from IPython import get_ipython # register cell magic
+from IPython import get_ipython
+from IPython.core.display import HTML
+from IPython.display import display
import pkg_resources
__version__: str = pkg_resources.get_distribution(__name__).version
@@ -10,5 +14,17 @@
ipy = get_ipython()
ipy.register_magics(SplitViewMagic)
+ css_path = Path(__file__).parents[1] / "vendor/juxtapose/build/css/juxtapose.css"
+ js_path = Path(__file__).parents[1] / "vendor/juxtapose/build/js/juxtapose.min.js"
+
+ html_code = f"""
+
+
+ """
+ display(HTML(html_code))
+
+
except AttributeError:
- print("Can not load SplitViewMagic because this is not a notebook")
\ No newline at end of file
+ print("Can not load SplitViewMagic because this is not a notebook")
+
+
diff --git a/jupyter_splitview/inject.html b/jupyter_splitview/inject.html
new file mode 100644
index 00000000..71af1053
--- /dev/null
+++ b/jupyter_splitview/inject.html
@@ -0,0 +1,43 @@
+
+
+
+
+
+
+
+
diff --git a/jupyter_splitview/sw_cellmagic.py b/jupyter_splitview/sw_cellmagic.py
index df2fb171..4dc13f4e 100644
--- a/jupyter_splitview/sw_cellmagic.py
+++ b/jupyter_splitview/sw_cellmagic.py
@@ -1,4 +1,5 @@
import io
+import os
from base64 import b64decode
from IPython.core import magic_arguments
@@ -8,6 +9,15 @@
from IPython.utils.capture import capture_output
from PIL import Image
+from jinja2 import Template, StrictUndefined
+
+g_cell_id = 0
+
+def compile_template(in_file: str, **variables) -> str:
+ with open(f"{in_file}", "r", encoding="utf-8") as file:
+ template = Template(file.read(), undefined=StrictUndefined)
+ return template.render(**variables)
+
@magics_class
class SplitViewMagic(Magics):
@@ -16,16 +26,15 @@ class SplitViewMagic(Magics):
"--position",
"-p",
default="50%",
- help=("The position where the slider starts"),
+ help=("The start position of the slider"),
)
@magic_arguments.argument(
"--height",
"-h",
default="300",
help=(
- "The height that the widget has. The width will be adjusted automatically. \
- If height is choosen 'auto', the height will be defined by the resolution \
- in vertical direction of the first image."
+ "The widget's height. The width will be adjusted automatically. \
+ If height is `auto`, the vertical resolution of the first image is used."
),
)
@cell_magic
@@ -43,7 +52,7 @@ def splity(self, line, cell):
png_bytes_data = data["image/png"]
out_images_base64.append(png_bytes_data)
- # get the parameters the configure the widget
+ # get the parameters that configure the widget
args = magic_arguments.parse_argstring(SplitViewMagic.splity, line)
slider_position = args.position
@@ -53,17 +62,20 @@ def splity(self, line, cell):
imgdata = b64decode(out_images_base64[0])
# maybe possible without the PIL dependency?
im = Image.open(io.BytesIO(imgdata))
- width, height = im.size
- widget_height = height
+ widget_height = im.size[1]
- html_code = f"""
-