Skip to content

Commit

Permalink
Added functionality which allows user to create the widget without a …
Browse files Browse the repository at this point in the history
…docstring and dynamically add/remove it later in lifecycle.
  • Loading branch information
Taylor-96 committed Jan 18, 2025
1 parent 3b0e400 commit 1399daf
Show file tree
Hide file tree
Showing 3 changed files with 348 additions and 57 deletions.
133 changes: 103 additions & 30 deletions example/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,85 +3,158 @@
{
"cell_type": "code",
"execution_count": null,
"id": "ee3f55c6-5f98-4572-aea1-a66776dc7d7b",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 1,
"id": "5df2c405",
"metadata": {},
"outputs": [],
"source": [
"from widget_code_input import WidgetCodeInput\n",
"# import importlib\n",
"# importlib.reload(code_input_widget)\n",
"import importlib\n",
"\n",
"\n",
"\n",
"w = WidgetCodeInput(\n",
" function_name = \"my_function\",\n",
" function_parameters = \"a, b\",\n",
" docstring=\"\"\"\n",
" Input docstring here.\n",
"\"\"\",\n",
" function_body=\"# Give information for the function\\nreturn a+b\",\n",
" code_theme=\"basicLight\"\n",
"# docstring='abc',\n",
" docstring=\"abc\",\n",
" code_theme=\"basicLight\",\n",
" function_body=\"return a+b\"\n",
")\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "e74c9c9e",
"metadata": {
"scrolled": true
},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d1679bd64f174ba6a3c248a14e9f87f5",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"WidgetCodeInput(code_theme='basicLight', docstring='\"\"\"abc\"\"\"', function_body='return a+b', function_name='my_…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"w"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4d389a14",
"execution_count": 3,
"id": "e90010bd",
"metadata": {},
"outputs": [],
"source": [
"my_function = w.get_function_object()"
"w.code_theme=\"solarizedLight\""
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2fc2b3ed",
"execution_count": 6,
"id": "22853da3-2882-4b4a-b777-bf76bf301de9",
"metadata": {},
"outputs": [],
"source": [
"my_function(1, 2)"
"w.docstring=None"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e90010bd",
"execution_count": 7,
"id": "3d023823",
"metadata": {},
"outputs": [],
"source": [
"w.code_theme=\"solarizedLight\""
"w.docstring=\"334\""
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "5ea3d39d",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "eec6fdedac434c68ae22c7ad56283ef2",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"WidgetCodeInput(code_theme='basicLight', docstring='334', function_body='return a+b', function_name='my_functi…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"w"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "e8e56926",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "0bc406910d7f433b975a37e36cd7f248",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"WidgetCodeInput(code_theme='solarizedLight', docstring='123', function_body='return a+b', function_name='my_fu…"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"w"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "75900629",
"metadata": {},
"outputs": [],
"source": [
"w2 = WidgetCodeInput(\n",
" function_name = \"my_function\",\n",
" function_parameters = \"a, b, c\",\n",
" docstring=\"\"\"\n",
" Input docstring here.\n",
"\"\"\",\n",
" function_body=\"# Give information for the function\\nreturn a+b+c\",\n",
" code_theme=\"basicLight\"\n",
")\n",
"w2"
"# w2 = WidgetCodeInput(\n",
"# function_name = \"my_function\",\n",
"# function_parameters = \"a, b, c\",\n",
"# docstring=\"\"\"\n",
"# Input docstring here.\n",
"# \"\"\",\n",
"# function_body=\"# Give information for the function\\nreturn a+b+c\",\n",
"# code_theme=\"basicLight\"\n",
"# )\n",
"# w2"
]
}
],
Expand All @@ -101,7 +174,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.15"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit 1399daf

Please sign in to comment.