Skip to content

Commit

Permalink
add test for save_image
Browse files Browse the repository at this point in the history
  • Loading branch information
superstar54 committed Jan 10, 2025
1 parent 2251a53 commit be99491
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions js/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ function render({ model, el }) {
// loop through the data and update the model
// console.log("viewerUpdated: ", data);
for (const key in data) {
// skip atomScales, modelSticks, modelPolyhedras
if (key === "atomScales" || key === "modelSticks" || key === "modelPolyhedras") {
continue;
}
model.set(key, data[key]);
}
model.save_changes();
Expand Down
22 changes: 21 additions & 1 deletion tests/notebooks/tests/notebooks/widgets.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -252,11 +252,31 @@
"viewer.avr.atom_scales = [1 if atom.symbol == \"Pt\" else 0.4 for atom in slab]\n",
"viewer"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"## save image\n",
"# get path of current file\n",
"import os\n",
"from ipywidgets import Image\n",
"import time\n",
"\n",
"path = os.getcwd()\n",
"viewer.save_image(os.path.join(path, \"test.png\"))\n",
"\n",
"time.sleep(5)\n",
"\n",
"Image(value=open(os.path.join(path, \"test.png\"), \"rb\").read())"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "aiida",
"language": "python",
"name": "python3"
},
Expand Down

0 comments on commit be99491

Please sign in to comment.