napari.components.LayerList
- 
class 
napari.components.LayerList(data=())[source]¶ Bases:
napari.utils.events.containers._selectable_list.SelectableEventedList[napari.layers.base.base.Layer]List-like layer collection with built-in reordering and callback hooks.
- Parameters
 data (iterable) – Iterable of napari.layer.Layer
Methods
append(value)S.append(value) – append value to the end of the sequence
clear()copy()Return a shallow copy of the list.
count(value)extend(values)S.extend(iterable) – extend sequence by appending elements from the iterable
index(value[, start, stop])Return first index of value.
insert(index, value)Insert
valuebefore index.move(src_index[, dest_index])Insert object at
src_indexbeforedest_index.move_multiple(sources[, dest_index])Move a batch of sources indices, to a single destination.
move_selected(index, insert)Reorder list by moving the item at index and inserting it at the insert index.
pop([index])Raise IndexError if list is empty or index is out of range.
remove(value)S.remove(value) – remove first occurrence of value.
Remove selected items from list.
reverse()Reverse list IN PLACE.
save(path, *[, selected, plugin])Save all or only selected layers to a path using writer plugins.
Select all items in the list.
select_next([step, shift])Selects next item from list.
select_previous([shift])Selects previous item from list.
Toggle visibility of selected layers
Attributes
Extent of layers in data and world coordinates.
Maximum dimensionality of layers.
Get current selection.
Details
- 
append(value)¶ S.append(value) – append value to the end of the sequence
- 
clear() → None – remove all items from S¶ 
- 
copy()¶ Return a shallow copy of the list.
- Return type
 TypedMutableSequence[~_T]
- 
count(value) → integer – return number of occurrences of value¶ 
- 
extend(values)¶ S.extend(iterable) – extend sequence by appending elements from the iterable
- 
property 
extent¶ Extent of layers in data and world coordinates.
- Return type
 Extent
- 
index(value, start=0, stop=None)¶ Return first index of value.
- Parameters
 value (Any) – A value to lookup. If type(value) is in the lookups functions provided for this class, then values in the list will be searched using the corresponding lookup converter function.
start (int, optional) – The starting index to search, by default 0
stop (int, optional) – The ending index to search, by default None
- Returns
 The index of the value
- Return type
 - Raises
 ValueError – If the value is not present
- 
move(src_index, dest_index=0)¶ Insert object at
src_indexbeforedest_index.Both indices refer to the list prior to any object removal (pre-move space).
- Return type
 
- 
move_multiple(sources, dest_index=0)¶ Move a batch of sources indices, to a single destination.
Note, if dest_index is higher than any of the sources, then the resulting position of the moved objects after the move operation is complete will be lower than dest_index.
- Parameters
 dest_index (int, optional) – The destination index. All sources will be inserted before this index (in pre-move space), by default 0… which has the effect of “bringing to front” everything in
sources, or acting as a “reorder” method ifsourcescontains all indices.
- Returns
 The number of successful move operations completed.
- Return type
 - Raises
 TypeError – If the destination index is a slice, or any of the source indices are not
intorslice.
- 
move_selected(index, insert)[source]¶ Reorder list by moving the item at index and inserting it at the insert index. If additional items are selected these will get inserted at the insert index too. This allows for rearranging the list based on dragging and dropping a selection of items, where index is the index of the primary item being dragged, and insert is the index of the drop location, and the selection indicates if multiple items are being dragged. If the moved layer is not selected select it.
- 
property 
ndim¶ Maximum dimensionality of layers.
Defaults to 2 if no data is present.
- Returns
 ndim
- Return type
 
- 
pop([index]) → item – remove and return item at index (default last).¶ Raise IndexError if list is empty or index is out of range.
- 
remove(value)¶ S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.
- 
remove_selected()¶ Remove selected items from list.
- 
reverse()¶ Reverse list IN PLACE.
- Return type
 None
- 
save(path, *, selected=False, plugin=None)[source]¶ Save all or only selected layers to a path using writer plugins.
If
pluginis not provided and only one layer is targeted, then we directly call the corresponding``napari_write_<layer_type>`` hook (see single layer writer hookspecs) which will loop through implementations and stop when the first one returns a non-Noneresult. The order in which implementations are called can be changed with the Plugin sorter in the GUI or with the corresponding hook’sbring_to_front()method.If
pluginis not provided and multiple layers are targeted, then we callnapari_get_writer()which loops through plugins to find the first one that knows how to handle the combination of layers and is able to write the file. If no plugins offernapari_get_writer()for that combination of layers then the defaultnapari_get_writer()will create a folder and callnapari_write_<layer_type>for each layer using theLayer.namevariable to modify the path such that the layers are written to unique files in the folder.If
pluginis provided and a single layer is targeted, then we call thenapari_write_<layer_type>for that plugin, and if it fails we error.If
pluginis provided and multiple layers are targeted, then we call we callnapari_get_writer()for that plugin, and if it doesn’t return aWriterFunctionwe error, otherwise we call it and if that fails if it we error.- Parameters
 path (str) – A filepath, directory, or URL to open. Extensions may be used to specify output format (provided a plugin is available for the requested format).
selected (bool) – Optional flag to only save selected layers. False by default.
plugin (str, optional) – Name of the plugin to use for saving. If None then all plugins corresponding to appropriate hook specification will be looped through to find the first one that can save the data.
- Returns
 File paths of any files that were written.
- Return type
 list of str
- 
select_all()¶ Select all items in the list.
- 
select_next(step=1, shift=False)¶ Selects next item from list.
- 
select_previous(shift=False)¶ Selects previous item from list.
- 
property 
selection¶ Get current selection.
- Return type
 Selection[~_S]