-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddon_base.py
More file actions
78 lines (59 loc) · 2.16 KB
/
addon_base.py
File metadata and controls
78 lines (59 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""
Addon Base Class
All Bifrost addons must subclass AddonBase and override the required
metadata attributes and create_panel() method.
"""
import logging
logger = logging.getLogger(__name__)
class AddonBase:
"""Base class for Bifrost addons.
Subclass this and set the class-level metadata attributes.
The addon's __init__.py must expose the subclass as ``addon_class``.
Example::
# addons/my_addon/__init__.py
from .addon import MyAddon
addon_class = MyAddon
# addons/my_addon/addon.py
from addon_base import AddonBase
class MyAddon(AddonBase):
name = "My Addon"
version = "1.0.0"
description = "Does something cool"
icon = "🔌"
def create_panel(self):
from PyQt5.QtWidgets import QWidget, QLabel, QVBoxLayout
panel = QWidget()
layout = QVBoxLayout(panel)
layout.addWidget(QLabel("Hello from My Addon"))
return panel
"""
# -- Required metadata (override in subclass) --
name: str = "Unnamed Addon"
version: str = "0.0.0"
description: str = ""
icon: str = "" # Emoji shown on the mode tab button
def __init__(self, api):
"""Initialise addon with a BifrostAPI instance.
Args:
api: BifrostAPI providing access to robot state, commands, and events.
"""
self.api = api
def create_panel(self):
"""Return a QWidget to display in this addon's mode tab.
Called once during addon loading. The returned widget is added
to the mode stack and shown when the user clicks the tab.
Returns:
QWidget: The panel widget for this addon.
"""
raise NotImplementedError(
f"Addon '{self.name}' must implement create_panel()"
)
def on_activate(self):
"""Called when the user switches to this addon's tab."""
pass
def on_deactivate(self):
"""Called when the user switches away from this addon's tab."""
pass
def on_unload(self):
"""Called on application shutdown. Release resources here."""
pass