How to use the kiwisolver.Variable function in kiwisolver

To help you get started, we’ve selected a few kiwisolver examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nucleic / enaml / enaml / workbench / ui / menu_helper.py View on Github external
Parameters
    ----------
    nodes : list
        The list of PathNode objects which should be ordered. It
        is assumed that all nodes reside in the same group.

    Returns
    -------
    result : list
        The PathNode objects ordered according to the constraints
        specified by the 'before' and 'after' items attributes.

    """
    variables = {}
    for node in nodes:
        variables[node.id] = kiwi.Variable(str(node.id))

    prev_var = None
    constraints = []
    for node in nodes:
        this_var = variables[node.id]
        constraints.append(this_var >= 0)
        if prev_var is not None:  # weakly preserve relative order
            constraints.append((prev_var + 0.1 <= this_var) | 'weak')
        before = node.item.before
        if before:
            if before not in variables:
                msg = "item '%s' has invalid `before` reference '%s'"
                raise ValueError(msg % (node.path, before))
            target_var = variables[before]
            constraints.append((this_var + 0.1 <= target_var) | 'strong')
        after = node.item.after
github enthought / enable / enable / layout / constraints_namespace.py View on Github external
----------
        name : str
            The name of the constraint variable to return.

        """
        try:
            return super(ConstraintsNamespace, self).__getattr__(name)
        except AttributeError:
            pass

        constraints = self._constraints
        if name in constraints:
            res = constraints[name]
        else:
            label = '{0}|{1}|{2}'.format(self._name, self._owner, name)
            res = constraints[name] = Variable(label)
        return res
github enthought / enable / enable / layout / layout_helpers.py View on Github external
other_attrs = attrs[:]
            constraints = [
                getattr(self, attr) == getattr(component, other)
                for (attr, other) in zip(attrs, other_attrs)
            ]
        else:
            constraints = []

        # Create the row and column constraint variables along with
        # some default limits
        row_vars = []
        col_vars = []
        cn_id = self.constraints_id
        for idx in sm.range(num_rows + 1):
            name = 'row' + str(idx)
            var = Variable('{0}|{1}'.format(cn_id, name))
            row_vars.append(var)
            constraints.append(var >= 0)
        for idx in sm.range(num_cols + 1):
            name = 'col' + str(idx)
            var = Variable('{0}|{1}'.format(cn_id, name))
            col_vars.append(var)
            constraints.append(var >= 0)

        # Add some neighbor relations to the row and column vars.
        for r1, r2 in zip(row_vars[:-1], row_vars[1:]):
            constraints.append(r1 >= r2)
        for c1, c2 in zip(col_vars[:-1], col_vars[1:]):
            constraints.append(c1 <= c2)

        # Setup the initial interior bounding box for the grid.
        margins = self.margins
github nucleic / enaml / enaml / layout / linear_symbolic.py View on Github external
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file LICENSE, distributed with this software.
#------------------------------------------------------------------------------
from abc import ABCMeta

import kiwisolver as kiwi


class LinearSymbolic(object, metaclass=ABCMeta):
    """ An abstract base class for testing linear symbolic interfaces.

    """


LinearSymbolic.register(kiwi.Variable)
LinearSymbolic.register(kiwi.Term)
LinearSymbolic.register(kiwi.Expression)
github nucleic / enaml / enaml / layout / grid_helper.py View on Github external
num_cols = max(num_cols, len(row))
            for col_idx, item in enumerate(row):
                if item is None:
                    continue
                elif item in cell_map:
                    cell_map[item].expand_to(row_idx, col_idx)
                else:
                    cell = self._Cell(item, row_idx, col_idx)
                    cell_map[item] = cell
                    cells.append(cell)

        # Create the row and column variables and their default limits.
        row_vars = []
        col_vars = []
        for idx in range(num_rows + 1):
            var = kiwi.Variable('row%d' % idx)
            row_vars.append(var)
            cns.append(var >= 0)
        for idx in range(num_cols + 1):
            var = kiwi.Variable('col%d' % idx)
            col_vars.append(var)
            cns.append(var >= 0)

        # Add the neighbor constraints for the row and column vars.
        for r1, r2 in zip(row_vars[:-1], row_vars[1:]):
            cns.append(r1 <= r2)
        for c1, c2 in zip(col_vars[:-1], col_vars[1:]):
            cns.append(c1 <= c2)

        # Setup the initial interior bounding box for the grid.
        firsts = (self.top, col_vars[-1], row_vars[-1], self.left)
        seconds = (row_vars[0], self.right, self.bottom, col_vars[0])
github nucleic / enaml / enaml / layout / constrainable.py View on Github external
def default(self, owner):
        return kiwi.Variable(self.name)

kiwisolver

A fast implementation of the Cassowary constraint solver

BSD-3-Clause
Latest version published 3 months ago

Package Health Score

89 / 100
Full package analysis

Similar packages