mirror of
https://github.com/jupyter/notebook.git
synced 2024-12-27 04:20:22 +08:00
sync=True isntead of a keys list
This commit is contained in:
parent
00650fd64a
commit
b4a83b6044
@ -30,8 +30,6 @@ class Widget(LoggingConfigurable):
|
||||
widget_construction_callback = None
|
||||
widgets = {}
|
||||
|
||||
keys = ['view_name'] # TODO: Sync = True
|
||||
|
||||
def on_widget_constructed(callback):
|
||||
"""Class method, registers a callback to be called when a widget is
|
||||
constructed. The callback must have the following signature:
|
||||
@ -49,7 +47,7 @@ class Widget(LoggingConfigurable):
|
||||
model_name = Unicode('widget', help="""Name of the backbone model
|
||||
registered in the front-end to create and sync this widget with.""")
|
||||
view_name = Unicode(help="""Default view registered in the front-end
|
||||
to use to represent the widget.""")
|
||||
to use to represent the widget.""", sync=True)
|
||||
|
||||
@contextmanager
|
||||
def property_lock(self, key, value):
|
||||
@ -69,6 +67,15 @@ class Widget(LoggingConfigurable):
|
||||
return key != self._property_lock[0] or \
|
||||
value != self._property_lock[1]
|
||||
|
||||
@property
|
||||
def keys(self):
|
||||
if self._keys is None:
|
||||
self._keys = []
|
||||
for trait_name in self.trait_names():
|
||||
if self.trait_metadata(trait_name, 'sync'):
|
||||
self._keys.append(trait_name)
|
||||
return self._keys
|
||||
|
||||
# Private/protected declarations
|
||||
_comm = Instance('IPython.kernel.comm.Comm')
|
||||
|
||||
@ -79,6 +86,7 @@ class Widget(LoggingConfigurable):
|
||||
self._property_lock = (None, None)
|
||||
self._display_callbacks = []
|
||||
self._msg_callbacks = []
|
||||
self._keys = None
|
||||
super(Widget, self).__init__(**kwargs)
|
||||
|
||||
self.on_trait_change(self._handle_property_changed, self.keys)
|
||||
|
@ -24,8 +24,7 @@ class BoolWidget(DOMWidget):
|
||||
view_name = Unicode('CheckboxView')
|
||||
|
||||
# Model Keys
|
||||
keys = ['value', 'description', 'disabled'] + DOMWidget.keys
|
||||
value = Bool(False, help="Bool value")
|
||||
description = Unicode('', help="Description of the boolean (label).")
|
||||
disabled = Bool(False, help="Enable or disable user changes.")
|
||||
value = Bool(False, help="Bool value", sync=True)
|
||||
description = Unicode('', help="Description of the boolean (label).", sync=True)
|
||||
disabled = Bool(False, help="Enable or disable user changes.", sync=True)
|
||||
|
@ -28,9 +28,8 @@ class ButtonWidget(DOMWidget):
|
||||
view_name = Unicode('ButtonView')
|
||||
|
||||
# Keys
|
||||
keys = ['description', 'disabled'] + DOMWidget.keys
|
||||
description = Unicode('', help="Description of the button (label).")
|
||||
disabled = Bool(False, help="Enable or disable user changes.")
|
||||
description = Unicode('', help="Description of the button (label).", sync=True)
|
||||
disabled = Bool(False, help="Enable or disable user changes.", sync=True)
|
||||
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
|
@ -25,8 +25,7 @@ class ContainerWidget(DOMWidget):
|
||||
|
||||
# Keys, all private and managed by helper methods. Flexible box model
|
||||
# classes...
|
||||
keys = ['description', 'button_text', 'children'] + DOMWidget.keys # TODO: Use add/remove_class
|
||||
children = List(Instance(DOMWidget))
|
||||
children = List(Instance(DOMWidget), sync=True)
|
||||
|
||||
description = Unicode()
|
||||
button_text = Unicode()
|
||||
description = Unicode(sync=True)
|
||||
button_text = Unicode(sync=True)
|
||||
|
@ -24,7 +24,6 @@ class FloatWidget(DOMWidget):
|
||||
view_name = Unicode('FloatTextView')
|
||||
|
||||
# Keys
|
||||
keys = ['value', 'disabled', 'description'] + DOMWidget.keys
|
||||
value = Float(0.0, help="Float value")
|
||||
disabled = Bool(False, help="Enable or disable user changes")
|
||||
description = Unicode(help="Description of the value this widget represents")
|
||||
value = Float(0.0, help="Float value", sync=True)
|
||||
disabled = Bool(False, help="Enable or disable user changes", sync=True)
|
||||
description = Unicode(help="Description of the value this widget represents", sync=True)
|
||||
|
@ -27,11 +27,10 @@ class ImageWidget(DOMWidget):
|
||||
view_name = Unicode('ImageView')
|
||||
|
||||
# Define the custom state properties to sync with the front-end
|
||||
keys = ['format', 'width', 'height', '_b64value'] + DOMWidget.keys
|
||||
format = Unicode('png')
|
||||
width = Unicode() # TODO: C unicode
|
||||
height = Unicode()
|
||||
_b64value = Unicode()
|
||||
format = Unicode('png', sync=True)
|
||||
width = Unicode(sync=True) # TODO: C unicode
|
||||
height = Unicode(sync=True)
|
||||
_b64value = Unicode(sync=True)
|
||||
|
||||
value = Bytes()
|
||||
def _value_changed(self, name, old, new):
|
||||
|
@ -24,7 +24,6 @@ class IntWidget(DOMWidget):
|
||||
view_name = Unicode('IntTextView')
|
||||
|
||||
# Keys
|
||||
keys = ['value', 'disabled', 'description'] + DOMWidget.keys
|
||||
value = Int(0, help="Int value")
|
||||
disabled = Bool(False, help="Enable or disable user changes")
|
||||
description = Unicode(help="Description of the value this widget represents")
|
||||
value = Int(0, help="Int value", sync=True)
|
||||
disabled = Bool(False, help="Enable or disable user changes", sync=True)
|
||||
description = Unicode(help="Description of the value this widget represents", sync=True)
|
||||
|
@ -24,9 +24,8 @@ class SelectionWidget(DOMWidget):
|
||||
view_name = Unicode('DropdownView')
|
||||
|
||||
# Keys
|
||||
keys = ['value', 'values', 'disabled', 'description'] + DOMWidget.keys
|
||||
value = Unicode(help="Selected value") # TODO: Any support
|
||||
values = List(help="List of values the user can select")
|
||||
disabled = Bool(False, help="Enable or disable user changes")
|
||||
description = Unicode(help="Description of the value this widget represents")
|
||||
value = Unicode(help="Selected value", sync=True) # TODO: Any support
|
||||
values = List(help="List of values the user can select", sync=True)
|
||||
disabled = Bool(False, help="Enable or disable user changes", sync=True)
|
||||
description = Unicode(help="Description of the value this widget represents", sync=True)
|
||||
|
@ -25,9 +25,8 @@ class SelectionContainerWidget(DOMWidget):
|
||||
view_name = Unicode('TabView')
|
||||
|
||||
# Keys
|
||||
keys = ['_titles', 'selected_index', 'children'] + DOMWidget.keys
|
||||
_titles = Dict(help="Titles of the pages")
|
||||
selected_index = Int(0)
|
||||
_titles = Dict(help="Titles of the pages", sync=True)
|
||||
selected_index = Int(0, sync=True)
|
||||
|
||||
children = List(Instance(DOMWidget))
|
||||
|
||||
|
@ -27,10 +27,9 @@ class StringWidget(DOMWidget):
|
||||
view_name = Unicode('TextBoxView')
|
||||
|
||||
# Keys
|
||||
keys = ['value', 'disabled', 'description'] + DOMWidget.keys
|
||||
value = Unicode(help="String value")
|
||||
disabled = Bool(False, help="Enable or disable user changes")
|
||||
description = Unicode(help="Description of the value this widget represents")
|
||||
value = Unicode(help="String value", sync=True)
|
||||
disabled = Bool(False, help="Enable or disable user changes", sync=True)
|
||||
description = Unicode(help="Description of the value this widget represents", sync=True)
|
||||
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
|
Loading…
Reference in New Issue
Block a user