Skip to content

Refactor Review widget UI - #135

Merged
C-Achard merged 16 commits into
cy/fix-lr-schedulerfrom
cy/review-dock-shape
Nov 25, 2026
Merged

C-Achard merged 16 commits into
cy/fix-lr-schedulerfrom
cy/review-dock-shape

Conversation

@C-Achard

Copy link
Copy Markdown
Collaborator

Reworks the Review plugin so a review runs inside the current napari viewer instead of opening a new one, and has a clean finish state.
Also changes the dock layout and makes the projection plots match napari display better.

Summary

Reworks the Review plugin so a review runs inside the current napari viewer instead of opening a new one, and can be finished cleanly. Also changes the dock layout and makes the projection plots match how napari displays the volume.

Review in the current viewer

Before this PR, "Start reviewing" opened a new napari.Viewer. Any layers or widgets in that viewer were lost.

Now the review runs in the existing viewer:

  • Start: the chosen image and labels layers are reviewed in place. They are added when reviewing from files, and an empty uint16 labels layer is added when no labels are given. Every other layer is hidden, and the two review layers are locked so they can't be deleted from the UI.
  • Finish: the start button becomes "Finish review", and the bottom dock has a new "Exit review" button. Finishing removes the review docks and callbacks, then restores the other layers' visibility, the lock state and the layer selection. If the labels changed since the last save, it asks to Save / Discard / Cancel.
  • Closing the plugin finishes the review first, with the same save prompt.
  • Session state is kept in a new ReviewSession dataclass, which records what to restore when the review ends.

Layout

  • Left dock: a single dock holds the slice checker/timer (Datamanager), the save folder field, and the "Choose directory", "Open directory", "Save" and "Exit review" buttons. This replaces the magicgui save widget.
  • Bottom dock: the three projections (X-Y, Y-Z, X-Z) sit side by side, leaving the right dock for main plugin menus.

Projections follow the layer

The projections previously used hardcoded inferno with contrast 200–2000, and the crop was cast to int16. Now:

  • the plots use the volume layer's colormap, contrast limits and gamma (gamma through PowerNorm)
  • they redraw on a display setting change
  • the crop keeps the data's dtype, or float32 when resized for anisotropy

crop_volume_around_point is now a module-level function and takes an array instead of a layer.

Fixes

  • self.anisotropy_widgets.enabled was tested without being called, so the zoom factor was always applied.
  • datamanager read the volume shape from viewer.layers], which is wrong in a viewer that has other layers. The shape is now passed in as image_shape.

Behaviour changes

  • No second viewer opened, and the current one is no longer force-closed.
  • During a review, other layers are hidden and the review layers are locked. Both are restored on finish.
  • When no labels are given, the empty labels layer is uint16. It used to take the image's dtype.

Stack created with GitHub Stacks CLI • Give Feedback 💬

@C-Achard
C-Achard added this pull request to stack #138 November 20, 2026 09:04
@C-Achard C-Achard self-assigned this Nov 20, 2026
@C-Achard
C-Achard requested a balanced review from Copilot November 20, 2026 09:05
@C-Achard C-Achard added the enhancement New feature or request label Nov 20, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Review startup uses APIs unavailable in supported napari versions, and setup failures can leave layers hidden or locked without a usable session to restore the viewer.

6 open issues
What changed in this PR

Refactors the Review plugin to run in the current napari viewer, with an explicit finish flow, reorganized controls, and projections that follow the image’s display settings.

Changes:

  • Adds session tracking, save prompts, and viewer-state restoration when finishing a review.
  • Combines review controls in a left dock and places projections side by side below the viewer.
  • Updates projection styling and crop dtype handling, passes the reviewed image shape to the slice checker, and expands tests.
File Description
napari_cellseg3d/​interface.py Adds button hover styling and an OS folder-opening helper.
napari_cellseg3d/​code_plugins/​plugin_review.py Implements in-viewer review sessions, finish handling, dock layout, and layer-aware projection styling.
napari_cellseg3d/​code_plugins/​plugin_review_dock.py Accepts the reviewed image shape instead of relying on the first viewer layer.
napari_cellseg3d/​_tests/​test_review.py Expands coverage for session lifecycle, saving, controls, projections, and cropping.

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Review teardown bypasses cleanup and save prompts on native dock closure, omits final-slice timing, and fails to restore original layer visibility, while dirty-label save, discard, cancel, and save-failure behavior lack test coverage.

4 open issues
6 resolved since last review

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Label-data replacements can bypass the save prompt, and the Python 3.9 pin conflicts with napari 0.7.1’s requirements, preventing environment creation.

No open issues 🎉

3 previously missed issues

In code that hasn't changed since last review

High severity This environment still pins python=3.9 on line 7, but napari 0.7.1 requires Python 3.10 or newer.…

conda/​napari_CellSeg3D_ARM64.yml:13

This environment still pins python=3.9 on line 7, but napari 0.7.1 requires Python 3.10 or newer. Raising only the napari minimum therefore makes the pip stage of environment creation fail to resolve a compatible version. Please update the Python pin alongside this dependency change.

High severity Only listening to paint misses replacement of labels.data, which remains possible through other…

napari_cellseg3d/​code_plugins/​plugin_review.py:531

Only listening to paint misses replacement of labels.data, which remains possible through other widgets or the console in the current viewer. After such a change, session.modified stays false and finishing skips the save prompt. Please also track labels.events.data and register that callback for teardown.

Medium severity This now turns on the existing viewer's scale bar, but _restore_viewer never restores its…

napari_cellseg3d/​code_plugins/​plugin_review.py:527

This now turns on the existing viewer's scale bar, but _restore_viewer never restores its previous visibility. Starting and finishing a review therefore leaves the scale bar enabled even if it was hidden beforehand; failed setup also leaves this change behind. Please capture its initial visibility in the session and restore it during teardown.

4 resolved since last review

Review effort: Balanced

@C-Achard
C-Achard marked this pull request as ready for review November 24, 2026 13:52
@C-Achard C-Achard added this to the v0.2.5 milestone Nov 25, 2026
- Implemented volume_slice_index function to accurately track the current slice in the viewer.
- Updated Datamanager to accept an optional slice_num parameter for better integration with viewer dimensions.
- Enhanced test cases to validate slice behavior with additional viewer axes.
- Closing the Review dock from napari's title bar now ends the review.
  The dock is already gone, so the save prompt offers Save/Discard only.
- Review layers that were hidden before the review are hidden again
  when it finishes.
- Time spent on the last slice is written to the CSV on finish.
- Add tests for the save prompt (Save/Discard/Cancel, cancelled close,
  failed save) and for each fix above.
… the console triggers the save prompt. Disconnected on teardown with the other layer callbacks.
@C-Achard
C-Achard force-pushed the cy/review-dock-shape branch from 2df093d to 7450b02 Compare November 25, 2026 09:58
@C-Achard
C-Achard merged commit 59d7e4b into main Nov 25, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants