2014-07-19 03:47:33 +08:00
|
|
|
"""Container 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-01-07 20:04:24 +08:00
|
|
|
from .widget import DOMWidget
|
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-07-19 03:47:33 +08:00
|
|
|
class Container(DOMWidget):
|
2014-07-22 02:37:42 +08:00
|
|
|
"""Displays multiple widgets in a group."""
|
2014-01-23 08:21:00 +08:00
|
|
|
_view_name = Unicode('ContainerView', 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-02-24 02:57:07 +08:00
|
|
|
|
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-07-19 03:47:33 +08:00
|
|
|
super(Container, self).__init__(**kwargs)
|
|
|
|
self.on_displayed(Container._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-07-19 03:47:33 +08:00
|
|
|
class Popup(Container):
|
2014-07-22 02:37:42 +08:00
|
|
|
"""Displays multiple widgets in an in page popup div."""
|
2014-01-23 08:21:00 +08:00
|
|
|
_view_name = Unicode('PopupView', sync=True)
|
2014-01-16 22:48:56 +08:00
|
|
|
|
|
|
|
description = Unicode(sync=True)
|
|
|
|
button_text = Unicode(sync=True)
|
2014-07-12 21:32:49 +08:00
|
|
|
|
|
|
|
|
2014-07-19 03:47:33 +08:00
|
|
|
class FlexContainer(Container):
|
2014-07-22 02:37:42 +08:00
|
|
|
"""Displays multiple widgets using the flexible box model."""
|
2014-07-12 21:32:49 +08:00
|
|
|
_view_name = Unicode('FlexContainerView', 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'
|
|
|
|
return FlexContainer(*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'
|
|
|
|
return FlexContainer(*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-07-19 03:47:33 +08:00
|
|
|
ContainerWidget = DeprecatedClass(Container, 'ContainerWidget')
|
|
|
|
PopupWidget = DeprecatedClass(Popup, 'PopupWidget')
|
|
|
|
|