tk-rt-viewer 2.3.4__tar.gz → 2.3.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/CHANGELOG.md +20 -0
  2. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/PKG-INFO +7 -2
  3. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/README.md +6 -1
  4. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/__init__.py +1 -1
  5. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/rendering/view_axes.py +9 -5
  6. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/viewer.py +22 -1
  7. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/tests/test_event_controllers.py +36 -0
  8. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/.gitattributes +0 -0
  9. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/.github/workflows/ci.yml +0 -0
  10. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/.gitignore +0 -0
  11. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/LICENSE +0 -0
  12. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/pyproject.toml +0 -0
  13. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/event_controllers/__init__.py +0 -0
  14. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/event_controllers/bbox3d_handler.py +0 -0
  15. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/event_controllers/bbox_handler.py +0 -0
  16. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/event_controllers/brush_handler.py +0 -0
  17. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/event_controllers/crosshair_handler.py +0 -0
  18. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/event_controllers/rect_drag.py +0 -0
  19. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/event_controllers/viewer_events.py +0 -0
  20. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/events.py +0 -0
  21. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/geometry.py +0 -0
  22. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/io.py +0 -0
  23. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/isodose_levels.py +0 -0
  24. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/protocols.py +0 -0
  25. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/py.typed +0 -0
  26. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/reg_io.py +0 -0
  27. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/registration/__init__.py +0 -0
  28. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/registration/deformable.py +0 -0
  29. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/registration/errors.py +0 -0
  30. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/registration/params.py +0 -0
  31. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/registration/rigid.py +0 -0
  32. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/registration/session.py +0 -0
  33. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/registration/template.py +0 -0
  34. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/rendering/__init__.py +0 -0
  35. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/rendering/blit_compositor.py +0 -0
  36. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/rendering/contour_overlay.py +0 -0
  37. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/rendering/drawing_manager.py +0 -0
  38. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/rendering/dvh.py +0 -0
  39. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/rendering/image_layer.py +0 -0
  40. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/rendering/isodose.py +0 -0
  41. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/rendering/layout.py +0 -0
  42. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/rendering/render.py +0 -0
  43. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/roi_operations.py +0 -0
  44. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/rtstruct_io.py +0 -0
  45. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/state/__init__.py +0 -0
  46. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/state/dose_manager.py +0 -0
  47. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/state/phase_manager.py +0 -0
  48. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/state/roi_editor.py +0 -0
  49. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/state/roi_manager.py +0 -0
  50. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/state/secondary_manager.py +0 -0
  51. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/state/structure_set.py +0 -0
  52. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/state/viewer_cache.py +0 -0
  53. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/state/viewer_state.py +0 -0
  54. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/src/tk_rt_viewer/window_level.py +0 -0
  55. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/tests/test_bbox3d.py +0 -0
  56. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/tests/test_bbox3d_handler.py +0 -0
  57. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/tests/test_brush_handler.py +0 -0
  58. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/tests/test_geometry.py +0 -0
  59. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/tests/test_io.py +0 -0
  60. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/tests/test_isodose_levels.py +0 -0
  61. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/tests/test_performance_opt.py +0 -0
  62. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/tests/test_reg_io.py +0 -0
  63. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/tests/test_registration.py +0 -0
  64. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/tests/test_render.py +0 -0
  65. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/tests/test_rendering.py +0 -0
  66. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/tests/test_roi_operations.py +0 -0
  67. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/tests/test_rtstruct_io.py +0 -0
  68. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/tests/test_state_extensions.py +0 -0
  69. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/tests/test_state_managers.py +0 -0
  70. {tk_rt_viewer-2.3.4 → tk_rt_viewer-2.3.5}/tests/test_viewer_state.py +0 -0
@@ -4,6 +4,26 @@ All notable changes to this project are documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/).
6
6
 
7
+ ## [2.3.5]
8
+
9
+ ### Fixed
10
+
11
+ - **The toolbar's Home button works again.** Its click (and Back / Forward)
12
+ raised `TypeError: ImageViewAxes._set_view() missing 3 required positional
13
+ arguments`, because `ImageViewAxes` defined a `_set_view(cx, cy, span_x,
14
+ span_y)` that shadowed Matplotlib's `Axes._set_view(view)`, which the
15
+ navigation toolbar calls to restore a saved view. The private helper is now
16
+ `ImageViewAxes._apply_view`, so Matplotlib's own `_get_view` / `_set_view`
17
+ are inherited again and the toolbar's zoom-rectangle and pan history can be
18
+ stepped through with Back / Forward.
19
+ - **Home fits the views after Ctrl + wheel zoom and middle-button pan.** Neither
20
+ goes through the toolbar's view history, so Home had nothing to return to
21
+ and did nothing. Home now calls `DicomViewer.reset_zoom()` and fits every
22
+ view. Back / Forward are unchanged: they still replay only the toolbar's own
23
+ zoom and pan, not the wheel zoom or the middle-button pan.
24
+ - Switching the layout now clears the toolbar's view history, which named the
25
+ Axes discarded by the switch.
26
+
7
27
  ## [2.3.4]
8
28
 
9
29
  ### Added
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: tk-rt-viewer
3
- Version: 2.3.4
3
+ Version: 2.3.5
4
4
  Summary: SimpleITK-based DICOM-RT MPR viewer widget for Tkinter (CT, RT-DOSE, RT-STRUCT, DVH)
5
5
  Project-URL: Homepage, https://github.com/oki1002/DICOM_RT_Viewer
6
6
  Project-URL: Repository, https://github.com/oki1002/DICOM_RT_Viewer
@@ -59,7 +59,7 @@ The distribution name on PyPI is `tk-rt-viewer`; the import package is
59
59
  - **Observer-pattern state management** — All view state lives in `SliceViewerState`; the widget reacts to changes without polling.
60
60
  - **SimpleITK-native coordinates** — Physical LPS coordinates, origin, spacing, and direction cosines are preserved throughout; axis reordering between SimpleITK and NumPy conventions is handled internally by the library.
61
61
  - **Interactive navigation** — Crosshair drag, mouse wheel (direction reversible), and keyboard (↑ / ↓ / PageUp / PageDown).
62
- - **Per-view zoom and pan** — Ctrl + mouse wheel zooms the view under the pointer about the pointer, and dragging with the middle button (the wheel pressed) pans it; each view keeps its own zoom factor and position. The views fill their layout cells, so a zoomed slice uses the whole cell.
62
+ - **Per-view zoom and pan** — Ctrl + mouse wheel zooms the view under the pointer about the pointer, and dragging with the middle button (the wheel pressed) pans it; each view keeps its own zoom factor and position; the toolbar's Home button fits every view again. The views fill their layout cells, so a zoomed slice uses the whole cell.
63
63
  - **Independent window / level per image** — The primary and secondary images each carry their own display window, so a PET, MR, or dose overlay can be windowed without disturbing the CT underneath. The secondary follows the primary until an override is set. Right-click drag adjusts whichever image is targeted: horizontal → window width (WW), vertical → window centre (WL).
64
64
  - **RT-STRUCT support** — ROI masks stored in `StructureSet` (keyed by integer ROI number); contour overlay with optional semi-transparent fill; brush tool for mask editing.
65
65
  - **ROI operations** — Shape-based inter-slice interpolation, true Euclidean margins (uniform or 6-direction anisotropic), Gaussian smoothing, and boolean operations (union / intersection / subtraction).
@@ -775,6 +775,11 @@ while the brush tool is active. `reset_zoom()` fits the view again, which
775
775
  undoes the pan as well. A view keeps its position across a figure resize and
776
776
  starts fitted when a new primary image is loaded or the layout is switched.
777
777
 
778
+ The toolbar's Home button does the same as `reset_zoom()`: it fits every view,
779
+ undoing Ctrl + wheel zoom and middle-button pan. The toolbar's Back / Forward
780
+ buttons step through the toolbar's own zoom-rectangle and pan history only;
781
+ Ctrl + wheel zoom and middle-button pan are not recorded there.
782
+
778
783
  ```python
779
784
  viewer.set_zoom("axial", 2.5) # about the view centre
780
785
  viewer.set_zoom("coronal", 4.0, anchor=(x, z)) # keep (x, z) in place
@@ -22,7 +22,7 @@ The distribution name on PyPI is `tk-rt-viewer`; the import package is
22
22
  - **Observer-pattern state management** — All view state lives in `SliceViewerState`; the widget reacts to changes without polling.
23
23
  - **SimpleITK-native coordinates** — Physical LPS coordinates, origin, spacing, and direction cosines are preserved throughout; axis reordering between SimpleITK and NumPy conventions is handled internally by the library.
24
24
  - **Interactive navigation** — Crosshair drag, mouse wheel (direction reversible), and keyboard (↑ / ↓ / PageUp / PageDown).
25
- - **Per-view zoom and pan** — Ctrl + mouse wheel zooms the view under the pointer about the pointer, and dragging with the middle button (the wheel pressed) pans it; each view keeps its own zoom factor and position. The views fill their layout cells, so a zoomed slice uses the whole cell.
25
+ - **Per-view zoom and pan** — Ctrl + mouse wheel zooms the view under the pointer about the pointer, and dragging with the middle button (the wheel pressed) pans it; each view keeps its own zoom factor and position; the toolbar's Home button fits every view again. The views fill their layout cells, so a zoomed slice uses the whole cell.
26
26
  - **Independent window / level per image** — The primary and secondary images each carry their own display window, so a PET, MR, or dose overlay can be windowed without disturbing the CT underneath. The secondary follows the primary until an override is set. Right-click drag adjusts whichever image is targeted: horizontal → window width (WW), vertical → window centre (WL).
27
27
  - **RT-STRUCT support** — ROI masks stored in `StructureSet` (keyed by integer ROI number); contour overlay with optional semi-transparent fill; brush tool for mask editing.
28
28
  - **ROI operations** — Shape-based inter-slice interpolation, true Euclidean margins (uniform or 6-direction anisotropic), Gaussian smoothing, and boolean operations (union / intersection / subtraction).
@@ -738,6 +738,11 @@ while the brush tool is active. `reset_zoom()` fits the view again, which
738
738
  undoes the pan as well. A view keeps its position across a figure resize and
739
739
  starts fitted when a new primary image is loaded or the layout is switched.
740
740
 
741
+ The toolbar's Home button does the same as `reset_zoom()`: it fits every view,
742
+ undoing Ctrl + wheel zoom and middle-button pan. The toolbar's Back / Forward
743
+ buttons step through the toolbar's own zoom-rectangle and pan history only;
744
+ Ctrl + wheel zoom and middle-button pan are not recorded there.
745
+
741
746
  ```python
742
747
  viewer.set_zoom("axial", 2.5) # about the view centre
743
748
  viewer.set_zoom("coronal", 4.0, anchor=(x, z)) # keep (x, z) in place
@@ -104,7 +104,7 @@ __all__ = [
104
104
  "StructureSet",
105
105
  "to_gy_pairs",
106
106
  ]
107
- __version__ = "2.3.4"
107
+ __version__ = "2.3.5"
108
108
 
109
109
 
110
110
  def __getattr__(name: str) -> Any:
@@ -88,7 +88,7 @@ class ImageViewAxes(Axes):
88
88
  if anchor is not None and old_x > 0 and old_y > 0:
89
89
  cx = anchor[0] + (cx - anchor[0]) * new_x / old_x
90
90
  cy = anchor[1] + (cy - anchor[1]) * new_y / old_y
91
- self._set_view(cx, cy, new_x, new_y)
91
+ self._apply_view(cx, cy, new_x, new_y)
92
92
 
93
93
  def view_center(self) -> tuple[float, float]:
94
94
  """Return the data coordinates of the centre of the current view."""
@@ -107,7 +107,7 @@ class ImageViewAxes(Axes):
107
107
  span_x, span_y = self._spans()
108
108
  if span_x <= 0 or span_y <= 0:
109
109
  return
110
- self._set_view(cx, cy, span_x, span_y)
110
+ self._apply_view(cx, cy, span_x, span_y)
111
111
 
112
112
  # ------------------------------------------------------------------
113
113
  # Internals
@@ -143,11 +143,15 @@ class ImageViewAxes(Axes):
143
143
  else:
144
144
  span_x = span_y / ratio
145
145
 
146
- self._set_view(cx, cy, span_x, span_y)
146
+ self._apply_view(cx, cy, span_x, span_y)
147
147
  self._conformed = (self.get_xlim(), self.get_ylim(), ratio)
148
148
 
149
- def _set_view(self, cx: float, cy: float, span_x: float, span_y: float) -> None:
150
- """Set the limits around a centre, clamped to the slice, keeping inversion."""
149
+ def _apply_view(self, cx: float, cy: float, span_x: float, span_y: float) -> None:
150
+ """Set the limits around a centre, clamped to the slice, keeping inversion.
151
+
152
+ Not named ``_set_view``: that name belongs to Matplotlib's Axes, which
153
+ the navigation toolbar calls with one saved-view argument.
154
+ """
151
155
  if self._image_extent is not None:
152
156
  x0, x1, y0, y1 = self._image_extent
153
157
  cx = _clamp_center(cx, span_x, x0, x1)
@@ -98,6 +98,25 @@ from .state.viewer_state import SliceViewerState
98
98
  logger = logging.getLogger(__name__)
99
99
 
100
100
 
101
+ class _ViewerToolbar(NavigationToolbar2Tk):
102
+ """Navigation toolbar whose Home button fits every view.
103
+
104
+ Ctrl + wheel zoom and middle-button pan do not go through the toolbar's
105
+ view history, so its own Home would have nothing to return to.
106
+ """
107
+
108
+ def __init__(
109
+ self, canvas: FigureCanvasTkAgg, window: tk.Widget, on_home: Callable[[], None]
110
+ ) -> None:
111
+ # Must be set first: the base class binds the buttons while building
112
+ self._on_home = on_home
113
+ super().__init__(canvas, window)
114
+
115
+ def home(self, *args) -> None:
116
+ """Fit the views instead of replaying the toolbar's view history."""
117
+ self._on_home()
118
+
119
+
101
120
  class DicomViewer(ttk.Frame):
102
121
  """Three-plane MPR viewer widget for Tkinter.
103
122
 
@@ -185,7 +204,7 @@ class DicomViewer(ttk.Frame):
185
204
  )
186
205
  self.canvas = FigureCanvasTkAgg(self.fig, master=self)
187
206
  self.canvas.get_tk_widget().pack(fill=tk.BOTH, expand=True)
188
- self.toolbar = NavigationToolbar2Tk(self.canvas, self)
207
+ self.toolbar = _ViewerToolbar(self.canvas, self, on_home=self.reset_zoom)
189
208
  self.toolbar.update()
190
209
  self.toolbar.pack(side=tk.BOTTOM, fill=tk.X)
191
210
 
@@ -764,6 +783,8 @@ class DicomViewer(ttk.Frame):
764
783
  self._compositor.cancel_pending()
765
784
 
766
785
  self.fig.clear()
786
+ # The toolbar's view history names the Axes that were just discarded
787
+ self.toolbar.update()
767
788
  self._layout_mode = mode
768
789
  self.axs, self._dvh_ax = self.layout.build(mode)
769
790
  self._reset_artists()
@@ -15,6 +15,7 @@ matplotlib.use("Agg")
15
15
  import numpy as np
16
16
  import pytest
17
17
  import SimpleITK as sitk
18
+ from matplotlib.backend_bases import NavigationToolbar2
18
19
  from matplotlib.backends.backend_agg import FigureCanvasAgg
19
20
  from matplotlib.figure import Figure
20
21
 
@@ -566,6 +567,41 @@ class TestImageViewAxesPan:
566
567
  assert axial.view_center() == pytest.approx(fitted)
567
568
 
568
569
 
570
+ class TestImageViewAxesToolbarCompatibility:
571
+ """The navigation toolbar saves and restores views through Axes._set_view."""
572
+
573
+ def test_toolbar_view_round_trip_restores_the_limits(self) -> None:
574
+ state = loaded_state((8, 16, 32))
575
+ axial = zoomable_axes(state, "axial")
576
+ saved = axial._get_view()
577
+ axial.zoom_to(4.0)
578
+ axial.pan_to(5.0, 3.0)
579
+ axial._set_view(saved)
580
+ assert axial.get_xlim() == pytest.approx(saved["xlim"])
581
+ assert axial.get_ylim() == pytest.approx(saved["ylim"])
582
+
583
+ def test_toolbar_back_and_home_do_not_raise(self) -> None:
584
+ state = loaded_state((8, 16, 32))
585
+ axial = zoomable_axes(state, "axial")
586
+ toolbar = NavigationToolbar2(axial.figure.canvas)
587
+ toolbar.push_current()
588
+ axial.zoom_to(4.0)
589
+ toolbar.push_current()
590
+ toolbar.back()
591
+ assert axial.zoom_factor() == pytest.approx(1.0)
592
+ toolbar.forward()
593
+ toolbar.home()
594
+ assert axial.zoom_factor() == pytest.approx(1.0)
595
+
596
+ def test_toolbar_update_drops_the_history_of_discarded_axes(self) -> None:
597
+ state = loaded_state((8, 16, 32))
598
+ axial = zoomable_axes(state, "axial")
599
+ toolbar = NavigationToolbar2(axial.figure.canvas)
600
+ toolbar.push_current()
601
+ toolbar.update()
602
+ assert toolbar._nav_stack() is None
603
+
604
+
569
605
  class TestKeyboardNavigation:
570
606
  @pytest.mark.parametrize(
571
607
  "key,expected", [("up", 5), ("down", 3), ("pageup", 7), ("pagedown", 0)]
File without changes
File without changes