ui_state
anomaly_match_ui.utils.ui_state
¶
Per-user UI state persistence for AnomalyMatch.
Stores small bits of UX state (chooser last-browsed directories, window-level preferences) in a JSON file under the user's home directory. Anything that the user expects to "remember" between notebook sessions but that is not part of the current run's config belongs here.
Schema (schema_version=1):
{
"schema_version": 1,
"last_browsed_dirs": {
"model_chooser": "/path/last/visited",
"source_chooser": "/path/last/visited",
...
},
"normalisation_settings": {
"training_setup": {
"extensions": ["VIS", "NIR-H"],
"settings": {"normalisation_method": 3, "image_size": [150, 150], ...}
}
}
}
Storage location: ~/.config/anomalymatch/ui_state.json. We use
the same path on every platform so the test suite and behaviour stay
cross-platform consistent without pulling in platformdirs for one
small dotfile.
Override location: set ANOMALYMATCH_CONFIG_DIR to point the state
file at a different directory (the same hook the test suite uses to
keep its writes in tmp_path). Useful for portable installs and
for users who prefer a non-default state location.
Failure mode: the helpers swallow any I/O or JSON error and return
None / no-op. Persistence is a UX nicety — a corrupt state file
must never crash the screen build path.
get_last_browsed_dir(purpose)
¶
Return the last directory the user finalised for purpose.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
purpose
|
str
|
A stable key identifying the chooser site (e.g.
|
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The persisted directory path, or |
str | None
|
recorded for purpose yet, or the recorded path no longer |
str | None
|
exists on disk. |
Source code in anomaly_match_ui/utils/ui_state.py
set_last_browsed_dir(purpose, path)
¶
Record path as the last directory the user finalised for purpose.
path may point at a file or a directory; in both cases the parent directory is what gets stored, since that is what the chooser should restore on next open.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
purpose
|
str
|
A stable key identifying the chooser site. |
required |
path
|
str
|
The selection the user just confirmed (file or directory). |
required |
Source code in anomaly_match_ui/utils/ui_state.py
get_normalisation_settings(purpose)
¶
Return the normalisation settings last confirmed for purpose.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
purpose
|
str
|
A stable key identifying the screen (e.g. |
required |
Returns:
| Type | Description |
|---|---|
dict | None
|
|
dict | None
|
func: |
dict | None
|
recorded yet or the stored record does not have that shape. |
dict | None
|
|
dict | None
|
against; a caller must not apply a stored |
dict | None
|
matrix to a source exposing a different set of channels. |
Source code in anomaly_match_ui/utils/ui_state.py
set_normalisation_settings(purpose, settings, extensions)
¶
Record the normalisation settings the user confirmed for purpose.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
purpose
|
str
|
A stable key identifying the screen. |
required |
settings
|
dict
|
Normalisation config dict. Values must already be
JSON-serialisable — run a widget config through
|
required |
extensions
|
list[str]
|
Input-channel names the channel-combination matrix was built against, stored so a later restore can tell whether that matrix still describes the selected source. |
required |