c2f4dt.plugins.example_display_button.plugin
c2f4dt.plugins.example_display_button.plugin
¶
Example plugin: adds a panel with a button inside the scrollDISPLAY (DisplayPanel).
HOW INTEGRATION WITH YOUR PluginManager WORKS¶
-
Your PluginManager: 1) Scans the "plugins/" folder looking for subfolders. 2) For each folder, reads "plugin.yaml" (if present) and determines: - name, version, order, requires, entry_point = "module:attribute". 3) Imports the package "plugins.
" (thanks to the plugins folder in the file system). 4) Resolves the entry_point: imports the submodule (here "plugin") and retrieves the attribute (here "register"). 5) Calls the factory "register(window)" which must return the plugin instance. -
This file provides:
- a
DisplayButtonPlugin
class (QObject) that receives the MainWindow and modifies the UI. - a
register(window)
function used as the entry-point by the manager.
- a
WHERE THE BUTTON ENDS UP¶
- Your UI has: MainWindow.scrollDISPLAY -> QScrollArea └─ widget() -> DisplayPanel (custom QWidget with an internal layout)
- We DO NOT touch the QScrollArea directly; we go to its content (DisplayPanel)
and add our
QGroupBox
with a button.
SIMPLE BEST PRACTICES FOR YOUR PLUGINS¶
- Do not block the UI thread: if you perform long tasks, use QThread/worker (as you normally would).
- Avoid assuming overly specific layout details; use
layout().addWidget(...)
at the end. - Provide an
actions()
(orget_actions()
) method to make commands appear in the Plugins menu. - If you add elements to the scene or panel, consider a
teardown()
method to clean up (optional).
DisplayButtonPlugin
¶
Bases: QObject
Minimal plugin that
1) Inserts a panel into the DisplayPanel with a "Hello from Plugin" button. 2) Exposes an action in the &Plugins menu ("Say Hello") that displays a message.
The constructor receives the MainWindow (window) from the PluginManager.
Source code in src/c2f4dt/plugins/example_display_button/plugin.py
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
|
window = window
instance-attribute
¶
actions()
¶
Returns a list of structured actions that the MainWindow attaches to the Plugins menu. See MainWindow._rebuild_plugins_menu/_invoke_plugin_action.
Source code in src/c2f4dt/plugins/example_display_button/plugin.py
focus_button()
¶
Brings focus to the button created by the plugin (if it exists).
Source code in src/c2f4dt/plugins/example_display_button/plugin.py
run(*_, **__)
¶
Default entry-point if you launch the plugin from the combo without actions: focuses the button so it's immediately visible where it was added.
say_hello()
¶
Menu action: identical to the button action, but callable from the Plugins menu.
teardown()
¶
Removes the box from the DisplayPanel (best-effort). You can call this manually if you foresee plugin unload/refresh.