widget_box.py
82 lines
| 3.0 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. | ||
Sylvain Corlay
|
r21157 | from .widget import DOMWidget, Widget, register, widget_serialization | ||
Jonathan Frederic
|
r17596 | from IPython.utils.traitlets import Unicode, Tuple, TraitError, Int, CaselessStrEnum | ||
Min RK
|
r21081 | from .deprecated import DeprecatedClass | ||
Jonathan Frederic
|
r14239 | |||
Jason Grout
|
r20935 | |||
Sylvain Corlay
|
r18533 | @register('IPython.Box') | ||
Jonathan Frederic
|
r17637 | class Box(DOMWidget): | ||
Jonathan Frederic
|
r17602 | """Displays multiple widgets in a group.""" | ||
Jason Grout
|
r20935 | _model_name = Unicode('BoxModel', sync=True) | ||
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
|
r20839 | children = Tuple(sync=True, **widget_serialization) | ||
Jonathan Frederic
|
r17727 | |||
_overflow_values = ['visible', 'hidden', 'scroll', 'auto', 'initial', 'inherit', ''] | ||||
overflow_x = CaselessStrEnum( | ||||
values=_overflow_values, | ||||
Sylvain Corlay
|
r20483 | default_value='', sync=True, help="""Specifies what | ||
Jonathan Frederic
|
r17727 | happens to content that is too large for the rendered region.""") | ||
overflow_y = CaselessStrEnum( | ||||
values=_overflow_values, | ||||
Sylvain Corlay
|
r20483 | default_value='', sync=True, help="""Specifies what | ||
Jonathan Frederic
|
r17727 | happens to content that is too large for the rendered region.""") | ||
zah
|
r15446 | |||
Jonathan Frederic
|
r17728 | box_style = CaselessStrEnum( | ||
values=['success', 'info', 'warning', 'danger', ''], | ||||
default_value='', allow_none=True, sync=True, help="""Use a | ||||
predefined styling for the box.""") | ||||
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 | |||
Sylvain Corlay
|
r18533 | @register('IPython.FlexBox') | ||
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, | ||||
Sylvain Corlay
|
r20483 | default_value='start', sync=True) | ||
Jonathan Frederic
|
r17597 | align = CaselessStrEnum( | ||
values=_locations, | ||||
Sylvain Corlay
|
r20483 | default_value='start', 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') | ||