38 lines
1.1 KiB
Python
38 lines
1.1 KiB
Python
"""Toolbar provider registration.
|
|
|
|
Wraps the C++ ``kcsdk.register_toolbar()`` API with a Python fallback
|
|
that extracts toolbar data and calls ``inject_commands()`` directly.
|
|
"""
|
|
|
|
|
|
def _kcsdk_available():
|
|
"""Return the kcsdk module if available, else None."""
|
|
try:
|
|
import kcsdk
|
|
|
|
return kcsdk
|
|
except ImportError:
|
|
return None
|
|
|
|
|
|
def register_toolbar(provider):
|
|
"""Register a toolbar provider for automatic context injection.
|
|
|
|
When the C++ ``kcsdk`` module is available, delegates to its
|
|
``register_toolbar()`` which stores the provider and auto-injects
|
|
commands into the target editing contexts.
|
|
|
|
Falls back to extracting data from the provider and calling
|
|
``inject_commands()`` directly for each target context.
|
|
"""
|
|
kcsdk = _kcsdk_available()
|
|
if kcsdk is not None:
|
|
kcsdk.register_toolbar(provider)
|
|
return
|
|
|
|
# Fallback: extract data and call inject_commands directly
|
|
from kindred_sdk import inject_commands
|
|
|
|
for ctx_id in provider.context_ids():
|
|
inject_commands(ctx_id, provider.toolbar_name(), provider.commands())
|