mitk.mxn.layout.MxNLayoutDocument#
- class mitk.mxn.layout.MxNLayoutDocument(root, name=None, version='2.0')#
Bases:
objectA complete MxN layout document. In-memory documents are always strict:
groupscovers every label any window references.- __init__(root, name=None, version='2.0')#
Methods
__init__(root[, name, version])create(root, *[, name, groups, version])Primary constructor.
find_window(id)Return the leaf window with the given id, or
Noneif the document does not contain one.from_json(doc)Parse a v2.0 JSON document.
to_json()Emit a strict-mode v2.0 JSON document with stable key ordering.
validate()Run cross-document checks on
self.Pre-order list of window ids (the routing identities).
windows()Pre-order iterator over every leaf window in the document.
with_default_ids(*[, editor_name, ...])Re-number all leaves in pre-order to qualified form.
Attributes
Read-only
Mappingview; mutations to the returned object do not affect the document.Entry point for the fluent
MxNWindowSelectorfilter and bulk-transform API.- __eq__(other)#
Return self==value.
- classmethod create(root, *, name=None, groups=None, version='2.0')#
Primary constructor. Always materialises a strict-mode document.
- Parameters:
root (
Split) – Tree root. Always a Split (matches schema).groups (
Mapping[str,Group] |Iterable[Group] |None) – Group registry.Mapping[str, Group](key must equalGroup.name),Iterable[Group](uniqueness enforced), orNoneto auto-materialise: every label referenced in any window’slinksbecomes aGroupwith property defaults.version (str)
- Return type:
- find_window(id)#
Return the leaf window with the given id, or
Noneif the document does not contain one.- Return type:
- Parameters:
id (str)
- classmethod from_json(doc)#
Parse a v2.0 JSON document.
Accepts either a parsed mapping or a JSON-string. Up-front version check raises
ValueErrorbefore any structural parsing when the document’sversionis notLAYOUT_VERSION. Lazy-mode input (no top-levelgroups) is materialised to strict eagerly during parse – the in-memory document never represents lazy state.- Return type:
- Parameters:
- property groups: Mapping[str, Group]#
Read-only
Mappingview; mutations to the returned object do not affect the document.
- property select_windows: MxNWindowSelector[MxNLayoutDocument]#
Entry point for the fluent
MxNWindowSelectorfilter and bulk-transform API. Selector terminals return a freshMxNLayoutDocument(the original is left untouched).
- to_json()#
Emit a strict-mode v2.0 JSON document with stable key ordering.
Key order follows the schema’s example ordering: - top-level:
version,name?,groups,root- per window:type,id,name?,view_direction,links,size- per split:type,orientation,children,size?sizeon the document root is always omitted (no parent splitter).
- validate()#
Run cross-document checks on
self.Raises
ValueErrorwith a message that names the offending element. Per-window structural checks are not re-run here – those are enforced once inLayoutWindow.create().- Return type:
- windows()#
Pre-order iterator over every leaf window in the document.
- Return type:
- with_default_ids(*, editor_name='mxn', bare_id_stem='widget', start_index=0)#
Re-number all leaves in pre-order to qualified form.
Produces
f"{editor_name}__{bare_id_stem}{i}"foristarting atstart_index. Display names (.name) are preserved; only ids change.WARNING: same caveat as
LayoutWindow.with_id()– re-numbering an already-published document invalidates persisted references. Intended for use on freshly-built or freshly-loaded documents prior to PUT.- Return type:
- Parameters: