{ "cells": [ { "cell_type": "markdown", "id": "2b8ad740", "metadata": {}, "source": [ "# Basic GUI usage" ] }, { "cell_type": "code", "execution_count": 2, "id": "2eba55b1-2ab7-4f07-a76c-34f5a184da4d", "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Warning: no DISPLAY environment variable.\n", "--No graphics will be displayed.\n" ] } ], "source": [ "import time\n", "from hnn_core.gui.gui import HNNGUI\n", "from ipywidgets import Output\n", "from IPython.display import Javascript\n", "\n", "# do not mix this with GUI operations\n", "gui = HNNGUI()" ] }, { "cell_type": "code", "execution_count": 10, "id": "norwegian-angola", "metadata": { "require": [ "html2canvas" ], "scrolled": true }, "outputs": [], "source": [ "gui.compose(return_layout=False)" ] }, { "cell_type": "code", "execution_count": 11, "id": "0cda6c80-b159-443f-a425-1da555784bc8", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "gui.capture(width=1380, height=600)" ] }, { "cell_type": "code", "execution_count": 12, "id": "d39f7169", "metadata": {}, "outputs": [], "source": [ "gui.app_layout.left_sidebar.selected_index = 2" ] }, { "cell_type": "code", "execution_count": 13, "id": "86b15f2c-fb02-46aa-a4ce-69030a8fcf32", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "gui.capture()" ] }, { "cell_type": "markdown", "id": "ff875b7c", "metadata": {}, "source": [ "Now let's click the \"Run\" button to launch the simulation." ] }, { "cell_type": "code", "execution_count": 14, "id": "7889c5ef-4e2c-439f-82a7-9b075440d799", "metadata": {}, "outputs": [], "source": [ "gui.run_button.click()" ] }, { "cell_type": "markdown", "id": "2fdad219", "metadata": {}, "source": [ "You can observe the simulation results at the right side of the GUI:" ] }, { "cell_type": "code", "execution_count": 15, "id": "87b85cc9-097b-45fa-b4e1-643bd08dd356", "metadata": { "scrolled": true }, "outputs": [ { "data": { "text/html": [ "\n", " \n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "gui.capture()" ] }, { "cell_type": "code", "execution_count": 9, "id": "696e649c", "metadata": {}, "outputs": [ { "data": { "application/javascript": "\n function sleep(ms) {\n return new Promise(resolve => setTimeout(resolve, ms));\n }\n function getRunningStatus(idx){\n const htmlContent = Jupyter.notebook.get_cell(idx).element[0];\n return htmlContent.childNodes[0].childNodes[0].textContent;\n }\n function cellContainsInit(idx){\n const textVal = Jupyter.notebook.get_cell(\n idx).element[0].childNodes[0].textContent;\n return textVal.includes('HNNGUI()') || textVal.includes('HNNGUI');\n }\n function cellContainsRunCells(idx){\n const textVal = Jupyter.notebook.get_cell(\n idx).element[0].childNodes[0].textContent;\n return textVal.includes('run_notebook_cells()');\n }\n async function runNotebook() {\n console.log(\"run notebook cell by cell\");\n const cellHtmlContents = Jupyter.notebook.element[0].children[0];\n const nCells = cellHtmlContents.childElementCount;\n console.log(`In total we have ${nCells} cells`);\n\n for(let i=1; i" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "Javascript(gui.run_notebook_cells())" ] } ], "metadata": { "finalized": { "timestamp": 1659128328299, "trusted": true }, "kernelspec": { "display_name": "Python 3.8.12 ('gsoc')", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.12" }, "require": { "paths": { "html2canvas": "https://html2canvas.hertzen.com/dist/html2canvas" }, "shim": {} }, "vscode": { "interpreter": { "hash": "43b52e66020a3206304124443c3dbfb478b19fdebbaacdf952e81bd31b11f0ba" } } }, "nbformat": 4, "nbformat_minor": 5 }