409 lines
8.4 KiB
Text
409 lines
8.4 KiB
Text
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<script>$(\"div.input\").hide()</script>"
|
|
],
|
|
"text/plain": [
|
|
"<IPython.core.display.HTML object>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
"model_id": "2577c5a004bf43bab5d87bfda405e6f2",
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
},
|
|
"text/plain": [
|
|
"ToggleButton(value=False, description='Show code')"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"<script>$(\"div.input\").show()</script>"
|
|
],
|
|
"text/plain": [
|
|
"<IPython.core.display.HTML object>"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"import ipywidgets as widgets\n",
|
|
"from IPython.display import display, HTML\n",
|
|
"\n",
|
|
"javascript_functions = {False: \"hide()\", True: \"show()\"}\n",
|
|
"button_descriptions = {False: \"Show code\", True: \"Hide code\"}\n",
|
|
"\n",
|
|
"\n",
|
|
"def toggle_code(state):\n",
|
|
"\n",
|
|
" \"\"\"\n",
|
|
" Toggles the JavaScript show()/hide() function on the div.input element.\n",
|
|
" \"\"\"\n",
|
|
"\n",
|
|
" output_string = \"<script>$(\\\"div.input\\\").{}</script>\"\n",
|
|
" output_args = (javascript_functions[state],)\n",
|
|
" output = output_string.format(*output_args)\n",
|
|
"\n",
|
|
" display(HTML(output))\n",
|
|
"\n",
|
|
"\n",
|
|
"def button_action(value):\n",
|
|
"\n",
|
|
" \"\"\"\n",
|
|
" Calls the toggle_code function and updates the button description.\n",
|
|
" \"\"\"\n",
|
|
"\n",
|
|
" state = value.new\n",
|
|
"\n",
|
|
" toggle_code(state)\n",
|
|
"\n",
|
|
" value.owner.description = button_descriptions[state]\n",
|
|
"\n",
|
|
"\n",
|
|
"state = False\n",
|
|
"toggle_code(state)\n",
|
|
"\n",
|
|
"button = widgets.ToggleButton(state, description = button_descriptions[state])\n",
|
|
"button.observe(button_action, \"value\")\n",
|
|
"\n",
|
|
"display(button)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {
|
|
"tags": [
|
|
"hide_input"
|
|
]
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"\n",
|
|
"import ipywidgets as widgets"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 3,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"\n",
|
|
"a = widgets.Button(\n",
|
|
" description='Click me',\n",
|
|
" disabled=False,\n",
|
|
" button_style='info', # 'success', 'info', 'warning', 'danger' or ''\n",
|
|
" tooltip='Click me',\n",
|
|
" icon='check'\n",
|
|
")\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"metadata": {
|
|
"scrolled": true
|
|
},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
"model_id": "a01d7a898a854340895b5e2db50ac6f6",
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
},
|
|
"text/plain": [
|
|
"Button(button_style='info', description='Click me', icon='check', style=ButtonStyle(), tooltip='Click me')"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"display(a)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 5,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def f():\n",
|
|
" print('oi')"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
"model_id": "4bd67cab7f73498d817f247cd81bc78e",
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
},
|
|
"text/plain": [
|
|
"interactive(children=(Button(description='Run Interact', style=ButtonStyle()), Output()), _dom_classes=('widge…"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
},
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"<function __main__.f()>"
|
|
]
|
|
},
|
|
"execution_count": 6,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"\n",
|
|
"widgets.interact_manual(f)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 7,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"{'manual': True, 'auto_display': True, 'manual_name': 'Run Interact'}\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(widgets.interact_manual.opts)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 8,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"a = widgets.Textarea(value='Hello World!', disabled=False)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
"model_id": "b83754a4bd7f4301a7e88ab25f10af7c",
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
},
|
|
"text/plain": [
|
|
"Textarea(value='Hello World!')"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"display(a)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"Hello World!\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(a.value)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 11,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"b = widgets.Checkbox(\n",
|
|
" value=True,\n",
|
|
" description='Check me',\n",
|
|
" disabled=False\n",
|
|
")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 12,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"application/vnd.jupyter.widget-view+json": {
|
|
"model_id": "a00cc061e21b4f949576e2a4de2bc30c",
|
|
"version_major": 2,
|
|
"version_minor": 0
|
|
},
|
|
"text/plain": [
|
|
"Checkbox(value=True, description='Check me')"
|
|
]
|
|
},
|
|
"metadata": {},
|
|
"output_type": "display_data"
|
|
}
|
|
],
|
|
"source": [
|
|
"display(b)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 13,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"True\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(b.value)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 19,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"from oi import *"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 20,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"oi = oi()\n",
|
|
"def function():\n",
|
|
" \n",
|
|
" ale = oi.CellInputText2Splitsentences(a.value)\n",
|
|
" print(ale)\n",
|
|
" return None"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 21,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"ename": "SyntaxError",
|
|
"evalue": "invalid syntax (<ipython-input-21-d0d88c89e015>, line 1)",
|
|
"output_type": "error",
|
|
"traceback": [
|
|
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-21-d0d88c89e015>\"\u001b[0;36m, line \u001b[0;32m1\u001b[0m\n\u001b[0;31m widgets.interact_manual.opts[manual_name=Output the Text to splitsentences]\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"widgets.interact_manual.opts['manual_name']= 'Output the Text to splitsentences'\n",
|
|
"widgets.interact_manual(function)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 17,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"<class 'str'>\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"print(type(a.value))"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.5.3"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|