Exemplo n.º 1
0
def test_widget_arrange_margin(root):
    parent = Widget(root)

    Widget(parent, name='child_a', y=1, x=1,
           position='fixed', height=10, width=10, margin={'top': 5})
    Widget(parent, name='child_b', y=16, x=1,
           position='fixed', height=10, width=10, margin={'bottom': 2})
    Widget(parent, name='child_c', y=1, x=1,
           position='fixed', height=10, width=10, margin={'left': 3})
    Widget(parent, name='child_d', y=1, x=85,
           position='fixed', height=10, width=10, margin={'right': 4})

    parent.render()

    arrangement = parent.arrange(parent.children)

    assert len(arrangement) == 4

    _, child_a_dimensions = arrangement[0]
    assert child_a_dimensions == {'y': 5, 'x': 1, 'height': 10, 'width': 10}

    _, child_b_dimensions = arrangement[1]
    assert child_b_dimensions == {'y': 6, 'x': 1, 'height': 10, 'width': 10}

    _, child_c_dimensions = arrangement[2]
    assert child_c_dimensions == {'y': 1, 'x': 3, 'height': 10, 'width': 10}

    _, child_d_dimensions = arrangement[3]
    assert child_d_dimensions == {'y': 1, 'x': 76, 'height': 10, 'width': 10}
Exemplo n.º 2
0
def test_widget_arrange_align(root):
    parent = Widget(root)

    Widget(parent, name='child_a',
           position='fixed', height=10, width=10, align='LL')
    Widget(parent, name='child_b',
           position='fixed', height=10, width=10, align='LC')
    Widget(parent, name='child_c',
           position='fixed', height=10, width=10, align='LR')

    Widget(parent, name='child_d',
           position='fixed', height=10, width=10, align='CL')
    Widget(parent, name='child_e',
           position='fixed', height=10, width=10, align='CC')
    Widget(parent, name='child_f',
           position='fixed', height=10, width=10, align='CR')

    Widget(parent, name='child_g',
           position='fixed', height=10, width=10, align='RL')
    Widget(parent, name='child_h',
           position='fixed', height=10, width=10, align='RC')
    Widget(parent, name='child_i',
           position='fixed', height=10, width=10, align='RR')

    parent.render()

    arrangement = parent.arrange(parent.children)

    assert len(arrangement) == 9

    _, child_a_dimensions = arrangement[0]
    assert child_a_dimensions == {'y': 0, 'x': 0, 'height': 10, 'width': 10}

    _, child_b_dimensions = arrangement[1]
    assert child_b_dimensions == {'y': 0, 'x': 40, 'height': 10, 'width': 10}

    _, child_c_dimensions = arrangement[2]
    assert child_c_dimensions == {'y': 0, 'x': 80, 'height': 10, 'width': 10}

    _, child_d_dimensions = arrangement[3]
    assert child_d_dimensions == {'y': 4, 'x': 0, 'height': 10, 'width': 10}

    _, child_e_dimensions = arrangement[4]
    assert child_e_dimensions == {'y': 4, 'x': 40, 'height': 10, 'width': 10}

    _, child_f_dimensions = arrangement[5]
    assert child_f_dimensions == {'y': 4, 'x': 80, 'height': 10, 'width': 10}

    _, child_g_dimensions = arrangement[6]
    assert child_g_dimensions == {'y': 8, 'x': 0, 'height': 10, 'width': 10}

    _, child_h_dimensions = arrangement[7]
    assert child_h_dimensions == {'y': 8, 'x': 40, 'height': 10, 'width': 10}

    _, child_i_dimensions = arrangement[8]
    assert child_i_dimensions == {'y': 8, 'x': 80, 'height': 10, 'width': 10}
Exemplo n.º 3
0
def test_widget_arrange_proportion(root):
    parent = Widget(root)

    child_a = Widget(parent, position='fixed').pin(y=5, x=5, height=5, width=5)
    child_b = Widget(parent)
    child_c = Widget(
        parent, position='fixed', proportion={'height': 0.8, 'width': 0.8})

    assert parent.arrange(parent.children) == []

    parent.render()

    arrangement = parent.arrange(parent.children)

    assert len(arrangement) == 2

    _, child_a_dimensions = arrangement[0]

    assert child_a_dimensions == {'y': 5, 'x': 5, 'height': 5, 'width': 5}

    _, child_c_dimensions = arrangement[1]

    assert child_c_dimensions == {'y': 0, 'x': 0, 'height': 14, 'width': 72}