diff --git a/CHANGELOG.md b/CHANGELOG.md index 8405ec0..4c517d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning][]. [keep a changelog]: https://keepachangelog.com/en/1.0.0/ [semantic versioning]: https://semver.org/spec/v2.0.0.html +## incoming release + +- Global setting variables for showing circles as points and point size for scatter widget #309 #334 +- Sorting the element names and coordinate system names alphabetically #285 + ## [0.5.4] - 2024-11-26 ### Changed diff --git a/src/napari_spatialdata/_sdata_widgets.py b/src/napari_spatialdata/_sdata_widgets.py index 355589f..9915706 100644 --- a/src/napari_spatialdata/_sdata_widgets.py +++ b/src/napari_spatialdata/_sdata_widgets.py @@ -3,6 +3,7 @@ import platform from collections.abc import Iterable from importlib.metadata import version +from operator import itemgetter from pathlib import Path from typing import TYPE_CHECKING, cast @@ -16,6 +17,7 @@ from qtpy.QtGui import QIcon from qtpy.QtWidgets import QLabel, QListWidget, QListWidgetItem, QProgressBar, QVBoxLayout, QWidget from spatialdata import SpatialData +from spatialdata.models._utils import DEFAULT_COORDINATE_SYSTEM from napari_spatialdata._viewer import SpatialDataViewer from napari_spatialdata.constants.config import N_CIRCLES_WARNING_THRESHOLD, N_SHAPES_WARNING_THRESHOLD @@ -59,7 +61,7 @@ def _onItemChange(self, selected_coordinate_system: QListWidgetItem | int | Iter self._elements = elements def _set_element_widget_items(self, elements: dict[str, dict[str, str | int]]) -> None: - for key, dict_val in elements.items(): + for key, dict_val in sorted(elements.items(), key=itemgetter(0)): sdata = self._sdata[dict_val["sdata_index"]] element_type = dict_val["element_type"] element_name = dict_val["original_name"] @@ -95,7 +97,11 @@ def __init__(self, sdata: EventedList): self._sdata = sdata self._system: None | str = None - coordinate_systems = {cs for sdata in self._sdata for cs in sdata.coordinate_systems} + # Sort alphabetically, but keep default "global" at the top. + coordinate_systems = sorted(cs for sdata in self._sdata for cs in sdata.coordinate_systems) + if DEFAULT_COORDINATE_SYSTEM in coordinate_systems: + coordinate_systems.remove(DEFAULT_COORDINATE_SYSTEM) + coordinate_systems.insert(0, DEFAULT_COORDINATE_SYSTEM) self.addItems(coordinate_systems) def _select_coord_sys(self, selected_coordinate_system: QListWidgetItem | int | Iterable[str]) -> None: diff --git a/src/napari_spatialdata/_viewer.py b/src/napari_spatialdata/_viewer.py index 0935235..de90a4d 100644 --- a/src/napari_spatialdata/_viewer.py +++ b/src/napari_spatialdata/_viewer.py @@ -422,7 +422,7 @@ def inherit_metadata(self, layers: list[Layer], ref_layer: Layer) -> None: def _get_table_data( self, sdata: SpatialData, element_name: str ) -> tuple[AnnData | None, str | None, list[str] | None]: - table_names: list[str] = list(get_element_annotators(sdata, element_name)) + table_names: list[str] = sorted(get_element_annotators(sdata, element_name)) table_name = table_names[0] if len(table_names) > 0 else None adata = _get_init_metadata_adata(sdata, table_name, element_name) return adata, table_name, table_names diff --git a/tests/test_viewer.py b/tests/test_viewer.py index d66a5b7..4c1d815 100644 --- a/tests/test_viewer.py +++ b/tests/test_viewer.py @@ -172,8 +172,9 @@ def test_save_layer(qtbot, tmp_path: str, make_napari_viewer: any): n = len(widget.elements_widget) # I would have expected Shapes to be in position -2 and Points in position -1, but we have the following order # because elements of the same type are grouped together - assert widget.elements_widget.item(n - 1).text() == "Shapes" - assert widget.elements_widget.item(n - 5).text() == "Points" + all_elements = [widget.elements_widget.item(i).text() for i in range(n)] + assert "Shapes" in all_elements + assert "Points" in all_elements # add a new layer to the viewer with the newly saved shapes element widget._onClick("Shapes")