mirror of
https://github.com/jupyter/notebook.git
synced 2024-12-21 04:10:17 +08:00
Merge pull request #5221 from jdfreder/ctuple
Change widget children List to Tuple.
This commit is contained in:
commit
4038421da6
@ -308,7 +308,7 @@ class Widget(LoggingConfigurable):
|
|||||||
their model ids. Return value must be JSON-able."""
|
their model ids. Return value must be JSON-able."""
|
||||||
if isinstance(x, dict):
|
if isinstance(x, dict):
|
||||||
return {k: self._pack_widgets(v) for k, v in x.items()}
|
return {k: self._pack_widgets(v) for k, v in x.items()}
|
||||||
elif isinstance(x, list):
|
elif isinstance(x, (list, tuple)):
|
||||||
return [self._pack_widgets(v) for v in x]
|
return [self._pack_widgets(v) for v in x]
|
||||||
elif isinstance(x, Widget):
|
elif isinstance(x, Widget):
|
||||||
return x.model_id
|
return x.model_id
|
||||||
@ -322,7 +322,7 @@ class Widget(LoggingConfigurable):
|
|||||||
their model ids."""
|
their model ids."""
|
||||||
if isinstance(x, dict):
|
if isinstance(x, dict):
|
||||||
return {k: self._unpack_widgets(v) for k, v in x.items()}
|
return {k: self._unpack_widgets(v) for k, v in x.items()}
|
||||||
elif isinstance(x, list):
|
elif isinstance(x, (list, tuple)):
|
||||||
return [self._unpack_widgets(v) for v in x]
|
return [self._unpack_widgets(v) for v in x]
|
||||||
elif isinstance(x, string_types):
|
elif isinstance(x, string_types):
|
||||||
return x if x not in Widget.widgets else Widget.widgets[x]
|
return x if x not in Widget.widgets else Widget.widgets[x]
|
||||||
@ -412,7 +412,7 @@ class DOMWidget(Widget):
|
|||||||
be added to.
|
be added to.
|
||||||
"""
|
"""
|
||||||
class_list = class_names
|
class_list = class_names
|
||||||
if isinstance(class_list, list):
|
if isinstance(class_list, (list, tuple)):
|
||||||
class_list = ' '.join(class_list)
|
class_list = ' '.join(class_list)
|
||||||
|
|
||||||
self.send({
|
self.send({
|
||||||
@ -433,7 +433,7 @@ class DOMWidget(Widget):
|
|||||||
be removed from.
|
be removed from.
|
||||||
"""
|
"""
|
||||||
class_list = class_names
|
class_list = class_names
|
||||||
if isinstance(class_list, list):
|
if isinstance(class_list, (list, tuple)):
|
||||||
class_list = ' '.join(class_list)
|
class_list = ' '.join(class_list)
|
||||||
|
|
||||||
self.send({
|
self.send({
|
||||||
|
@ -14,7 +14,7 @@ Represents a boolean using a widget.
|
|||||||
# Imports
|
# Imports
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
from .widget import DOMWidget
|
from .widget import DOMWidget
|
||||||
from IPython.utils.traitlets import Unicode, Bool, List
|
from IPython.utils.traitlets import Unicode, Bool
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
# Classes
|
# Classes
|
||||||
|
@ -14,18 +14,20 @@ Represents a container that can be used to group other widgets.
|
|||||||
# Imports
|
# Imports
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
from .widget import DOMWidget
|
from .widget import DOMWidget
|
||||||
from IPython.utils.traitlets import Unicode, Bool, List, Instance
|
from IPython.utils.traitlets import Unicode, Tuple, TraitError
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
# Classes
|
# Classes
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
|
|
||||||
class ContainerWidget(DOMWidget):
|
class ContainerWidget(DOMWidget):
|
||||||
_view_name = Unicode('ContainerView', sync=True)
|
_view_name = Unicode('ContainerView', sync=True)
|
||||||
|
|
||||||
# Keys, all private and managed by helper methods. Flexible box model
|
# Child widgets in the container.
|
||||||
# classes...
|
# Using a tuple here to force reassignment to update the list.
|
||||||
children = List(Instance(DOMWidget))
|
# When a proper notifying-list trait exists, that is what should be used here.
|
||||||
_children = List(Instance(DOMWidget), sync=True)
|
children = Tuple()
|
||||||
|
_children = Tuple(sync=True)
|
||||||
|
|
||||||
def _children_changed(self, name, old, new):
|
def _children_changed(self, name, old, new):
|
||||||
"""Validate children list.
|
"""Validate children list.
|
||||||
@ -36,7 +38,7 @@ class ContainerWidget(DOMWidget):
|
|||||||
http://www.peterbe.com/plog/uniqifiers-benchmark
|
http://www.peterbe.com/plog/uniqifiers-benchmark
|
||||||
which provides the inspiration for using this implementation. Below
|
which provides the inspiration for using this implementation. Below
|
||||||
I've implemented the `f5` algorithm using Python comprehensions."""
|
I've implemented the `f5` algorithm using Python comprehensions."""
|
||||||
if new is not None and isinstance(new, list):
|
if new is not None:
|
||||||
seen = {}
|
seen = {}
|
||||||
def add_item(i):
|
def add_item(i):
|
||||||
seen[i.model_id] = True
|
seen[i.model_id] = True
|
||||||
|
@ -14,7 +14,7 @@ Represents an unbounded float using a widget.
|
|||||||
# Imports
|
# Imports
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
from .widget import DOMWidget
|
from .widget import DOMWidget
|
||||||
from IPython.utils.traitlets import Unicode, CFloat, Bool, List, Enum
|
from IPython.utils.traitlets import Unicode, CFloat, Bool, Enum
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
# Classes
|
# Classes
|
||||||
|
@ -14,7 +14,7 @@ Represents an unbounded int using a widget.
|
|||||||
# Imports
|
# Imports
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
from .widget import DOMWidget
|
from .widget import DOMWidget
|
||||||
from IPython.utils.traitlets import Unicode, CInt, Bool, List, Enum
|
from IPython.utils.traitlets import Unicode, CInt, Bool, Enum
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
# Classes
|
# Classes
|
||||||
|
@ -15,7 +15,7 @@ pages.
|
|||||||
# Imports
|
# Imports
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
from .widget_container import ContainerWidget
|
from .widget_container import ContainerWidget
|
||||||
from IPython.utils.traitlets import Unicode, Dict, CInt, List, Instance
|
from IPython.utils.traitlets import Unicode, Dict, CInt
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
# Classes
|
# Classes
|
||||||
|
@ -14,7 +14,7 @@ Represents a unicode string using a widget.
|
|||||||
# Imports
|
# Imports
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
from .widget import DOMWidget, CallbackDispatcher
|
from .widget import DOMWidget, CallbackDispatcher
|
||||||
from IPython.utils.traitlets import Unicode, Bool, List
|
from IPython.utils.traitlets import Unicode, Bool
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------
|
||||||
# Classes
|
# Classes
|
||||||
|
Loading…
Reference in New Issue
Block a user