From 64edae4c042a9e53aed6e28b5c9361705871d058 Mon Sep 17 00:00:00 2001 From: forbes-0023 Date: Tue, 17 Feb 2026 08:59:56 -0600 Subject: [PATCH] refactor: migrate ztools and Silo to kindred-addon-sdk (#250) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Route platform API calls through kindred_sdk wrappers: ZTools: - Replace hardcoded MOCHA dict with kindred_sdk.get_theme_tokens() - Add sdk dependency to package.xml Silo: - Replace FreeCADGui.registerEditingOverlay() with kindred_sdk.register_overlay() - Replace FreeCADGui.addOrigin()/removeOrigin() with kindred_sdk wrappers - Replace hardcoded _MOCHA palette subset with kindred_sdk.get_theme_tokens() - Add sdk dependency to package.xml Create module: - Replace dock panel boilerplate with kindred_sdk.register_dock_panel() Behavior is identical before and after — this is a refactor only. Closes #250 --- mods/silo | 2 +- mods/ztools | 2 +- src/Mod/Create/InitGui.py | 86 +++++++++++++++------------------------ 3 files changed, 34 insertions(+), 56 deletions(-) diff --git a/mods/silo b/mods/silo index 7a4ed3550a..d605844cb5 160000 --- a/mods/silo +++ b/mods/silo @@ -1 +1 @@ -Subproject commit 7a4ed3550aea680b6b733753b7d3f32d1878bc4a +Subproject commit d605844cb55ac845fc3ac15a6f30835e8752465b diff --git a/mods/ztools b/mods/ztools index 29ca89e533..55be41e697 160000 --- a/mods/ztools +++ b/mods/ztools @@ -1 +1 @@ -Subproject commit 29ca89e5337428cc4e4a8a5336d3da6f5f78105d +Subproject commit 55be41e6972645e64c4fabba12bab5aafb420966 diff --git a/src/Mod/Create/InitGui.py b/src/Mod/Create/InitGui.py index 8a56b33f33..705dc5d6d6 100644 --- a/src/Mod/Create/InitGui.py +++ b/src/Mod/Create/InitGui.py @@ -55,26 +55,17 @@ def _register_silo_origin(): def _setup_silo_auth_panel(): """Dock the Silo authentication panel in the right-hand side panel.""" try: - from PySide import QtCore, QtWidgets + from kindred_sdk import register_dock_panel - mw = FreeCADGui.getMainWindow() - if mw is None: - return + def _factory(): + import silo_commands - # Don't create duplicate panels - if mw.findChild(QtWidgets.QDockWidget, "SiloDatabaseAuth"): - return + auth = silo_commands.SiloAuthDockWidget() + # Prevent GC of the auth timer by stashing on the widget + auth.widget._auth = auth + return auth.widget - import silo_commands - - auth = silo_commands.SiloAuthDockWidget() - - panel = QtWidgets.QDockWidget("Database Auth", mw) - panel.setObjectName("SiloDatabaseAuth") - panel.setWidget(auth.widget) - # Keep the auth object alive so its QTimer isn't destroyed while running - panel._auth = auth - mw.addDockWidget(QtCore.Qt.RightDockWidgetArea, panel) + register_dock_panel("SiloDatabaseAuth", "Database Auth", _factory) except Exception as e: FreeCAD.Console.PrintLog(f"Create: Silo auth panel skipped: {e}\n") @@ -82,49 +73,36 @@ def _setup_silo_auth_panel(): def _setup_silo_activity_panel(): """Show a dock widget with recent Silo database activity.""" try: - from PySide import QtCore, QtWidgets + from kindred_sdk import register_dock_panel - mw = FreeCADGui.getMainWindow() - if mw is None: - return + def _factory(): + from PySide import QtWidgets - # Don't create duplicate panels - if mw.findChild(QtWidgets.QDockWidget, "SiloDatabaseActivity"): - return + widget = QtWidgets.QWidget() + layout = QtWidgets.QVBoxLayout(widget) + activity_list = QtWidgets.QListWidget() + layout.addWidget(activity_list) - panel = QtWidgets.QDockWidget("Database Activity", mw) - panel.setObjectName("SiloDatabaseActivity") + try: + import silo_commands - widget = QtWidgets.QWidget() - layout = QtWidgets.QVBoxLayout(widget) + items = silo_commands._client.list_items() + if isinstance(items, list): + for item in items[:20]: + pn = item.get("part_number", "") + desc = item.get("description", "") + updated = item.get("updated_at", "") + if updated: + updated = updated[:10] + activity_list.addItem(f"{pn} - {desc} - {updated}") + if activity_list.count() == 0: + activity_list.addItem("(No items in database)") + except Exception: + activity_list.addItem("(Unable to connect to Silo database)") - activity_list = QtWidgets.QListWidget() - layout.addWidget(activity_list) + return widget - try: - import silo_commands - - items = silo_commands._client.list_items() - if isinstance(items, list): - for item in items[:20]: - pn = item.get("part_number", "") - desc = item.get("description", "") - updated = item.get("updated_at", "") - if updated: - updated = updated[:10] - activity_list.addItem(f"{pn} - {desc} - {updated}") - if activity_list.count() == 0: - activity_list.addItem("(No items in database)") - except Exception: - activity_list.addItem("(Unable to connect to Silo database)") - - panel.setWidget(widget) - mw.addDockWidget(QtCore.Qt.RightDockWidgetArea, panel) - - # Give the activity panel most of the vertical space - auth_panel = mw.findChild(QtWidgets.QDockWidget, "SiloDatabaseAuth") - if auth_panel: - mw.resizeDocks([auth_panel, panel], [120, 500], QtCore.Qt.Vertical) + register_dock_panel("SiloDatabaseActivity", "Database Activity", _factory) except Exception as e: FreeCAD.Console.PrintLog(f"Create: Silo activity panel skipped: {e}\n")