Some checks failed
Build and Test / build (pull_request) Failing after 1m40s
Add mods/sdk/ with the kindred_sdk Python package providing a stable API layer for addon integration with Kindred Create platform features. Modules: - context: editing context/overlay registration wrappers - theme: YAML-driven palette system (Catppuccin Mocha) - origin: FileOrigin registration helpers - dock: deferred dock panel registration - compat: version detection utilities The SDK loads at priority 0 (before all other addons) via the existing manifest-driven loader. Theme colors are defined in a single YAML palette file instead of hardcoded Python dicts, enabling future theme support and eliminating color duplication across addons. Closes #249
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
"""FileOrigin registration wrappers.
|
|
|
|
Wraps ``FreeCADGui.addOrigin()`` / ``removeOrigin()`` with validation
|
|
and error handling. Addons implement the FileOrigin duck-typed
|
|
interface directly (see Silo's ``SiloOrigin`` for the full contract).
|
|
"""
|
|
|
|
import FreeCAD
|
|
|
|
_REQUIRED_METHODS = ("id", "name", "type", "ownsDocument")
|
|
|
|
|
|
def _gui():
|
|
import FreeCADGui
|
|
|
|
return FreeCADGui
|
|
|
|
|
|
def register_origin(origin):
|
|
"""Register a FileOrigin with FreeCADGui.
|
|
|
|
*origin* must be a Python object implementing at least ``id()``,
|
|
``name()``, ``type()``, and ``ownsDocument(doc)`` methods.
|
|
"""
|
|
missing = [m for m in _REQUIRED_METHODS if not hasattr(origin, m)]
|
|
if missing:
|
|
raise TypeError(f"origin is missing required methods: {', '.join(missing)}")
|
|
|
|
try:
|
|
_gui().addOrigin(origin)
|
|
FreeCAD.Console.PrintLog(f"kindred_sdk: Registered origin '{origin.id()}'\n")
|
|
except Exception as e:
|
|
FreeCAD.Console.PrintWarning(f"kindred_sdk: Failed to register origin: {e}\n")
|
|
|
|
|
|
def unregister_origin(origin):
|
|
"""Remove a previously registered FileOrigin."""
|
|
try:
|
|
_gui().removeOrigin(origin)
|
|
FreeCAD.Console.PrintLog(f"kindred_sdk: Unregistered origin '{origin.id()}'\n")
|
|
except Exception as e:
|
|
FreeCAD.Console.PrintWarning(f"kindred_sdk: Failed to unregister origin: {e}\n")
|