docs: add example addon template (#395)
All checks were successful
Build and Test / build (pull_request) Successful in 30m3s
All checks were successful
Build and Test / build (pull_request) Successful in 30m3s
- Create docs/examples/example-addon/ with a complete, copy-paste-ready addon skeleton demonstrating command registration, context injection, dock panels, lifecycle hooks, and event bus subscription - Add Examples section to docs/src/SUMMARY.md - Add quick-start cross-reference in writing-an-addon.md
This commit is contained in:
1
docs/examples/example-addon/example_addon/__init__.py
Normal file
1
docs/examples/example-addon/example_addon/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Example addon for Kindred Create."""
|
||||
29
docs/examples/example-addon/example_addon/commands.py
Normal file
29
docs/examples/example-addon/example_addon/commands.py
Normal file
@@ -0,0 +1,29 @@
|
||||
"""Example addon commands.
|
||||
|
||||
Each command is registered via ``kindred_sdk.register_command()`` which
|
||||
wraps FreeCAD's ``Gui.addCommand()`` with input validation.
|
||||
"""
|
||||
|
||||
from kindred_sdk import register_command
|
||||
|
||||
|
||||
def register_commands():
|
||||
"""Register all commands for this addon."""
|
||||
register_command(
|
||||
name="ExampleAddon_Hello",
|
||||
activated=_on_hello,
|
||||
resources={
|
||||
"MenuText": "Hello World",
|
||||
"ToolTip": "Show a greeting in the console",
|
||||
# "Pixmap": "path/to/icon.svg", # optional icon
|
||||
# "Accel": "Ctrl+Shift+H", # optional shortcut
|
||||
},
|
||||
is_active=lambda: True,
|
||||
)
|
||||
|
||||
|
||||
def _on_hello():
|
||||
"""Command handler — prints a greeting to the FreeCAD console."""
|
||||
import FreeCAD
|
||||
|
||||
FreeCAD.Console.PrintMessage("Hello from example-addon!\n")
|
||||
21
docs/examples/example-addon/example_addon/panel.py
Normal file
21
docs/examples/example-addon/example_addon/panel.py
Normal file
@@ -0,0 +1,21 @@
|
||||
"""Example addon dock panel.
|
||||
|
||||
The factory function is passed to ``kindred_sdk.register_dock_panel()``
|
||||
and called once after the configured delay to create the widget.
|
||||
"""
|
||||
|
||||
|
||||
def create_panel():
|
||||
"""Create the example dock panel widget.
|
||||
|
||||
Must return a QWidget. The widget is embedded in a QDockWidget and
|
||||
managed by FreeCAD's DockWindowManager.
|
||||
"""
|
||||
from PySide6 import QtWidgets
|
||||
|
||||
widget = QtWidgets.QWidget()
|
||||
layout = QtWidgets.QVBoxLayout(widget)
|
||||
layout.addWidget(QtWidgets.QLabel("Example Addon Panel"))
|
||||
layout.addWidget(QtWidgets.QLabel("Replace this with your content."))
|
||||
layout.addStretch()
|
||||
return widget
|
||||
Reference in New Issue
Block a user