コード例 #1
0
def test_adding_layers(qtbot):
    """
    Test adding layers.
    """
    layers = LayerList()
    view = QtLayerList(layers)

    qtbot.addWidget(view)

    # Check that new layer and divider get added to vbox_layout
    layer_a = Image(np.random.random((10, 10)))
    layers.append(layer_a)
    assert view.vbox_layout.count() == 2 * (len(layers) + 1)
    assert check_layout_layers(view.vbox_layout, layers)
    assert check_layout_dividers(view.vbox_layout, len(layers))

    # Check that new layers and dividers get added to vbox_layout
    layer_b = Image(np.random.random((15, 15)))
    layer_c = Image(np.random.random((15, 15)))
    layer_d = Image(np.random.random((15, 15)))
    layers.append(layer_b)
    layers.append(layer_c)
    layers.append(layer_d)
    assert view.vbox_layout.count() == 2 * (len(layers) + 1)
    assert check_layout_layers(view.vbox_layout, layers)
    assert check_layout_dividers(view.vbox_layout, len(layers))
コード例 #2
0
def test_reordering_layers(qtbot):
    """
    Test reordering layers.
    """
    layers = LayerList()
    view = QtLayerList(layers)

    qtbot.addWidget(view)

    layer_a = Image(np.random.random((10, 10)), name='image_a')
    layer_b = Image(np.random.random((15, 15)), name='image_b')
    layer_c = Image(np.random.random((15, 15)), name='image_c')
    layer_d = Image(np.random.random((15, 15)), name='image_d')
    layers.append(layer_a)
    layers.append(layer_b)
    layers.append(layer_c)
    layers.append(layer_d)

    # Check layout and layers list match after rearranging layers
    layers[:] = [layers[i] for i in (1, 0, 3, 2)]
    assert view.vbox_layout.count() == 2 * (len(layers) + 1)
    assert check_layout_layers(view.vbox_layout, layers)
    assert check_layout_dividers(view.vbox_layout, len(layers))

    # Do another reorder and check layout and layers list match
    # after swapping layers again
    layers[:] = [layers[i] for i in (1, 0, 3, 2)]
    assert view.vbox_layout.count() == 2 * (len(layers) + 1)
    assert check_layout_layers(view.vbox_layout, layers)
    assert check_layout_dividers(view.vbox_layout, len(layers))

    # Check layout and layers list match after reversing list
    layers.reverse()
    assert view.vbox_layout.count() == 2 * (len(layers) + 1)
    assert check_layout_layers(view.vbox_layout, layers)
    assert check_layout_dividers(view.vbox_layout, len(layers))

    # Check layout and layers list match after rearranging selected layers
    layer_e = Image(np.random.random((15, 15)))
    layer_f = Image(np.random.random((15, 15)))
    layers.append(layer_e)
    layers.append(layer_f)
    for layer, s in zip(layers, [False, True, False, False, True, False]):
        layer.selected = s
    layers.move_selected(1, 2)
    assert view.vbox_layout.count() == 2 * (len(layers) + 1)
    assert check_layout_layers(view.vbox_layout, layers)
    assert check_layout_dividers(view.vbox_layout, len(layers))
コード例 #3
0
def test_creating_empty_view(qtbot):
    """
    Test creating LayerList view.
    """
    layers = LayerList()
    view = QtLayerList(layers)

    qtbot.addWidget(view)

    # Check that the layers model has been appended to the layers view
    assert view.layers == layers

    # Check that vbox_layout only contains one QtDivider and one spacer
    assert view.vbox_layout.count() == 2
    assert check_layout_layers(view.vbox_layout, layers)
    assert check_layout_dividers(view.vbox_layout, 0)
コード例 #4
0
def test_clearing_layerlist(qtbot):
    """Test clearing layer list."""
    layers = LayerList()
    view = QtLayerList(layers)

    qtbot.addWidget(view)

    layers.extend([Image(np.random.random((15, 15))) for _ in range(4)])

    assert view.vbox_layout.count() == 2 * (len(layers) + 1)
    assert check_layout_layers(view.vbox_layout, layers)
    assert check_layout_dividers(view.vbox_layout, len(layers))

    layers.clear()
    assert len(layers) == 0
    assert view.vbox_layout.count() == 2 * (len(layers) + 1)
    assert check_layout_layers(view.vbox_layout, layers)
    assert check_layout_dividers(view.vbox_layout, len(layers))
コード例 #5
0
def test_removing_layers(qtbot):
    """
    Test removing layers.
    """
    layers = LayerList()
    view = QtLayerList(layers)

    qtbot.addWidget(view)

    layer_a = Image(np.random.random((10, 10)))
    layer_b = Image(np.random.random((15, 15)))
    layer_c = Image(np.random.random((15, 15)))
    layer_d = Image(np.random.random((15, 15)))
    layers.append(layer_a)
    layers.append(layer_b)
    layers.append(layer_c)
    layers.append(layer_d)

    # Check layout and layers list match after removing a layer
    layers.remove(layer_b)
    assert view.vbox_layout.count() == 2 * (len(layers) + 1)
    assert check_layout_layers(view.vbox_layout, layers)
    assert check_layout_dividers(view.vbox_layout, len(layers))

    # Check layout and layers list match after removing a layer
    layers.remove(layer_d)
    assert view.vbox_layout.count() == 2 * (len(layers) + 1)
    assert check_layout_layers(view.vbox_layout, layers)
    assert check_layout_dividers(view.vbox_layout, len(layers))

    layers.append(layer_b)
    layers.append(layer_d)
    # Select first and third layers
    for layer, s in zip(layers, [True, True, False, False]):
        layer.selected = s
    layers.remove_selected()
    assert view.vbox_layout.count() == 2 * (len(layers) + 1)
    assert check_layout_layers(view.vbox_layout, layers)
    assert check_layout_dividers(view.vbox_layout, len(layers))