From 295166154cff304c24be1e375498684d21a8f970 Mon Sep 17 00:00:00 2001 From: bcalford Date: Mon, 2 Dec 2024 16:21:57 -0500 Subject: [PATCH] updated drawing example to match main ipywidget strucute --- examples/drawing.ipynb | 30 +++++++++++++++--------------- js/widget.ts | 4 ++-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/examples/drawing.ipynb b/examples/drawing.ipynb index 98610b7..211bc5c 100644 --- a/examples/drawing.ipynb +++ b/examples/drawing.ipynb @@ -23,7 +23,7 @@ "source": [ "import ipywidgets\n", "\n", - "from ipyniivue import NiiVue, SliceType, WidgetChange\n", + "from ipyniivue import NiiVue, SliceType, WidgetObserver\n", "\n", "volumes = [\n", " {\n", @@ -59,26 +59,26 @@ "\n", "widgetArray = []\n", "\n", - "widget_pen_value = [\n", - " ipywidgets.RadioButtons(\n", + "widget_pen_value = {\n", + " \"widget\": ipywidgets.RadioButtons(\n", " options=[(\"Erase\", 0), (\"Red\", 1), (\"Green\", 2), (\"Blue\", 3)],\n", " value=1,\n", " description=\"Draw Color:\",\n", " ),\n", - " nv,\n", - " \"pen_value\",\n", - "]\n", + " \"object\": nv,\n", + " \"attribute\": \"pen_value\",\n", + "}\n", "widgetArray.append(widget_pen_value)\n", "\n", - "widget_slice_type = [\n", - " ipywidgets.ToggleButton(value=False, description=\"Fill Drawing\", button_style=\"\"),\n", - " nv,\n", - " \"is_filled_pen\",\n", - "]\n", + "widget_slice_type = {\n", + " \"widget\": ipywidgets.ToggleButton(value=False, description=\"Fill Drawing\"),\n", + " \"object\": nv,\n", + " \"attribute\": \"is_filled_pen\",\n", + "}\n", "widgetArray.append(widget_slice_type)\n", "\n", - "for i in widgetArray:\n", - " i[0].observe(WidgetChange(i[1], i[2]).widget_change, names=[\"value\"])" + "for widget in widgetArray:\n", + " WidgetObserver(**widget)" ] }, { @@ -98,8 +98,8 @@ "metadata": {}, "outputs": [], "source": [ - "for i in widgetArray:\n", - " display(i[0])" + "for widget in widgetArray:\n", + " display(widget[\"widget\"])" ] }, { diff --git a/js/widget.ts b/js/widget.ts index 18ee335..62fc234 100644 --- a/js/widget.ts +++ b/js/widget.ts @@ -21,11 +21,11 @@ export default { model.on("change:_volumes", () => render_volumes(nv, model, disposer)); await render_meshes(nv, model, disposer); model.on("change:_meshes", () => render_meshes(nv, model, disposer)); - + nv.createEmptyDrawing(); // Any time we change the options, we need to update the nv object - // and redraw the scene. + // and redraw the scene. model.on("change:_opts", () => { nv.document.opts = { ...nv.opts, ...model.get("_opts") }; nv.drawScene();