Skip to content

Commit

Permalink
#6716 fixed code interaction for combobox in python
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukasz Mitusinski committed Feb 1, 2018
1 parent dbe869b commit af8bccf
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 17 additions & 4 deletions beakerx/beakerx/beakerx_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
SelectMultiple, Select, Dropdown, Checkbox, HBox, \
VBox, RadioButtons, register, Layout, widget_serialization, HTML
from ipywidgets.widgets.trait_types import InstanceDict
from traitlets import Int, Unicode, Dict, Bool, Union, List
from traitlets import Int, Unicode, Dict, Bool, Union, List, Any, observe
from IPython.display import display
import types

Expand Down Expand Up @@ -45,6 +45,9 @@ def fireChanged(self, x=None):
for f in self.onChangeListeners:
f(x)

def set_value(self, new_value):
self.value = new_value


class BeakerxLayout(Layout):
_view_module = Unicode('@jupyter-widgets/base').tag(sync=True)
Expand Down Expand Up @@ -205,18 +208,28 @@ def __init__(self, **kwargs):
_model_module_version = Unicode('*').tag(sync=True)
_view_module_version = Unicode('*').tag(sync=True)
editable = Bool(default_value=False).tag(sync=True)
value = Any(None, allow_none=True).tag(sync=True)
original_options = Union([List(), Dict()])
style = None

def _update_options_list(self, new_value):
if new_value not in self.options:
self.options = self.original_options[:]
self.options += (new_value,)
self._options_values = tuple(tuple(self.options))

def _handle_msg(self, msg):
if 'value' in msg['content']['data']['state']:
value = msg['content']['data']['state']['value']
if msg['content']['data']['state']['value'] not in self.options:
self.options = self.original_options[:]
self.options += (msg['content']['data']['state']['value'],)
self._update_options_list(value)
self.value = value
super(BeakerxComboBox, self)._handle_msg(msg)

def set_value(self, value):
if self.editable:
self._update_options_list(value)
self.value = value


class BeakerxCheckbox(Checkbox, EasyFormComponent):
def __init__(self, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion beakerx/beakerx/easyform/easyform.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def get(self, key):
return ""

def put(self, key, value):
self.components[key].value = value
self.components[key].set_value(value)

@staticmethod
def getDescription(args, kwargs):
Expand Down

0 comments on commit af8bccf

Please sign in to comment.