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))
def test_reordering(): """ Test indexing into a LayerList by name """ layers = LayerList() 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') layers.append(layer_a) layers.append(layer_b) layers.append(layer_c) # Rearrange layers by tuple layers[:] = [layers[i] for i in (1, 0, 2)] assert list(layers) == [layer_b, layer_a, layer_c] # Reverse layers layers.reverse() assert list(layers) == [layer_c, layer_a, layer_b]