Page Contents

This Page

Container

class enaml.widgets.container.Container(parent=None, **kwargs)[source]

Bases: enaml.widgets.constraints_widget.ConstraintsWidget

A ConstraintsWidget subclass that provides functionality for laying out constrainable children according to their system of constraints.

The Container is the canonical component used to arrange child widgets using constraints-based layout. Given a heierarchy of components, the top-most Container will be charged with the actual layout of the decendents. This allows constraints to cross the boundaries of Containers, enabling powerful and flexible layouts.

There are widgets whose boundaries constraints may not cross. Some examples of these would be a ScrollArea or a TabGroup. See the documentation of a given container component as to whether or not constraints may cross its boundaries.

share_layout = None

A boolean which indicates whether or not to allow the layout ownership of this container to be transferred to an ancestor. This is False by default, which means that every container get its own layout solver. This improves speed and reduces memory use (by keeping a solver’s internal tableaux small) but at the cost of not being able to share constraints across Container boundaries. This flag must be explicitly marked as True to enable sharing.

contents_left = None

A read-only symbolic object that represents the internal left boundary of the content area of the container.

contents_right = None

A read-only symbolic object that represents the internal right boundary of the content area of the container.

contents_top = None

A read-only symbolic object that represents the internal top boundary of the content area of the container.

contents_bottom = None

A read-only symbolic object that represents the internal bottom boundary of the content area of the container.

contents_width = None

A read-only symbolic object that represents the internal width of the content area of the container.

contents_height = None

A read-only symbolic object that represents the internal height of the content area of the container.

contents_v_center = None

A read-only symbolic object that represents the internal center along the vertical direction the content area of the container.

contents_h_center = None

A read-only symbolic object that represents the internal center along the horizontal direction of the content area of the container.

padding = None

A box object which holds the padding for this component. The padding is the amount of space between the outer boundary box and the content box. The default padding is (10, 10, 10, 10). Certain subclasses, such as GroupBox, may provide additional margin than what is specified by the padding.

widgets = None

A read only property which returns this container’s widgets.

hug_width = None

Containers freely exapnd in width and height. The size hint constraints for a Container are used when the container is not sharing its layout. In these cases, expansion of the container is typically desired.

bind()[source]

Bind the necessary change handlers for the control.

children_event(event)[source]

Handle a ChildrenEvent on a container.

This event handler will send a relayout event if the Container is active and the user has not defined their own constraints.

__implements__

alias of __NoInterface__

Backends

Qt

Inheritance diagram of enaml.qt.qt_container.QtContainer

class enaml.qt.qt_container.QtContainer(object_id, parent, session)[source]

Bases: enaml.qt.qt_constraints_widget.QtConstraintsWidget

A Qt implementation of an Enaml Container.

create_widget(parent, tree)[source]

Creates the underlying QContainer widget.

create(tree)[source]

Create and initialize the underlying widget.

init_layout()[source]

Initializes the layout for the container.

relayout()[source]

Rebuilds the constraints layout for this widget if it owns the responsibility for laying out its descendents.

refresh()[source]

Makes a layout pass over the descendents if this widget owns the responsibility for their layout.

refresh_sizes()[source]

Refresh the min/max/best sizes for the underlying widget.

This method is normally called automatically at the proper times. It should not normally need to be called by user code.

replace_constraints(old_cns, new_cns)[source]

Replace constraints in the given layout.

This method can be used to selectively add/remove/replace constraints in the layout system, when it is more efficient than performing a full relayout.

Parameters:
  • old_cns (list) – The list of casuarius constraints to remove from the the current layout system.
  • new_cns (list) – The list of casuarius constraints to add to the current layout system.
clear_constraints(cns)[source]

Clear the given constraints from the current layout.

Parameters:cns (list) – The list of casuarius constraints to remove from the current layout system.
layout()[source]

The callback invoked by the layout manager when there are new layout values available.

This iterates over the layout table and calls the geometry updater functions.

contents_margins()[source]

Get the contents margins for the container.

The contents margins are added to the user provided padding to determine the final offset from a layout box boundary to the corresponding content line. The default content margins are zero. This method can be reimplemented by subclasses to supply different margins.

Returns:result (tuple) – A tuple of ‘top’, ‘right’, ‘bottom’, ‘left’ contents margins to use for computing the contents constraints.
contents_margins_updated()[source]

Notify the layout system that the contents margins of this widget have been updated.

contents_constraints()[source]

Create the contents constraints for the container.

The contents contraints are generated by combining the user padding with the margins returned by ‘contents_margins’ method.

Returns:result (list) – The list of casuarius constraints for the content.
transfer_layout_ownership(owner)[source]

A method which can be called by other components in the hierarchy to gain ownership responsibility for the layout of the children of this container. By default, the transfer is allowed and is the mechanism which allows constraints to cross widget boundaries. Subclasses should reimplement this method if different behavior is desired.

Parameters:owner (Declarative) – The component which has taken ownership responsibility for laying out the children of this component. All relayout and refresh requests will be forwarded to this component.
Returns:results (bool) – True if the transfer was allowed, False otherwise.
will_transfer()[source]

Whether or not the container expects to transfer its layout ownership to its parent.

This method is predictive in nature and exists so that layout managers are not senslessly created during the bottom-up layout initialization pass. It is declared public so that subclasses can override the behavior if necessary.

compute_min_size()[source]

Calculates the minimum size of the container which would allow all constraints to be satisfied.

If the container’s resist properties have a strength less than ‘medium’, the returned size will be zero. If the container does not own its layout, the returned size will be invalid.

Returns:result (QSize) – A (potentially invalid) QSize which is the minimum size required to satisfy all constraints.
compute_best_size()[source]

Calculates the best size of the container.

The best size of the container is obtained by computing the min size of the layout using a strength which is much weaker than a normal resize. This takes into account the size of any widgets which have their resist clip property set to ‘weak’ while still allowing the window to be resized smaller by the user. If the container does not own its layout, the returned size will be invalid.

Returns:result (QSize) – A (potentially invalid) QSize which is the best size that will satisfy all constraints.
compute_max_size()[source]

Calculates the maximum size of the container which would allow all constraints to be satisfied.

If the container’s hug properties have a strength less than ‘medium’, or if the container does not own its layout, the returned size will be the Qt maximum.

Returns:result (QSize) – A (potentially invalid) QSize which is the maximum size allowable while still satisfying all constraints.

Wx

Inheritance diagram of enaml.wx.wx_container.WxContainer

class enaml.wx.wx_container.WxContainer(object_id, parent, session)[source]

Bases: enaml.wx.wx_constraints_widget.WxConstraintsWidget

A Wx implementation of an Enaml Container.

create_widget(parent, tree)[source]

Creates the underlying wxContainer widget.

create(tree)[source]

Create and initialize the container.

init_layout()[source]

Initializes the layout for the container.

on_resize(event)[source]

The event handler for the EVT_SIZE event.

This handler triggers a layout pass when the container widget is resized.

on_show(event)[source]

The event handler for the EVT_SHOW event.

This handler toggles the value of the _is_shown flag.

relayout()[source]

Rebuilds the constraints layout for this widget if it owns the responsibility for laying out its descendents.

refresh()[source]

Makes a layout pass over the descendents if this widget owns the responsibility for their layout.

If the widget is not visible on the screen, the refresh will be skipped.

refresh_sizes()[source]

Refresh the min/max/best sizes for the underlying widget.

This method is normally called automatically at the proper times. It should not normally need to be called by user code.

replace_constraints(old_cns, new_cns)[source]

Replace constraints in the given layout.

This method can be used to selectively add/remove/replace constraints in the layout system, when it is more efficient than performing a full relayout.

Parameters:
  • old_cns (list) – The list of casuarius constraints to remove from the the current layout system.
  • new_cns (list) – The list of casuarius constraints to add to the current layout system.
clear_constraints(cns)[source]

Clear the given constraints from the current layout.

Parameters:cns (list) – The list of casuarius constraints to remove from the current layout system.
layout()[source]

The callback invoked by the layout manager when there are new layout values available.

This iterates over the layout table and calls the geometry updater functions.

contents_margins()[source]

Get the contents margins for the container.

The contents margins are added to the user provided padding to determine the final offset from a layout box boundary to the corresponding content line. The default content margins are zero. This method can be reimplemented by subclasses to supply different margins.

Returns:result (tuple) – A tuple of ‘top’, ‘right’, ‘bottom’, ‘left’ contents margins to use for computing the contents constraints.
contents_margins_updated()[source]

Notify the layout system that the contents margins of this widget have been updated.

contents_constraints()[source]

Create the contents constraints for the container.

The contents contraints are generated by combining the user padding with the margins returned by ‘contents_margins’ method.

Returns:result (list) – The list of casuarius constraints for the content.
transfer_layout_ownership(owner)[source]

A method which can be called by other components in the hierarchy to gain ownership responsibility for the layout of the children of this container. By default, the transfer is allowed and is the mechanism which allows constraints to cross widget boundaries. Subclasses should reimplement this method if different behavior is desired.

Parameters:owner (Declarative) – The component which has taken ownership responsibility for laying out the children of this component. All relayout and refresh requests will be forwarded to this component.
Returns:results (bool) – True if the transfer was allowed, False otherwise.
will_transfer()[source]

Whether or not the container expects to transfer its layout ownership to its parent.

This method is predictive in nature and exists so that layout managers are not senslessly created during the bottom-up layout initialization pass. It is declared public so that subclasses can override the behavior if necessary.

compute_min_size()[source]

Calculates the minimum size of the container which would allow all constraints to be satisfied.

If this container does not own its layout then it will return an invalid wxSize.

Returns:result (wxSize) – A (potentially) invalid wxSize which is the minimum size required to satisfy all constraints.
compute_best_size()[source]

Calculates the best size of the container.

The best size of the container is obtained by computing the min size of the layout using a strength which is much weaker than a normal resize. This takes into account the size of any widgets which have their resist clip property set to ‘weak’ while still allowing the window to be resized smaller by the user. If this container does not own its layout then it will return an invalid QSize.

Returns:result (wxSize) – A (potentially) invalid wxSize which is the minimum size required to satisfy all constraints.
compute_max_size()[source]

Calculates the maximum size of the container which would allow all constraints to be satisfied.

If this container does not own its layout then it will return an invalid wxSize.

Returns:result (wxSize) – A (potentially) invalid wxSize which is the maximum size allowable while still satisfying all constraints.