From 4261d43c0e2b0db9f2769c7ab595751df18c692b Mon Sep 17 00:00:00 2001 From: David Marx Date: Thu, 23 Jun 2022 08:49:34 -0700 Subject: [PATCH] re-added make_hbox for show_palette --- src/pytti/update_func.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/pytti/update_func.py b/src/pytti/update_func.py index 435f1e2..5fbf601 100644 --- a/src/pytti/update_func.py +++ b/src/pytti/update_func.py @@ -34,6 +34,34 @@ OUTPATH = f"{os.getcwd()}/images_out" +def make_hbox(im, fig): + # https://stackoverflow.com/questions/51315566/how-to-display-the-images-side-by-side-in-jupyter-notebook/51316108 + import io + import ipywidgets as widgets + from ipywidgets import Layout + + with io.BytesIO() as buf: + im.save(buf, format="png") + buf.seek(0) + wi1 = widgets.Image( + value=buf.read(), + format="png", + layout=Layout(border="0", margin="0", padding="0"), + ) + with io.BytesIO() as buf: + fig.savefig(buf, format="png", bbox_inches="tight") + buf.seek(0) + wi2 = widgets.Image( + value=buf.read(), + format="png", + layout=Layout(border="0", margin="0", padding="0"), + ) + return widgets.HBox( + [wi1, wi2], + layout=Layout(border="0", margin="0", padding="0", align_items="flex-start"), + ) + + # Update is called each step. def update( model, @@ -140,9 +168,9 @@ def save_out( # delete the file. if file not found, nothing happens. if fpath.exists(): fpath.unlink() - #fpath.unlink( + # fpath.unlink( # missing_ok=True - #) + # ) j = i + 1