widget_container.py
101 lines
| 3.4 KiB
| text/x-python
|
PythonLexer
Jonathan Frederic
|
r14283 | """ContainerWidget class. | ||
Represents a container that can be used to group other widgets. | ||||
""" | ||||
#----------------------------------------------------------------------------- | ||||
# Copyright (c) 2013, the IPython Development Team. | ||||
# | ||||
# Distributed under the terms of the Modified BSD License. | ||||
# | ||||
# The full license is in the file COPYING.txt, distributed with this software. | ||||
#----------------------------------------------------------------------------- | ||||
#----------------------------------------------------------------------------- | ||||
# Imports | ||||
#----------------------------------------------------------------------------- | ||||
Jonathan Frederic
|
r14274 | from widget import Widget | ||
Jonathan Frederic
|
r14268 | from IPython.utils.traitlets import Unicode, Bool | ||
Jonathan Frederic
|
r14239 | |||
Jonathan Frederic
|
r14283 | #----------------------------------------------------------------------------- | ||
# Classes | ||||
#----------------------------------------------------------------------------- | ||||
Jonathan Frederic
|
r14239 | class ContainerWidget(Widget): | ||
Jonathan Frederic
|
r14275 | target_name = Unicode('ContainerWidgetModel') | ||
Jonathan Frederic
|
r14239 | default_view_name = Unicode('ContainerView') | ||
Jonathan Frederic
|
r14268 | |||
Jonathan Frederic
|
r14283 | # Keys, all private and managed by helper methods. Flexible box model | ||
# classes... | ||||
_keys = ['_vbox', '_hbox', '_start', '_end', '_center'] | ||||
Jonathan Frederic
|
r14269 | _hbox = Bool(False) | ||
_vbox = Bool(False) | ||||
_start = Bool(False) | ||||
_end = Bool(False) | ||||
_center = Bool(False) | ||||
def hbox(self, enabled=True): | ||||
Jonathan Frederic
|
r14283 | """Make this container an hbox. Automatically disables conflicting | ||
features. | ||||
Parameters | ||||
---------- | ||||
enabled: bool (optional) | ||||
Enabled or disable the hbox feature of the container, defaults to | ||||
True.""" | ||||
Jonathan Frederic
|
r14269 | self._hbox = enabled | ||
if enabled: | ||||
self._vbox = False | ||||
def vbox(self, enabled=True): | ||||
Jonathan Frederic
|
r14283 | """Make this container an vbox. Automatically disables conflicting | ||
features. | ||||
Parameters | ||||
---------- | ||||
enabled: bool (optional) | ||||
Enabled or disable the vbox feature of the container, defaults to | ||||
True.""" | ||||
Jonathan Frederic
|
r14269 | self._vbox = enabled | ||
if enabled: | ||||
self._hbox = False | ||||
def start(self, enabled=True): | ||||
Jonathan Frederic
|
r14283 | """Make the contents of this container align to the start of the axis. | ||
Automatically disables conflicting alignments. | ||||
Parameters | ||||
---------- | ||||
enabled: bool (optional) | ||||
Enabled or disable the start alignment of the container, defaults to | ||||
True.""" | ||||
Jonathan Frederic
|
r14269 | self._start = enabled | ||
if enabled: | ||||
self._end = False | ||||
self._center = False | ||||
def end(self, enabled=True): | ||||
Jonathan Frederic
|
r14283 | """Make the contents of this container align to the end of the axis. | ||
Automatically disables conflicting alignments. | ||||
Parameters | ||||
---------- | ||||
enabled: bool (optional) | ||||
Enabled or disable the end alignment of the container, defaults to | ||||
True.""" | ||||
Jonathan Frederic
|
r14269 | self._end = enabled | ||
if enabled: | ||||
self._start = False | ||||
self._center = False | ||||
def center(self, enabled=True): | ||||
Jonathan Frederic
|
r14283 | """Make the contents of this container align to the center of the axis. | ||
Automatically disables conflicting alignments. | ||||
Parameters | ||||
---------- | ||||
enabled: bool (optional) | ||||
Enabled or disable the center alignment of the container, defaults to | ||||
True.""" | ||||
Jonathan Frederic
|
r14269 | self._center = enabled | ||
if enabled: | ||||
self._start = False | ||||
self._end = False | ||||