Use return types, not Dicts#324
Merged
Merged
Conversation
Introduce `ImageDisplay`, `ImageViewGUI`, and `ImageROI` as the return types of `imshow`, `imshow_gui`, and the low-level `imshow(canvas, ...)` respectively. `ImageDisplay` forwards field access to its nested `gui` and `roi` so users can write `disp.window`, `disp.zoomregion`, `disp.image_roi`, etc. The custom `show` methods print only a compact summary — never the underlying image array — which fixes the long-standing usability problem where forgetting a trailing semicolon at the REPL caused multi-second hangs while Julia's default dict `show` recursively printed the entire image. The concrete types also give downstream packages a dispatch target; extensions that need to support multiple plotting backends can now write methods like `f(::ImageView.ImageDisplay, ...)`. The pre-existing string-key API (`guidict["gui"]["window"]`, `guidict["roi"]["zoomregion"]`, etc.) is preserved through a deprecation shim implemented via `Base.getindex` on each new struct; each call emits a `Base.depwarn`. This commit deliberately leaves `test/` and `README.md` untouched — the existing test suite is the correctness check that the shim faithfully reproduces the old API. Isolates the legacy string-key indexing methods so the next breaking release can remove the shim by deleting one file and the corresponding `include`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Converts every call site that indexes the `imshow` return value by string to the new struct field syntax (e.g. `result["gui"]["window"]` → `result.window`, `result["roi"]["zoomregion"]` → `result.zoomregion`, `result["roi"]["image roi"]` → `result.image_roi`). Updates the README's tutorial and script-usage examples, the `imshow`/`imshow_gui`/ `scalebar` docstrings, and adds a NEWS.md entry describing the change and the deprecation shim. The shim itself is untouched — the legacy string-key API continues to work with a `Base.depwarn`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ImageView has historically returned all the GUI-state info as a
Dict. This has caused several problems, of which perhaps the most severe stems from the default REPL-printing of Dicts which would try to print out the entire image. This creates a dedicated type of each major entry point, and customshowmethods allow us to determine what gets printed.This is split into two commits. The first changes the code and adds deprecation shims for the old code. No tests are changed. This establishes that this PR is fundamentally non-breaking, thanks to the shims. Downstream consumers should run with
julia --depwarn=yesand fix the deprecation warnings with a[compat]set to 0.13.2.The second commit migrates the README and tests to the new API. Forward-looking packages can use this API, but ImageView's
[compat]should be no lower than 0.13.2.Fixes #292