Skip to content

Commit

Permalink
updated drawing example to match main ipywidget strucute
Browse files Browse the repository at this point in the history
  • Loading branch information
bcalford committed Dec 2, 2024
1 parent 54a257e commit 2951661
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
30 changes: 15 additions & 15 deletions examples/drawing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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)"
]
},
{
Expand All @@ -98,8 +98,8 @@
"metadata": {},
"outputs": [],
"source": [
"for i in widgetArray:\n",
" display(i[0])"
"for widget in widgetArray:\n",
" display(widget[\"widget\"])"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions js/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 2951661

Please sign in to comment.