Example #1
0
    def _default_constraints(self):
        """ Supplies a default vbox constraint to the constraints
        children of the container if other constraints are not given.

        """
        cns = super(Container, self)._default_constraints()
        cns.append(vbox(*self.widgets))
        return cns
Example #2
0
    def layout_constraints(self):
        """ The constraints generation for a Container.

        This method supplies default vbox constraints to the children of
        the container unless the user has given explicit 'constraints'.

        """
        if self.constraints:
            return self.constraints
        return [vbox(*self.visible_widgets())]
Example #3
0
    def layout_constraints(self):
        """ The constraints generation for a Container.

        This method supplies default vbox constraints to the children of
        the container unless the user has given explicit 'constraints'.

        """
        cns = self.constraints[:]
        if not cns:
            cns.append(vbox(*self.widgets()))
        return cns
Example #4
0
    def layout_constraints(self):
        """ The constraints generation for a Container.

        This method supplies default vbox constraints to the children of
        the container unless the user has given explicit 'constraints'.

        """
        cns = self.constraints[:]
        if not cns:
            cns.append(vbox(*self.widgets()))
        return cns
Example #5
0
    def _get_default_constraints(self):
        """ The default constraints for a Container.

        This method supplies default vbox constraint to the children of
        the container if other constraints are not given.

        """
        cns = super(Container, self)._get_default_constraints()
        ws = (c for c in self.children if isinstance(c, ConstraintsWidget))
        cns.append(vbox(*ws))
        return cns
Example #6
0
    def _get_default_constraints(self):
        """ The default constraints for a Container.

        This method supplies default vbox constraint to the children of
        the container if other constraints are not given.

        """
        cns = super(Container, self)._get_default_constraints()
        ws = (c for c in self.children if isinstance(c, ConstraintsWidget))
        cns.append(vbox(*ws))
        return cns
Example #7
0
    def layout_constraints(self):
        """ The constraints generation for a Container.

        This method supplies default vbox constraints to the visible
        children of the container unless the user has given explicit
        'constraints'.

        This method may also be overridden from Enaml syntax.

        """
        if self.constraints:
            return self.constraints
        return [vbox(*self.visible_widgets())]
Example #8
0
    def layout_constraints(self):
        """ The constraints generation for a VGroup.

        This method supplies left-aligned vertical group constraints for
        the children of the container in addition to any user-supplied
        constraints.

        """
        widgets = self.visible_widgets()
        items = [self.leading_spacer] + widgets + [self.trailing_spacer]
        cns = self.constraints[:]
        cns.append(vbox(*items, spacing=self.spacing))
        cns.append(align('left', *widgets))
        return cns
Example #9
0
    def layout_constraints(self):
        """ The constraints generation for a VGroup.

        This method supplies left-aligned vertical group constraints for
        the children of the container in addition to any user-supplied
        constraints.

        This method cannot be overridden from Enaml syntax.

        """
        widgets = self.visible_widgets()
        items = [self.leading_spacer] + widgets + [self.trailing_spacer]
        cns = self.constraints[:]
        cns.append(vbox(*items, spacing=self.spacing))
        cns.append(align('left', *widgets))
        return cns
Example #10
0
    def _component_constraints(self):
        """ Supplies the constraints which layout the children in a
        two column form.

        """
        # FIXME: do something sensible when children are not visible.
        children = list(self.widgets)
        labels = children[::2]
        widgets = children[1::2]

        n_labels = len(labels)
        n_widgets = len(widgets)

        if n_labels != n_widgets:
            if n_labels > n_widgets:
                odd_child = labels.pop()
            else:
                odd_child = widgets.pop()
        else:
            odd_child = None

        layout_strength = self.layout_strength
        constraints = []

        # Align the left side of each widget with the midline constraint
        # variable of the form.
        midline = self.midline
        for widget in widgets:
            cn = (widget.left == midline) | layout_strength
            constraints.append(cn)

        # Arrange each label/widget pair horizontally in the form
        # XXX this is a highly inefficient way to generate these
        # constraints. It starts to be noticeably slow when the
        # form has around 20 rows. This can be done better.
        labels_widgets = zip(labels, widgets)
        vbox_args = [hbox(label, widget) for label, widget in labels_widgets]
        if odd_child is not None:
            vbox_args.append(odd_child)
        constraints.append(vbox(*vbox_args))

        for label, widget in labels_widgets:
            # FIXME: baselines would be much better.
            constraints.append(
                align('v_center', label, widget) | layout_strength)

        return constraints
Example #11
0
File: form.py Project: 5n1p/enaml
    def _component_constraints(self):
        """ Supplies the constraints which layout the children in a
        two column form.

        """
        # FIXME: do something sensible when children are not visible.
        children = list(self.widgets)
        labels = children[::2]
        widgets = children[1::2]

        n_labels = len(labels)
        n_widgets = len(widgets)

        if n_labels != n_widgets:
            if n_labels > n_widgets:
                odd_child = labels.pop()
            else:
                odd_child = widgets.pop()
        else:
            odd_child = None

        layout_strength = self.layout_strength
        constraints = []

        # Align the left side of each widget with the midline constraint
        # variable of the form.
        midline = self.midline
        for widget in widgets:
            cn = (widget.left == midline) | layout_strength
            constraints.append(cn)

        # Arrange each label/widget pair horizontally in the form
        # XXX this is a highly inefficient way to generate these
        # constraints. It starts to be noticeably slow when the
        # form has around 20 rows. This can be done better.
        labels_widgets = zip(labels, widgets)
        vbox_args = [hbox(label, widget) for label, widget in labels_widgets]
        if odd_child is not None:
            vbox_args.append(odd_child)
        constraints.append(vbox(*vbox_args))

        for label, widget in labels_widgets:
            # FIXME: baselines would be much better.
            constraints.append(align('v_center', label, widget) | layout_strength)

        return constraints