fix: register commands and manipulator at module scope (#52)
Move command imports and PartDesign manipulator installation from ZToolsWorkbench.Initialize() to module scope. This ensures commands are registered and the manipulator is available before any workbench activates, fixing the case where PartDesign activates before ZTools and ztools buttons never appear.
This commit is contained in:
@@ -66,13 +66,8 @@ class ZToolsWorkbench(Gui.Workbench):
|
|||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
from ztools.commands import (
|
# Command imports moved to module scope (after Gui.addWorkbench) so they
|
||||||
assembly_pattern_commands,
|
# are available before Initialize() runs. See end of file.
|
||||||
datum_commands,
|
|
||||||
pattern_commands,
|
|
||||||
pocket_commands,
|
|
||||||
spreadsheet_commands,
|
|
||||||
)
|
|
||||||
|
|
||||||
# =====================================================================
|
# =====================================================================
|
||||||
# PartDesign Structure Tools
|
# PartDesign Structure Tools
|
||||||
@@ -306,12 +301,6 @@ class ZToolsWorkbench(Gui.Workbench):
|
|||||||
+ self.ztools_spreadsheet_tools,
|
+ self.ztools_spreadsheet_tools,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Register the PartDesign manipulator now that commands exist.
|
|
||||||
# Guard so it only registers once even if Initialize is called again.
|
|
||||||
if not getattr(ZToolsWorkbench, "_manipulator_installed", False):
|
|
||||||
ZToolsWorkbench._manipulator_installed = True
|
|
||||||
Gui.addWorkbenchManipulator(_ZToolsPartDesignManipulator())
|
|
||||||
|
|
||||||
App.Console.PrintMessage("ztools workbench initialized\n")
|
App.Console.PrintMessage("ztools workbench initialized\n")
|
||||||
|
|
||||||
def Activated(self):
|
def Activated(self):
|
||||||
@@ -337,11 +326,24 @@ class ZToolsWorkbench(Gui.Workbench):
|
|||||||
Gui.addWorkbench(ZToolsWorkbench())
|
Gui.addWorkbench(ZToolsWorkbench())
|
||||||
|
|
||||||
|
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Eager command registration
|
||||||
|
# ---------------------------------------------------------------------------
|
||||||
|
# Import command modules at module scope so Gui.addCommand() calls run before
|
||||||
|
# any workbench activates. This ensures the PartDesign manipulator can
|
||||||
|
# reference them regardless of workbench activation order (#52).
|
||||||
|
|
||||||
|
from ztools.commands import (
|
||||||
|
assembly_pattern_commands,
|
||||||
|
datum_commands,
|
||||||
|
pattern_commands,
|
||||||
|
pocket_commands,
|
||||||
|
spreadsheet_commands,
|
||||||
|
)
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# WorkbenchManipulator: inject ZTools commands into PartDesign workbench
|
# WorkbenchManipulator: inject ZTools commands into PartDesign workbench
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
# Registered in ZToolsWorkbench.Initialize() after commands are imported,
|
|
||||||
# so the commands exist before the manipulator references them.
|
|
||||||
|
|
||||||
|
|
||||||
class _ZToolsPartDesignManipulator:
|
class _ZToolsPartDesignManipulator:
|
||||||
@@ -384,3 +386,6 @@ class _ZToolsPartDesignManipulator:
|
|||||||
"after": "",
|
"after": "",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
Gui.addWorkbenchManipulator(_ZToolsPartDesignManipulator())
|
||||||
|
|||||||
Reference in New Issue
Block a user