enable.layout.layout_manager module

class enable.layout.layout_manager.LayoutManager[source]

Bases: object

A class which uses a kiwi solver to manage a system of constraints.

get_max_size(width, height, strength=1000.0)[source]

Run an iteration of the solver with the suggested size of the component set to a very large value. This will cause the solver to effectively compute the maximum size that the window can be to solve the system. The return value is a tuple numbers. If one of the numbers is -1, it indicates there is no maximum in that direction.

Parameters
  • width (Constraint Variable) – The constraint variable representing the width of the main layout container.

  • height (Constraint Variable) – The constraint variable representing the height of the main layout container.

  • strength (kiwisolver strength, optional) – The strength with which to perform the layout using the current size of the container. i.e. the strength of the resize. The default is kiwisolver.strength.medium.

Returns

result – The floating point (max_width, max_height) size of the container which would best satisfy the set of constraints.

Return type

(float or -1, float or -1)

get_min_size(width, height, strength=1000.0)[source]

Run an iteration of the solver with the suggested size of the component set to (0, 0). This will cause the solver to effectively compute the minimum size that the window can be to solve the system.

Parameters
  • width (Constraint Variable) – The constraint variable representing the width of the main layout container.

  • height (Constraint Variable) – The constraint variable representing the height of the main layout container.

  • strength (kiwisolver strength, optional) – The strength with which to perform the layout using the current size of the container. i.e. the strength of the resize. The default is kiwisolver.strength.medium.

Returns

result – The floating point (min_width, min_height) size of the container which would best satisfy the set of constraints.

Return type

(float, float)

initialize(constraints)[source]

Initialize the solver with the given constraints.

Parameters

constraints (Iterable) – An iterable that yields the constraints to add to the solvers.

layout(cb, width, height, size, strength=1000.0)[source]

Perform an iteration of the solver for the new width and height constraint variables.

Parameters
  • cb (callable) – A callback which will be called when new values from the solver are available. This will be called from within a solver context while the solved values are valid. Thus the new values should be consumed before the callback returns.

  • width (Constraint Variable) – The constraint variable representing the width of the main layout container.

  • height (Constraint Variable) – The constraint variable representing the height of the main layout container.

  • size ((int, int)) – The (width, height) size tuple which is the current size of the main layout container.

  • strength (kiwisolver strength, optional) – The strength with which to perform the layout using the current size of the container. i.e. the strength of the resize. The default is kiwisolver.strength.medium.

replace_constraints(old_cns, new_cns)[source]

Replace constraints in the solver.

Parameters
  • old_cns (list) – The list of kiwi constraints to remove from the solver.

  • new_cns (list) – The list of kiwi constraints to add to the solver.