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.
- mitk/MitkCore/MitkDICOMImageIO.dll +0 -0
- mitk/MitkCore/MitkDICOMPMIO.dll +0 -0
- mitk/MitkCore/MitkDICOMRTIO.dll +0 -0
- mitk/MitkCore/MitkDICOMSegIO.dll +0 -0
- mitk/MitkCore/MitkIOExt.dll +0 -0
- mitk/MitkCore/MitkModelFitIOServices.dll +0 -0
- mitk/MitkCore/MitkMultilabelIO.dll +0 -0
- mitk/MitkCore/MitkPlanarFigureIO.dll +0 -0
- mitk/MitkCore/MitkROIIO.dll +0 -0
- mitk/MitkCore/MitkSceneSerializationIO.dll +0 -0
- mitk/MitkCore/MitkSegmentationIO.dll +0 -0
- mitk/MitkDICOM/MitkCESTIO.dll +0 -0
- mitk/MitkModelFit/MitkModelFitModelsServices.dll +0 -0
- mitk/MitkModelFit/MitkPharmacokineticModelsServices.dll +0 -0
- mitk/__init__.py +68 -0
- mitk/mitk.cp312-win_amd64.pyd +0 -0
- mitk/mxn/__init__.py +17 -0
- mitk/mxn/layout/__init__.py +106 -0
- mitk/mxn/layout/_builders.py +220 -0
- mitk/mxn/layout/_io.py +65 -0
- mitk/mxn/layout/_model.py +848 -0
- mitk/mxn/layout/_presets.py +71 -0
- mitk/mxn/layout/_repr.py +170 -0
- mitk/mxn/layout/_selector.py +271 -0
- mitk/mxn/layout/_validation.py +122 -0
- mitk/mxn/layout/_vocabulary.py +59 -0
- mitk/property_view.py +123 -0
- mitk_python-2026.6.dev2.dist-info/DELVEWHEEL +2 -0
- mitk_python-2026.6.dev2.dist-info/METADATA +67 -0
- mitk_python-2026.6.dev2.dist-info/RECORD +194 -0
- mitk_python-2026.6.dev2.dist-info/WHEEL +4 -0
- mitk_python-2026.6.dev2.dist-info/top_level.txt +1 -0
- mitk_python.libs/ITKCommon-5.4.dll +0 -0
- mitk_python.libs/ITKIOBMP-5.4.dll +0 -0
- mitk_python.libs/ITKIOBioRad-5.4.dll +0 -0
- mitk_python.libs/ITKIOBruker-5.4.dll +0 -0
- mitk_python.libs/ITKIOGDCM-5.4.dll +0 -0
- mitk_python.libs/ITKIOGE-5.4.dll +0 -0
- mitk_python.libs/ITKIOGIPL-5.4.dll +0 -0
- mitk_python.libs/ITKIOHDF5-5.4.dll +0 -0
- mitk_python.libs/ITKIOIPL-5.4.dll +0 -0
- mitk_python.libs/ITKIOImageBase-5.4.dll +0 -0
- mitk_python.libs/ITKIOJPEG-5.4.dll +0 -0
- mitk_python.libs/ITKIOJPEG2000-5.4.dll +0 -0
- mitk_python.libs/ITKIOLSM-5.4.dll +0 -0
- mitk_python.libs/ITKIOMINC-5.4.dll +0 -0
- mitk_python.libs/ITKIOMRC-5.4.dll +0 -0
- mitk_python.libs/ITKIOMeta-5.4.dll +0 -0
- mitk_python.libs/ITKIONIFTI-5.4.dll +0 -0
- mitk_python.libs/ITKIONRRD-5.4.dll +0 -0
- mitk_python.libs/ITKIOPNG-5.4.dll +0 -0
- mitk_python.libs/ITKIOStimulate-5.4.dll +0 -0
- mitk_python.libs/ITKIOTIFF-5.4.dll +0 -0
- mitk_python.libs/ITKIOVTK-5.4.dll +0 -0
- mitk_python.libs/ITKLabelMap-5.4.dll +0 -0
- mitk_python.libs/ITKMathematicalMorphology-5.4.dll +0 -0
- mitk_python.libs/ITKOptimizers-5.4.dll +0 -0
- mitk_python.libs/ITKQuadEdgeMesh-5.4.dll +0 -0
- mitk_python.libs/ITKRegionGrowing-5.4.dll +0 -0
- mitk_python.libs/ITKSmoothing-5.4.dll +0 -0
- mitk_python.libs/ITKStatistics-5.4.dll +0 -0
- mitk_python.libs/ITKTransform-5.4.dll +0 -0
- mitk_python.libs/MitkAlgorithmsExt.dll +0 -0
- mitk_python.libs/MitkAnnotation.dll +0 -0
- mitk_python.libs/MitkBoundingShape.dll +0 -0
- mitk_python.libs/MitkCEST.dll +0 -0
- mitk_python.libs/MitkContourModel.dll +0 -0
- mitk_python.libs/MitkCore.dll +0 -0
- mitk_python.libs/MitkCppMicroServices.dll +0 -0
- mitk_python.libs/MitkDICOM.dll +0 -0
- mitk_python.libs/MitkDICOMPM.dll +0 -0
- mitk_python.libs/MitkDICOMQI.dll +0 -0
- mitk_python.libs/MitkDataTypesExt.dll +0 -0
- mitk_python.libs/MitkLog.dll +0 -0
- mitk_python.libs/MitkMapperExt.dll +0 -0
- mitk_python.libs/MitkModelFit.dll +0 -0
- mitk_python.libs/MitkMultilabel.dll +0 -0
- mitk_python.libs/MitkPharmacokinetics.dll +0 -0
- mitk_python.libs/MitkPlanarFigure.dll +0 -0
- mitk_python.libs/MitkROI.dll +0 -0
- mitk_python.libs/MitkRT.dll +0 -0
- mitk_python.libs/MitkSceneSerialization.dll +0 -0
- mitk_python.libs/MitkSceneSerializationBase.dll +0 -0
- mitk_python.libs/MitkSegmentation.dll +0 -0
- mitk_python.libs/MitkSurfaceInterpolation.dll +0 -0
- mitk_python.libs/PocoFoundation.dll +0 -0
- mitk_python.libs/PocoZip.dll +0 -0
- mitk_python.libs/ann.dll +0 -0
- mitk_python.libs/dcmdata.dll +0 -0
- mitk_python.libs/dcmfg.dll +0 -0
- mitk_python.libs/dcmimage.dll +0 -0
- mitk_python.libs/dcmimgle.dll +0 -0
- mitk_python.libs/dcmiod.dll +0 -0
- mitk_python.libs/dcmpmap.dll +0 -0
- mitk_python.libs/dcmrt.dll +0 -0
- mitk_python.libs/dcmseg.dll +0 -0
- mitk_python.libs/dcmsr.dll +0 -0
- mitk_python.libs/gdcmCommon.dll +0 -0
- mitk_python.libs/gdcmDICT.dll +0 -0
- mitk_python.libs/gdcmDSED.dll +0 -0
- mitk_python.libs/gdcmIOD.dll +0 -0
- mitk_python.libs/gdcmMSFF.dll +0 -0
- mitk_python.libs/gdcmcharls.dll +0 -0
- mitk_python.libs/gdcmexpat.dll +0 -0
- mitk_python.libs/gdcmjpeg12.dll +0 -0
- mitk_python.libs/gdcmjpeg16.dll +0 -0
- mitk_python.libs/gdcmjpeg8.dll +0 -0
- mitk_python.libs/gdcmopenjp2.dll +0 -0
- mitk_python.libs/gdcmzlib.dll +0 -0
- mitk_python.libs/itkGrowCut-5.4.dll +0 -0
- mitk_python.libs/itkhdf5-shared-5.4.dll +0 -0
- mitk_python.libs/itkhdf5_cpp-shared-5.4.dll +0 -0
- mitk_python.libs/libcrypto-3-x64.dll +0 -0
- mitk_python.libs/libssl-3-x64.dll +0 -0
- mitk_python.libs/lz4.dll +0 -0
- mitk_python.libs/msvcp140.dll +0 -0
- mitk_python.libs/oficonv.dll +0 -0
- mitk_python.libs/oflog.dll +0 -0
- mitk_python.libs/ofstd.dll +0 -0
- mitk_python.libs/tbb12.dll +0 -0
- mitk_python.libs/vcomp140.dll +0 -0
- mitk_python.libs/vtkCommonColor-9.5.dll +0 -0
- mitk_python.libs/vtkCommonComputationalGeometry-9.5.dll +0 -0
- mitk_python.libs/vtkCommonCore-9.5.dll +0 -0
- mitk_python.libs/vtkCommonDataModel-9.5.dll +0 -0
- mitk_python.libs/vtkCommonExecutionModel-9.5.dll +0 -0
- mitk_python.libs/vtkCommonMath-9.5.dll +0 -0
- mitk_python.libs/vtkCommonMisc-9.5.dll +0 -0
- mitk_python.libs/vtkCommonSystem-9.5.dll +0 -0
- mitk_python.libs/vtkCommonTransforms-9.5.dll +0 -0
- mitk_python.libs/vtkDICOMParser-9.5.dll +0 -0
- mitk_python.libs/vtkFiltersCellGrid-9.5.dll +0 -0
- mitk_python.libs/vtkFiltersCore-9.5.dll +0 -0
- mitk_python.libs/vtkFiltersExtraction-9.5.dll +0 -0
- mitk_python.libs/vtkFiltersGeneral-9.5.dll +0 -0
- mitk_python.libs/vtkFiltersGeometry-9.5.dll +0 -0
- mitk_python.libs/vtkFiltersHybrid-9.5.dll +0 -0
- mitk_python.libs/vtkFiltersHyperTree-9.5.dll +0 -0
- mitk_python.libs/vtkFiltersModeling-9.5.dll +0 -0
- mitk_python.libs/vtkFiltersParallel-9.5.dll +0 -0
- mitk_python.libs/vtkFiltersReduction-9.5.dll +0 -0
- mitk_python.libs/vtkFiltersSources-9.5.dll +0 -0
- mitk_python.libs/vtkFiltersStatistics-9.5.dll +0 -0
- mitk_python.libs/vtkFiltersTexture-9.5.dll +0 -0
- mitk_python.libs/vtkFiltersVerdict-9.5.dll +0 -0
- mitk_python.libs/vtkIOCellGrid-9.5.dll +0 -0
- mitk_python.libs/vtkIOCore-9.5.dll +0 -0
- mitk_python.libs/vtkIOGeometry-9.5.dll +0 -0
- mitk_python.libs/vtkIOImage-9.5.dll +0 -0
- mitk_python.libs/vtkIOLegacy-9.5.dll +0 -0
- mitk_python.libs/vtkIOPLY-9.5.dll +0 -0
- mitk_python.libs/vtkIOXML-9.5.dll +0 -0
- mitk_python.libs/vtkIOXMLParser-9.5.dll +0 -0
- mitk_python.libs/vtkImagingColor-9.5.dll +0 -0
- mitk_python.libs/vtkImagingCore-9.5.dll +0 -0
- mitk_python.libs/vtkImagingGeneral-9.5.dll +0 -0
- mitk_python.libs/vtkImagingHybrid-9.5.dll +0 -0
- mitk_python.libs/vtkImagingMath-9.5.dll +0 -0
- mitk_python.libs/vtkImagingSources-9.5.dll +0 -0
- mitk_python.libs/vtkImagingStencil-9.5.dll +0 -0
- mitk_python.libs/vtkInteractionStyle-9.5.dll +0 -0
- mitk_python.libs/vtkInteractionWidgets-9.5.dll +0 -0
- mitk_python.libs/vtkParallelCore-9.5.dll +0 -0
- mitk_python.libs/vtkParallelDIY-9.5.dll +0 -0
- mitk_python.libs/vtkRenderingAnnotation-9.5.dll +0 -0
- mitk_python.libs/vtkRenderingContext2D-9.5.dll +0 -0
- mitk_python.libs/vtkRenderingContextOpenGL2-9.5.dll +0 -0
- mitk_python.libs/vtkRenderingCore-9.5.dll +0 -0
- mitk_python.libs/vtkRenderingFreeType-9.5.dll +0 -0
- mitk_python.libs/vtkRenderingHyperTreeGrid-9.5.dll +0 -0
- mitk_python.libs/vtkRenderingLabel-9.5.dll +0 -0
- mitk_python.libs/vtkRenderingOpenGL2-9.5.dll +0 -0
- mitk_python.libs/vtkRenderingUI-9.5.dll +0 -0
- mitk_python.libs/vtkRenderingVolume-9.5.dll +0 -0
- mitk_python.libs/vtkRenderingVolumeOpenGL2-9.5.dll +0 -0
- mitk_python.libs/vtkdoubleconversion-9.5.dll +0 -0
- mitk_python.libs/vtkexpat-9.5.dll +0 -0
- mitk_python.libs/vtkfmt-9.5.dll +0 -0
- mitk_python.libs/vtkfreetype-9.5.dll +0 -0
- mitk_python.libs/vtkglad-9.5.dll +0 -0
- mitk_python.libs/vtkjpeg-9.5.dll +0 -0
- mitk_python.libs/vtkkissfft-9.5.dll +0 -0
- mitk_python.libs/vtkloguru-9.5.dll +0 -0
- mitk_python.libs/vtklz4-9.5.dll +0 -0
- mitk_python.libs/vtklzma-9.5.dll +0 -0
- mitk_python.libs/vtkmetaio-9.5.dll +0 -0
- mitk_python.libs/vtkpng-9.5.dll +0 -0
- mitk_python.libs/vtkpugixml-9.5.dll +0 -0
- mitk_python.libs/vtksys-9.5.dll +0 -0
- mitk_python.libs/vtktiff-9.5.dll +0 -0
- mitk_python.libs/vtktoken-9.5.dll +0 -0
- mitk_python.libs/vtkverdict-9.5.dll +0 -0
- mitk_python.libs/vtkzlib-9.5.dll +0 -0
- mitk_python.libs/zlib1.dll +0 -0
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
"""Named preset registry.
|
|
14
|
+
|
|
15
|
+
Presets are *named, complete documents* registered for lookup. Builders
|
|
16
|
+
return :class:`Split`; presets wrap the result with
|
|
17
|
+
``MxNLayoutDocument.create(...)`` and are returned ready-to-use.
|
|
18
|
+
|
|
19
|
+
Named factories (rather than lambdas) so tracebacks point to a real
|
|
20
|
+
qualified name when a preset blows up.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from __future__ import annotations
|
|
24
|
+
|
|
25
|
+
from collections.abc import Callable, Mapping
|
|
26
|
+
|
|
27
|
+
from ._builders import single_window, three_up, two_rows_each_direction
|
|
28
|
+
from ._model import MxNLayoutDocument
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _preset_three_up() -> MxNLayoutDocument:
|
|
32
|
+
return MxNLayoutDocument.create(root=three_up(), name="Three Views")
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _preset_two_rows_each_direction() -> MxNLayoutDocument:
|
|
36
|
+
return MxNLayoutDocument.create(
|
|
37
|
+
root=two_rows_each_direction(),
|
|
38
|
+
name="Two Rows Each Direction",
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _preset_single() -> MxNLayoutDocument:
|
|
43
|
+
return MxNLayoutDocument.create(root=single_window())
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
PRESETS: Mapping[str, Callable[[], MxNLayoutDocument]] = {
|
|
47
|
+
"three-up": _preset_three_up,
|
|
48
|
+
"two-rows-each-direction": _preset_two_rows_each_direction,
|
|
49
|
+
"single": _preset_single,
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def preset(name: str) -> MxNLayoutDocument:
|
|
54
|
+
"""Return a fresh ``MxNLayoutDocument`` for the named preset.
|
|
55
|
+
|
|
56
|
+
Each call invokes the registered factory, so callers receive an
|
|
57
|
+
independent, mutation-safe document.
|
|
58
|
+
"""
|
|
59
|
+
try:
|
|
60
|
+
factory = PRESETS[name]
|
|
61
|
+
except KeyError:
|
|
62
|
+
available = ", ".join(sorted(PRESETS.keys()))
|
|
63
|
+
raise KeyError(
|
|
64
|
+
f"unknown preset {name!r}; available presets: [{available}]"
|
|
65
|
+
) from None
|
|
66
|
+
return factory()
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def list_presets() -> list[str]:
|
|
70
|
+
"""Names of all registered presets, sorted lexicographically."""
|
|
71
|
+
return sorted(PRESETS.keys())
|
mitk/mxn/layout/_repr.py
ADDED
|
@@ -0,0 +1,170 @@
|
|
|
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
|
+
"""Plain-text and HTML representations for the dataclass model.
|
|
14
|
+
|
|
15
|
+
HTML trust boundary: every string sourced from user-controlled content
|
|
16
|
+
(window id, window name, group name, view direction enum value, document
|
|
17
|
+
name, link dimension keys) passes through :func:`_html_escape` before
|
|
18
|
+
being interpolated. Inline styles only -- no JavaScript, no external
|
|
19
|
+
assets, no network.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
from html import escape as _stdlib_html_escape
|
|
25
|
+
|
|
26
|
+
from ._model import LayoutWindow, MxNLayoutDocument, Split
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _html_escape(text: str) -> str:
|
|
30
|
+
"""Escape HTML metacharacters including single and double quotes.
|
|
31
|
+
|
|
32
|
+
Centralised so a future audit can grep for ``f"...{...}..."`` in
|
|
33
|
+
this module and confirm every interpolation runs through here.
|
|
34
|
+
"""
|
|
35
|
+
return _stdlib_html_escape(text, quote=True)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# --------------------------------------------------------------------------- #
|
|
39
|
+
# Plain-text repr
|
|
40
|
+
# --------------------------------------------------------------------------- #
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def window_repr(window: LayoutWindow) -> str:
|
|
44
|
+
parts = [
|
|
45
|
+
f"id={window.id!r}",
|
|
46
|
+
f"view_direction={window.view_direction.name}",
|
|
47
|
+
f"selection={window.selection!r}",
|
|
48
|
+
]
|
|
49
|
+
if window.name is not None:
|
|
50
|
+
parts.append(f"name={window.name!r}")
|
|
51
|
+
if window.size != 1:
|
|
52
|
+
parts.append(f"size={window.size}")
|
|
53
|
+
return f"LayoutWindow({', '.join(parts)})"
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def split_repr(split: Split) -> str:
|
|
57
|
+
return (
|
|
58
|
+
f"Split(orientation={split.orientation!r}, "
|
|
59
|
+
f"children=<{len(split.children)} nodes>, size={split.size})"
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def document_repr(doc: MxNLayoutDocument) -> str:
|
|
64
|
+
label = f"name={doc.name!r}, " if doc.name is not None else ""
|
|
65
|
+
group_count = len(doc.groups)
|
|
66
|
+
window_count = sum(1 for _ in doc.windows())
|
|
67
|
+
return (
|
|
68
|
+
f"MxNLayoutDocument({label}version={doc.version!r}, "
|
|
69
|
+
f"windows={window_count}, groups={group_count})"
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
# --------------------------------------------------------------------------- #
|
|
74
|
+
# HTML repr (notebook)
|
|
75
|
+
# --------------------------------------------------------------------------- #
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
_WINDOW_STYLE = (
|
|
79
|
+
"border:1px solid #999; padding:6px 8px; margin:2px; "
|
|
80
|
+
"font-family:sans-serif; min-width:120px; min-height:60px; "
|
|
81
|
+
"display:inline-block; vertical-align:top; background:#fafafa;"
|
|
82
|
+
)
|
|
83
|
+
_TABLE_STYLE = (
|
|
84
|
+
"border-collapse:collapse; margin:2px;"
|
|
85
|
+
)
|
|
86
|
+
_CELL_STYLE = (
|
|
87
|
+
"padding:0; vertical-align:top;"
|
|
88
|
+
)
|
|
89
|
+
_DOC_HEADER_STYLE = (
|
|
90
|
+
"font-family:sans-serif; padding:4px 0; color:#333;"
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def window_html(window: LayoutWindow) -> str:
|
|
95
|
+
"""Render a single window as a bordered ``<div>``."""
|
|
96
|
+
parts: list[str] = []
|
|
97
|
+
parts.append(f'<div style="{_WINDOW_STYLE}">')
|
|
98
|
+
if window.name is not None:
|
|
99
|
+
parts.append(
|
|
100
|
+
f'<div style="font-weight:600; margin-bottom:2px;">'
|
|
101
|
+
f"{_html_escape(window.name)}</div>"
|
|
102
|
+
)
|
|
103
|
+
parts.append(
|
|
104
|
+
f'<div style="font-family:monospace; font-size:0.85em; color:#666;">'
|
|
105
|
+
f"{_html_escape(window.id)}</div>"
|
|
106
|
+
)
|
|
107
|
+
parts.append(
|
|
108
|
+
f'<div style="font-size:0.9em;">view: '
|
|
109
|
+
f"{_html_escape(window.view_direction.value)}</div>"
|
|
110
|
+
)
|
|
111
|
+
# Selection link first (it is the only required v2 dimension); other
|
|
112
|
+
# link dimensions follow in sorted order so the output is stable.
|
|
113
|
+
selection = window.selection
|
|
114
|
+
parts.append(
|
|
115
|
+
f'<div style="font-size:0.9em;">selection: '
|
|
116
|
+
f"{_html_escape(selection)}</div>"
|
|
117
|
+
)
|
|
118
|
+
extras = [
|
|
119
|
+
(dim, value if isinstance(value, str) else value.group)
|
|
120
|
+
for dim, value in window._links
|
|
121
|
+
if dim != "selection"
|
|
122
|
+
]
|
|
123
|
+
for dim, value in extras:
|
|
124
|
+
parts.append(
|
|
125
|
+
f'<div style="font-size:0.9em;">'
|
|
126
|
+
f"{_html_escape(dim)}: {_html_escape(value)}</div>"
|
|
127
|
+
)
|
|
128
|
+
parts.append("</div>")
|
|
129
|
+
return "".join(parts)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _node_html(node: Split | LayoutWindow) -> str:
|
|
133
|
+
if isinstance(node, LayoutWindow):
|
|
134
|
+
return window_html(node)
|
|
135
|
+
return split_html(node)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def split_html(split: Split) -> str:
|
|
139
|
+
"""Render a split as a tiny ``<table>`` whose layout (rows for
|
|
140
|
+
vertical, single row for horizontal) mirrors the splitter orientation.
|
|
141
|
+
"""
|
|
142
|
+
children_html = [_node_html(c) for c in split.children]
|
|
143
|
+
if split.orientation == "horizontal":
|
|
144
|
+
cells = "".join(f'<td style="{_CELL_STYLE}">{html}</td>' for html in children_html)
|
|
145
|
+
return f'<table style="{_TABLE_STYLE}"><tr>{cells}</tr></table>'
|
|
146
|
+
rows = "".join(
|
|
147
|
+
f'<tr><td style="{_CELL_STYLE}">{html}</td></tr>' for html in children_html
|
|
148
|
+
)
|
|
149
|
+
return f'<table style="{_TABLE_STYLE}">{rows}</table>'
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def document_html(doc: MxNLayoutDocument) -> str:
|
|
153
|
+
parts: list[str] = []
|
|
154
|
+
if doc.name is not None:
|
|
155
|
+
parts.append(
|
|
156
|
+
f'<div style="{_DOC_HEADER_STYLE} font-weight:600;">'
|
|
157
|
+
f"{_html_escape(doc.name)}</div>"
|
|
158
|
+
)
|
|
159
|
+
group_summary = ", ".join(
|
|
160
|
+
f"{_html_escape(name)} ({'select-all' if g.select_all else 'curated'})"
|
|
161
|
+
for name, g in sorted(doc.groups.items())
|
|
162
|
+
)
|
|
163
|
+
parts.append(
|
|
164
|
+
f'<div style="{_DOC_HEADER_STYLE} font-size:0.9em; color:#555;">'
|
|
165
|
+
f"version {_html_escape(doc.version)} · groups: "
|
|
166
|
+
f"{group_summary or '(none)'}"
|
|
167
|
+
f"</div>"
|
|
168
|
+
)
|
|
169
|
+
parts.append(split_html(doc.root))
|
|
170
|
+
return "".join(parts)
|
|
@@ -0,0 +1,271 @@
|
|
|
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
|
+
"""``MxNWindowSelector`` -- pandas-style filter + bulk transform over a layout tree.
|
|
14
|
+
|
|
15
|
+
A selector is bound to a *source* tree (``MxNLayoutDocument`` or ``Split``).
|
|
16
|
+
Filters return a new selector; terminals return either a value (read) or a
|
|
17
|
+
new instance of the source type (update). All immutable -- the source tree
|
|
18
|
+
is never mutated.
|
|
19
|
+
|
|
20
|
+
The selector is local-only: it knows nothing about HTTP, transports, or
|
|
21
|
+
workbench state. It operates on layout *documents* as values.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
from __future__ import annotations
|
|
25
|
+
|
|
26
|
+
from collections.abc import Callable, Iterable, Iterator
|
|
27
|
+
from dataclasses import replace
|
|
28
|
+
from typing import Generic, TypeVar, Union
|
|
29
|
+
|
|
30
|
+
from . import _validation as _v
|
|
31
|
+
from ._model import (
|
|
32
|
+
Group,
|
|
33
|
+
LayoutWindow,
|
|
34
|
+
LinkLike,
|
|
35
|
+
MxNLayoutDocument,
|
|
36
|
+
Split,
|
|
37
|
+
_normalise_link_value,
|
|
38
|
+
)
|
|
39
|
+
from ._vocabulary import LinkDimension, ViewDirection
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
_Source = TypeVar("_Source", MxNLayoutDocument, Split)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _coerce_view_direction(value: ViewDirection | str) -> ViewDirection:
|
|
46
|
+
if isinstance(value, ViewDirection):
|
|
47
|
+
return value
|
|
48
|
+
if isinstance(value, str):
|
|
49
|
+
return ViewDirection(value)
|
|
50
|
+
raise ValueError(f"view direction must be ViewDirection or str, got {type(value).__name__}")
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _root_of(source: _Source) -> Split:
|
|
54
|
+
return source.root if isinstance(source, MxNLayoutDocument) else source
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def _rewrap(source: _Source, new_root: Split) -> _Source:
|
|
58
|
+
"""Rebuild the source with a new root, preserving document metadata."""
|
|
59
|
+
if isinstance(source, MxNLayoutDocument):
|
|
60
|
+
return replace(source, root=new_root) # type: ignore[return-value]
|
|
61
|
+
return new_root # type: ignore[return-value]
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _rewrite_tree(
|
|
65
|
+
node: Split | LayoutWindow,
|
|
66
|
+
transform: Callable[[LayoutWindow], LayoutWindow],
|
|
67
|
+
keep: Callable[[LayoutWindow], bool],
|
|
68
|
+
) -> Split | LayoutWindow:
|
|
69
|
+
"""Walk the tree and replace each leaf for which ``keep`` returns True
|
|
70
|
+
with ``transform(leaf)``; pass through other leaves. Splits are
|
|
71
|
+
rebuilt structurally (size/orientation preserved).
|
|
72
|
+
"""
|
|
73
|
+
if isinstance(node, LayoutWindow):
|
|
74
|
+
return transform(node) if keep(node) else node
|
|
75
|
+
new_children = tuple(_rewrite_tree(c, transform, keep) for c in node.children)
|
|
76
|
+
if new_children == node.children:
|
|
77
|
+
return node
|
|
78
|
+
return replace(node, children=new_children)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _ensure_group(source: _Source, group_name: str) -> _Source:
|
|
82
|
+
"""When the source is a document, ensure ``group_name`` is in its
|
|
83
|
+
groups registry; on ``Split`` sources this is a no-op (groups live on
|
|
84
|
+
the document).
|
|
85
|
+
"""
|
|
86
|
+
if not isinstance(source, MxNLayoutDocument):
|
|
87
|
+
return source
|
|
88
|
+
if group_name in source.groups:
|
|
89
|
+
return source
|
|
90
|
+
new_groups = dict(source.groups)
|
|
91
|
+
new_groups[group_name] = Group(group_name)
|
|
92
|
+
new_storage = tuple(sorted(new_groups.items()))
|
|
93
|
+
return replace(source, _groups=new_storage) # type: ignore[return-value]
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
class MxNWindowSelector(Generic[_Source]):
|
|
97
|
+
"""Filter + bulk-transform over a tree's windows.
|
|
98
|
+
|
|
99
|
+
Each filter call returns a new selector; each terminal call returns
|
|
100
|
+
a value (read) or a new ``T`` (update). All operations are immutable.
|
|
101
|
+
"""
|
|
102
|
+
|
|
103
|
+
__slots__ = ("_source", "_predicate")
|
|
104
|
+
|
|
105
|
+
def __init__(
|
|
106
|
+
self,
|
|
107
|
+
source: _Source,
|
|
108
|
+
predicate: Callable[[LayoutWindow], bool] | None = None,
|
|
109
|
+
) -> None:
|
|
110
|
+
self._source = source
|
|
111
|
+
self._predicate: Callable[[LayoutWindow], bool] = predicate or (lambda _w: True)
|
|
112
|
+
|
|
113
|
+
# ---- internals ------------------------------------------------------
|
|
114
|
+
|
|
115
|
+
def _and(
|
|
116
|
+
self, extra: Callable[[LayoutWindow], bool]
|
|
117
|
+
) -> "MxNWindowSelector[_Source]":
|
|
118
|
+
prior = self._predicate
|
|
119
|
+
return MxNWindowSelector(self._source, lambda w: prior(w) and extra(w))
|
|
120
|
+
|
|
121
|
+
def _selected_windows(self) -> list[LayoutWindow]:
|
|
122
|
+
return [w for w in _root_of(self._source).windows() if self._predicate(w)]
|
|
123
|
+
|
|
124
|
+
# ---- filtering ------------------------------------------------------
|
|
125
|
+
|
|
126
|
+
def where(
|
|
127
|
+
self,
|
|
128
|
+
*,
|
|
129
|
+
view_direction: ViewDirection | str | None = None,
|
|
130
|
+
ids: Iterable[str] | None = None,
|
|
131
|
+
display_names: Iterable[str | None] | None = None,
|
|
132
|
+
predicate: Callable[[LayoutWindow], bool] | None = None,
|
|
133
|
+
group: str | Group | None = None,
|
|
134
|
+
dim: LinkDimension | str = LinkDimension.SELECTION,
|
|
135
|
+
) -> "MxNWindowSelector[_Source]":
|
|
136
|
+
"""Compose multiple filter predicates AND-style.
|
|
137
|
+
|
|
138
|
+
All keyword arguments are optional; the resulting selector keeps
|
|
139
|
+
only windows that satisfy every supplied predicate.
|
|
140
|
+
"""
|
|
141
|
+
result: MxNWindowSelector[_Source] = self
|
|
142
|
+
if view_direction is not None:
|
|
143
|
+
target_view = _coerce_view_direction(view_direction)
|
|
144
|
+
result = result._and(lambda w, v=target_view: w.view_direction == v)
|
|
145
|
+
if ids is not None:
|
|
146
|
+
id_set = set(ids)
|
|
147
|
+
result = result._and(lambda w, s=id_set: w.id in s)
|
|
148
|
+
if display_names is not None:
|
|
149
|
+
name_set = set(display_names)
|
|
150
|
+
result = result._and(lambda w, s=name_set: w.name in s)
|
|
151
|
+
if group is not None:
|
|
152
|
+
target_group = group.name if isinstance(group, Group) else group
|
|
153
|
+
dim_key = _v.validate_dimension_key(dim)
|
|
154
|
+
result = result._and(
|
|
155
|
+
lambda w, g=target_group, d=dim_key: w.linked_to(g, dim=d)
|
|
156
|
+
)
|
|
157
|
+
if predicate is not None:
|
|
158
|
+
result = result._and(predicate)
|
|
159
|
+
return result
|
|
160
|
+
|
|
161
|
+
def by_id(self, *ids: str) -> "MxNWindowSelector[_Source]":
|
|
162
|
+
"""Keep only windows whose ids match any of ``ids``."""
|
|
163
|
+
return self.where(ids=ids)
|
|
164
|
+
|
|
165
|
+
def by_display_name(
|
|
166
|
+
self, *names: str | None
|
|
167
|
+
) -> "MxNWindowSelector[_Source]":
|
|
168
|
+
"""Keep only windows whose display names match any of ``names``.
|
|
169
|
+
|
|
170
|
+
``None`` matches windows that have no display label set.
|
|
171
|
+
"""
|
|
172
|
+
return self.where(display_names=names)
|
|
173
|
+
|
|
174
|
+
def by_view(
|
|
175
|
+
self, *view_directions: ViewDirection | str
|
|
176
|
+
) -> "MxNWindowSelector[_Source]":
|
|
177
|
+
"""Keep only windows in any of the supplied view directions."""
|
|
178
|
+
coerced = [_coerce_view_direction(v) for v in view_directions]
|
|
179
|
+
coerced_set = set(coerced)
|
|
180
|
+
return self._and(lambda w, s=coerced_set: w.view_direction in s)
|
|
181
|
+
|
|
182
|
+
# ---- terminals: read ------------------------------------------------
|
|
183
|
+
|
|
184
|
+
def to_list(self) -> list[LayoutWindow]:
|
|
185
|
+
return self._selected_windows()
|
|
186
|
+
|
|
187
|
+
def ids(self) -> list[str]:
|
|
188
|
+
return [w.id for w in self._selected_windows()]
|
|
189
|
+
|
|
190
|
+
def __iter__(self) -> Iterator[LayoutWindow]:
|
|
191
|
+
return iter(self._selected_windows())
|
|
192
|
+
|
|
193
|
+
def __len__(self) -> int:
|
|
194
|
+
return len(self._selected_windows())
|
|
195
|
+
|
|
196
|
+
# ---- terminals: bulk update ----------------------------------------
|
|
197
|
+
|
|
198
|
+
def link_to(
|
|
199
|
+
self,
|
|
200
|
+
link: LinkLike,
|
|
201
|
+
*,
|
|
202
|
+
dim: LinkDimension | str = LinkDimension.SELECTION,
|
|
203
|
+
) -> _Source:
|
|
204
|
+
"""Re-link every selected window to ``link`` on dimension ``dim``.
|
|
205
|
+
|
|
206
|
+
On a document source, materialises a default ``Group`` entry for
|
|
207
|
+
a previously-unknown group name so strict-mode invariants hold on
|
|
208
|
+
the returned document. On a ``Split`` source there is no group
|
|
209
|
+
registry to update.
|
|
210
|
+
"""
|
|
211
|
+
new_value = _normalise_link_value(link)
|
|
212
|
+
dim_key = _v.validate_dimension_key(dim)
|
|
213
|
+
|
|
214
|
+
ids = {w.id for w in self._selected_windows()}
|
|
215
|
+
|
|
216
|
+
def transform(window: LayoutWindow) -> LayoutWindow:
|
|
217
|
+
return window.with_link(dim_key, new_value)
|
|
218
|
+
|
|
219
|
+
new_root = _rewrite_tree(_root_of(self._source), transform, lambda w: w.id in ids)
|
|
220
|
+
assert isinstance(new_root, Split)
|
|
221
|
+
new_source = _rewrap(self._source, new_root)
|
|
222
|
+
return _ensure_group(new_source, new_value)
|
|
223
|
+
|
|
224
|
+
def with_view_direction(self, vd: ViewDirection | str) -> _Source:
|
|
225
|
+
target = _coerce_view_direction(vd)
|
|
226
|
+
ids = {w.id for w in self._selected_windows()}
|
|
227
|
+
|
|
228
|
+
def transform(window: LayoutWindow) -> LayoutWindow:
|
|
229
|
+
return replace(window, view_direction=target)
|
|
230
|
+
|
|
231
|
+
new_root = _rewrite_tree(_root_of(self._source), transform, lambda w: w.id in ids)
|
|
232
|
+
assert isinstance(new_root, Split)
|
|
233
|
+
return _rewrap(self._source, new_root)
|
|
234
|
+
|
|
235
|
+
def with_display_name(
|
|
236
|
+
self,
|
|
237
|
+
name: Union[str, None, Callable[[LayoutWindow], str | None]],
|
|
238
|
+
) -> _Source:
|
|
239
|
+
ids = {w.id for w in self._selected_windows()}
|
|
240
|
+
|
|
241
|
+
if callable(name):
|
|
242
|
+
fn = name
|
|
243
|
+
|
|
244
|
+
def transform(window: LayoutWindow) -> LayoutWindow:
|
|
245
|
+
return window.with_name(fn(window))
|
|
246
|
+
|
|
247
|
+
else:
|
|
248
|
+
value: str | None = name
|
|
249
|
+
|
|
250
|
+
def transform(window: LayoutWindow) -> LayoutWindow:
|
|
251
|
+
return window.with_name(value)
|
|
252
|
+
|
|
253
|
+
new_root = _rewrite_tree(_root_of(self._source), transform, lambda w: w.id in ids)
|
|
254
|
+
assert isinstance(new_root, Split)
|
|
255
|
+
return _rewrap(self._source, new_root)
|
|
256
|
+
|
|
257
|
+
def map(
|
|
258
|
+
self, fn: Callable[[LayoutWindow], LayoutWindow]
|
|
259
|
+
) -> _Source:
|
|
260
|
+
"""Escape hatch -- replace each selected window with ``fn(window)``.
|
|
261
|
+
|
|
262
|
+
The selector preserves no invariants beyond what
|
|
263
|
+
``MxNLayoutDocument.create`` enforces on construction; if the
|
|
264
|
+
caller introduces a duplicate id, ``MxNLayoutDocument.validate()``
|
|
265
|
+
will catch it on the next ``validate()`` call (or implicitly via
|
|
266
|
+
``MxNLayoutDocument.create`` if the result is rebuilt).
|
|
267
|
+
"""
|
|
268
|
+
ids = {w.id for w in self._selected_windows()}
|
|
269
|
+
new_root = _rewrite_tree(_root_of(self._source), fn, lambda w: w.id in ids)
|
|
270
|
+
assert isinstance(new_root, Split)
|
|
271
|
+
return _rewrap(self._source, new_root)
|
|
@@ -0,0 +1,122 @@
|
|
|
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
|
+
"""Per-field validation rule helpers.
|
|
14
|
+
|
|
15
|
+
These helpers operate on primitive values; they have no knowledge of the
|
|
16
|
+
dataclass model. Cross-document rules (id uniqueness, group resolution)
|
|
17
|
+
live on `MxNLayoutDocument.validate()` since they need access to the
|
|
18
|
+
whole tree.
|
|
19
|
+
|
|
20
|
+
Single source of truth: per-window structural rules are enforced once in
|
|
21
|
+
`LayoutWindow.create`; cross-document rules are enforced in
|
|
22
|
+
`MxNLayoutDocument.validate()`.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
from __future__ import annotations
|
|
26
|
+
|
|
27
|
+
import re
|
|
28
|
+
from typing import Final
|
|
29
|
+
|
|
30
|
+
from ._vocabulary import (
|
|
31
|
+
GROUP_NAME_PATTERN,
|
|
32
|
+
LAYOUT_VERSION,
|
|
33
|
+
LinkDimension,
|
|
34
|
+
ViewDirection,
|
|
35
|
+
WINDOW_ID_PATTERN,
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
_WINDOW_ID_RE: Final = re.compile(WINDOW_ID_PATTERN)
|
|
40
|
+
_GROUP_NAME_RE: Final = re.compile(GROUP_NAME_PATTERN)
|
|
41
|
+
_VIEW_DIRECTION_VALUES: Final = frozenset(v.value for v in ViewDirection)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def validate_window_id(value: str) -> None:
|
|
45
|
+
"""Reject anything that does not match the qualified-id pattern.
|
|
46
|
+
|
|
47
|
+
Pre-condition: caller passes a `str`.
|
|
48
|
+
"""
|
|
49
|
+
if not isinstance(value, str):
|
|
50
|
+
raise ValueError(f"window id must be a string, got {type(value).__name__}")
|
|
51
|
+
if not _WINDOW_ID_RE.fullmatch(value):
|
|
52
|
+
raise ValueError(
|
|
53
|
+
f"window id {value!r} does not match qualified-id pattern "
|
|
54
|
+
f"{WINDOW_ID_PATTERN!r}; expected '<editor_name>__<bare_id>'"
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def validate_window_name(value: str | None) -> None:
|
|
59
|
+
"""Display name: optional; when set, must be a non-empty string."""
|
|
60
|
+
if value is None:
|
|
61
|
+
return
|
|
62
|
+
if not isinstance(value, str):
|
|
63
|
+
raise ValueError(f"window name must be a string or None, got {type(value).__name__}")
|
|
64
|
+
if len(value) < 1:
|
|
65
|
+
raise ValueError("window name must be a non-empty string when set; pass None to omit")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def validate_group_name(value: str) -> None:
|
|
69
|
+
"""Group name: must match the URL-segment-safe pattern."""
|
|
70
|
+
if not isinstance(value, str):
|
|
71
|
+
raise ValueError(f"group name must be a string, got {type(value).__name__}")
|
|
72
|
+
if not _GROUP_NAME_RE.fullmatch(value):
|
|
73
|
+
raise ValueError(
|
|
74
|
+
f"group name {value!r} does not match pattern {GROUP_NAME_PATTERN!r}"
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def validate_view_direction(value: object) -> None:
|
|
79
|
+
"""Accept either a `ViewDirection` enum member or its string value."""
|
|
80
|
+
if isinstance(value, ViewDirection):
|
|
81
|
+
return
|
|
82
|
+
if isinstance(value, str) and value in _VIEW_DIRECTION_VALUES:
|
|
83
|
+
return
|
|
84
|
+
raise ValueError(
|
|
85
|
+
f"view_direction must be one of {sorted(_VIEW_DIRECTION_VALUES)}, "
|
|
86
|
+
f"got {value!r}"
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def validate_size(value: int) -> None:
|
|
91
|
+
"""Splitter weight: positive integer; bool is rejected."""
|
|
92
|
+
# bool is a subclass of int -- rule that out explicitly so True/False
|
|
93
|
+
# don't masquerade as a valid weight.
|
|
94
|
+
if isinstance(value, bool) or not isinstance(value, int):
|
|
95
|
+
raise ValueError(f"size must be an int, got {type(value).__name__}")
|
|
96
|
+
if value < 1:
|
|
97
|
+
raise ValueError(f"size must be >= 1, got {value}")
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def validate_dimension_key(value: object) -> str:
|
|
101
|
+
"""Coerce a dimension key to its string form; reject non-string keys.
|
|
102
|
+
|
|
103
|
+
Free-form strings are accepted (forward-compat for v3 dimensions); the
|
|
104
|
+
caller cross-checks the v2-required `selection` key separately.
|
|
105
|
+
"""
|
|
106
|
+
if isinstance(value, LinkDimension):
|
|
107
|
+
return value.value
|
|
108
|
+
if isinstance(value, str):
|
|
109
|
+
if len(value) < 1:
|
|
110
|
+
raise ValueError("link dimension key must be a non-empty string")
|
|
111
|
+
return value
|
|
112
|
+
raise ValueError(
|
|
113
|
+
f"link dimension key must be LinkDimension or str, got {type(value).__name__}"
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def validate_layout_version(value: str) -> None:
|
|
118
|
+
"""The DSL targets a single schema version; anything else is rejected."""
|
|
119
|
+
if value != LAYOUT_VERSION:
|
|
120
|
+
raise ValueError(
|
|
121
|
+
f"DSL targets version {LAYOUT_VERSION!r}; document is version {value!r}"
|
|
122
|
+
)
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
"""Vocabulary for the `mitk.mxn.layout` DSL.
|
|
14
|
+
|
|
15
|
+
Enums, constants, and regex patterns mirroring the v2.0 schema
|
|
16
|
+
(`Modules/QtWidgets/resource/mxn-layout-v2.schema.json`). The whole package
|
|
17
|
+
imports from here so the schema-derived strings live in exactly one place.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
from enum import Enum
|
|
23
|
+
from typing import Final
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
LAYOUT_VERSION: Final[str] = "2.0"
|
|
27
|
+
DEFAULT_GROUP_NAME: Final[str] = "main"
|
|
28
|
+
DEFAULT_EDITOR_NAME: Final[str] = "mxn"
|
|
29
|
+
NAMESPACE_DELIMITER: Final[str] = "__"
|
|
30
|
+
|
|
31
|
+
# Mirror of the schema's `window.id` pattern (qualified form).
|
|
32
|
+
WINDOW_ID_PATTERN: Final[str] = r"^[A-Za-z][A-Za-z0-9.-]*__[A-Za-z0-9_.-]+$"
|
|
33
|
+
|
|
34
|
+
# Mirror of the schema's `groups.propertyNames.pattern` and the `links.selection.pattern`.
|
|
35
|
+
GROUP_NAME_PATTERN: Final[str] = r"^[A-Za-z0-9_.-]+$"
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class LinkDimension(str, Enum):
|
|
39
|
+
"""Synchronization dimension keys recognised by the v2.0 schema.
|
|
40
|
+
|
|
41
|
+
v2.0 knows only SELECTION. v3.0 will additively introduce ZOOM, TIME,
|
|
42
|
+
CROSSHAIR, etc. APIs that take a dimension accept ``LinkDimension`` or a
|
|
43
|
+
plain ``str`` so callers can pass forward-compat strings before the enum
|
|
44
|
+
is updated.
|
|
45
|
+
"""
|
|
46
|
+
|
|
47
|
+
SELECTION = "selection"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class ViewDirection(str, Enum):
|
|
51
|
+
"""Anatomical plane shown in a render window. Lowercase string values
|
|
52
|
+
matching the schema's `view_direction` enum and the rest of the
|
|
53
|
+
rendering REST surface.
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
AXIAL = "axial"
|
|
57
|
+
SAGITTAL = "sagittal"
|
|
58
|
+
CORONAL = "coronal"
|
|
59
|
+
ORIGINAL = "original"
|