mitk-python 2026.6.dev2__cp312-cp312-win_amd64.whl

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 (194) hide show
  1. mitk/MitkCore/MitkDICOMImageIO.dll +0 -0
  2. mitk/MitkCore/MitkDICOMPMIO.dll +0 -0
  3. mitk/MitkCore/MitkDICOMRTIO.dll +0 -0
  4. mitk/MitkCore/MitkDICOMSegIO.dll +0 -0
  5. mitk/MitkCore/MitkIOExt.dll +0 -0
  6. mitk/MitkCore/MitkModelFitIOServices.dll +0 -0
  7. mitk/MitkCore/MitkMultilabelIO.dll +0 -0
  8. mitk/MitkCore/MitkPlanarFigureIO.dll +0 -0
  9. mitk/MitkCore/MitkROIIO.dll +0 -0
  10. mitk/MitkCore/MitkSceneSerializationIO.dll +0 -0
  11. mitk/MitkCore/MitkSegmentationIO.dll +0 -0
  12. mitk/MitkDICOM/MitkCESTIO.dll +0 -0
  13. mitk/MitkModelFit/MitkModelFitModelsServices.dll +0 -0
  14. mitk/MitkModelFit/MitkPharmacokineticModelsServices.dll +0 -0
  15. mitk/__init__.py +68 -0
  16. mitk/mitk.cp312-win_amd64.pyd +0 -0
  17. mitk/mxn/__init__.py +17 -0
  18. mitk/mxn/layout/__init__.py +106 -0
  19. mitk/mxn/layout/_builders.py +220 -0
  20. mitk/mxn/layout/_io.py +65 -0
  21. mitk/mxn/layout/_model.py +848 -0
  22. mitk/mxn/layout/_presets.py +71 -0
  23. mitk/mxn/layout/_repr.py +170 -0
  24. mitk/mxn/layout/_selector.py +271 -0
  25. mitk/mxn/layout/_validation.py +122 -0
  26. mitk/mxn/layout/_vocabulary.py +59 -0
  27. mitk/property_view.py +123 -0
  28. mitk_python-2026.6.dev2.dist-info/DELVEWHEEL +2 -0
  29. mitk_python-2026.6.dev2.dist-info/METADATA +67 -0
  30. mitk_python-2026.6.dev2.dist-info/RECORD +194 -0
  31. mitk_python-2026.6.dev2.dist-info/WHEEL +4 -0
  32. mitk_python-2026.6.dev2.dist-info/top_level.txt +1 -0
  33. mitk_python.libs/ITKCommon-5.4.dll +0 -0
  34. mitk_python.libs/ITKIOBMP-5.4.dll +0 -0
  35. mitk_python.libs/ITKIOBioRad-5.4.dll +0 -0
  36. mitk_python.libs/ITKIOBruker-5.4.dll +0 -0
  37. mitk_python.libs/ITKIOGDCM-5.4.dll +0 -0
  38. mitk_python.libs/ITKIOGE-5.4.dll +0 -0
  39. mitk_python.libs/ITKIOGIPL-5.4.dll +0 -0
  40. mitk_python.libs/ITKIOHDF5-5.4.dll +0 -0
  41. mitk_python.libs/ITKIOIPL-5.4.dll +0 -0
  42. mitk_python.libs/ITKIOImageBase-5.4.dll +0 -0
  43. mitk_python.libs/ITKIOJPEG-5.4.dll +0 -0
  44. mitk_python.libs/ITKIOJPEG2000-5.4.dll +0 -0
  45. mitk_python.libs/ITKIOLSM-5.4.dll +0 -0
  46. mitk_python.libs/ITKIOMINC-5.4.dll +0 -0
  47. mitk_python.libs/ITKIOMRC-5.4.dll +0 -0
  48. mitk_python.libs/ITKIOMeta-5.4.dll +0 -0
  49. mitk_python.libs/ITKIONIFTI-5.4.dll +0 -0
  50. mitk_python.libs/ITKIONRRD-5.4.dll +0 -0
  51. mitk_python.libs/ITKIOPNG-5.4.dll +0 -0
  52. mitk_python.libs/ITKIOStimulate-5.4.dll +0 -0
  53. mitk_python.libs/ITKIOTIFF-5.4.dll +0 -0
  54. mitk_python.libs/ITKIOVTK-5.4.dll +0 -0
  55. mitk_python.libs/ITKLabelMap-5.4.dll +0 -0
  56. mitk_python.libs/ITKMathematicalMorphology-5.4.dll +0 -0
  57. mitk_python.libs/ITKOptimizers-5.4.dll +0 -0
  58. mitk_python.libs/ITKQuadEdgeMesh-5.4.dll +0 -0
  59. mitk_python.libs/ITKRegionGrowing-5.4.dll +0 -0
  60. mitk_python.libs/ITKSmoothing-5.4.dll +0 -0
  61. mitk_python.libs/ITKStatistics-5.4.dll +0 -0
  62. mitk_python.libs/ITKTransform-5.4.dll +0 -0
  63. mitk_python.libs/MitkAlgorithmsExt.dll +0 -0
  64. mitk_python.libs/MitkAnnotation.dll +0 -0
  65. mitk_python.libs/MitkBoundingShape.dll +0 -0
  66. mitk_python.libs/MitkCEST.dll +0 -0
  67. mitk_python.libs/MitkContourModel.dll +0 -0
  68. mitk_python.libs/MitkCore.dll +0 -0
  69. mitk_python.libs/MitkCppMicroServices.dll +0 -0
  70. mitk_python.libs/MitkDICOM.dll +0 -0
  71. mitk_python.libs/MitkDICOMPM.dll +0 -0
  72. mitk_python.libs/MitkDICOMQI.dll +0 -0
  73. mitk_python.libs/MitkDataTypesExt.dll +0 -0
  74. mitk_python.libs/MitkLog.dll +0 -0
  75. mitk_python.libs/MitkMapperExt.dll +0 -0
  76. mitk_python.libs/MitkModelFit.dll +0 -0
  77. mitk_python.libs/MitkMultilabel.dll +0 -0
  78. mitk_python.libs/MitkPharmacokinetics.dll +0 -0
  79. mitk_python.libs/MitkPlanarFigure.dll +0 -0
  80. mitk_python.libs/MitkROI.dll +0 -0
  81. mitk_python.libs/MitkRT.dll +0 -0
  82. mitk_python.libs/MitkSceneSerialization.dll +0 -0
  83. mitk_python.libs/MitkSceneSerializationBase.dll +0 -0
  84. mitk_python.libs/MitkSegmentation.dll +0 -0
  85. mitk_python.libs/MitkSurfaceInterpolation.dll +0 -0
  86. mitk_python.libs/PocoFoundation.dll +0 -0
  87. mitk_python.libs/PocoZip.dll +0 -0
  88. mitk_python.libs/ann.dll +0 -0
  89. mitk_python.libs/dcmdata.dll +0 -0
  90. mitk_python.libs/dcmfg.dll +0 -0
  91. mitk_python.libs/dcmimage.dll +0 -0
  92. mitk_python.libs/dcmimgle.dll +0 -0
  93. mitk_python.libs/dcmiod.dll +0 -0
  94. mitk_python.libs/dcmpmap.dll +0 -0
  95. mitk_python.libs/dcmrt.dll +0 -0
  96. mitk_python.libs/dcmseg.dll +0 -0
  97. mitk_python.libs/dcmsr.dll +0 -0
  98. mitk_python.libs/gdcmCommon.dll +0 -0
  99. mitk_python.libs/gdcmDICT.dll +0 -0
  100. mitk_python.libs/gdcmDSED.dll +0 -0
  101. mitk_python.libs/gdcmIOD.dll +0 -0
  102. mitk_python.libs/gdcmMSFF.dll +0 -0
  103. mitk_python.libs/gdcmcharls.dll +0 -0
  104. mitk_python.libs/gdcmexpat.dll +0 -0
  105. mitk_python.libs/gdcmjpeg12.dll +0 -0
  106. mitk_python.libs/gdcmjpeg16.dll +0 -0
  107. mitk_python.libs/gdcmjpeg8.dll +0 -0
  108. mitk_python.libs/gdcmopenjp2.dll +0 -0
  109. mitk_python.libs/gdcmzlib.dll +0 -0
  110. mitk_python.libs/itkGrowCut-5.4.dll +0 -0
  111. mitk_python.libs/itkhdf5-shared-5.4.dll +0 -0
  112. mitk_python.libs/itkhdf5_cpp-shared-5.4.dll +0 -0
  113. mitk_python.libs/libcrypto-3-x64.dll +0 -0
  114. mitk_python.libs/libssl-3-x64.dll +0 -0
  115. mitk_python.libs/lz4.dll +0 -0
  116. mitk_python.libs/msvcp140.dll +0 -0
  117. mitk_python.libs/oficonv.dll +0 -0
  118. mitk_python.libs/oflog.dll +0 -0
  119. mitk_python.libs/ofstd.dll +0 -0
  120. mitk_python.libs/tbb12.dll +0 -0
  121. mitk_python.libs/vcomp140.dll +0 -0
  122. mitk_python.libs/vtkCommonColor-9.5.dll +0 -0
  123. mitk_python.libs/vtkCommonComputationalGeometry-9.5.dll +0 -0
  124. mitk_python.libs/vtkCommonCore-9.5.dll +0 -0
  125. mitk_python.libs/vtkCommonDataModel-9.5.dll +0 -0
  126. mitk_python.libs/vtkCommonExecutionModel-9.5.dll +0 -0
  127. mitk_python.libs/vtkCommonMath-9.5.dll +0 -0
  128. mitk_python.libs/vtkCommonMisc-9.5.dll +0 -0
  129. mitk_python.libs/vtkCommonSystem-9.5.dll +0 -0
  130. mitk_python.libs/vtkCommonTransforms-9.5.dll +0 -0
  131. mitk_python.libs/vtkDICOMParser-9.5.dll +0 -0
  132. mitk_python.libs/vtkFiltersCellGrid-9.5.dll +0 -0
  133. mitk_python.libs/vtkFiltersCore-9.5.dll +0 -0
  134. mitk_python.libs/vtkFiltersExtraction-9.5.dll +0 -0
  135. mitk_python.libs/vtkFiltersGeneral-9.5.dll +0 -0
  136. mitk_python.libs/vtkFiltersGeometry-9.5.dll +0 -0
  137. mitk_python.libs/vtkFiltersHybrid-9.5.dll +0 -0
  138. mitk_python.libs/vtkFiltersHyperTree-9.5.dll +0 -0
  139. mitk_python.libs/vtkFiltersModeling-9.5.dll +0 -0
  140. mitk_python.libs/vtkFiltersParallel-9.5.dll +0 -0
  141. mitk_python.libs/vtkFiltersReduction-9.5.dll +0 -0
  142. mitk_python.libs/vtkFiltersSources-9.5.dll +0 -0
  143. mitk_python.libs/vtkFiltersStatistics-9.5.dll +0 -0
  144. mitk_python.libs/vtkFiltersTexture-9.5.dll +0 -0
  145. mitk_python.libs/vtkFiltersVerdict-9.5.dll +0 -0
  146. mitk_python.libs/vtkIOCellGrid-9.5.dll +0 -0
  147. mitk_python.libs/vtkIOCore-9.5.dll +0 -0
  148. mitk_python.libs/vtkIOGeometry-9.5.dll +0 -0
  149. mitk_python.libs/vtkIOImage-9.5.dll +0 -0
  150. mitk_python.libs/vtkIOLegacy-9.5.dll +0 -0
  151. mitk_python.libs/vtkIOPLY-9.5.dll +0 -0
  152. mitk_python.libs/vtkIOXML-9.5.dll +0 -0
  153. mitk_python.libs/vtkIOXMLParser-9.5.dll +0 -0
  154. mitk_python.libs/vtkImagingColor-9.5.dll +0 -0
  155. mitk_python.libs/vtkImagingCore-9.5.dll +0 -0
  156. mitk_python.libs/vtkImagingGeneral-9.5.dll +0 -0
  157. mitk_python.libs/vtkImagingHybrid-9.5.dll +0 -0
  158. mitk_python.libs/vtkImagingMath-9.5.dll +0 -0
  159. mitk_python.libs/vtkImagingSources-9.5.dll +0 -0
  160. mitk_python.libs/vtkImagingStencil-9.5.dll +0 -0
  161. mitk_python.libs/vtkInteractionStyle-9.5.dll +0 -0
  162. mitk_python.libs/vtkInteractionWidgets-9.5.dll +0 -0
  163. mitk_python.libs/vtkParallelCore-9.5.dll +0 -0
  164. mitk_python.libs/vtkParallelDIY-9.5.dll +0 -0
  165. mitk_python.libs/vtkRenderingAnnotation-9.5.dll +0 -0
  166. mitk_python.libs/vtkRenderingContext2D-9.5.dll +0 -0
  167. mitk_python.libs/vtkRenderingContextOpenGL2-9.5.dll +0 -0
  168. mitk_python.libs/vtkRenderingCore-9.5.dll +0 -0
  169. mitk_python.libs/vtkRenderingFreeType-9.5.dll +0 -0
  170. mitk_python.libs/vtkRenderingHyperTreeGrid-9.5.dll +0 -0
  171. mitk_python.libs/vtkRenderingLabel-9.5.dll +0 -0
  172. mitk_python.libs/vtkRenderingOpenGL2-9.5.dll +0 -0
  173. mitk_python.libs/vtkRenderingUI-9.5.dll +0 -0
  174. mitk_python.libs/vtkRenderingVolume-9.5.dll +0 -0
  175. mitk_python.libs/vtkRenderingVolumeOpenGL2-9.5.dll +0 -0
  176. mitk_python.libs/vtkdoubleconversion-9.5.dll +0 -0
  177. mitk_python.libs/vtkexpat-9.5.dll +0 -0
  178. mitk_python.libs/vtkfmt-9.5.dll +0 -0
  179. mitk_python.libs/vtkfreetype-9.5.dll +0 -0
  180. mitk_python.libs/vtkglad-9.5.dll +0 -0
  181. mitk_python.libs/vtkjpeg-9.5.dll +0 -0
  182. mitk_python.libs/vtkkissfft-9.5.dll +0 -0
  183. mitk_python.libs/vtkloguru-9.5.dll +0 -0
  184. mitk_python.libs/vtklz4-9.5.dll +0 -0
  185. mitk_python.libs/vtklzma-9.5.dll +0 -0
  186. mitk_python.libs/vtkmetaio-9.5.dll +0 -0
  187. mitk_python.libs/vtkpng-9.5.dll +0 -0
  188. mitk_python.libs/vtkpugixml-9.5.dll +0 -0
  189. mitk_python.libs/vtksys-9.5.dll +0 -0
  190. mitk_python.libs/vtktiff-9.5.dll +0 -0
  191. mitk_python.libs/vtktoken-9.5.dll +0 -0
  192. mitk_python.libs/vtkverdict-9.5.dll +0 -0
  193. mitk_python.libs/vtkzlib-9.5.dll +0 -0
  194. mitk_python.libs/zlib1.dll +0 -0
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
mitk/__init__.py ADDED
@@ -0,0 +1,68 @@
1
+ """""" # start delvewheel patch
2
+ def _delvewheel_patch_1_12_1():
3
+ import os
4
+ if os.path.isdir(libs_dir := os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir, 'mitk_python.libs'))):
5
+ os.add_dll_directory(libs_dir)
6
+
7
+
8
+ _delvewheel_patch_1_12_1()
9
+ del _delvewheel_patch_1_12_1
10
+ # end delvewheel patch
11
+
12
+ import glob as _glob
13
+ import os as _os
14
+ import sys as _sys
15
+
16
+ _pkg_dir = _os.path.dirname(_os.path.abspath(__file__))
17
+
18
+ # Detect a wheel install by locating the bundled native-library directory.
19
+ # delvewheel (Windows) and auditwheel (Linux) create it as a sibling of the
20
+ # package, named after the distribution (e.g. "mitk_python.libs"); delocate
21
+ # (macOS) creates a ".dylibs" directory inside the package. The sibling name
22
+ # tracks the PyPI distribution name, so match it by prefix instead of
23
+ # hardcoding it. In a build-tree install none of these exist and the
24
+ # wheel-only environment setup below is skipped.
25
+ _libs_dir = _os.path.join(_pkg_dir, ".dylibs")
26
+ if not _os.path.isdir(_libs_dir):
27
+ _siblings = _glob.glob(_os.path.join(_os.path.dirname(_pkg_dir), "mitk*.libs"))
28
+ if _siblings:
29
+ _libs_dir = _siblings[0]
30
+ _is_wheel = _os.path.isdir(_libs_dir)
31
+
32
+ if _is_wheel:
33
+ # Tell PreloadPython activator to skip (Python is already loaded).
34
+ _os.environ["PYMITK"] = "1"
35
+
36
+ # Tell CppMicroServices where to find auto-load module subdirectories.
37
+ _os.environ["US_AUTOLOAD_PATHS"] = _pkg_dir
38
+
39
+ # Windows: register DLL search directory for bundled native libraries.
40
+ # add_dll_directory covers Python extension loading (pyd files), while
41
+ # PATH is needed for CppMicroServices auto-load which uses LoadLibrary.
42
+ if _sys.platform == "win32":
43
+ _os.add_dll_directory(_libs_dir)
44
+ _os.environ["PATH"] = _libs_dir + _os.pathsep + _os.environ.get("PATH", "")
45
+ # Linux: auditwheel sets the extension RPATH to the sibling .libs dir.
46
+ # macOS: delocate rewrites @loader_path references.
47
+
48
+ from .mitk import *
49
+
50
+
51
+ def _rebind_module_names():
52
+ # Rewrite __module__ on exposed names so tooling renders mitk.X rather
53
+ # than mitk.mitk.X (the inner "mitk" is the pybind11 extension). Covers
54
+ # classes and free functions; pybind11 enum values inherit __module__
55
+ # from their enum type, which is itself rebound here.
56
+ from . import mitk as ext
57
+ for obj in vars(ext).values():
58
+ if getattr(obj, "__module__", None) == "mitk.mitk":
59
+ try:
60
+ obj.__module__ = "mitk"
61
+ except (AttributeError, TypeError):
62
+ pass
63
+
64
+
65
+ _rebind_module_names()
66
+ del _rebind_module_names
67
+
68
+ __version__ = "2026.6.dev2"
Binary file
mitk/mxn/__init__.py ADDED
@@ -0,0 +1,17 @@
1
+ # ============================================================================
2
+ #
3
+ # The Medical Imaging Interaction Toolkit (MITK)
4
+ #
5
+ # Copyright (c) German Cancer Research Center (DKFZ)
6
+ # All rights reserved.
7
+ #
8
+ # Use of this source code is governed by a 3-clause BSD license that can be
9
+ # found in the LICENSE file.
10
+ #
11
+ # ============================================================================
12
+
13
+ # Namespace marker for the `mitk.mxn` sub-namespace.
14
+ #
15
+ # Empty by design. Future MxN-related Python subpackages
16
+ # (`mitk.mxn.runtime`, ...) live here; the parent package keeps their import
17
+ # paths stable and grouping discoverable.
@@ -0,0 +1,106 @@
1
+ # ============================================================================
2
+ #
3
+ # The Medical Imaging Interaction Toolkit (MITK)
4
+ #
5
+ # Copyright (c) German Cancer Research Center (DKFZ)
6
+ # All rights reserved.
7
+ #
8
+ # Use of this source code is governed by a 3-clause BSD license that can be
9
+ # found in the LICENSE file.
10
+ #
11
+ # ============================================================================
12
+
13
+ """``mitk.mxn.layout`` -- typed Python DSL for MxN multi-widget layouts.
14
+
15
+ A self-contained, transport-free Python DSL for constructing, inspecting,
16
+ validating, and round-tripping MxN multi-widget layout documents (schema
17
+ v2.0). Round-trips byte-stable with the wire/file JSON consumed by
18
+ ``QmitkMxNMultiWidget::ApplyLayout`` and produced by
19
+ ``QmitkMxNMultiWidget::SerializeLayout``.
20
+
21
+ Window identity vs. display label
22
+ ---------------------------------
23
+ Every window has a required ``id`` (qualified form ``<editor_name>__<bare_id>``,
24
+ e.g. ``mxn__widget0``) and an optional ``name`` (free-form display label).
25
+ Routing -- REST URL paths, engine-side render-window names, persisted state
26
+ keys -- uses ``id`` exclusively. The DSL never adds, strips, or otherwise
27
+ translates a prefix; the qualified form is canonical everywhere.
28
+
29
+ Public surface
30
+ --------------
31
+ - :class:`MxNLayoutDocument`, :class:`Split`, :class:`LayoutWindow`,
32
+ :class:`Group`, :class:`Link` -- typed dataclasses.
33
+ - :func:`grid`, :func:`three_up`, :func:`two_rows_each_direction`,
34
+ :func:`single_window` -- split-returning builders.
35
+ - :data:`PRESETS`, :func:`preset`, :func:`list_presets` -- named registry.
36
+ - :func:`load_preset`, :func:`save_preset` -- file I/O.
37
+ - :class:`MxNWindowSelector` -- pandas-style filter + bulk transform.
38
+ - Vocabulary: :class:`LinkDimension`, :class:`ViewDirection`,
39
+ :data:`LAYOUT_VERSION`, :data:`DEFAULT_GROUP_NAME`,
40
+ :data:`DEFAULT_GROUP`, :data:`DEFAULT_EDITOR_NAME`,
41
+ :data:`NAMESPACE_DELIMITER`, :data:`WINDOW_ID_PATTERN`,
42
+ :data:`GROUP_NAME_PATTERN`.
43
+ """
44
+
45
+ from __future__ import annotations
46
+
47
+ from ._builders import grid, single_window, three_up, two_rows_each_direction
48
+ from ._io import load_preset, save_preset
49
+ from ._model import (
50
+ DEFAULT_GROUP,
51
+ Group,
52
+ LayoutWindow,
53
+ Link,
54
+ LinkLike,
55
+ LinkValue,
56
+ MxNLayoutDocument,
57
+ Split,
58
+ )
59
+ from ._presets import PRESETS, list_presets, preset
60
+ from ._selector import MxNWindowSelector
61
+ from ._vocabulary import (
62
+ DEFAULT_EDITOR_NAME,
63
+ DEFAULT_GROUP_NAME,
64
+ GROUP_NAME_PATTERN,
65
+ LAYOUT_VERSION,
66
+ NAMESPACE_DELIMITER,
67
+ WINDOW_ID_PATTERN,
68
+ LinkDimension,
69
+ ViewDirection,
70
+ )
71
+
72
+
73
+ __all__ = [
74
+ # Vocabulary
75
+ "LAYOUT_VERSION",
76
+ "DEFAULT_GROUP_NAME",
77
+ "DEFAULT_GROUP",
78
+ "DEFAULT_EDITOR_NAME",
79
+ "NAMESPACE_DELIMITER",
80
+ "WINDOW_ID_PATTERN",
81
+ "GROUP_NAME_PATTERN",
82
+ "LinkDimension",
83
+ "ViewDirection",
84
+ # Model
85
+ "Group",
86
+ "Link",
87
+ "LinkValue",
88
+ "LinkLike",
89
+ "LayoutWindow",
90
+ "Split",
91
+ "MxNLayoutDocument",
92
+ # Selector
93
+ "MxNWindowSelector",
94
+ # Builders
95
+ "grid",
96
+ "three_up",
97
+ "two_rows_each_direction",
98
+ "single_window",
99
+ # Presets
100
+ "PRESETS",
101
+ "preset",
102
+ "list_presets",
103
+ # File I/O
104
+ "load_preset",
105
+ "save_preset",
106
+ ]
@@ -0,0 +1,220 @@
1
+ # ============================================================================
2
+ #
3
+ # The Medical Imaging Interaction Toolkit (MITK)
4
+ #
5
+ # Copyright (c) German Cancer Research Center (DKFZ)
6
+ # All rights reserved.
7
+ #
8
+ # Use of this source code is governed by a 3-clause BSD license that can be
9
+ # found in the LICENSE file.
10
+ #
11
+ # ============================================================================
12
+
13
+ """Ergonomic split-returning builders for the common layouts.
14
+
15
+ Builders return :class:`Split`. Callers wanting a complete document wrap
16
+ with ``MxNLayoutDocument.create(root=..., name=...)``. The earlier two-tier
17
+ (split + document) is collapsed: convenience cost is one line per script,
18
+ and the smaller surface halves the test matrix.
19
+
20
+ Builders synthesise qualified ids as
21
+ ``f"{editor_name}{NAMESPACE_DELIMITER}{bare_id_stem}{i}"``. With defaults
22
+ (``editor_name='mxn'``, ``bare_id_stem='widget'``, ``start_index=0``) this
23
+ yields ``mxn__widget0``, ``mxn__widget1``, ... -- the convention the engine
24
+ emits via ``QmitkMxNMultiWidget::SerializeLayout``.
25
+ """
26
+
27
+ from __future__ import annotations
28
+
29
+ from collections.abc import Sequence
30
+ from itertools import count
31
+
32
+ from ._model import DEFAULT_GROUP, Group, LayoutWindow, Split
33
+ from ._vocabulary import (
34
+ DEFAULT_EDITOR_NAME,
35
+ NAMESPACE_DELIMITER,
36
+ ViewDirection,
37
+ )
38
+
39
+
40
+ _GRID_VIEW_CYCLE: tuple[ViewDirection, ...] = (
41
+ ViewDirection.AXIAL,
42
+ ViewDirection.SAGITTAL,
43
+ ViewDirection.CORONAL,
44
+ )
45
+
46
+
47
+ def _qualify(editor_name: str, bare_id_stem: str, index: int) -> str:
48
+ return f"{editor_name}{NAMESPACE_DELIMITER}{bare_id_stem}{index}"
49
+
50
+
51
+ def grid(
52
+ rows: int,
53
+ cols: int,
54
+ *,
55
+ view_directions: Sequence[ViewDirection] | None = None,
56
+ group: str | Group = DEFAULT_GROUP,
57
+ editor_name: str = DEFAULT_EDITOR_NAME,
58
+ bare_id_stem: str = "widget",
59
+ start_index: int = 0,
60
+ display_names: Sequence[str | None] | None = None,
61
+ ) -> Split:
62
+ """Build a ``rows`` x ``cols`` grid of windows.
63
+
64
+ Outer split is vertical (rows), inner splits are horizontal (cells in
65
+ each row).
66
+
67
+ Args:
68
+ rows: Number of rows (>= 1).
69
+ cols: Number of columns (>= 1).
70
+ view_directions: Per-cell view directions, length ``rows * cols``.
71
+ When omitted, cycles through axial/sagittal/coronal.
72
+ group: Selection group every cell links to. Accepts a group name
73
+ string or a ``Group`` instance.
74
+ editor_name: Editor-name segment for synthesised ids; almost all
75
+ callers leave this at ``'mxn'``.
76
+ bare_id_stem: Prefix of the bare-id segment (the index is
77
+ appended).
78
+ start_index: Starting index for synthesised ids; lets callers
79
+ compose multiple grids without id collisions.
80
+ display_names: Per-cell display labels, length ``rows * cols``.
81
+ Entries that are ``None`` produce no ``name`` field.
82
+ """
83
+ if isinstance(rows, bool) or not isinstance(rows, int) or rows < 1:
84
+ raise ValueError(f"rows must be a positive int, got {rows!r}")
85
+ if isinstance(cols, bool) or not isinstance(cols, int) or cols < 1:
86
+ raise ValueError(f"cols must be a positive int, got {cols!r}")
87
+
88
+ cell_count = rows * cols
89
+
90
+ if view_directions is None:
91
+ views = [
92
+ _GRID_VIEW_CYCLE[i % len(_GRID_VIEW_CYCLE)]
93
+ for i in range(cell_count)
94
+ ]
95
+ else:
96
+ if len(view_directions) != cell_count:
97
+ raise ValueError(
98
+ f"view_directions has length {len(view_directions)}; "
99
+ f"expected {cell_count} (rows*cols)"
100
+ )
101
+ views = list(view_directions)
102
+
103
+ if display_names is None:
104
+ names = [None] * cell_count
105
+ else:
106
+ if len(display_names) != cell_count:
107
+ raise ValueError(
108
+ f"display_names has length {len(display_names)}; "
109
+ f"expected {cell_count} (rows*cols)"
110
+ )
111
+ names = list(display_names)
112
+
113
+ selection = group
114
+ counter = count(start_index)
115
+ cells_by_row: list[list[LayoutWindow]] = []
116
+ for r in range(rows):
117
+ cells: list[LayoutWindow] = []
118
+ for c in range(cols):
119
+ cell_idx = r * cols + c
120
+ window_index = next(counter)
121
+ cells.append(
122
+ LayoutWindow.create(
123
+ id=_qualify(editor_name, bare_id_stem, window_index),
124
+ view_direction=views[cell_idx],
125
+ name=names[cell_idx],
126
+ selection=selection,
127
+ )
128
+ )
129
+ cells_by_row.append(cells)
130
+
131
+ # Collapse degenerate splits so the output matches what a human
132
+ # author would write: a 1xN grid is a single horizontal split,
133
+ # an Mx1 grid is a single vertical split, an MxN grid is a vertical
134
+ # of horizontals.
135
+ if rows == 1:
136
+ return Split.horizontal(*cells_by_row[0])
137
+ if cols == 1:
138
+ return Split.vertical(*[row[0] for row in cells_by_row])
139
+ return Split.vertical(*[Split.horizontal(*row) for row in cells_by_row])
140
+
141
+
142
+ def three_up(
143
+ *,
144
+ group: str | Group = DEFAULT_GROUP,
145
+ editor_name: str = DEFAULT_EDITOR_NAME,
146
+ bare_id_stem: str = "widget",
147
+ start_index: int = 0,
148
+ ) -> Split:
149
+ """Three windows side by side: axial, sagittal, coronal."""
150
+ return grid(
151
+ 1,
152
+ 3,
153
+ group=group,
154
+ editor_name=editor_name,
155
+ bare_id_stem=bare_id_stem,
156
+ start_index=start_index,
157
+ )
158
+
159
+
160
+ def two_rows_each_direction(
161
+ *,
162
+ group_top: str | Group = DEFAULT_GROUP,
163
+ group_bottom: str | Group = "row2",
164
+ editor_name: str = DEFAULT_EDITOR_NAME,
165
+ bare_id_stem: str = "widget",
166
+ start_index: int = 0,
167
+ ) -> Split:
168
+ """Two horizontal rows; each row has axial / sagittal / coronal.
169
+
170
+ Top row links to ``group_top``, bottom row to ``group_bottom``. By
171
+ default the top is the ``main`` group and the bottom is its own
172
+ ``row2`` group -- matches the in-tree preset
173
+ ``mxnLayout_twoRowsEachDirection.json``.
174
+ """
175
+ counter = count(start_index)
176
+
177
+ def row(selection: str | Group) -> Split:
178
+ cells = [
179
+ LayoutWindow.create(
180
+ id=_qualify(editor_name, bare_id_stem, next(counter)),
181
+ view_direction=vd,
182
+ selection=selection,
183
+ )
184
+ for vd in _GRID_VIEW_CYCLE
185
+ ]
186
+ return Split.horizontal(*cells)
187
+
188
+ return Split.vertical(row(group_top), row(group_bottom))
189
+
190
+
191
+ def single_window(
192
+ view_direction: ViewDirection | str = ViewDirection.AXIAL,
193
+ *,
194
+ id_qualified: str | None = None,
195
+ editor_name: str = DEFAULT_EDITOR_NAME,
196
+ bare_id_stem: str = "widget",
197
+ start_index: int = 0,
198
+ display_name: str | None = None,
199
+ group: str | Group = DEFAULT_GROUP,
200
+ ) -> Split:
201
+ """A single-window layout, wrapped in a horizontal split.
202
+
203
+ Args:
204
+ view_direction: Anatomical plane.
205
+ id_qualified: Optional explicit qualified id. Must be the canonical
206
+ qualified form (``"mxn__alpha"``); a bare id (``"alpha"``)
207
+ raises ``ValueError`` from the regex check. When ``None``
208
+ (default), synthesises ``f"{editor_name}__{bare_id_stem}{start_index}"``.
209
+ display_name: Optional display label for the cell.
210
+ group: Selection group.
211
+ """
212
+ if id_qualified is None:
213
+ id_qualified = _qualify(editor_name, bare_id_stem, start_index)
214
+ window = LayoutWindow.create(
215
+ id=id_qualified,
216
+ view_direction=view_direction,
217
+ name=display_name,
218
+ selection=group,
219
+ )
220
+ return Split.horizontal(window)
mitk/mxn/layout/_io.py ADDED
@@ -0,0 +1,65 @@
1
+ # ============================================================================
2
+ #
3
+ # The Medical Imaging Interaction Toolkit (MITK)
4
+ #
5
+ # Copyright (c) German Cancer Research Center (DKFZ)
6
+ # All rights reserved.
7
+ #
8
+ # Use of this source code is governed by a 3-clause BSD license that can be
9
+ # found in the LICENSE file.
10
+ #
11
+ # ============================================================================
12
+
13
+ """File I/O helpers for layout JSON documents.
14
+
15
+ The module intentionally stays thin: the heavy lifting lives in
16
+ ``MxNLayoutDocument.from_json`` / ``MxNLayoutDocument.to_json``.
17
+ """
18
+
19
+ from __future__ import annotations
20
+
21
+ import json
22
+ from collections.abc import Mapping
23
+ from pathlib import Path
24
+ from typing import Any
25
+
26
+ from ._model import MxNLayoutDocument
27
+
28
+
29
+ def load_preset(path: str | Path) -> MxNLayoutDocument:
30
+ """Read a JSON file from disk and parse it via
31
+ :meth:`MxNLayoutDocument.from_json`.
32
+
33
+ Up-front version mismatch raises a clear ``ValueError`` before any
34
+ structural parsing -- see ``MxNLayoutDocument.from_json``.
35
+ """
36
+ text = Path(path).read_text(encoding="utf-8")
37
+ return MxNLayoutDocument.from_json(text)
38
+
39
+
40
+ def save_preset(
41
+ path: str | Path,
42
+ doc: MxNLayoutDocument | Mapping[str, Any],
43
+ ) -> None:
44
+ """Write ``doc`` as JSON to disk.
45
+
46
+ Accepts either a typed :class:`MxNLayoutDocument` (preferred) or a
47
+ raw mapping previously produced by :meth:`MxNLayoutDocument.to_json`.
48
+ For a typed document, calls :meth:`MxNLayoutDocument.to_json` first.
49
+ Output uses ``indent=2`` and explicit (schema-aligned) key ordering;
50
+ ``sort_keys`` is **not** enabled because we want ``version, name?,
51
+ groups, root`` rather than alphabetic order.
52
+ """
53
+ payload: Mapping[str, Any]
54
+ if isinstance(doc, MxNLayoutDocument):
55
+ payload = doc.to_json()
56
+ elif isinstance(doc, Mapping):
57
+ payload = doc
58
+ else:
59
+ raise ValueError(
60
+ f"doc must be MxNLayoutDocument or Mapping, got {type(doc).__name__}"
61
+ )
62
+ Path(path).write_text(
63
+ json.dumps(payload, indent=2, sort_keys=False, ensure_ascii=False) + "\n",
64
+ encoding="utf-8",
65
+ )