feat(sdk): add event bus for inter-addon communication (#382) #398

Merged
forbes merged 1 commits from feat/sdk-event-bus into main 2026-03-04 15:48:19 +00:00
Owner

Closes #382

Summary

Adds a lightweight publish-subscribe event bus so addons can communicate without importing each other directly.

New API

import kindred_sdk as sdk

def handler(data):
    print(f"Document locked: {data}")

sdk.on("silo.document_locked", handler)
sdk.emit("silo.document_locked", {"doc_id": "abc", "user": "forbes"})
sdk.off("silo.document_locked", handler)
  • sdk.on(event, handler) — subscribe (deduplicates)
  • sdk.off(event, handler) — unsubscribe (silent no-op if not found)
  • sdk.emit(event, data) — publish dict payload to all subscribers

Design

  • Pure Python, no kcsdk C++ dependency
  • Synchronous dispatch on Qt main thread
  • Snapshot iteration — safe under re-entrancy (handler emits, self-unsubscribe, handler-adds-handler)
  • Handler exceptions logged via PrintWarning, remaining handlers still fire
  • Follows registry.py / statusbar.py patterns: input validation, defensive defaults, FreeCAD.Console logging

Changes

  • mods/sdk/kindred_sdk/events.py (new) — event bus module
  • mods/sdk/kindred_sdk/__init__.py — import and export emit, on, off
Closes #382 ## Summary Adds a lightweight publish-subscribe event bus so addons can communicate without importing each other directly. ## New API ```python import kindred_sdk as sdk def handler(data): print(f"Document locked: {data}") sdk.on("silo.document_locked", handler) sdk.emit("silo.document_locked", {"doc_id": "abc", "user": "forbes"}) sdk.off("silo.document_locked", handler) ``` - `sdk.on(event, handler)` — subscribe (deduplicates) - `sdk.off(event, handler)` — unsubscribe (silent no-op if not found) - `sdk.emit(event, data)` — publish dict payload to all subscribers ## Design - Pure Python, no kcsdk C++ dependency - Synchronous dispatch on Qt main thread - Snapshot iteration — safe under re-entrancy (handler emits, self-unsubscribe, handler-adds-handler) - Handler exceptions logged via `PrintWarning`, remaining handlers still fire - Follows `registry.py` / `statusbar.py` patterns: input validation, defensive defaults, `FreeCAD.Console` logging ## Changes - **`mods/sdk/kindred_sdk/events.py`** (new) — event bus module - **`mods/sdk/kindred_sdk/__init__.py`** — import and export `emit`, `on`, `off`
forbes added 1 commit 2026-03-04 15:46:07 +00:00
feat(sdk): add event bus for inter-addon communication (#382)
All checks were successful
Build and Test / build (pull_request) Successful in 25m4s
7567054882
New module kindred_sdk/events.py provides lightweight publish-subscribe
so addons can signal each other without direct imports.

New public API:
- sdk.on(event, handler) — subscribe to a named event
- sdk.off(event, handler) — unsubscribe
- sdk.emit(event, data) — publish event with dict payload

Pure Python, synchronous dispatch, snapshot-safe iteration.
Handlers that raise are logged and skipped without breaking the chain.
forbes force-pushed feat/sdk-event-bus from 7567054882 to 54b926a925 2026-03-04 15:47:51 +00:00 Compare
forbes merged commit 9f71d0efe6 into main 2026-03-04 15:48:19 +00:00
forbes deleted branch feat/sdk-event-bus 2026-03-04 15:48:19 +00:00
Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: kindred/create#398