pygra.state
state.py — save and load application state as JSON
- pygra.state.save_state(path, dataset_widgets, axis_settings, style_settings, annotations=None)[source]
Serialise the full application state to a JSON file.
- Parameters:
path (str) – Destination file path. Created or overwritten.
dataset_widgets (list of DatasetWidget) – All active series panels. Each widget’s dataset data and visual configuration are included in the output.
axis_settings (dict) – Axis labels, title, log-scale flags, and manual axis-limit strings as returned by
MainWindow._get_axis_settings().style_settings (dict) – Global plot style settings (font sizes, grid, theme, DPI, legend).
annotations (list of dict, optional) – Text annotations with keys
"text","x","y","fontsize","color","bold".
- Raises:
OSError – If path cannot be opened for writing.
- pygra.state.load_state(path)[source]
Load application state from a JSON session file.
Reads a file produced by
save_state()and converts each series"data"field from a nested list back to a NumPy array.- Parameters:
path (str) – Path to a
.jsonsession file.- Returns:
State dictionary with keys
"version","series","axis_settings", and"style_settings". The"data"value inside each series entry is a 2-Dnumpy.ndarray.- Return type:
dict
- Raises:
OSError – If path does not exist or cannot be read.
json.JSONDecodeError – If the file is not valid JSON.
KeyError – If the file does not contain a
"series"key.