From 42653af1168b4666676e6a82b4e736d76f2f2313 Mon Sep 17 00:00:00 2001 From: David Huss <dh@atoav.com> Date: Thu, 16 Nov 2023 23:12:05 +0100 Subject: [PATCH] Add output to jupyter script --- circuitsim/lookup-tables.ipynb | 41 +++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/circuitsim/lookup-tables.ipynb b/circuitsim/lookup-tables.ipynb index 2dba0b1..b30e8f1 100644 --- a/circuitsim/lookup-tables.ipynb +++ b/circuitsim/lookup-tables.ipynb @@ -480,14 +480,14 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 4, "id": "e51416f3-f34d-4513-9f0c-fa52c468274e", "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "e9fff586d6da4132a47d3bb55ba0a36f", + "model_id": "1ca5e203dc524b9d939312138ecffcea", "version_major": 2, "version_minor": 0 }, @@ -500,11 +500,25 @@ }, { "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "6418d780e5664aa6b160a0322d143213", + "version_major": 2, + "version_minor": 0 + }, "text/plain": [ - "<function __main__.draw(f)>" + "Button(button_style='success', description='copy C++ to clipboard', style=ButtonStyle())" + ] + }, + "metadata": {}, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "42" ] }, - "execution_count": 1, + "execution_count": 4, "metadata": {}, "output_type": "execute_result" } @@ -515,6 +529,7 @@ "from ipywidgets import interact, FloatSlider\n", "import matplotlib.transforms as transforms\n", "import math\n", + "import clipboard\n", "\n", "def draw(f):\n", " fig = plt.figure(figsize=(8, 4))\n", @@ -630,8 +645,24 @@ "# draw(x, y, 0.45/2)\n", "\n", "interact(draw, f=FloatSlider(min=min(x), max=max(x), step=0.001, value=0.2))\n", + "text = \"\"\n", + "text += \"// Lookup Table for Pitch Knob\\n\"\n", + "text += f\"float pitch_knob_x[] = {{{', '.join(str(xv) for xv in x)}}};\\n\\n\"\n", + "text += f\"float pitch_knob_y[] = {{{', '.join(str(yv) for yv in y)}}};\\n\\n\"\n", + "\n", + "import ipywidgets as widgets\n", + "from IPython.display import display, HTML, Javascript\n", + "mybtn = widgets.Button(description='copy C++ to clipboard', button_style='success')\n", + "\n", + "def mybtn_event_handler(b):\n", + " print(\"copied\")\n", + " clipboard.copy(text)\n", + "\n", + "mybtn.on_click(mybtn_event_handler)\n", + "\n", + "display(mybtn)\n", "\n", - " " + "len(x)" ] }, { -- GitLab