Skip to content

Project Save / Load (functions/saves.py)

functions/saves.py implements project save / load: it serializes the text boxes, formula views, combo boxes, function list, equation / inequality / vector lists, cache, plane / solid geometry objects and the Blockly workspace of every tab into JSON.

Function Description
savefile(main_class) Opens a save dialog and writes the current project to a JSON file
openfile(main_class) Opens a load dialog, reads the JSON file and restores the project

Both receive the main window instance main_class (a QMainWindow):

  • savefile walks the tabs of main_class.tabs and collects their text boxes / combo boxes / formula views, together with fs (function dict), eqs (equation list), rels (inequality list), vs (vector list), pjs / ljs (plane / solid geometry objects), cache (rendered cache) and similar attributes, then writes them to the chosen JSON file;
  • openfile reads the JSON, rebuilds the tabs, restores texts / views / combo selections, refreshes the formula rendering and geometry plots, and stays compatible with older save formats through _fix_old_format / _fix_old_format_3d.
from functions.saves import savefile, openfile

# call on a MainWindow instance
savefile(self)     # save
openfile(self)     # load

Warning

Loading rebuilds the tabs and overwrites the current text / view / combo contents; a corrupted save file raises a warning and leaves the current state untouched. The "Save / Open" menu entries call these two functions.