Skip to content

Commit 1399daf

Browse files
committed
Added functionality which allows user to create the widget without a docstring and dynamically add/remove it later in lifecycle.
1 parent 3b0e400 commit 1399daf

File tree

3 files changed

+348
-57
lines changed

3 files changed

+348
-57
lines changed

example/example.ipynb

Lines changed: 103 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,85 +3,158 @@
33
{
44
"cell_type": "code",
55
"execution_count": null,
6+
"id": "ee3f55c6-5f98-4572-aea1-a66776dc7d7b",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": []
10+
},
11+
{
12+
"cell_type": "code",
13+
"execution_count": 1,
614
"id": "5df2c405",
715
"metadata": {},
816
"outputs": [],
917
"source": [
1018
"from widget_code_input import WidgetCodeInput\n",
11-
"# import importlib\n",
12-
"# importlib.reload(code_input_widget)\n",
19+
"import importlib\n",
20+
"\n",
21+
"\n",
1322
"\n",
1423
"w = WidgetCodeInput(\n",
1524
" function_name = \"my_function\",\n",
1625
" function_parameters = \"a, b\",\n",
17-
" docstring=\"\"\"\n",
18-
" Input docstring here.\n",
19-
"\"\"\",\n",
20-
" function_body=\"# Give information for the function\\nreturn a+b\",\n",
21-
" code_theme=\"basicLight\"\n",
26+
"# docstring='abc',\n",
27+
" docstring=\"abc\",\n",
28+
" code_theme=\"basicLight\",\n",
29+
" function_body=\"return a+b\"\n",
2230
")\n",
2331
"\n"
2432
]
2533
},
2634
{
2735
"cell_type": "code",
28-
"execution_count": null,
36+
"execution_count": 2,
2937
"id": "e74c9c9e",
3038
"metadata": {
3139
"scrolled": true
3240
},
33-
"outputs": [],
41+
"outputs": [
42+
{
43+
"data": {
44+
"application/vnd.jupyter.widget-view+json": {
45+
"model_id": "d1679bd64f174ba6a3c248a14e9f87f5",
46+
"version_major": 2,
47+
"version_minor": 0
48+
},
49+
"text/plain": [
50+
"WidgetCodeInput(code_theme='basicLight', docstring='\"\"\"abc\"\"\"', function_body='return a+b', function_name='my_…"
51+
]
52+
},
53+
"metadata": {},
54+
"output_type": "display_data"
55+
}
56+
],
3457
"source": [
3558
"w"
3659
]
3760
},
3861
{
3962
"cell_type": "code",
40-
"execution_count": null,
41-
"id": "4d389a14",
63+
"execution_count": 3,
64+
"id": "e90010bd",
4265
"metadata": {},
4366
"outputs": [],
4467
"source": [
45-
"my_function = w.get_function_object()"
68+
"w.code_theme=\"solarizedLight\""
4669
]
4770
},
4871
{
4972
"cell_type": "code",
50-
"execution_count": null,
51-
"id": "2fc2b3ed",
73+
"execution_count": 6,
74+
"id": "22853da3-2882-4b4a-b777-bf76bf301de9",
5275
"metadata": {},
5376
"outputs": [],
5477
"source": [
55-
"my_function(1, 2)"
78+
"w.docstring=None"
5679
]
5780
},
5881
{
5982
"cell_type": "code",
60-
"execution_count": null,
61-
"id": "e90010bd",
83+
"execution_count": 7,
84+
"id": "3d023823",
6285
"metadata": {},
6386
"outputs": [],
6487
"source": [
65-
"w.code_theme=\"solarizedLight\""
88+
"w.docstring=\"334\""
6689
]
6790
},
6891
{
6992
"cell_type": "code",
70-
"execution_count": null,
93+
"execution_count": 6,
94+
"id": "5ea3d39d",
95+
"metadata": {},
96+
"outputs": [
97+
{
98+
"data": {
99+
"application/vnd.jupyter.widget-view+json": {
100+
"model_id": "eec6fdedac434c68ae22c7ad56283ef2",
101+
"version_major": 2,
102+
"version_minor": 0
103+
},
104+
"text/plain": [
105+
"WidgetCodeInput(code_theme='basicLight', docstring='334', function_body='return a+b', function_name='my_functi…"
106+
]
107+
},
108+
"metadata": {},
109+
"output_type": "display_data"
110+
}
111+
],
112+
"source": [
113+
"w"
114+
]
115+
},
116+
{
117+
"cell_type": "code",
118+
"execution_count": 7,
119+
"id": "e8e56926",
120+
"metadata": {},
121+
"outputs": [
122+
{
123+
"data": {
124+
"application/vnd.jupyter.widget-view+json": {
125+
"model_id": "0bc406910d7f433b975a37e36cd7f248",
126+
"version_major": 2,
127+
"version_minor": 0
128+
},
129+
"text/plain": [
130+
"WidgetCodeInput(code_theme='solarizedLight', docstring='123', function_body='return a+b', function_name='my_fu…"
131+
]
132+
},
133+
"metadata": {},
134+
"output_type": "display_data"
135+
}
136+
],
137+
"source": [
138+
"w"
139+
]
140+
},
141+
{
142+
"cell_type": "code",
143+
"execution_count": 8,
71144
"id": "75900629",
72145
"metadata": {},
73146
"outputs": [],
74147
"source": [
75-
"w2 = WidgetCodeInput(\n",
76-
" function_name = \"my_function\",\n",
77-
" function_parameters = \"a, b, c\",\n",
78-
" docstring=\"\"\"\n",
79-
" Input docstring here.\n",
80-
"\"\"\",\n",
81-
" function_body=\"# Give information for the function\\nreturn a+b+c\",\n",
82-
" code_theme=\"basicLight\"\n",
83-
")\n",
84-
"w2"
148+
"# w2 = WidgetCodeInput(\n",
149+
"# function_name = \"my_function\",\n",
150+
"# function_parameters = \"a, b, c\",\n",
151+
"# docstring=\"\"\"\n",
152+
"# Input docstring here.\n",
153+
"# \"\"\",\n",
154+
"# function_body=\"# Give information for the function\\nreturn a+b+c\",\n",
155+
"# code_theme=\"basicLight\"\n",
156+
"# )\n",
157+
"# w2"
85158
]
86159
}
87160
],
@@ -101,7 +174,7 @@
101174
"name": "python",
102175
"nbconvert_exporter": "python",
103176
"pygments_lexer": "ipython3",
104-
"version": "3.10.15"
177+
"version": "3.10.12"
105178
}
106179
},
107180
"nbformat": 4,

0 commit comments

Comments
 (0)