Skip to content

Commit 78ee72c

Browse files
committed
Cleanup of the control notebook
1 parent 5b3dcf9 commit 78ee72c

1 file changed

Lines changed: 2 additions & 14 deletions

File tree

control.ipynb

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,15 @@
1414
"id": "1",
1515
"metadata": {},
1616
"outputs": [],
17-
"source": [
18-
"import ipywidgets as ipw\n",
19-
"from aiida import load_profile\n",
20-
"from IPython.display import clear_output\n",
21-
"\n",
22-
"load_profile()\n",
23-
"from home.control import (\n",
24-
" DaemonControlWidget,\n",
25-
" GroupControlWidget,\n",
26-
" ProcessControlWidget,\n",
27-
" ProfileControlWidget,\n",
28-
")"
29-
]
17+
"source": "import ipywidgets as ipw\nfrom aiida import load_profile\n\nload_profile()\nfrom home.control import (\n DaemonControlWidget,\n GroupControlWidget,\n ProcessControlWidget,\n ProfileControlWidget,\n)"
3018
},
3119
{
3220
"cell_type": "code",
3321
"execution_count": null,
3422
"id": "2",
3523
"metadata": {},
3624
"outputs": [],
37-
"source": "correspondance = {\n \"Daemon\": DaemonControlWidget,\n \"Group\": GroupControlWidget,\n \"Process\": ProcessControlWidget,\n \"Profile\": ProfileControlWidget,\n}\n\ntoc = ipw.ToggleButtons(\n options=correspondance.keys(),\n value=None,\n orientation=\"vertical\",\n layout=ipw.Layout(width=\"200px\"),\n)\n\n\noutput = ipw.Output()\n\n\ndef update_output(value=None):\n if value is None:\n value = {\"new\": \"Group\"}\n if value[\"new\"] in correspondance:\n with output:\n clear_output()\n try:\n widget = correspondance[value[\"new\"]]()\n except Exception as exc:\n widget = ipw.HTML(\n f'<div class=\"alert alert-danger\" role=\"alert\">'\n f'Failed to open the \"{value[\"new\"]}\" section: {exc}</div>'\n )\n display(widget)\n\n\ntoc.observe(update_output, names=\"value\")\n\ntoc.value = \"Daemon\"\ndisplay(ipw.HBox([toc, output]))"
25+
"source": "sections = {\n \"Daemon\": DaemonControlWidget,\n \"Group\": GroupControlWidget,\n \"Process\": ProcessControlWidget,\n \"Profile\": ProfileControlWidget,\n}\n\ntoc = ipw.ToggleButtons(\n options=sections.keys(),\n value=None,\n orientation=\"vertical\",\n layout=ipw.Layout(width=\"200px\"),\n)\n\ncontent = ipw.VBox()\nsection_instances = {}\n\n\ndef open_section(change):\n name = change[\"new\"]\n if name not in sections:\n return\n widget = section_instances.get(name)\n if widget is None:\n try:\n widget = sections[name]()\n except Exception as exc:\n content.children = [\n ipw.HTML(\n f'<div class=\"alert alert-danger\" role=\"alert\">'\n f'Failed to open the \"{name}\" section: {exc}</div>'\n )\n ]\n return\n section_instances[name] = widget\n content.children = [widget]\n\n\ntoc.observe(open_section, names=\"value\")\ntoc.value = \"Daemon\"\ndisplay(ipw.HBox([toc, content]))"
3826
}
3927
],
4028
"metadata": {

0 commit comments

Comments
 (0)