diff --git a/example/example.ipynb b/example/example.ipynb index 0f50079..f2c9da0 100644 --- a/example/example.ipynb +++ b/example/example.ipynb @@ -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", @@ -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": [], @@ -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": [], @@ -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", @@ -109,7 +142,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.11.7" + "version": "3.10.12" } }, "nbformat": 4, diff --git a/src/widget_code_input/__init__.py b/src/widget_code_input/__init__.py index e4df366..f1458f5 100644 --- a/src/widget_code_input/__init__.py +++ b/src/widget_code_input/__init__.py @@ -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 @@ -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