Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ipywidgets python api #6868

Merged
merged 1 commit into from
Feb 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions beakerx/beakerx/beakerx_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ def fireChanged(self, x=None):
def set_value(self, new_value):
self.value = new_value

def add_interface_to(target):
target.onInitListeners = list()
target.onChangeListeners = list()
target.onInit = types.MethodType(EasyFormComponent.onInit, target)
target.onChange = types.MethodType(EasyFormComponent.onChange, target)
target.fireInit = types.MethodType(EasyFormComponent.fireInit, target)
target.fireChanged = types.MethodType(EasyFormComponent.fireChanged, target)
target.set_value = types.MethodType(EasyFormComponent.set_value, target)



class BeakerxLayout(Layout):
_view_module = Unicode('@jupyter-widgets/base').tag(sync=True)
Expand Down
6 changes: 6 additions & 0 deletions beakerx/beakerx/easyform/easyform.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ def addRadioButtons(self, *args, **kwargs):
self.components[radio_buttons.description] = radio_buttons
return radio_buttons

def addWidget(self, name, widget):
EasyFormComponent.add_interface_to(widget)
self.children += (widget,)
self.components[name] = widget
return widget

def __iter__(self):
return iter(self.components)

Expand Down
38 changes: 38 additions & 0 deletions doc/python/EasyForm.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,44 @@
"\n",
"result"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## JupyterJSWidgets work with EasyForm\n",
"\n",
"The widgets from JupyterJSWidgets are compatible and can appear in forms."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from beakerx import *\n",
"from ipywidgets import * \n",
"w = IntSlider()\n",
"\n",
"f = EasyForm(\"Form and Run\")\n",
"f.addTextField(\"first\")\n",
"f.addTextField(\"last\")\n",
"f.addWidget(\"slider\", w)\n",
"f['first'] = \"First\"\n",
"f['last'] = \"Last\"\n",
"f.addButton(\"Go!\", tag=\"run\")\n",
"f"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"f['slider']"
]
}
],
"metadata": {
Expand Down