stratified_packager.gui.widgets
Reusable scope-editor widgets and field tables for the defaults GUI (SPEC §19).
Three scopes edit the same families of value: the plugin settings (concrete base
values), the project variables and the per-layer variables. The project fields
are inheritance-aware — an empty editor means “inherit the effective value from the next
tier of the SPEC §5 chain”, with that inherited value shown as an inherit (= X)
placeholder. The layer fields have no higher tier to inherit from (only their builtin
default), so with inheriting=False the same editors present the unset state plainly
instead: 2-state booleans as checkboxes (checked = true, unchecked = unset), a
sentinel-labelled combo for the tri-state ones, and plain placeholders. Plugin-scope fields
are concrete (the base of the chain, always a real value).
Three shared field tables (default_fields(), project_only_fields(),
layer_fields()) drive every page, so the GUI stays in step with the
parameter/variable schema. Editors are built programmatically from those tables; the host
pages supply the .ui skeleton.
Module Attributes
|
|
|
|
|
|
Per-layer matching-method combo labels keyed by SPEC §4 token ( |
|
Any scope editor; all expose |
|
Key of the stratification-layer project-only field (its project-variable suffix). |
|
Key of the stratum-name-expression project-only field (its project-variable suffix). |
Functions
|
Write explicit values to target, removing keys whose value is |
|
Read a concrete editor's value as its stored string token. |
Return the settings-backed default fields (the ✓ rows of SPEC §3, in table order). |
|
|
Format the placeholder shown by an empty (inheriting) editor. |
Return the per-layer variable fields (SPEC §4, in table order). |
|
|
Build the concrete editor for spec (plugin-settings scope). |
|
Build the scope editor for spec (project or layer scope). |
Return the project-only default fields (the SPEC §3 inputs with a variable but no setting). |
|
|
Set a concrete editor's value from its stored string token. |
Classes
|
How a field's value is edited and coerced (SPEC §3/§4 value types). |
|
One editable field on a defaults page (one §3 setting or §4 layer variable). |
|
A default-aware 2-state boolean editor whose unset state mirrors the builtin default. |
|
A checkable multi-select whose empty (nothing-checked) state means inherit. |
|
A combo whose "inherit" choice (or empty edit text) means inherit. |
|
An expression line edit whose empty state means "unset" (project-only rows). |
|
A multi-select of the layer's field names whose value is a JSON list. |
|
A form of inheritance-aware editors for a set of fields (project/layer scope). |
|
A project-layer combo whose labeled empty row means "unset" (project-only rows). |
|
A line edit whose empty state means "inherit". |
|
Spatial-predicate editor: checkable named predicates + a validated DE-9IM free-text row. |
|
A range-bound integer spin box whose below-range value means "inherit". |
- class stratified_packager.gui.widgets.FieldKind(*values)[source]
How a field’s value is edited and coerced (SPEC §3/§4 value types).
- BOOL = 'bool'
Boolean, stored as the tokens
true/false.
- ENUM = 'enum'
One of a fixed token set.
- EXPRESSION = 'expression'
A QGIS expression string, edited with the expression-builder line edit (the project-only §3 fields; empty = unset).
- FIELDS = 'fields'
Multi-select of the layer’s own field names, stored as a JSON list (SPEC §4).
- INT = 'int'
Non-negative integer.
- LAYER = 'layer'
A project vector layer, stored as its layer id (the project-only §3 fields).
- MULTI_ENUM = 'multi_enum'
Any subset of a fixed token set, stored as comma-separated tokens.
- PREDICATES = 'predicates'
Checkable named spatial predicates plus a validated free-text DE-9IM row (SPEC §4).
- STRING = 'string'
Free text (also expressions and JSON lists).
- class stratified_packager.gui.widgets.FieldSpec(key, label, kind, choices=(), labeled_choices=(), max_value=9, placeholder='', tristate=False, default_true=False)[source]
One editable field on a defaults page (one §3 setting or §4 layer variable).
- Parameters:
- __init__(key, label, kind, choices=(), labeled_choices=(), max_value=9, placeholder='', tristate=False, default_true=False)
- choices: tuple[str, ...] = ()
Allowed tokens for
FieldKind.ENUM.
- default_true: bool = False
The builtin default of a 2-state
FieldKind.BOOLfield. Only consulted for a non-inheriting field rendered as anOverrideCheckBox: whenTruethe checkbox renders inverted (checked by default = unset, unchecking = explicitfalse), so the sole meaningful override of a True-default variable stays expressible.
- key: str
Storage key: always the bare variable/setting suffix (e.g.
compression_level,exclude) — a validStratifiedPackagerSettingsattribute name for the ✓ inputs. The fullstratified_packager_<key>variable name isvariable.
- labeled_choices: tuple[tuple[str, str], ...] = ()
(label, token)pairs forFieldKind.MULTI_ENUM(label shown, token stored).
- max_value: int = 9
Upper bound for
FieldKind.INTeditors (lower bound is always 0).
- placeholder: str = ''
Plain placeholder shown for the unset state in non-inheriting (layer) scope, and the sentinel item’s label for a non-inheriting combo (e.g.
auto). Ignored when the form is inheriting (the Project Properties page shows aninherit (= X)placeholder instead).
- tristate: bool = False
Whether a
FieldKind.BOOLfield is genuinely tri-state (true/false/unset, likestage). In non-inheriting scope such a field renders as a sentinel-labelled combo rather than a 2-state checkbox, so the explicitfalse(force-off) state stays expressible.
- property variable: str
The full project/layer variable name backing this field.
keyis always the bare suffix (a settings attribute name for the ✓ inputs); this prepends thestratified_packager_prefix in exactly one place, so a host never hand-builds the variable name.- Returns:
stratified_packager_<key>.
- class stratified_packager.gui.widgets.OverrideCheckBox(default_value=False, parent=None)[source]
A default-aware 2-state boolean editor whose unset state mirrors the builtin default.
Used in non-inheriting (layer) scope, where a boolean variable has no higher tier to inherit from — only a builtin default that applies while the variable is unset. The box’s checked state mirrors the effective boolean, so an unset field rests on its default; an override is stored only when the box differs from that default. With a
Falsedefault (the common case) that means checked =trueand unchecked = unset; with aTruedefault it inverts — checked = unset and unchecking = explicitfalse— keeping the sole meaningful override of a True-default variable expressible. Tri-state booleans (stage) use a sentinel combo instead, so all three oftrue/false/unset stay distinct.- Parameters:
default_value (bool)
parent (QWidget | None)
- __init__(default_value=False, parent=None)[source]
Build the checkbox resting on its builtin default (so an unset field shows that state).
- Parameters:
default_value (bool) – The field’s builtin default; the box starts in this state and reads back as unset whenever it matches it.
parent (QWidget | None) – Optional parent widget.
- scope_value()[source]
Return the explicit override, or
None(unset) when the box matches the default.
- class stratified_packager.gui.widgets.OverrideCheckableCombo(choices, parent=None)[source]
A checkable multi-select whose empty (nothing-checked) state means inherit.
- Parameters:
choices (Sequence[tuple[str, str]])
parent (QWidget | None)
- __init__(choices, parent=None)[source]
Build the checkable combo with choices (all unchecked = inherit).
- Parameters:
choices (Sequence[tuple[str, str]]) –
(label, token)pairs in display order.parent (QWidget | None) – Optional parent widget.
- class stratified_packager.gui.widgets.OverrideComboBox(choices, *, sentinel_label=None, parent=None)[source]
A combo whose “inherit” choice (or empty edit text) means inherit.
- Parameters:
choices (Sequence[tuple[str, str]])
sentinel_label (str | None)
parent (QWidget | None)
- __init__(choices, *, sentinel_label=None, parent=None)[source]
Build the combo with an unset affordance plus choices.
- Parameters:
choices (Sequence[tuple[str, str]]) –
(label, token)pairs in display order.sentinel_label (str | None) – Fixed label for the unset/sentinel item (data
None), used by non-inheriting (layer) scope, e.g.auto. WhenNonethe item shows the inheritinginherit (= X)placeholder instead (set viaset_effective()).parent (QWidget | None) – Optional parent widget.
- class stratified_packager.gui.widgets.OverrideExpressionEdit(parent=None)[source]
An expression line edit whose empty state means “unset” (project-only rows).
- Parameters:
parent (QWidget | None)
- __init__(parent=None)[source]
Initialize the editor.
- Parameters:
parent (QWidget | None) – Optional parent widget.
- set_context_layer(layer)[source]
Give the expression builder layer’s fields as context (a non-vector layer clears it).
- Parameters:
layer (QgsMapLayer | None) – The layer to take fields from, or
Noneto clear.- Return type:
None
- class stratified_packager.gui.widgets.OverrideFieldsCombo(field_names, parent=None)[source]
A multi-select of the layer’s field names whose value is a JSON list.
Like
OverrideCheckableCombo(nothing checked = inherit) but the checked names are serialised as a JSON list rather than CSV, because field names may contain commas and the matching engine readsexcluded_fieldsas JSON. The only inheritable value is the builtin[](exclude nothing), so the empty state simply readsinherit.- Parameters:
field_names (Sequence[str])
parent (QWidget | None)
- __init__(field_names, parent=None)[source]
Build the combo with one checkable item per field name (all unchecked = inherit).
- Parameters:
field_names (Sequence[str]) – The layer’s field names, in display order.
parent (QWidget | None) – Optional parent widget.
- scope_value()[source]
Return the checked field names as a JSON list, or
Nonewhen nothing is checked.
- set_effective(effective)[source]
Show the inherited (always-empty) state as the no-selection placeholder.
- class stratified_packager.gui.widgets.OverrideForm(fields, *, inheriting=True)[source]
A form of inheritance-aware editors for a set of fields (project/layer scope).
Builds one labelled editor per
FieldSpecinto a caller-suppliedQFormLayout, then loads/dumps the explicit values keyed by field key. Used by the Project Properties page and the per-layer page so the inherit-vs-override behaviour lives in one place.- __init__(fields, *, inheriting=True)[source]
Initialize the form for fields (call
build()to create the editors).
- build(form_layout, parent=None, field_names=())[source]
Create the editors and add them as labelled rows to form_layout.
- Parameters:
form_layout (QFormLayout) – The layout to populate (one row per field).
parent (QObject | None) – Optional parent for the editors.
field_names (Sequence[str]) – The host layer’s field names, forwarded to any
FieldKind.FIELDSeditor; ignored for every other kind.
- Return type:
None
- dump()[source]
Read the explicit value of every field, keyed by its bare
FieldSpec.key.
- dump_variables()[source]
Read the explicit value of every field, keyed by its full variable name.
The single place the
stratified_packager_prefix is applied on write, so a host never hand-builds variable names fromdump()keys.
- editor(key)[source]
Return one field’s editor (e.g. to wire cross-field signals).
- Parameters:
key (
str) – The field key.- Return type:
OverrideLineEdit|OverrideComboBox|OverrideCheckBox|OverrideCheckableCombo|OverrideFieldsCombo|OverridePredicateCombo|OverrideSpinBox|OverrideExpressionEdit|OverrideLayerCombo- Returns:
The field’s scope editor.
- Raises:
KeyError – If key is not a field of this form.
- load(current, effective)[source]
Populate the editors from the current explicit values and inherited values.
- set_enabled(key, *, enabled)[source]
Enable or disable one field’s editor (e.g. gate an inapplicable field).
- class stratified_packager.gui.widgets.OverrideLayerCombo(parent=None)[source]
A project-layer combo whose labeled empty row means “unset” (project-only rows).
Stores the selected layer’s id — the format the runtime resolver feeds to
mapLayer()(SPEC §5). The filter admits geometryless tables, matchingSTRATIFICATION_LAYER’sTypeVector(SPEC §3). A stale/unknown id loads as unset, so applying the page clears it (fail-fast).- Parameters:
parent (QWidget | None)
- __init__(parent=None)[source]
Initialize the combo (vector layers incl. geometryless tables, empty row first).
- Parameters:
parent (QWidget | None) – Optional parent widget.
- class stratified_packager.gui.widgets.OverrideLineEdit(parent=None)[source]
A line edit whose empty state means “inherit”.
- Parameters:
parent (QWidget | None)
- __init__(parent=None)[source]
Initialize the editor.
- Parameters:
parent (QWidget | None) – Optional parent widget.
- class stratified_packager.gui.widgets.OverridePredicateCombo(named, parent=None)[source]
Spatial-predicate editor: checkable named predicates + a validated DE-9IM free-text row.
The named predicates (SPEC §4) are checkable items; the last, non-checkable popup row hosts a line edit for one or more comma-separated DE-9IM patterns, validated live against
DE9IM_PATTERN. The empty state (nothing checked, blank text) means inherit. The value read and written is the comma-joined token list the matching engine parses.- Parameters:
named (Sequence[str])
parent (QWidget | None)
- __init__(named, parent=None)[source]
Build the combo with the named predicates and the DE-9IM row.
- Parameters:
named (Sequence[str]) – The named-predicate tokens, in display order.
parent (QWidget | None) – Optional parent widget.
- _on_de9im_changed(text)[source]
Validate the DE-9IM row live, flagging invalid patterns with a red border.
- _refresh_display()[source]
Mirror the checked names and DE-9IM patterns into the collapsed display bar.
- Return type:
- de9im_row_width_hint()[source]
Return the pixel width needed to show the DE-9IM popup row’s full placeholder.
- Return type:
- Returns:
Width of the
DE-9IM:label plus theDE-9IM pattern(s)…placeholder plus popup chrome, so the column (hence the popup) shows the placeholder in full.
- set_effective(effective)[source]
Show the inherited effective value as the no-selection placeholder.
- set_placeholder(text)[source]
Set the no-selection placeholder text verbatim (non-inheriting scope).
- set_scope_value(value)[source]
Check the named tokens in value and route the remaining tokens to the DE-9IM row.
- class stratified_packager.gui.widgets.OverrideSpinBox(max_value, parent=None)[source]
A range-bound integer spin box whose below-range value means “inherit”.
- Parameters:
max_value (int)
parent (QWidget | None)
- __init__(max_value, parent=None)[source]
Build the spin box over
0..max_valuewith a below-range inherit sentinel.The minimum is
-1(one step below the valid range); resting there shows the inherit placeholder viasetSpecialValueText()and reads back as inherit. The valid override range stays0..max_value.- Parameters:
max_value (int) – The inclusive upper bound (lower bound is always 0).
parent (QWidget | None) – Optional parent widget.
- stratified_packager.gui.widgets._checkable_csv(combo)[source]
Read a checkable combo’s checked tokens as a comma-separated string (item order).
- Parameters:
combo (
QgsCheckableComboBox) – The checkable combo.- Return type:
- Returns:
The checked tokens joined by
,(empty when nothing is checked).
- stratified_packager.gui.widgets._default_field(key, label, kind)[source]
Build one settings-backed field from its parameter-table facts.
- stratified_packager.gui.widgets._populate_checkable(combo, choices)[source]
Add
(label, token)items (initially unchecked) to a checkable combo.
- stratified_packager.gui.widgets._set_checkable_csv(combo, csv)[source]
Check exactly the items whose token appears in csv, unchecking the rest.
- Parameters:
combo (
QgsCheckableComboBox) – The checkable combo.csv (
str) – Comma-separated tokens to check.
- Return type:
- stratified_packager.gui.widgets._unexpected_editor(spec, editor)[source]
Build the message for an editor that does not match its field kind.
- stratified_packager.gui.widgets.apply_overrides(target, values)[source]
Write explicit values to target, removing keys whose value is
None(inherit).Shared by every defaults page so the write-back rule lives in one place.
- stratified_packager.gui.widgets.concrete_value(spec, editor)[source]
Read a concrete editor’s value as its stored string token.
- Parameters:
spec (
FieldSpec) – The field being read.editor (
QWidget) – The editor built bymake_concrete_editor().
- Return type:
- Returns:
The value as a string token (
true/falsefor booleans).- Raises:
TypeError – If editor is not the widget type spec implies.
- stratified_packager.gui.widgets.default_fields()[source]
Return the settings-backed default fields (the ✓ rows of SPEC §3, in table order).
Derived from the parameter table: each
keyis the attribute name onStratifiedPackagerSettings(the input id lowercased) and the suffix of the matchingstratified_packager_<x>project variable; the label is the input’s canonical translated label. A new settings-backed input therefore appears on the Options and Project pages without touching this module.
- stratified_packager.gui.widgets.inherit_placeholder(effective)[source]
Format the placeholder shown by an empty (inheriting) editor.
- stratified_packager.gui.widgets.layer_fields()[source]
Return the per-layer variable fields (SPEC §4, in table order).
Derived from
LAYER_VAR_SPECS: keys, labels and order come from the table; only the presentation (editor kind, choices, placeholders) is decided here. Eachkeyis the layer variable’s bare suffix (as withdefault_fields()); the fullstratified_packager_<x>name isFieldSpec.variable. These variables have no project/plugin tier to inherit from, so the pages build them withinheriting=False(make_override_editor()): theFieldSpec.placeholderis the plain unset affordance,autodoubling as the sentinel-item label for the tri-state fields.
- stratified_packager.gui.widgets.make_concrete_editor(spec, parent=None)[source]
Build the concrete editor for spec (plugin-settings scope).
- Parameters:
spec (FieldSpec) – The field to edit.
parent (QWidget | None) – Optional parent widget.
- Return type:
QWidget
- Returns:
A plain
QCheckBox/QSpinBox/QComboBox/QLineEdit.
- stratified_packager.gui.widgets.make_override_editor(spec, parent=None, field_names=(), *, inheriting=True)[source]
Build the scope editor for spec (project or layer scope).
With
inheriting=True(project scope) the editor surfaces the next-tier value as aninherit (= X)placeholder. Withinheriting=False(layer scope, no tier to inherit from) it presents the unset state plainly: aOverrideCheckBoxfor a 2-state boolean, asentinel_labelcombo for a tri-state boolean or enum, and the field’sFieldSpec.placeholderfor the text/predicate editors.- Parameters:
spec (FieldSpec) – The field to edit.
parent (QWidget | None) – Optional parent widget.
field_names (Sequence[str]) – The host layer’s field names, used to populate a
FieldKind.FIELDSeditor; ignored for every other kind.inheriting (bool) – Whether the field inherits from a higher tier (project scope) or falls back only to its builtin default (layer scope). The project-only
FieldKind.EXPRESSION/FieldKind.LAYERkinds ignore it (no tier below them either way).
- Return type:
ScopeEditor
- Returns:
An
OverrideLineEdit,OverrideComboBox,OverrideCheckBox,OverrideCheckableCombo,OverrideFieldsCombo,OverridePredicateCombo,OverrideSpinBox,OverrideExpressionEditorOverrideLayerCombo.
- stratified_packager.gui.widgets.project_only_fields()[source]
Return the project-only default fields (the SPEC §3 inputs with a variable but no setting).
These inputs hold project-dependent values (a layer id, an expression over that layer’s fields), so they have no global plugin-setting tier: the Project Properties page is their only defaults surface. Each
keyis the input’s project-variable suffix (the SPEC §5variable_namerule).
- stratified_packager.gui.widgets.set_concrete_value(spec, editor, value)[source]
Set a concrete editor’s value from its stored string token.
- stratified_packager.gui.widgets.MATCHING_METHOD_LABELS: Final[dict[str, str]] = {'attribute': qgis.PyQt.QtCore.QCoreApplication.translate, 'spatial': qgis.PyQt.QtCore.QCoreApplication.translate, 'whole_export': qgis.PyQt.QtCore.QCoreApplication.translate}
Per-layer matching-method combo labels keyed by SPEC §4 token (
autois the sentinel, not a selectable option).
- stratified_packager.gui.widgets.OVERWRITE_MODE_LABELS: Final[dict[str, str]] = {'error': qgis.PyQt.QtCore.QCoreApplication.translate, 'overwrite': qgis.PyQt.QtCore.QCoreApplication.translate, 'skip-existing': qgis.PyQt.QtCore.QCoreApplication.translate}
OVERWRITE_MODEcombo labels keyed by SPEC §10 token.
- stratified_packager.gui.widgets.PROJECT_FIELD_STRATIFICATION_LAYER: Final = 'stratification_layer'
Key of the stratification-layer project-only field (its project-variable suffix).
- stratified_packager.gui.widgets.PROJECT_FIELD_STRATUM_NAME_EXPRESSION: Final = 'stratum_name_expression'
Key of the stratum-name-expression project-only field (its project-variable suffix).
- stratified_packager.gui.widgets.PROJECT_INCLUSION_LABELS: Final[dict[str, str]] = {'gpkg': qgis.PyQt.QtCore.QCoreApplication.translate, 'none': qgis.PyQt.QtCore.QCoreApplication.translate, 'qgz': qgis.PyQt.QtCore.QCoreApplication.translate}
PROJECT_INCLUSIONcombo labels keyed by SPEC §13 token.
- stratified_packager.gui.widgets.ScopeEditor = stratified_packager.gui.widgets.OverrideLineEdit | stratified_packager.gui.widgets.OverrideComboBox | stratified_packager.gui.widgets.OverrideCheckBox | stratified_packager.gui.widgets.OverrideCheckableCombo | stratified_packager.gui.widgets.OverrideFieldsCombo | stratified_packager.gui.widgets.OverridePredicateCombo | stratified_packager.gui.widgets.OverrideSpinBox | stratified_packager.gui.widgets.OverrideExpressionEdit | stratified_packager.gui.widgets.OverrideLayerCombo
Any scope editor; all expose
scope_value/set_scope_value/set_effectiveand areQWidgetsubclasses.