def test_invalid_layout(self):
        """ Make sure proper exceptions are thrown with an invalid layout.

        """
        self.assertRaises(TypeError, setattr,
                          self.container.layout_constraints,
                          [hbox(self.c1, spacer, spacer)])
Exemplo n.º 2
0
    def test_invalid_layout(self):
        """ Make sure proper exceptions are thrown with an invalid layout.

        """
        from enable.layout.api import hbox, spacer

        self.assertRaises(TypeError, setattr,
                          self.container.layout_constraints,
                          [hbox(self.c1, spacer, spacer)])
    def test_hbox_order(self):
        """ Test the order of components in an hbox.

        """
        self.container.layout_constraints = [
            hbox(self.c1, self.c2)
        ]

        dx = self.c2.position[0] - self.c1.position[0]
        self.assert_(dx > 0)
Exemplo n.º 4
0
    def test_hbox_order(self):
        """ Test the order of components in an hbox.

        """
        from enable.layout.api import hbox

        self.container.layout_constraints = [hbox(self.c1, self.c2)]

        dx = self.c2.position[0] - self.c1.position[0]
        self.assertTrue(dx > 0)
    def test_hbox_order(self):
        """ Test the order of components in an hbox.

        """
        from enable.layout.api import hbox

        self.container.layout_constraints = [
            hbox(self.c1, self.c2)
        ]

        dx = self.c2.position[0] - self.c1.position[0]
        self.assertTrue(dx > 0)
Exemplo n.º 6
0
    def test_constraint_function(self):
        """ Test using a function to create constraints.

        """
        from enable.layout.api import hbox, align

        cns = [hbox(self.c1, self.c2), align("layout_width", self.c1, self.c2)]

        def get_constraints(container):
            return cns

        self.container.layout_constraints = get_constraints

        self.assertTrue(self.c1.bounds[0] == self.c2.bounds[0])
    def test_constraint_function(self):
        """ Test using a function to create constraints.

        """
        cns = [
            hbox(self.c1, self.c2),
            align('layout_width', self.c1, self.c2)
        ]

        def get_constraints(container):
            return cns

        self.container.layout_constraints = get_constraints

        self.assert_(self.c1.bounds[0] == self.c2.bounds[0])
    def test_layout_manager_replace_constraints(self):
        """ Test replacing constraints in the layout manager.

        """
        manager = LayoutManager()
        cns = hbox(self.c1, self.c2).get_constraints(self.container)
        new_cns = vbox(self.c1, self.c2).get_constraints(self.container)

        self.assertRaises(RuntimeError, manager.replace_constraints, cns[0],
                          new_cns[0])

        manager.initialize(cns)
        manager.replace_constraints(cns, new_cns)

        self.assert_(not manager._solver.hasConstraint(cns[0]))
        self.assert_(manager._solver.hasConstraint(new_cns[0]))
Exemplo n.º 9
0
    def test_layout_manager_replace_constraints(self):
        """ Test replacing constraints in the layout manager.

        """
        from enable.layout.api import hbox, vbox
        from enable.layout.layout_manager import LayoutManager

        manager = LayoutManager()
        cns = hbox(self.c1, self.c2).get_constraints(self.container)
        new_cns = vbox(self.c1, self.c2).get_constraints(self.container)

        self.assertRaises(RuntimeError, manager.replace_constraints, cns[0],
                          new_cns[0])

        manager.initialize(cns)
        manager.replace_constraints(cns, new_cns)

        self.assertTrue(not manager._solver.hasConstraint(cns[0]))
        self.assertTrue(manager._solver.hasConstraint(new_cns[0]))
    def test_share_layout(self):
        """ Test sharing layouts with a child container.

        """
        self.child_container = ConstraintsContainer(bounds=[50, 50])
        c3 = Component()
        self.child_container.add(c3)
        self.container.add(self.child_container)

        self.container.layout_constraints = [
            hbox(self.c1, self.c2, c3),
            align('layout_width', self.c1, self.c2, c3)
        ]

        self.assert_(self.c1.bounds[0] == self.c2.bounds[0] != c3.bounds[0])

        self.child_container.share_layout = True
        self.container.relayout()

        self.assert_(self.c1.bounds[0] == self.c2.bounds[0] == c3.bounds[0])
Exemplo n.º 11
0
    def test_share_layout(self):
        """ Test sharing layouts with a child container.

        """
        from enable.api import ConstraintsContainer
        from enable.layout.api import hbox, align

        self.child_container = ConstraintsContainer(bounds=[50, 50])
        c3 = Component()
        self.child_container.add(c3)
        self.container.add(self.child_container)

        self.container.layout_constraints = [
            hbox(self.c1, self.c2, c3),
            align("layout_width", self.c1, self.c2, c3),
        ]

        self.assertTrue(self.c1.bounds[0] == self.c2.bounds[0] != c3.bounds[0])

        self.child_container.share_layout = True
        self.container.relayout()

        self.assertTrue(self.c1.bounds[0] == self.c2.bounds[0] == c3.bounds[0])