feat(sdk): add context lifecycle callbacks (#381) #399
Reference in New Issue
Block a user
Delete Branch "feat/sdk-lifecycle-callbacks"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Expose
EditingContextResolver::contextChangedto Python addons via a two-layer design, enabling addons to declaratively react to context transitions without connecting to raw FreeCAD signals.Changes
C++ layer (
src/Gui/SDK/)onContextChanged(callback)method that storesstd::functioncallbacks and lazily connects to the QtcontextChangedsignal on first registration. Thread-safe callback iteration with mutex-guarded snapshot.kcsdk.on_context_changed(callback)pybind11 binding that wraps Python callables with GIL-safe invocation anderror_already_sethandling.Python layer (
mods/sdk/kindred_sdk/)on_context_enter(context_id, callback)— subscribe to context activation ("*"wildcard supported)on_context_exit(context_id, callback)— subscribe to context deactivationcontext.enter/context.exiton the SDK event bus (#382)kcsdkC++ module unavailableon_context_enter,on_context_exit_init_lifecycle()during SDK GUI initUsage
Verification
ninja -C build/debug KCSDK— compiles clean (776/776 targets)Closes #381
Expose EditingContextResolver::contextChanged to Python addons via two-layer design: C++ layer: - SDKRegistry::onContextChanged() stores callbacks and lazily connects to the Qt signal on first registration - pybind11 binding kcsdk.on_context_changed() wraps Python callables with GIL-safe invocation Python layer: - kindred_sdk.on_context_enter(context_id, callback) subscribes to context activation ("*" wildcard supported) - kindred_sdk.on_context_exit(context_id, callback) subscribes to context deactivation - Internal tracking of previous context derives enter/exit transitions - Emits context.enter / context.exit on the SDK event bus Closes #381