feat(sdk): context lifecycle callbacks — on_context_enter / on_context_exit #381

Open
opened 2026-03-03 23:01:58 +00:00 by forbes · 0 comments
Owner

Summary

Add declarative lifecycle hooks so addons can react to context transitions without connecting to raw FreeCAD signals.

Current state (PARTIAL)

contextChanged signal exists in C++ (EditingContextResolver) and is exposed to Python via kcsdk pybind11 bindings. However:

  • No on_context_enter() / on_context_exit() hooks for addons
  • No enter/exit distinction — only a single state-change notification
  • Addons must connect to raw signals and re-derive context themselves

Proposed API

import kindred_sdk as sdk

sdk.on_context_enter("sketcher.edit", my_setup_callback)
sdk.on_context_exit("sketcher.edit", my_teardown_callback)
sdk.on_context_enter("*", my_global_callback)  # wildcard

Callbacks receive the full EditingContext snapshot (id, label, color, toolbars, breadcrumb).

Implementation notes

  • Build on top of existing contextChanged signal
  • SDK layer tracks previous context to derive enter/exit events
  • Add on_context_enter(), on_context_exit() to kindred_sdk/context.py
  • Wildcard "*" form for addons that need global awareness

Roadmap

v0.2.0 — SDK Core

## Summary Add declarative lifecycle hooks so addons can react to context transitions without connecting to raw FreeCAD signals. ## Current state (PARTIAL) `contextChanged` signal exists in C++ (`EditingContextResolver`) and is exposed to Python via kcsdk pybind11 bindings. However: - No `on_context_enter()` / `on_context_exit()` hooks for addons - No enter/exit distinction — only a single state-change notification - Addons must connect to raw signals and re-derive context themselves ## Proposed API ```python import kindred_sdk as sdk sdk.on_context_enter("sketcher.edit", my_setup_callback) sdk.on_context_exit("sketcher.edit", my_teardown_callback) sdk.on_context_enter("*", my_global_callback) # wildcard ``` Callbacks receive the full `EditingContext` snapshot (id, label, color, toolbars, breadcrumb). ## Implementation notes - Build on top of existing `contextChanged` signal - SDK layer tracks previous context to derive enter/exit events - Add `on_context_enter()`, `on_context_exit()` to `kindred_sdk/context.py` - Wildcard `"*"` form for addons that need global awareness ## Roadmap v0.2.0 — SDK Core
forbes added the enhancement label 2026-03-03 23:01:58 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: kindred/create#381