| 1 | """ |
| 2 | SaveUtils FreeCAD Addon - InitGui.py |
| 3 | """ |
| 4 | |
| 5 | import FreeCAD |
| 6 | if FreeCAD.GuiUp: |
| 7 | import FreeCADGui |
| 8 | |
| 9 | FreeCAD.Console.PrintLog("=== SaveUtils: InitGui.py loading ===\n") |
| 10 | |
| 11 | |
| 12 | class SaveUtilsWorkbench(FreeCADGui.Workbench): |
| 13 | MenuText = "SaveUtils" |
| 14 | ToolTip = "Save utility commands" |
| 15 | |
| 16 | def Initialize(self): |
| 17 | pass |
| 18 | |
| 19 | def Activated(self): |
| 20 | pass |
| 21 | |
| 22 | def Deactivated(self): |
| 23 | pass |
| 24 | |
| 25 | |
| 26 | FreeCADGui.addWorkbench(SaveUtilsWorkbench()) |
| 27 | |
| 28 | |
| 29 | def _on_workbench_activated(name): |
| 30 | # NoneWorkbench fires before the UI is ready — skip it |
| 31 | if name == "NoneWorkbench": |
| 32 | return |
| 33 | |
| 34 | # Disconnect immediately so this only runs once |
| 35 | try: |
| 36 | FreeCADGui.getMainWindow().workbenchActivated.disconnect( |
| 37 | _on_workbench_activated |
| 38 | ) |
| 39 | except Exception: |
| 40 | pass |
| 41 | |
| 42 | try: |
| 43 | import SaveUtils |
| 44 | |
| 45 | SaveUtils.install() |
| 46 | except Exception as e: |
| 47 | FreeCAD.Console.PrintError(f"=== SaveUtils install error: {e} ===\n") |
| 48 | |
| 49 | |
| 50 | FreeCADGui.getMainWindow().workbenchActivated.connect(_on_workbench_activated) |
| 51 |