Page Contents

This Page

ConstraintsWidget

class enaml.widgets.constraints_widget.ConstraintsWidget(parent=None, **kwargs)[source]

Bases: enaml.widgets.widget.Widget

A Widget subclass which adds constraint information.

A ConstraintsWidget is augmented with symbolic constraint variables which define a box model on the widget. This box model is used to declare constraints between this widget and other components which participate in constraints-based layout.

Constraints are added to a widget by assigning a list to the ‘constraints’ attribute. This list may contain raw LinearConstraint objects (which are created by manipulating the symbolic constraint variables) or DeferredConstraints objects which generated these LinearConstraint objects on-the-fly.

A ConstraintsWidget also has a ‘constraints_id’ which is a uuid given to the object and to each of its constraint variables in order to track ownership of the constraint variables. This id is automatically generated, and should not be modified by the user.

constraints = None

The list of user-specified constraints or constraint-generating objects for this component.

left = None

A read-only symbolic object that represents the left boundary of the component

top = None

A read-only symbolic object that represents the top boundary of the component

width = None

A read-only symbolic object that represents the width of the component

height = None

A read-only symbolic object that represents the height of the component

right = None

A read-only symbolic object that represents the right boundary of the component

bottom = None

A read-only symbolic object that represents the bottom boundary of the component

v_center = None

A read-only symbolic object that represents the vertical center of the component

h_center = None

A read-only symbolic object that represents the horizontal center of the component

hug_width = None

How strongly a component hugs it’s width hint. Valid strengths are ‘weak’, ‘medium’, ‘strong’, ‘required’ and ‘ignore’. Default is ‘strong’. This trait should be overridden on a per-control basis to specify a logical default for the given control.

hug_height = None

How strongly a component hugs it’s height hint. Valid strengths are ‘weak’, ‘medium’, ‘strong’, ‘required’ and ‘ignore’. Default is ‘strong’. This trait should be overridden on a per-control basis to specify a logical default for the given control.

resist_width = None

How strongly a component resists clipping its contents. Valid strengths are ‘weak’, ‘medium’, ‘strong’, ‘required’ and ‘ignore’. The default is ‘strong’ for width.

resist_height = None

How strongly a component resists clipping its contents. Valid strengths are ‘weak’, ‘medium’, ‘strong’, ‘required’ and ‘ignore’. The default is ‘strong’ for height.

snapshot()[source]

Populates the initial attributes dict for the component.

A ConstraintsWidget adds the ‘layout’ key to the creation attributes dict. The value is a dict with the following keys.

‘constraints’
A list of dictionaries representing linear constraints.
‘resist_clip’
A tuple containing width and height clip policies.
‘hug’
A tuple containing width and height hug policies.
bind()[source]

Binds the change handlers for the component.

when(switch)[source]

A method which returns self or None based on the truthness of the argument.

This can be useful to easily turn off the effects of an object in constraints-based layout.

Parameters:switch (bool) – A boolean which indicates whether this instance or None should be returned.
Returns:result (self or None) – If ‘switch’ is boolean True, self is returned. Otherwise, None is returned.
__implements__

alias of __NoInterface__

Backends

Qt

Inheritance diagram of enaml.qt.qt_constraints_widget.QtConstraintsWidget

class enaml.qt.qt_constraints_widget.QtConstraintsWidget(object_id, parent, session)[source]

Bases: enaml.qt.qt_widget.QtWidget

A Qt implementation of an Enaml ConstraintsWidget.

create(tree)[source]

Create and initialize the underlyling widget.

on_action_relayout(content)[source]

Handle the ‘relayout’ action from the Enaml widget.

relayout()[source]

Peform a relayout for this constraints widget.

The default behavior of this method is to proxy the call up the tree of ancestors until it is either handled by a subclass which has reimplemented this method (see QtContainer), or the ancestor is not an instance of QtConstraintsWidget, at which point the layout request is dropped.

replace_constraints(old_cns, new_cns)[source]

Replace constraints in the current layout system.

The default behavior of this method is to proxy the call up the tree of ancestors until it is either handled by a subclass which has reimplemented this method (see QtContainer), or the ancestor is not an instance of QtConstraintsWidget, at which point the request is dropped.

Parameters:
  • old_cns (list) – The list of casuarius constraints to remove from 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 system.

The default behavior of this method is to proxy the call up the tree of ancestors until it is either handled by a subclass which has reimplemented this method (see QtContainer), or the ancestor is not an instance of QtConstraintsWidget, at which point the request is dropped. This method will not trigger a relayout.

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

Creates the list of size hint constraints for this widget.

This method uses the provided size hint of the widget and the policies for ‘hug’ and ‘resist’ to generate constraints which respect the size hinting of the widget.

If the size hint of the underlying widget is not valid, then no constraints will be generated.

Returns:result (list) – A list of casuarius LinearConstraint instances.
size_hint_updated()[source]

Notify the layout system that the size hint of this widget has been updated.

clear_size_hint_constraints()[source]

Clear the size hint constraints from the layout system.

hard_constraints()[source]

Generate the constraints which must always be applied.

These constraints are generated once the first time this method is called. The results are then cached and returned immediately on future calls.

Returns:result (list) – A list of casuarius LinearConstraint instance.
user_constraints()[source]

Get the list of user constraints defined for this widget.

The default implementation returns the list of constraint information sent by the server.

Returns:result (list) – The list of dictionaries which represent the user defined linear constraints.
geometry_updater()[source]

A method which can be called to create a function which will update the layout geometry of the underlying widget.

The parameter and return values below describe the function that is returned by calling this method.

Parameters:
  • dx (float) – The offset of the parent widget from the computed origin of the layout. This amount is subtracted from the computed layout ‘x’ amount, which is expressed in the coordinates of the owner widget.
  • dy (float) – The offset of the parent widget from the computed origin of the layout. This amount is subtracted from the computed layout ‘y’ amount, which is expressed in the coordinates of the layout owner widget.
Returns:

result ((x, y)) – The computed layout ‘x’ and ‘y’ amount, expressed in the coordinates of the layout owner widget.

Wx

Inheritance diagram of enaml.wx.wx_constraints_widget.WxConstraintsWidget

class enaml.wx.wx_constraints_widget.WxConstraintsWidget(object_id, parent, session)[source]

Bases: enaml.wx.wx_widget.WxWidget

A Wx implementation of an Enaml ConstraintsWidget.

create(tree)[source]

Create and initialize the control.

on_action_relayout(content)[source]

Handle the ‘relayout’ action from the Enaml widget.

relayout()[source]

Peform a relayout for this constraints widget.

The default behavior of this method is to proxy the call up the tree of ancestors until it is either handled by a subclass which has reimplemented this method (see WxContainer), or the ancestor is not an instance of WxConstraintsWidget, at which point the layout request is dropped.

replace_constraints(old_cns, new_cns)[source]

Replace constraints in the current layout system.

The default behavior of this method is to proxy the call up the tree of ancestors until it is either handled by a subclass which has reimplemented this method (see WxContainer), or the ancestor is not an instance of WxConstraintsWidget, at which point the request is dropped.

Parameters:
  • old_cns (list) – The list of casuarius constraints to remove from 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 system.

The default behavior of this method is to proxy the call up the tree of ancestors until it is either handled by a subclass which has reimplemented this method (see WxContainer), or the ancestor is not an instance of WxConstraintsWidget, at which point the request is dropped. This method will not trigger a relayout.

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

Creates the list of size hint constraints for this widget.

This method uses the provided size hint of the widget and the policies for ‘hug’ and ‘resist_clip’ to generate casuarius LinearConstraint objects which respect the size hinting of the widget.

If the size hint of the underlying widget is not valid, then no constraints will be generated.

Returns:result (list) – A list of casuarius LinearConstraint instances.
size_hint_updated()[source]

Notify the layout system that the size hint of this widget has been updated.

clear_size_hint_constraints()[source]

Clear the size hint constraints from the layout system.

hard_constraints()[source]

Generate the constraints which must always be applied.

These constraints are generated once the first time this method is called. The results are then cached and returned immediately on future calls.

Returns:result (list) – A list of casuarius LinearConstraint instance.
user_constraints()[source]

Get the list of user constraints defined for this widget.

The default implementation returns the list of constraint information sent by the server.

Returns:result (list) – The list of dictionaries which represent the user defined linear constraints.
geometry_updater()[source]

A method which can be called to create a function which will update the layout geometry of the underlying widget.

The parameter and return values below describe the function that is returned by calling this method.

Parameters:
  • dx (float) – The offset of the parent widget from the computed origin of the layout. This amount is subtracted from the computed layout ‘x’ amount, which is expressed in the coordinates of the owner widget.
  • dy (float) – The offset of the parent widget from the computed origin of the layout. This amount is subtracted from the computed layout ‘y’ amount, which is expressed in the coordinates of the layout owner widget.
Returns:

result ((x, y)) – The computed layout ‘x’ and ‘y’ amount, expressed in the coordinates of the layout owner widget.