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.
|
|
|
|
"""
|
2014-06-10 04:38:44 +08:00
|
|
|
|
|
|
|
# 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
|
2014-07-19 03:47:33 +08:00
|
|
|
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):
|
2014-07-22 02:37:42 +08:00
|
|
|
"""Displays multiple widgets in a group."""
|
2014-08-14 04:19:27 +08:00
|
|
|
_view_name = Unicode('BoxView', sync=True)
|
2013-10-22 00:55:49 +08:00
|
|
|
|
2014-02-26 11:08:43 +08:00
|
|
|
# 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.
|
2014-07-19 00:59:41 +08:00
|
|
|
children = Tuple(sync=True, allow_none=False)
|
2014-08-26 12:28:45 +08:00
|
|
|
|
|
|
|
_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.""")
|
2014-02-24 02:57:07 +08:00
|
|
|
|
2014-08-27 07:49:13 +08:00
|
|
|
box_style = CaselessStrEnum(
|
|
|
|
values=['success', 'info', 'warning', 'danger', ''],
|
|
|
|
default_value='', allow_none=True, sync=True, help="""Use a
|
|
|
|
predefined styling for the box.""")
|
|
|
|
|
2014-07-19 00:59:41 +08:00
|
|
|
def __init__(self, children = (), **kwargs):
|
2014-07-18 04:07:37 +08:00
|
|
|
kwargs['children'] = children
|
2014-08-14 04:19:27 +08:00
|
|
|
super(Box, self).__init__(**kwargs)
|
|
|
|
self.on_displayed(Box._fire_children_displayed)
|
2014-02-24 02:57:07 +08:00
|
|
|
|
|
|
|
def _fire_children_displayed(self):
|
2014-06-11 00:57:50 +08:00
|
|
|
for child in self.children:
|
2014-02-24 02:57:07 +08:00
|
|
|
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):
|
2014-07-22 02:37:42 +08:00
|
|
|
"""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):
|
2014-07-22 02:37:42 +08:00
|
|
|
"""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):
|
2014-07-22 02:37:42 +08:00
|
|
|
"""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
|
|
|
|
2014-07-19 03:47:33 +08:00
|
|
|
|
2014-07-22 02:37:42 +08:00
|
|
|
# Remove in IPython 4.0
|
2014-08-14 04:19:27 +08:00
|
|
|
ContainerWidget = DeprecatedClass(Box, 'ContainerWidget')
|