GUIBRUSHR.core.functions.figure_pickle module

Helpers to persist matplotlib figures for interactive reload in the GUI.

Heavy plots are rendered in headless background subprocesses that only write PNG/PDF to disk, so the live matplotlib Figure never reaches the GUI process. To restore zoom/pan, each subprocess dumps the figure next to its PNG with dump_figure; MyFigure then loads it and embeds an interactive canvas (falling back to the static PNG when the dump is absent or unreadable).

Kept dependency-light (only pickle / os) so subprocesses can import it without pulling in the Tk backend.

GUIBRUSHR.core.functions.figure_pickle.figpkl_path(png_path) str[source]

Return the figpkl path that sits next to png_path.

GUIBRUSHR.core.functions.figure_pickle.figs_path(pdf_path) str[source]

Return the multi-figure pickle path for a PDF (.pdf -> .figs.pkl).

GUIBRUSHR.core.functions.figure_pickle.dump_figure(fig, png_path) None[source]

Pickle a matplotlib Figure next to its PNG for interactive reload.

Best-effort: any failure (an unpicklable figure, a read-only folder) is swallowed so it can never break the PNG/PDF generation that callers rely on.

Parameters:
  • fig – The matplotlib Figure to persist.

  • png_path – Path of the PNG the figure was saved to; the pickle is written alongside it with the .figpkl suffix.

GUIBRUSHR.core.functions.figure_pickle.load_figure(png_path)[source]

Load a pickled figure for png_path if present, else return None.

Best-effort: returns None on a missing file or any unpickling error so the caller can fall back to the static image.

GUIBRUSHR.core.functions.figure_pickle.save_figure_blobs(blobs, pdf_path) None[source]

Persist a list of already-pickled figure byte-blobs next to a PDF.

The on-disk .figs.pkl format is a list of pickle.dumps(figure) blobs. Storing bytes (rather than live figures) is deliberate: unpickling a figure re-registers it with pyplot’s figure manager, so a retained live copy would be wiped by a later plt.clf() in the page-producing code. Bytes captured at draw time are an immutable snapshot, immune to that.

Best-effort: any failure is swallowed so it can never break the PDF.

GUIBRUSHR.core.functions.figure_pickle.dump_figures(figures, pdf_path) None[source]

Serialize each figure to bytes immediately, then persist the blob list.

Convenience for callers holding stable live figures. Each figure is pickled to bytes right away (see save_figure_blobs for why bytes).

GUIBRUSHR.core.functions.figure_pickle.load_figures(pdf_path)[source]

Load the figures for pdf_path (unpickling each blob), else None.

Best-effort: returns None on a missing file or any unpickling error so the caller can fall back to the static PDF viewer.