Files
create/mods/sdk/kindred_sdk/statusbar.py
forbes ab8519c272
All checks were successful
Build and Test / build (pull_request) Successful in 29m13s
feat(sdk): add status bar widget wrapper and origin query bindings (#356)
register_status_widget(): pure Python wrapper that adds a live widget
to the main window status bar with context menu discoverability.

Origin query bindings (kcsdk.list_origins, active_origin, get_origin,
set_active_origin): thin C++ forwarding to OriginManager with Python
wrappers using kcsdk-first routing.

IOriginProvider and IStatusBarProvider C++ interfaces dropped — existing
FileOrigin stack is already complete, and status bar widgets don't need
C++ lifecycle management.
2026-03-01 14:13:31 -06:00

75 lines
2.5 KiB
Python

"""Status bar widget registration wrapper.
Provides a standardized SDK entry point for adding widgets to the main
window's status bar. This is a pure Python wrapper — no C++ interface
is needed since the widget is created once and Qt manages its lifecycle.
"""
import FreeCAD
def register_status_widget(object_name, label, widget, position="right"):
"""Add a widget to the main window status bar.
Parameters
----------
object_name : str
Qt object name for duplicate prevention.
label : str
Display name shown in the status bar's right-click context menu
(becomes the widget's ``windowTitle``).
widget : QWidget
The widget instance to add. The caller keeps its own reference
for live updates (e.g. connecting signals, updating text).
position : str, optional
``"left"`` (stretches) or ``"right"`` (permanent, fixed width).
Default ``"right"``.
"""
if not isinstance(object_name, str) or not object_name:
raise TypeError("object_name must be a non-empty string")
if not isinstance(label, str) or not label:
raise TypeError("label must be a non-empty string")
if position not in ("left", "right"):
raise ValueError(f"position must be 'left' or 'right', got {position!r}")
try:
import FreeCADGui
from PySide import QtWidgets
mw = FreeCADGui.getMainWindow()
if mw is None:
FreeCAD.Console.PrintWarning(
"kindred_sdk: Main window not available, "
f"cannot register status widget '{object_name}'\n"
)
return
sb = mw.statusBar()
# Duplicate check
for child in sb.children():
if (
isinstance(child, QtWidgets.QWidget)
and child.objectName() == object_name
):
FreeCAD.Console.PrintLog(
f"kindred_sdk: Status widget '{object_name}' already exists, skipping\n"
)
return
widget.setObjectName(object_name)
widget.setWindowTitle(label)
if position == "left":
sb.addWidget(widget)
else:
sb.addPermanentWidget(widget)
FreeCAD.Console.PrintLog(
f"kindred_sdk: Registered status widget '{object_name}'\n"
)
except Exception as e:
FreeCAD.Console.PrintWarning(
f"kindred_sdk: Failed to register status widget '{object_name}': {e}\n"
)