notebook/IPython/html/widgets/widget_box.py

81 lines
3.0 KiB
Python
Raw Normal View History

2014-08-14 04:19:27 +08:00
"""Box class.
2013-10-26 02:31:48 +08:00
Represents a container that can be used to group other widgets.
"""
# Copyright (c) IPython Development Team.
2013-10-26 02:31:48 +08:00
# Distributed under the terms of the Modified BSD License.
2014-09-18 05:04:03 +08:00
from .widget import DOMWidget, register
2014-07-12 21:32:49 +08:00
from IPython.utils.traitlets import Unicode, Tuple, TraitError, Int, CaselessStrEnum
from IPython.utils.warn import DeprecatedClass
2013-10-17 14:15:24 +08:00
2014-10-14 09:45:16 +08:00
@register('IPython.Box')
2014-08-14 04:19:27 +08:00
class Box(DOMWidget):
"""Displays multiple widgets in a group."""
2014-08-14 04:19:27 +08:00
_view_name = Unicode('BoxView', sync=True)
# Child widgets in the container.
# Using a tuple here to force reassignment to update the list.
# When a proper notifying-list trait exists, that is what should be used here.
children = Tuple(sync=True, allow_none=False)
_overflow_values = ['visible', 'hidden', 'scroll', 'auto', 'initial', 'inherit', '']
overflow_x = CaselessStrEnum(
values=_overflow_values,
default_value='', allow_none=False, sync=True, help="""Specifies what
happens to content that is too large for the rendered region.""")
overflow_y = CaselessStrEnum(
values=_overflow_values,
default_value='', allow_none=False, sync=True, help="""Specifies what
happens to content that is too large for the rendered region.""")
box_style = CaselessStrEnum(
values=['success', 'info', 'warning', 'danger', ''],
default_value='', allow_none=True, sync=True, help="""Use a
predefined styling for the box.""")
def __init__(self, children = (), **kwargs):
kwargs['children'] = children
2014-08-14 04:19:27 +08:00
super(Box, self).__init__(**kwargs)
self.on_displayed(Box._fire_children_displayed)
def _fire_children_displayed(self):
2014-06-11 00:57:50 +08:00
for child in self.children:
child._handle_displayed()
2014-01-16 22:20:04 +08:00
2014-10-14 09:45:16 +08:00
@register('IPython.FlexBox')
2014-08-14 04:19:27 +08:00
class FlexBox(Box):
"""Displays multiple widgets using the flexible box model."""
2014-08-14 04:19:27 +08:00
_view_name = Unicode('FlexBoxView', sync=True)
2014-07-19 05:34:39 +08:00
orientation = CaselessStrEnum(values=['vertical', 'horizontal'], default_value='vertical', sync=True)
2014-07-12 21:32:49 +08:00
flex = Int(0, sync=True, help="""Specify the flexible-ness of the model.""")
def _flex_changed(self, name, old, new):
new = min(max(0, new), 2)
if self.flex != new:
self.flex = new
2014-07-16 05:46:11 +08:00
_locations = ['start', 'center', 'end', 'baseline', 'stretch']
pack = CaselessStrEnum(
values=_locations,
default_value='start', allow_none=False, sync=True)
align = CaselessStrEnum(
values=_locations,
default_value='start', allow_none=False, sync=True)
2014-07-12 21:32:49 +08:00
2014-07-19 05:34:39 +08:00
def VBox(*pargs, **kwargs):
"""Displays multiple widgets vertically using the flexible box model."""
2014-07-19 05:34:39 +08:00
kwargs['orientation'] = 'vertical'
2014-08-14 04:19:27 +08:00
return FlexBox(*pargs, **kwargs)
2014-07-12 21:32:49 +08:00
2014-07-19 05:34:39 +08:00
def HBox(*pargs, **kwargs):
"""Displays multiple widgets horizontally using the flexible box model."""
2014-07-19 05:34:39 +08:00
kwargs['orientation'] = 'horizontal'
2014-08-14 04:19:27 +08:00
return FlexBox(*pargs, **kwargs)
2014-07-12 21:32:49 +08:00
# Remove in IPython 4.0
2014-08-14 04:19:27 +08:00
ContainerWidget = DeprecatedClass(Box, 'ContainerWidget')