widget_container.py
73 lines
| 2.4 KiB
| text/x-python
|
PythonLexer
Jonathan Frederic
|
r17637 | """Box class. | ||
Jonathan Frederic
|
r14283 | |||
Represents a container that can be used to group other widgets. | ||||
""" | ||||
Jonathan Frederic
|
r17172 | |||
# Copyright (c) IPython Development Team. | ||||
Jonathan Frederic
|
r14283 | # Distributed under the terms of the Modified BSD License. | ||
Jonathan Frederic
|
r14540 | from .widget import DOMWidget | ||
Jonathan Frederic
|
r17596 | from IPython.utils.traitlets import Unicode, Tuple, TraitError, Int, CaselessStrEnum | ||
Jonathan Frederic
|
r17598 | from IPython.utils.warn import DeprecatedClass | ||
Jonathan Frederic
|
r14239 | |||
Jonathan Frederic
|
r17637 | class Box(DOMWidget): | ||
Jonathan Frederic
|
r17602 | """Displays multiple widgets in a group.""" | ||
Jonathan Frederic
|
r17637 | _view_name = Unicode('BoxView', sync=True) | ||
Jonathan Frederic
|
r14268 | |||
MinRK
|
r15480 | # 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. | ||||
Jason Grout
|
r17266 | children = Tuple(sync=True, allow_none=False) | ||
zah
|
r15446 | |||
Jason Grout
|
r17266 | def __init__(self, children = (), **kwargs): | ||
Jason Grout
|
r17261 | kwargs['children'] = children | ||
Jonathan Frederic
|
r17637 | super(Box, self).__init__(**kwargs) | ||
self.on_displayed(Box._fire_children_displayed) | ||||
zah
|
r15446 | |||
def _fire_children_displayed(self): | ||||
Jonathan Frederic
|
r17173 | for child in self.children: | ||
zah
|
r15446 | child._handle_displayed() | ||
Jonathan Frederic
|
r14607 | |||
Jonathan Frederic
|
r17637 | class Popup(Box): | ||
Jonathan Frederic
|
r17602 | """Displays multiple widgets in an in page popup div.""" | ||
Jonathan Frederic
|
r14701 | _view_name = Unicode('PopupView', sync=True) | ||
Jonathan Frederic
|
r14608 | |||
description = Unicode(sync=True) | ||||
button_text = Unicode(sync=True) | ||||
Jonathan Frederic
|
r17596 | |||
Jonathan Frederic
|
r17637 | class FlexBox(Box): | ||
Jonathan Frederic
|
r17602 | """Displays multiple widgets using the flexible box model.""" | ||
Jonathan Frederic
|
r17637 | _view_name = Unicode('FlexBoxView', sync=True) | ||
Jonathan Frederic
|
r17601 | orientation = CaselessStrEnum(values=['vertical', 'horizontal'], default_value='vertical', sync=True) | ||
Jonathan Frederic
|
r17596 | 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 | ||||
Jonathan Frederic
|
r17597 | _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) | ||||
Jonathan Frederic
|
r17596 | |||
Jonathan Frederic
|
r17601 | def VBox(*pargs, **kwargs): | ||
Jonathan Frederic
|
r17602 | """Displays multiple widgets vertically using the flexible box model.""" | ||
Jonathan Frederic
|
r17601 | kwargs['orientation'] = 'vertical' | ||
Jonathan Frederic
|
r17637 | return FlexBox(*pargs, **kwargs) | ||
Jonathan Frederic
|
r17596 | |||
Jonathan Frederic
|
r17601 | def HBox(*pargs, **kwargs): | ||
Jonathan Frederic
|
r17602 | """Displays multiple widgets horizontally using the flexible box model.""" | ||
Jonathan Frederic
|
r17601 | kwargs['orientation'] = 'horizontal' | ||
Jonathan Frederic
|
r17637 | return FlexBox(*pargs, **kwargs) | ||
Jonathan Frederic
|
r17596 | |||
Jonathan Frederic
|
r17598 | |||
Jonathan Frederic
|
r17602 | # Remove in IPython 4.0 | ||
Jonathan Frederic
|
r17637 | ContainerWidget = DeprecatedClass(Box, 'ContainerWidget') | ||
Jonathan Frederic
|
r17598 | PopupWidget = DeprecatedClass(Popup, 'PopupWidget') | ||