示例#1
0
    def test_tutorial_0(self):
        root = TestNode('app',
                        style=Pack(),
                        children=[
                            TestNode('button',
                                     style=Pack(flex=1, padding=50),
                                     size=(at_least(120), 30)),
                        ])

        # Minimum size
        root.style.layout(root, Viewport(0, 0))
        self.assertLayout(
            root, (220, 130), {
                'origin': (0, 0),
                'content': (220, 130),
                'children': [{
                    'origin': (50, 50),
                    'content': (120, 30)
                }]
            })

        # Normal size
        root.style.layout(root, Viewport(640, 480))
        self.assertLayout(
            root, (640, 130), {
                'origin': (0, 0),
                'content': (640, 130),
                'children': [{
                    'origin': (50, 50),
                    'content': (540, 30)
                }]
            })
示例#2
0
    def test_refresh(self):
        "The layout can be refreshed, and the applicator invoked"

        # Define an applicator that tracks the node being rendered and it's size
        class Applicator:
            def __init__(self, node):
                self.tasks = []
                self.node = node

            def set_bounds(self):
                self.tasks.append((self.node, self.node.layout.content_width,
                                   self.node.layout.content_height))

        class TestNode(Node):
            def __init__(self, style, children=None):
                super().__init__(style=style,
                                 applicator=Applicator(self),
                                 children=children)

        # Define a simple 2 level tree of nodes.
        style = Style()
        child1 = TestNode(style=style)
        child2 = TestNode(style=style)
        child3 = TestNode(style=style)

        node = TestNode(style=style, children=[child1, child2, child3])

        # Refresh the root node
        node.refresh(Viewport(width=10, height=20))

        # Check the output is as expected
        self.assertEqual(node.applicator.tasks, [(node, 20, 40)])
        self.assertEqual(child1.applicator.tasks, [])
        self.assertEqual(child2.applicator.tasks, [])
        self.assertEqual(child3.applicator.tasks, [])

        # Reset the applicator
        node.applicator.tasks = []

        # Refresh a child node
        child1.refresh(Viewport(width=15, height=25))

        # The root node was rendered, not the child.
        self.assertEqual(node.applicator.tasks, [(node, 30, 50)])
        self.assertEqual(child1.applicator.tasks, [])
        self.assertEqual(child2.applicator.tasks, [])
        self.assertEqual(child3.applicator.tasks, [])
示例#3
0
文件: window.py 项目: yuntiaoOS/toga
    def show(self):
        self.native.show_all()

        # Now that the content is visible, we can do our initial hinting,
        # and use that as the basis for setting the minimum window size.
        self.interface.content._impl.rehint()
        self.interface.content.style.layout(self.interface.content,
                                            Viewport(0, 0))
        self.interface.content._impl.min_width = self.interface.content.layout.width
        self.interface.content._impl.min_height = self.interface.content.layout.height
示例#4
0
文件: window.py 项目: yihuang/toga
    def show(self):
        self.native.makeKeyAndOrderFront(None)

        # Render of the content with a 0 sized viewport; this will
        # establish the minimum possible content size. Use that to enforce
        # a minimum window size.
        self.interface.content.style.layout(self.interface.content, Viewport(0, 0))
        self._min_width_constraint.constant = self.interface.content.layout.width
        self._min_height_constraint.constant = self.interface.content.layout.height

        # Refresh with the actual viewport to do the proper rendering.
        self.interface.content.refresh()
示例#5
0
 def show(self):
     # The first render of the content will establish the
     # minimum possible content size; use that to enforce
     # a minimum window size.
     TITLEBAR_HEIGHT = WinForms.SystemInformation.CaptionHeight
     # Now that the content is visible, we can do our initial hinting,
     # and use that as the basis for setting the minimum window size.
     self.interface.content._impl.rehint()
     self.interface.content.style.layout(self.interface.content,
                                         Viewport(0, 0))
     self.native.MinimumSize = Size(
         int(self.interface.content.layout.width),
         int(self.interface.content.layout.height) + TITLEBAR_HEIGHT)
     self.interface.content.refresh()
示例#6
0
    def show(self):
        # The first render of the content will establish the
        # minimum possible content size; use that to enforce
        # a minimum window size.
        TITLEBAR_HEIGHT = 36  # FIXME: this shouldn't be hard coded...

        # Now that the content is visible, we can do our initial hinting,
        # and use that as the basis for setting the minimum window size.
        self.interface.content._impl.rehint()
        self.interface.content.style.layout(self.interface.content,
                                            Viewport(0, 0))
        self.native.MinimumSize = Size(
            int(self.interface.content.layout.width),
            int(self.interface.content.layout.height) + TITLEBAR_HEIGHT)
示例#7
0
    def test_constructor(self):
        viewport = Viewport(width=640, height=480, dpi=96)

        self.assertEqual(viewport.width, 640)
        self.assertEqual(viewport.height, 480)
        self.assertEqual(viewport.dpi, 96)
示例#8
0
    def test_default(self):
        viewport = Viewport()

        self.assertEqual(viewport.width, 0)
        self.assertEqual(viewport.height, 0)
        self.assertEqual(viewport.dpi, None)
示例#9
0
    def test_beeliza(self):
        root = TestNode('app',
                        style=Pack(direction=COLUMN),
                        children=[
                            TestNode('detailedlist',
                                     style=Pack(flex=1),
                                     size=(at_least(100), at_least(100))),
                            TestNode('box',
                                     style=Pack(direction=ROW),
                                     children=[
                                         TestNode('input',
                                                  style=Pack(flex=1,
                                                             padding=5),
                                                  size=(at_least(100), 15)),
                                         TestNode('button',
                                                  style=Pack(padding=5),
                                                  size=(at_least(40), 10)),
                                     ]),
                        ])

        # Minimum size
        root.style.layout(root, Viewport(0, 0, dpi=96))
        self.assertLayout(
            root, (160, 125), {
                'origin': (0, 0),
                'content': (160, 125),
                'children': [
                    {
                        'origin': (0, 0),
                        'content': (100, 100)
                    },
                    {
                        'origin': (0, 100),
                        'content': (160, 25),
                        'children': [
                            {
                                'origin': (5, 105),
                                'content': (100, 15)
                            },
                            {
                                'origin': (115, 105),
                                'content': (40, 10)
                            },
                        ]
                    },
                ]
            })

        # Normal size
        root.style.layout(root, Viewport(640, 480, dpi=96))
        self.assertLayout(
            root, (640, 480), {
                'origin': (0, 0),
                'content': (640, 480),
                'children': [
                    {
                        'origin': (0, 0),
                        'content': (640, 455)
                    },
                    {
                        'origin': (0, 455),
                        'content': (640, 25),
                        'children': [
                            {
                                'origin': (5, 460),
                                'content': (580, 15)
                            },
                            {
                                'origin': (595, 460),
                                'content': (40, 10)
                            },
                        ]
                    },
                ]
            })

        # HiDPI Normal size
        root.style.layout(root, Viewport(640, 480, dpi=144))
        self.assertLayout(
            root, (640, 480), {
                'origin': (0, 0),
                'content': (640, 480),
                'children': [
                    {
                        'origin': (0, 0),
                        'content': (640, 451)
                    },
                    {
                        'origin': (0, 451),
                        'content': (640, 29),
                        'children': [
                            {
                                'origin': (7, 458),
                                'content': (572, 15)
                            },
                            {
                                'origin': (593, 458),
                                'content': (40, 10)
                            },
                        ]
                    },
                ]
            })
示例#10
0
    def test_tutorial_3(self):
        root = TestNode('app',
                        style=Pack(direction=COLUMN),
                        children=[
                            TestNode('box',
                                     style=Pack(),
                                     children=[
                                         TestNode('input',
                                                  style=Pack(flex=1,
                                                             padding=5),
                                                  size=(at_least(100), 15)),
                                         TestNode('button',
                                                  style=Pack(width=50,
                                                             padding=5),
                                                  size=(at_least(40), 10)),
                                     ]),
                            TestNode('web',
                                     style=Pack(flex=1),
                                     size=(at_least(100), at_least(100))),
                        ])

        # Minimum size
        root.style.layout(root, Viewport(0, 0, dpi=96))
        self.assertLayout(
            root, (170, 125), {
                'origin': (0, 0),
                'content': (170, 125),
                'children': [{
                    'origin': (0, 0),
                    'content': (170, 25),
                    'children': [
                        {
                            'origin': (5, 5),
                            'content': (100, 15)
                        },
                        {
                            'origin': (115, 5),
                            'content': (50, 10)
                        },
                    ]
                }, {
                    'origin': (0, 25),
                    'content': (100, 100)
                }]
            })

        # Normal size
        root.style.layout(root, Viewport(640, 480, dpi=96))
        self.assertLayout(
            root, (640, 480), {
                'origin': (0, 0),
                'content': (640, 480),
                'children': [{
                    'origin': (0, 0),
                    'content': (640, 25),
                    'children': [
                        {
                            'origin': (5, 5),
                            'content': (570, 15)
                        },
                        {
                            'origin': (585, 5),
                            'content': (50, 10)
                        },
                    ]
                }, {
                    'origin': (0, 25),
                    'content': (640, 455)
                }]
            })

        # HiDPI Normal size
        root.style.layout(root, Viewport(640, 480, dpi=144))
        self.assertLayout(
            root, (640, 480), {
                'origin': (0, 0),
                'content': (640, 480),
                'children': [{
                    'origin': (0, 0),
                    'content': (640, 29),
                    'children': [
                        {
                            'origin': (7, 7),
                            'content': (537, 15)
                        },
                        {
                            'origin': (558, 7),
                            'content': (75, 10)
                        },
                    ]
                }, {
                    'origin': (0, 29),
                    'content': (640, 451)
                }]
            })
示例#11
0
    def test_tutorial_1(self):
        root = TestNode('app',
                        style=Pack(direction=COLUMN, padding_top=10),
                        children=[
                            TestNode('f_box',
                                     style=Pack(direction=ROW, padding=5),
                                     children=[
                                         TestNode('f_input',
                                                  style=Pack(flex=1,
                                                             padding_left=160),
                                                  size=(at_least(100), 15)),
                                         TestNode('f_label',
                                                  style=Pack(width=100,
                                                             padding_left=10),
                                                  size=(at_least(40), 10)),
                                     ]),
                            TestNode('c_box',
                                     style=Pack(direction=ROW, padding=5),
                                     children=[
                                         TestNode('join_label',
                                                  style=Pack(width=150,
                                                             padding_right=10),
                                                  size=(at_least(80), 10)),
                                         TestNode('c_input',
                                                  style=Pack(flex=1),
                                                  size=(at_least(100), 15)),
                                         TestNode('c_label',
                                                  style=Pack(width=100,
                                                             padding_left=10),
                                                  size=(at_least(40), 10)),
                                     ]),
                            TestNode('button',
                                     style=Pack(flex=1, padding=15),
                                     size=(at_least(120), 30)),
                        ])

        # Minimum size
        root.style.layout(root, Viewport(0, 0, dpi=96))
        self.assertLayout(
            root, (380, 120), {
                'origin': (0, 10),
                'content': (380, 110),
                'children': [{
                    'origin': (5, 15),
                    'content': (370, 15),
                    'children': [
                        {
                            'origin': (165, 15),
                            'content': (100, 15)
                        },
                        {
                            'origin': (275, 15),
                            'content': (100, 10)
                        },
                    ]
                }, {
                    'origin': (5, 40),
                    'content': (370, 15),
                    'children': [
                        {
                            'origin': (5, 40),
                            'content': (150, 10)
                        },
                        {
                            'origin': (165, 40),
                            'content': (100, 15)
                        },
                        {
                            'origin': (275, 40),
                            'content': (100, 10)
                        },
                    ]
                }, {
                    'origin': (15, 75),
                    'content': (120, 30)
                }]
            })

        # Normal size
        root.style.layout(root, Viewport(640, 480, dpi=96))
        self.assertLayout(
            root, (640, 120), {
                'origin': (0, 10),
                'content': (640, 110),
                'children': [{
                    'origin': (5, 15),
                    'content': (630, 15),
                    'children': [
                        {
                            'origin': (165, 15),
                            'content': (360, 15)
                        },
                        {
                            'origin': (535, 15),
                            'content': (100, 10)
                        },
                    ]
                }, {
                    'origin': (5, 40),
                    'content': (630, 15),
                    'children': [
                        {
                            'origin': (5, 40),
                            'content': (150, 10)
                        },
                        {
                            'origin': (165, 40),
                            'content': (360, 15)
                        },
                        {
                            'origin': (535, 40),
                            'content': (100, 10)
                        },
                    ]
                }, {
                    'origin': (15, 75),
                    'content': (610, 30)
                }]
            })

        # HiDPI Normal size
        root.style.layout(root, Viewport(640, 480, dpi=144))
        self.assertLayout(
            root, (640, 142), {
                'origin': (0, 10),
                'content': (640, 132),
                'children': [{
                    'origin': (7, 15),
                    'content': (626, 15),
                    'children': [
                        {
                            'origin': (247, 15),
                            'content': (221, 15)
                        },
                        {
                            'origin': (483, 15),
                            'content': (150, 10)
                        },
                    ]
                }, {
                    'origin': (7, 42),
                    'content': (626, 15),
                    'children': [
                        {
                            'origin': (7, 42),
                            'content': (225, 10)
                        },
                        {
                            'origin': (247, 42),
                            'content': (221, 15)
                        },
                        {
                            'origin': (483, 42),
                            'content': (150, 10)
                        },
                    ]
                }, {
                    'origin': (22, 79),
                    'content': (596, 30)
                }]
            })