enable.layout.layout_helpers module

class enable.layout.layout_helpers.AbstractConstraintFactory[source]

Bases: object

An abstract constraint factory class. Subclasses must implement the ‘constraints’ method implement which returns a LinearConstraint instance.

abstract constraints()[source]

An abstract method which must be implemented by subclasses. It should return a list of LinearConstraint instances.

static validate(items)[source]

A validator staticmethod that insures a sequence of items is appropriate for generating a sequence of linear constraints. The following conditions are verified of the sequence of given items:

  • The number of items in the sequence is 0 or >= 2.

  • The first and last items are instances of either LinearSymbolic or Constrainable.

  • All of the items in the sequence are instances of LinearSymbolic, Constrainable, Spacer, or int.

If any of the above conditions do not hold, an exception is raised with a (hopefully) useful error message.

class enable.layout.layout_helpers.AbutmentConstraintFactory(first_anchor, spacer, second_anchor)[source]

Bases: enable.layout.layout_helpers.SequenceConstraintFactory

A SequenceConstraintFactory subclass that represents an abutment constraint, which is a constraint between two anchors of different components separated by some amount of space. It has a ‘from_items’ classmethod which will create a sequence of abutment constraints from a sequence of items, a direction, and default spacing.

classmethod from_items(items, orientation, spacing)[source]

A classmethod that generates a list of abutment constraints given a sequence of items, an orientation, and default spacing.

Parameters
  • items (sequence) – A valid sequence of constrainable objects. These inclue instances of Constrainable, LinearSymbolic, Spacer, and int.

  • orientation (string) – Either ‘vertical’ or ‘horizontal’, which represents the orientation in which to abut the items.

  • spacing (int) – The spacing to use between items if no spacing is explicitly provided by in the sequence of items.

Returns

result – A list of AbutmentConstraint instances.

Return type

list

Notes

The order of abutment is left-to-right for horizontal direction and top-to-bottom for vertical direction.

orientation_map = {'horizontal': ('right', 'left'), 'vertical': ('top', 'bottom')}

A mapping from orientation to the order of anchor names to lookup for a pair of items in order to make the constraint.

class enable.layout.layout_helpers.AbutmentHelper(orientation, *items, **config)[source]

Bases: enable.layout.layout_helpers.DeferredConstraints

A concrete implementation of DeferredConstraints which will lay out its components by abutting them in a given orientation.

class enable.layout.layout_helpers.AlignmentConstraintFactory(first_anchor, spacer, second_anchor)[source]

Bases: enable.layout.layout_helpers.SequenceConstraintFactory

A SequenceConstraintFactory subclass which represents an alignmnent constraint, which is a constraint between two anchors of different components which are aligned but may be separated by some amount of space. It provides a ‘from_items’ classmethod which will create a list of alignment constraints from a sequence of items an anchor name, and a default spacing.

classmethod from_items(items, anchor_name, spacing)[source]

A classmethod that will create a seqence of alignment constraints given a sequence of items, an anchor name, and a default spacing.

Parameters
  • items (sequence) – A valid sequence of constrainable objects. These inclue instances of Constrainable, LinearSymbolic, Spacer, and int.

  • anchor_name (string) – The name of the anchor on the components which should be aligned. Either ‘left’, ‘right’, ‘top’, ‘bottom’, ‘v_center’, or ‘h_center’.

  • spacing (int) – The spacing to use between items if no spacing is explicitly provided by in the sequence of items.

Returns

result – A list of AbutmentConstraint instances.

Return type

list

Notes

For every item in the sequence, if the item is a component, then anchor for the given anchor_name on that component will be used. If a LinearSymbolic is given, then that symbolic will be used and the anchor_name will be ignored. Specifying space between items via integers or spacers is allowed.

class enable.layout.layout_helpers.AlignmentHelper(anchor, *items, **config)[source]

Bases: enable.layout.layout_helpers.DeferredConstraints

A deferred constraints helper class that lays out with a given anchor to align.

class enable.layout.layout_helpers.BaseConstraintFactory(first_anchor, spacer, second_anchor)[source]

Bases: enable.layout.layout_helpers.AbstractConstraintFactory

A base constraint factory class that implements basic common logic. It is not meant to be used directly but should rather be subclassed to be useful.

constraints()[source]

Returns LinearConstraint instance which is formed through an appropriate linear expression for the given space between the anchors.

class enable.layout.layout_helpers.BoxHelper(name)[source]

Bases: enable.layout.layout_helpers.DeferredConstraints

A DeferredConstraints helper class which adds a box model to the helper.

The addition of the box model allows the helper to be registered as ABConstrainable which has the effect of allowing box helper instances to be nested.

property bottom
property h_center
property layout_height
property layout_width
property left
property right
property top
property v_center
class enable.layout.layout_helpers.DeferredConstraints[source]

Bases: object

Abstract base class for objects that will yield lists of constraints upon request.

get_constraints(component)[source]

Returns a list of constraints.

Parameters

component (Component or None) – The component that owns this DeferredConstraints. It can be None for contexts in which there is not a containing component, such as in certain nested DeferredConstraints.

Returns

result – The list of Constraint objects which have been weighted by any provided strengths.

Return type

list of Constraints

when(switch)[source]

A simple method that can be used to switch off the generated constraints depending on a boolean value.

class enable.layout.layout_helpers.DeferredConstraintsFunction(func, *args, **kwds)[source]

Bases: enable.layout.layout_helpers.DeferredConstraints

A concrete implementation of DeferredConstraints which will call a function to get the constraint list upon request.

class enable.layout.layout_helpers.EqSpacer(amt, strength=None)[source]

Bases: enable.layout.layout_helpers.Spacer

A spacer which represents a fixed amount of space.

class enable.layout.layout_helpers.FlexSpacer(amt, min_strength='required', eq_strength='medium')[source]

Bases: enable.layout.layout_helpers.Spacer

A spacer which represents a space with a hard minimum, but also a weaker preference for being that minimum.

constrain(first_anchor, second_anchor)[source]

Return list of LinearConstraint objects that are appropriate to separate the two anchors according to the amount of space represented by the spacer.

class enable.layout.layout_helpers.GeSpacer(amt, strength=None)[source]

Bases: enable.layout.layout_helpers.Spacer

A spacer which represents a flexible space with a minimum value.

class enable.layout.layout_helpers.GridHelper(*rows, **config)[source]

Bases: enable.layout.layout_helpers.BoxHelper

A layout helper which arranges items in a grid.

class enable.layout.layout_helpers.LayoutSpacer(amt, strength=None)[source]

Bases: enable.layout.layout_helpers.Spacer

A Spacer instance which supplies convenience symbolic and normal methods to facilitate specifying spacers in layouts.

flex(**kwargs)[source]

Returns a flex spacer for the current amount.

class enable.layout.layout_helpers.LeSpacer(amt, strength=None)[source]

Bases: enable.layout.layout_helpers.Spacer

A spacer which represents a flexible space with a maximum value.

class enable.layout.layout_helpers.LinearBoxHelper(orientation, *items, **config)[source]

Bases: enable.layout.layout_helpers.BoxHelper

A layout helper which arranges items in a linear box.

orientation_map = {'horizontal': ('left', 'right'), 'vertical': ('top', 'bottom')}

A mapping orientation to the anchor names needed to make the constraints on the containing component.

ortho_map = {'horizontal': 'vertical', 'vertical': 'horizontal'}

A mapping of ortho orientations

class enable.layout.layout_helpers.SequenceConstraintFactory(first_anchor, spacer, second_anchor)[source]

Bases: enable.layout.layout_helpers.BaseConstraintFactory

A BaseConstraintFactory subclass that represents a constraint between two anchors of different components separated by some amount of space. It has a ‘_make_cns’ classmethod which will create a list of constraint factory instances from a sequence of items, the two anchor names, and a default spacing.

class enable.layout.layout_helpers.Spacer(amt, strength=None)[source]

Bases: object

An abstract base class for spacers. Subclasses must implement the ‘constrain’ method.

constrain(first_anchor, second_anchor)[source]

Returns the list of generated constraints appropriately weighted by the default strength, if provided.

when(switch)[source]

A simple method that can be used to switch off the generated space depending on a boolean value.

enable.layout.layout_helpers.align(anchor, *items, **config)[source]

Align the given anchors of the given components. Inter-component spacing is allowed.

enable.layout.layout_helpers.expand_constraints(component, constraints)[source]

A function which expands any DeferredConstraints in the provided list. This is a generator function which yields the flattened stream of constraints.

Parameters
  • component (Constrainable) – The constrainable component with which the constraints are associated. This will be passed to the .get_constraints() method of any DeferredConstraint instance.

  • constraints (list) – The list of constraints.

Yields

constraints – The stream of expanded constraints.

enable.layout.layout_helpers.grid(*rows, **config)[source]

Create a DeferredConstraints object which lays out items in a grid.

enable.layout.layout_helpers.hbox(*items, **config)[source]

Create a DeferredConstraints object composed of horizontal abutments for a given sequence of items.

enable.layout.layout_helpers.horizontal(*items, **config)[source]

Create a DeferredConstraints object composed of horizontal abutments for the given sequence of items.

enable.layout.layout_helpers.is_spacer(item)[source]

Returns True if the given item can be considered a spacer, False other otherwise.

enable.layout.layout_helpers.vbox(*items, **config)[source]

Create a DeferredConstraints object composed of vertical abutments for a given sequence of items.

enable.layout.layout_helpers.vertical(*items, **config)[source]

Create a DeferredConstraints object composed of vertical abutments for the given sequence of items.