You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/addons.md
+40-33Lines changed: 40 additions & 33 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -112,40 +112,44 @@ from src.programs.addons import AddonInterface # (1)!
112
112
ADDON_NAME="Your Displayed Name"
113
113
114
114
classAddon(AddonInterface): # (2)!
115
-
defsetup(self): # (3)!
115
+
defdefine_configuration(self): # (3)!
116
116
pass
117
117
118
-
defcleanup(self): # (4)!
118
+
defsetup(self): # (4)!
119
119
pass
120
120
121
-
defbefore_cocktail(self, data: dict): # (5)!
121
+
defcleanup(self): # (5)!
122
122
pass
123
123
124
-
defafter_cocktail(self, data: dict): # (6)!
124
+
defbefore_cocktail(self, data: dict): # (6)!
125
+
pass
126
+
127
+
defafter_cocktail(self, data: dict): # (7)!
125
128
pass
126
129
127
130
defcocktail_trigger(
128
131
self,
129
132
prepare: Callable[[Cocktail], tuple[bool, str]]
130
-
): # (7)!
133
+
): # (8)!
131
134
pass
132
135
133
136
defbuild_gui(
134
137
self,
135
138
container,
136
139
button_generator
137
-
) -> bool: # (8)!
140
+
) -> bool: # (9)!
138
141
returnFalse
139
142
```
140
143
141
-
1. Using the `AddonInterface` will give you intellisense for the existing functions available.
144
+
1. Using the `AddonInterface` will give you intellisense for the existing functions available.
142
145
2. Your class needs to have the name Addon and should inherit from the AddonInterface.
143
-
3. Initializes the addon, executed at program start.
144
-
4. Method for cleanup, executed a program end just before the program closes.
145
-
5. Executed right before the cocktail preparation. In case of a RuntimeError, the cocktail will not be prepared and the message will be shown to the user instead.
146
-
6. Executed right after the cocktail preparation, before other services are connected or DB is updated.
147
-
7. This function will be run in a thread on a continuous loop. You can use the `prepare` function to trigger a cocktail preparation. It will return a boolean if the cocktail was prepared successfully and a message string holding more information. There is currently no GUI indication that this cocktail preparation was triggered.
148
-
8. Will be used if the user navigates to the addon window and selects your addon. The container is a PyQt5 Layout widget you can (but not must) use to define custom GUI elements and connect them to functions. If you just want to have buttons executing functions, you can use the button generator function. Return False, if not implemented.
146
+
3. Define additional configuration values for your addon here, executed before setup.
147
+
4. Initializes the addon, executed at program start.
148
+
5. Method for cleanup, executed a program end just before the program closes.
149
+
6. Executed right before the cocktail preparation. In case of a RuntimeError, the cocktail will not be prepared and the message will be shown to the user instead.
150
+
7. Executed right after the cocktail preparation, before other services are connected or DB is updated.
151
+
8. This function will be run in a thread on a continuous loop. You can use the `prepare` function to trigger a cocktail preparation. It will return a boolean if the cocktail was prepared successfully and a message string holding more information. There is currently no GUI indication that this cocktail preparation was triggered.
152
+
9. Will be used if the user navigates to the addon window and selects your addon. The container is a PyQt5 Layout widget you can (but not must) use to define custom GUI elements and connect them to functions. If you just want to have buttons executing functions, you can use the button generator function. Return False, if not implemented.
149
153
150
154
Now that you know the skeleton, you can fill it with your program logic.
151
155
@@ -157,6 +161,7 @@ But this approach is not robust against code changes (new versions of addon), an
157
161
Therefore, the addon provider can use the CocktailBerry configuration.
158
162
To do so, the user needs to inject the config name, type and validation function into the config.
159
163
There is also the option to provided a description, as well as according translations.
164
+
It is important that you use the `define_configuration()` function for this, as it is executed before the setup of the addon and loading in local set config values.
160
165
You can find each direction in the subsections below.
161
166
162
167
#### Add Config Values
@@ -174,8 +179,11 @@ You can have a look at the other values as a reference.
174
179
```python
175
180
from src.config.config_manager importCONFIGas cfg # (1)!
0 commit comments