Skip to content

Commit

Permalink
Reverted back to original naming of widget class.
Browse files Browse the repository at this point in the history
  • Loading branch information
Taylor-96 committed Jun 26, 2024
1 parent f9ff2cf commit 247b6b7
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 28 deletions.
79 changes: 56 additions & 23 deletions example/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
"cells": [
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "5df2c405",
"metadata": {},
"outputs": [],
"source": [
"from widget_code_input import CodeInputWidget\n",
"from widget_code_input import WidgetCodeInput\n",
"# import importlib\n",
"# importlib.reload(code_input_widget)\n",
"\n",
"w = CodeInputWidget(\n",
"w = WidgetCodeInput(\n",
" function_name = \"my_function\",\n",
" function_parameters = \"a, b\",\n",
" docstring=\"\"\"\n",
Expand All @@ -25,17 +25,33 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"id": "e74c9c9e",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "80b8268cbfe0416494f266f6f8a19aa1",
"version_major": 2,
"version_minor": 1
},
"text/plain": [
"WidgetCodeInput(code_theme='basicLight', docstring='\\n Input docstring here.\\n', function_body='# Give infor…"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"w"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"id": "4d389a14",
"metadata": {},
"outputs": [],
Expand All @@ -45,27 +61,28 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "2fc2b3ed",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"my_function(1, 2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "601edb7d",
"metadata": {},
"outputs": [],
"source": [
"w.code_theme=\"nord\""
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "e90010bd",
"metadata": {},
"outputs": [],
Expand All @@ -75,12 +92,28 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"id": "75900629",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9238263cacc04a728e878c13d8fac749",
"version_major": 2,
"version_minor": 1
},
"text/plain": [
"WidgetCodeInput(code_theme='basicLight', docstring='\\n Input docstring here.\\n', function_body='# Give infor…"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"w2 = CodeInputWidget(\n",
"w2 = WidgetCodeInput(\n",
" function_name = \"my_function\",\n",
" function_parameters = \"a, b, c\",\n",
" docstring=\"\"\"\n",
Expand Down Expand Up @@ -109,7 +142,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
10 changes: 5 additions & 5 deletions src/widget_code_input/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
)


bundler_output_dir = pathlib.Path(os.path.dirname(os.path.abspath(__file__))) / "./static"



class CodeInputWidget(anywidget.AnyWidget):
class WidgetCodeInput(anywidget.AnyWidget):
_esm = pathlib.Path(__file__).parent / "static" / "widget.js"
_css = pathlib.Path(__file__).parent / "static" / "widget.css"
widget_instance_count=0 # counter to keep track of number of widget instances in use
Expand Down Expand Up @@ -90,15 +90,15 @@ def __init__( # pylint: disable=too-many-arguments
:param code_theme: the code theme of the code input box.
"""

super(CodeInputWidget, self).__init__()
super(WidgetCodeInput, self).__init__()

self.function_name = function_name
self.function_parameters = function_parameters
self.docstring = docstring
self.function_body = function_body
self.code_theme = code_theme
self.widget_instance_count_trait=f"{CodeInputWidget.widget_instance_count}"
CodeInputWidget.widget_instance_count+=1
self.widget_instance_count_trait=f"{WidgetCodeInput.widget_instance_count}"
WidgetCodeInput.widget_instance_count+=1



Expand Down

0 comments on commit 247b6b7

Please sign in to comment.