예제 #1
0
    def test_items(self):
        layout = BorderLayout()

        container = Frame(self.context, layout)

        child1 = Panel(self.context)
        child2 = Panel(self.context)
        child3 = Panel(self.context)
        child4 = Panel(self.context)
        child5 = Panel(self.context)

        container.add(child1)
        container.add(child2, Border.Left)
        container.add(child3, Border.Top, Insets(2, 2, 2, 2))
        container.add(child4, Border.Right, padding=Insets(5, 5, 5, 5))
        container.add(child5,
                      region=Border.Bottom,
                      padding=Insets(10, 10, 10, 10))

        def assert_item(item: BorderItem, child: Component, border: Border,
                        padding: Insets) -> None:
            self.assertEqual(child, item.component.unwrap())
            self.assertEqual(border, item.border)
            self.assertEqual(padding, item.padding)

        assert_item(layout.areas[Border.Center], child1, Border.Center,
                    Insets(0, 0, 0, 0))
        assert_item(layout.areas[Border.Top], child3, Border.Top,
                    Insets(2, 2, 2, 2))
        assert_item(layout.areas[Border.Right], child4, Border.Right,
                    Insets(5, 5, 5, 5))
        assert_item(layout.areas[Border.Bottom], child5, Border.Bottom,
                    Insets(10, 10, 10, 10))
        assert_item(layout.areas[Border.Left], child2, Border.Left,
                    Insets(0, 0, 0, 0))

        container.add(child1, Border.Right)
        container.remove(child2)
        container.remove(child3)

        assert_item(layout.areas[Border.Right], child1, Border.Right,
                    Insets(0, 0, 0, 0))

        # noinspection PyTypeChecker
        children = Fold.collect_all(
            map(lambda a: a.component, layout.areas.values()), Some(
                ())).unwrap()

        self.assertEqual({child5, child1}, set(children))
        self.assertEqual(Nothing, layout.areas[Border.Top].component)
        self.assertEqual(Some(child1), layout.areas[Border.Right].component)
        self.assertEqual(Some(child5), layout.areas[Border.Bottom].component)
        self.assertEqual(Nothing, layout.areas[Border.Left].component)
예제 #2
0
    def test_validation(self):
        container = Frame(self.context)
        container.bounds = Bounds(30, 30, 200, 200)

        child = Panel(self.context)
        child.bounds = Bounds(10, 10, 20, 20)

        container.validate()
        self.assertEqual(True, container.valid)

        container.add(child)

        self.assertEqual(False, container.valid)

        container.validate()
        child.bounds = Bounds(10, 10, 30, 30)

        self.assertEqual(False, container.valid)

        container.validate()
        child.preferred_size_override = Some(Dimension(60, 60))

        self.assertEqual(False, container.valid)

        container.validate()
        child.minimum_size_override = Some(Dimension(10, 10))

        self.assertEqual(False, container.valid)

        container.validate()
        child.visible = False

        self.assertEqual(False, container.valid)

        container.validate()
        container.remove(child)

        self.assertEqual(False, container.valid)