Architecture
CalculusCalculator uses a layered design that separates pure computation from the GUI, so the calculation logic is decoupled from the interface — making it easy to test and extend.
Directory Layout
CalculusCalculator/
├── run.py # Entry point: splash, language/theme init, main window
├── core/ # UI-independent foundation
│ ├── sympify.py # String → SymPy expression (unified input standard)
│ ├── render.py # LaTeX → SVG formula rendering (QGraphicsView)
│ ├── settings.py # Persisted settings: language, theme, onboarding flag
│ └── webengine.py # Lazy QWebEngine pre-initialization (kernel started on first Blockly editor / formula dialog open)
├── functions/ # Pure computation modules (no Qt dependency)
│ ├── derivative.py # Differentiation
│ ├── integral.py # Integration
│ ├── functions.py # Expression transformation
│ ├── simplification.py
│ ├── solvers.py # Equations / inequalities / differential equations
│ ├── planes.py # Plane geometry
│ ├── solids.py # Solid geometry
│ ├── paint2D.py / paint3D.py # Plotting
│ └── saves.py # Save / load
├── ui/ # PySide6 UI layer
│ ├── main.py # MainWindow
│ ├── __init__.py # Tab registry (lazy loading)
│ ├── functions.py # All-in-One page (Define / Compute / Plot areas)
│ └── <pinyin>.py # Remaining pages (e.g. shouye.py = Home, shezhi.py = Settings)
├── math_input/ # Visual formula input (MathLive editor)
├── blockly/ # Visual block-based computation editor (v2.0.0)
├── expr_calculator/ # Expression Calculator: expression canvas (v2.2.0)
│ ├── expr_tree.py # Expression tree, LaTeX printer and SymPy conversion (no Qt)
│ └── expr_viewer.py # Canvas window, MathJax page and operation dialogs
├── i18n/ # Translation sources .ts and compiled .qm
└── docs/ # This help site (mkdocs, zh / en)
Layer Responsibilities
- Entry layer
run.py: configures Qt, loads language, shows the splash screen (with staged startup profiling, disable viaCALC_BOOT_PROFILE=0), builds the main window, and shows the onboarding guide on first launch. QWebEngine is no longer pre-initialized at startup; instead the kernel process is lazily started bycore/webengine.pywhen the Blockly editor or the formula input dialog is opened for the first time. - Core layer
core/: provides three UI-independent services — input parsing, formula rendering, and settings persistence. Every feature page relies oncore.sympifyto parse input andcore.renderto render results. - Computation layer
functions/: each module exposes pure functions (SymPy expressions / parameters in, SymPy objects or strings out) with no Qt dependency, enabling standalone unit tests. - UI layer
ui/: each tab is aQWidgetsubclass. Since v2.1.0 there are 6 kinds of tabs (Home / Help / Settings / Cache / Blockly Editor / All-in-One); the former standalone feature tabs have been merged into the All-in-One page. v2.2.0 adds the "Expression Calculator" tab, for 7 kinds in total.ui/__init__.pykeeps a "tab registry" and useslazy_loaderso a module is imported only when its tab is first created, speeding up startup. - Visual input
math_input//blockly/: provide structured formula input and block-based flow editing respectively; both ultimately produce a standard SymPy expression that is handed to the computation layer. - Expression Calculator
expr_calculator/:expr_tree.pyonly converts between SymPy, the custom expression tree and LaTeX, without depending on Qt;expr_viewer.pyrenders the tree into aQWebEngineView(bundled MathJax) and reports canvas clicks, drags and transforms back to Python throughQWebChannel.ui/expr.pyis a thin tab wrapper that forwardsretranslateUiso the canvas follows language switches. - Unified input tables: the definition area and calculation area of
ui/functions.pyshare one table engine. Each type is described by a_Specwhoserowsyields "row title + default + role" for the current values;_InputTablebuilds the widgets from it, caches values per selection combination, and handles the interactions. Plane / solid geometry is simply a spec with "two dropdowns and parameter rows that follow the creation method"; its method tables (PLANE_GEOMETRY/SOLID_GEOMETRY) map one-to-one onto the constructors infunctions/planes.pyandfunctions/solids.py, so a new creation method only needs one extra row in the table. - Drawing area: the drawing area on the All-in-One page takes the geometry objects already defined in
parent.pjs/parent.ljs(or the functions inparent.fsin Function mode), callsfunctions/paint2D.py/functions/paint3D.pyto build the chart, and embeds a matplotlib canvas with the navigation toolbar.
Data Flow
User input → core.sympify.sympify() → SymPy expression
→ functions.<module>.<func>() → SymPy result
→ core.render.setGraphicsView() → SVG
→ QGraphicsView (live LaTeX rendering)
Tab Registry
_tab_registry, tabs_dict, and tabs_list in ui/__init__.py are the single source of truth mapping "feature page ↔ tab". A new feature must be registered in all three places (see Adding a Feature Tab).
Tip
For the public functions of each module, see the API Reference.